1   /**
2    * Copyright (c) 2000-2007 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.service.persistence;
24  
25  import com.liferay.portal.NoSuchSubscriptionException;
26  import com.liferay.portal.SystemException;
27  import com.liferay.portal.kernel.dao.DynamicQuery;
28  import com.liferay.portal.kernel.dao.DynamicQueryInitializer;
29  import com.liferay.portal.kernel.util.OrderByComparator;
30  import com.liferay.portal.kernel.util.StringMaker;
31  import com.liferay.portal.kernel.util.StringPool;
32  import com.liferay.portal.model.Subscription;
33  import com.liferay.portal.model.impl.SubscriptionImpl;
34  import com.liferay.portal.service.persistence.BasePersistence;
35  import com.liferay.portal.spring.hibernate.FinderCache;
36  import com.liferay.portal.spring.hibernate.HibernateUtil;
37  
38  import com.liferay.util.dao.hibernate.QueryUtil;
39  
40  import org.apache.commons.logging.Log;
41  import org.apache.commons.logging.LogFactory;
42  
43  import org.hibernate.Query;
44  import org.hibernate.Session;
45  
46  import java.util.Collections;
47  import java.util.Iterator;
48  import java.util.List;
49  
50  /**
51   * <a href="SubscriptionPersistenceImpl.java.html"><b><i>View Source</i></b></a>
52   *
53   * @author Brian Wing Shun Chan
54   *
55   */
56  public class SubscriptionPersistenceImpl extends BasePersistence
57      implements SubscriptionPersistence {
58      public Subscription create(long subscriptionId) {
59          Subscription subscription = new SubscriptionImpl();
60          subscription.setNew(true);
61          subscription.setPrimaryKey(subscriptionId);
62  
63          return subscription;
64      }
65  
66      public Subscription remove(long subscriptionId)
67          throws NoSuchSubscriptionException, SystemException {
68          Session session = null;
69  
70          try {
71              session = openSession();
72  
73              Subscription subscription = (Subscription)session.get(SubscriptionImpl.class,
74                      new Long(subscriptionId));
75  
76              if (subscription == null) {
77                  if (_log.isWarnEnabled()) {
78                      _log.warn("No Subscription exists with the primary key " +
79                          subscriptionId);
80                  }
81  
82                  throw new NoSuchSubscriptionException(
83                      "No Subscription exists with the primary key " +
84                      subscriptionId);
85              }
86  
87              return remove(subscription);
88          }
89          catch (NoSuchSubscriptionException nsee) {
90              throw nsee;
91          }
92          catch (Exception e) {
93              throw HibernateUtil.processException(e);
94          }
95          finally {
96              closeSession(session);
97          }
98      }
99  
100     public Subscription remove(Subscription subscription)
101         throws SystemException {
102         Session session = null;
103 
104         try {
105             session = openSession();
106             session.delete(subscription);
107             session.flush();
108 
109             return subscription;
110         }
111         catch (Exception e) {
112             throw HibernateUtil.processException(e);
113         }
114         finally {
115             closeSession(session);
116             FinderCache.clearCache(Subscription.class.getName());
117         }
118     }
119 
120     public Subscription update(
121         com.liferay.portal.model.Subscription subscription)
122         throws SystemException {
123         return update(subscription, false);
124     }
125 
126     public Subscription update(
127         com.liferay.portal.model.Subscription subscription, boolean merge)
128         throws SystemException {
129         Session session = null;
130 
131         try {
132             session = openSession();
133 
134             if (merge) {
135                 session.merge(subscription);
136             }
137             else {
138                 if (subscription.isNew()) {
139                     session.save(subscription);
140                 }
141             }
142 
143             session.flush();
144             subscription.setNew(false);
145 
146             return subscription;
147         }
148         catch (Exception e) {
149             throw HibernateUtil.processException(e);
150         }
151         finally {
152             closeSession(session);
153             FinderCache.clearCache(Subscription.class.getName());
154         }
155     }
156 
157     public Subscription findByPrimaryKey(long subscriptionId)
158         throws NoSuchSubscriptionException, SystemException {
159         Subscription subscription = fetchByPrimaryKey(subscriptionId);
160 
161         if (subscription == null) {
162             if (_log.isWarnEnabled()) {
163                 _log.warn("No Subscription exists with the primary key " +
164                     subscriptionId);
165             }
166 
167             throw new NoSuchSubscriptionException(
168                 "No Subscription exists with the primary key " +
169                 subscriptionId);
170         }
171 
172         return subscription;
173     }
174 
175     public Subscription fetchByPrimaryKey(long subscriptionId)
176         throws SystemException {
177         Session session = null;
178 
179         try {
180             session = openSession();
181 
182             return (Subscription)session.get(SubscriptionImpl.class,
183                 new Long(subscriptionId));
184         }
185         catch (Exception e) {
186             throw HibernateUtil.processException(e);
187         }
188         finally {
189             closeSession(session);
190         }
191     }
192 
193     public List findByUserId(long userId) throws SystemException {
194         String finderClassName = Subscription.class.getName();
195         String finderMethodName = "findByUserId";
196         String[] finderParams = new String[] { Long.class.getName() };
197         Object[] finderArgs = new Object[] { new Long(userId) };
198         Object result = FinderCache.getResult(finderClassName,
199                 finderMethodName, finderParams, finderArgs, getSessionFactory());
200 
201         if (result == null) {
202             Session session = null;
203 
204             try {
205                 session = openSession();
206 
207                 StringMaker query = new StringMaker();
208                 query.append(
209                     "FROM com.liferay.portal.model.Subscription WHERE ");
210                 query.append("userId = ?");
211                 query.append(" ");
212 
213                 Query q = session.createQuery(query.toString());
214                 int queryPos = 0;
215                 q.setLong(queryPos++, userId);
216 
217                 List list = q.list();
218                 FinderCache.putResult(finderClassName, finderMethodName,
219                     finderParams, finderArgs, list);
220 
221                 return list;
222             }
223             catch (Exception e) {
224                 throw HibernateUtil.processException(e);
225             }
226             finally {
227                 closeSession(session);
228             }
229         }
230         else {
231             return (List)result;
232         }
233     }
234 
235     public List findByUserId(long userId, int begin, int end)
236         throws SystemException {
237         return findByUserId(userId, begin, end, null);
238     }
239 
240     public List findByUserId(long userId, int begin, int end,
241         OrderByComparator obc) throws SystemException {
242         String finderClassName = Subscription.class.getName();
243         String finderMethodName = "findByUserId";
244         String[] finderParams = new String[] {
245                 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
246                 "com.liferay.portal.kernel.util.OrderByComparator"
247             };
248         Object[] finderArgs = new Object[] {
249                 new Long(userId), String.valueOf(begin), String.valueOf(end),
250                 String.valueOf(obc)
251             };
252         Object result = FinderCache.getResult(finderClassName,
253                 finderMethodName, finderParams, finderArgs, getSessionFactory());
254 
255         if (result == null) {
256             Session session = null;
257 
258             try {
259                 session = openSession();
260 
261                 StringMaker query = new StringMaker();
262                 query.append(
263                     "FROM com.liferay.portal.model.Subscription WHERE ");
264                 query.append("userId = ?");
265                 query.append(" ");
266 
267                 if (obc != null) {
268                     query.append("ORDER BY ");
269                     query.append(obc.getOrderBy());
270                 }
271 
272                 Query q = session.createQuery(query.toString());
273                 int queryPos = 0;
274                 q.setLong(queryPos++, userId);
275 
276                 List list = QueryUtil.list(q, getDialect(), begin, end);
277                 FinderCache.putResult(finderClassName, finderMethodName,
278                     finderParams, finderArgs, list);
279 
280                 return list;
281             }
282             catch (Exception e) {
283                 throw HibernateUtil.processException(e);
284             }
285             finally {
286                 closeSession(session);
287             }
288         }
289         else {
290             return (List)result;
291         }
292     }
293 
294     public Subscription findByUserId_First(long userId, OrderByComparator obc)
295         throws NoSuchSubscriptionException, SystemException {
296         List list = findByUserId(userId, 0, 1, obc);
297 
298         if (list.size() == 0) {
299             StringMaker msg = new StringMaker();
300             msg.append("No Subscription exists with the key ");
301             msg.append(StringPool.OPEN_CURLY_BRACE);
302             msg.append("userId=");
303             msg.append(userId);
304             msg.append(StringPool.CLOSE_CURLY_BRACE);
305             throw new NoSuchSubscriptionException(msg.toString());
306         }
307         else {
308             return (Subscription)list.get(0);
309         }
310     }
311 
312     public Subscription findByUserId_Last(long userId, OrderByComparator obc)
313         throws NoSuchSubscriptionException, SystemException {
314         int count = countByUserId(userId);
315         List list = findByUserId(userId, count - 1, count, obc);
316 
317         if (list.size() == 0) {
318             StringMaker msg = new StringMaker();
319             msg.append("No Subscription exists with the key ");
320             msg.append(StringPool.OPEN_CURLY_BRACE);
321             msg.append("userId=");
322             msg.append(userId);
323             msg.append(StringPool.CLOSE_CURLY_BRACE);
324             throw new NoSuchSubscriptionException(msg.toString());
325         }
326         else {
327             return (Subscription)list.get(0);
328         }
329     }
330 
331     public Subscription[] findByUserId_PrevAndNext(long subscriptionId,
332         long userId, OrderByComparator obc)
333         throws NoSuchSubscriptionException, SystemException {
334         Subscription subscription = findByPrimaryKey(subscriptionId);
335         int count = countByUserId(userId);
336         Session session = null;
337 
338         try {
339             session = openSession();
340 
341             StringMaker query = new StringMaker();
342             query.append("FROM com.liferay.portal.model.Subscription WHERE ");
343             query.append("userId = ?");
344             query.append(" ");
345 
346             if (obc != null) {
347                 query.append("ORDER BY ");
348                 query.append(obc.getOrderBy());
349             }
350 
351             Query q = session.createQuery(query.toString());
352             int queryPos = 0;
353             q.setLong(queryPos++, userId);
354 
355             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
356                     subscription);
357             Subscription[] array = new SubscriptionImpl[3];
358             array[0] = (Subscription)objArray[0];
359             array[1] = (Subscription)objArray[1];
360             array[2] = (Subscription)objArray[2];
361 
362             return array;
363         }
364         catch (Exception e) {
365             throw HibernateUtil.processException(e);
366         }
367         finally {
368             closeSession(session);
369         }
370     }
371 
372     public List findByC_C_C(long companyId, long classNameId, long classPK)
373         throws SystemException {
374         String finderClassName = Subscription.class.getName();
375         String finderMethodName = "findByC_C_C";
376         String[] finderParams = new String[] {
377                 Long.class.getName(), Long.class.getName(), Long.class.getName()
378             };
379         Object[] finderArgs = new Object[] {
380                 new Long(companyId), new Long(classNameId), new Long(classPK)
381             };
382         Object result = FinderCache.getResult(finderClassName,
383                 finderMethodName, finderParams, finderArgs, getSessionFactory());
384 
385         if (result == null) {
386             Session session = null;
387 
388             try {
389                 session = openSession();
390 
391                 StringMaker query = new StringMaker();
392                 query.append(
393                     "FROM com.liferay.portal.model.Subscription WHERE ");
394                 query.append("companyId = ?");
395                 query.append(" AND ");
396                 query.append("classNameId = ?");
397                 query.append(" AND ");
398                 query.append("classPK = ?");
399                 query.append(" ");
400 
401                 Query q = session.createQuery(query.toString());
402                 int queryPos = 0;
403                 q.setLong(queryPos++, companyId);
404                 q.setLong(queryPos++, classNameId);
405                 q.setLong(queryPos++, classPK);
406 
407                 List list = q.list();
408                 FinderCache.putResult(finderClassName, finderMethodName,
409                     finderParams, finderArgs, list);
410 
411                 return list;
412             }
413             catch (Exception e) {
414                 throw HibernateUtil.processException(e);
415             }
416             finally {
417                 closeSession(session);
418             }
419         }
420         else {
421             return (List)result;
422         }
423     }
424 
425     public List findByC_C_C(long companyId, long classNameId, long classPK,
426         int begin, int end) throws SystemException {
427         return findByC_C_C(companyId, classNameId, classPK, begin, end, null);
428     }
429 
430     public List findByC_C_C(long companyId, long classNameId, long classPK,
431         int begin, int end, OrderByComparator obc) throws SystemException {
432         String finderClassName = Subscription.class.getName();
433         String finderMethodName = "findByC_C_C";
434         String[] finderParams = new String[] {
435                 Long.class.getName(), Long.class.getName(), Long.class.getName(),
436                 "java.lang.Integer", "java.lang.Integer",
437                 "com.liferay.portal.kernel.util.OrderByComparator"
438             };
439         Object[] finderArgs = new Object[] {
440                 new Long(companyId), new Long(classNameId), new Long(classPK),
441                 String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
442             };
443         Object result = FinderCache.getResult(finderClassName,
444                 finderMethodName, finderParams, finderArgs, getSessionFactory());
445 
446         if (result == null) {
447             Session session = null;
448 
449             try {
450                 session = openSession();
451 
452                 StringMaker query = new StringMaker();
453                 query.append(
454                     "FROM com.liferay.portal.model.Subscription WHERE ");
455                 query.append("companyId = ?");
456                 query.append(" AND ");
457                 query.append("classNameId = ?");
458                 query.append(" AND ");
459                 query.append("classPK = ?");
460                 query.append(" ");
461 
462                 if (obc != null) {
463                     query.append("ORDER BY ");
464                     query.append(obc.getOrderBy());
465                 }
466 
467                 Query q = session.createQuery(query.toString());
468                 int queryPos = 0;
469                 q.setLong(queryPos++, companyId);
470                 q.setLong(queryPos++, classNameId);
471                 q.setLong(queryPos++, classPK);
472 
473                 List list = QueryUtil.list(q, getDialect(), begin, end);
474                 FinderCache.putResult(finderClassName, finderMethodName,
475                     finderParams, finderArgs, list);
476 
477                 return list;
478             }
479             catch (Exception e) {
480                 throw HibernateUtil.processException(e);
481             }
482             finally {
483                 closeSession(session);
484             }
485         }
486         else {
487             return (List)result;
488         }
489     }
490 
491     public Subscription findByC_C_C_First(long companyId, long classNameId,
492         long classPK, OrderByComparator obc)
493         throws NoSuchSubscriptionException, SystemException {
494         List list = findByC_C_C(companyId, classNameId, classPK, 0, 1, obc);
495 
496         if (list.size() == 0) {
497             StringMaker msg = new StringMaker();
498             msg.append("No Subscription exists with the key ");
499             msg.append(StringPool.OPEN_CURLY_BRACE);
500             msg.append("companyId=");
501             msg.append(companyId);
502             msg.append(", ");
503             msg.append("classNameId=");
504             msg.append(classNameId);
505             msg.append(", ");
506             msg.append("classPK=");
507             msg.append(classPK);
508             msg.append(StringPool.CLOSE_CURLY_BRACE);
509             throw new NoSuchSubscriptionException(msg.toString());
510         }
511         else {
512             return (Subscription)list.get(0);
513         }
514     }
515 
516     public Subscription findByC_C_C_Last(long companyId, long classNameId,
517         long classPK, OrderByComparator obc)
518         throws NoSuchSubscriptionException, SystemException {
519         int count = countByC_C_C(companyId, classNameId, classPK);
520         List list = findByC_C_C(companyId, classNameId, classPK, count - 1,
521                 count, obc);
522 
523         if (list.size() == 0) {
524             StringMaker msg = new StringMaker();
525             msg.append("No Subscription exists with the key ");
526             msg.append(StringPool.OPEN_CURLY_BRACE);
527             msg.append("companyId=");
528             msg.append(companyId);
529             msg.append(", ");
530             msg.append("classNameId=");
531             msg.append(classNameId);
532             msg.append(", ");
533             msg.append("classPK=");
534             msg.append(classPK);
535             msg.append(StringPool.CLOSE_CURLY_BRACE);
536             throw new NoSuchSubscriptionException(msg.toString());
537         }
538         else {
539             return (Subscription)list.get(0);
540         }
541     }
542 
543     public Subscription[] findByC_C_C_PrevAndNext(long subscriptionId,
544         long companyId, long classNameId, long classPK, OrderByComparator obc)
545         throws NoSuchSubscriptionException, SystemException {
546         Subscription subscription = findByPrimaryKey(subscriptionId);
547         int count = countByC_C_C(companyId, classNameId, classPK);
548         Session session = null;
549 
550         try {
551             session = openSession();
552 
553             StringMaker query = new StringMaker();
554             query.append("FROM com.liferay.portal.model.Subscription WHERE ");
555             query.append("companyId = ?");
556             query.append(" AND ");
557             query.append("classNameId = ?");
558             query.append(" AND ");
559             query.append("classPK = ?");
560             query.append(" ");
561 
562             if (obc != null) {
563                 query.append("ORDER BY ");
564                 query.append(obc.getOrderBy());
565             }
566 
567             Query q = session.createQuery(query.toString());
568             int queryPos = 0;
569             q.setLong(queryPos++, companyId);
570             q.setLong(queryPos++, classNameId);
571             q.setLong(queryPos++, classPK);
572 
573             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
574                     subscription);
575             Subscription[] array = new SubscriptionImpl[3];
576             array[0] = (Subscription)objArray[0];
577             array[1] = (Subscription)objArray[1];
578             array[2] = (Subscription)objArray[2];
579 
580             return array;
581         }
582         catch (Exception e) {
583             throw HibernateUtil.processException(e);
584         }
585         finally {
586             closeSession(session);
587         }
588     }
589 
590     public Subscription findByC_U_C_C(long companyId, long userId,
591         long classNameId, long classPK)
592         throws NoSuchSubscriptionException, SystemException {
593         Subscription subscription = fetchByC_U_C_C(companyId, userId,
594                 classNameId, classPK);
595 
596         if (subscription == null) {
597             StringMaker msg = new StringMaker();
598             msg.append("No Subscription exists with the key ");
599             msg.append(StringPool.OPEN_CURLY_BRACE);
600             msg.append("companyId=");
601             msg.append(companyId);
602             msg.append(", ");
603             msg.append("userId=");
604             msg.append(userId);
605             msg.append(", ");
606             msg.append("classNameId=");
607             msg.append(classNameId);
608             msg.append(", ");
609             msg.append("classPK=");
610             msg.append(classPK);
611             msg.append(StringPool.CLOSE_CURLY_BRACE);
612 
613             if (_log.isWarnEnabled()) {
614                 _log.warn(msg.toString());
615             }
616 
617             throw new NoSuchSubscriptionException(msg.toString());
618         }
619 
620         return subscription;
621     }
622 
623     public Subscription fetchByC_U_C_C(long companyId, long userId,
624         long classNameId, long classPK) throws SystemException {
625         String finderClassName = Subscription.class.getName();
626         String finderMethodName = "fetchByC_U_C_C";
627         String[] finderParams = new String[] {
628                 Long.class.getName(), Long.class.getName(), Long.class.getName(),
629                 Long.class.getName()
630             };
631         Object[] finderArgs = new Object[] {
632                 new Long(companyId), new Long(userId), new Long(classNameId),
633                 new Long(classPK)
634             };
635         Object result = FinderCache.getResult(finderClassName,
636                 finderMethodName, finderParams, finderArgs, getSessionFactory());
637 
638         if (result == null) {
639             Session session = null;
640 
641             try {
642                 session = openSession();
643 
644                 StringMaker query = new StringMaker();
645                 query.append(
646                     "FROM com.liferay.portal.model.Subscription WHERE ");
647                 query.append("companyId = ?");
648                 query.append(" AND ");
649                 query.append("userId = ?");
650                 query.append(" AND ");
651                 query.append("classNameId = ?");
652                 query.append(" AND ");
653                 query.append("classPK = ?");
654                 query.append(" ");
655 
656                 Query q = session.createQuery(query.toString());
657                 int queryPos = 0;
658                 q.setLong(queryPos++, companyId);
659                 q.setLong(queryPos++, userId);
660                 q.setLong(queryPos++, classNameId);
661                 q.setLong(queryPos++, classPK);
662 
663                 List list = q.list();
664                 FinderCache.putResult(finderClassName, finderMethodName,
665                     finderParams, finderArgs, list);
666 
667                 if (list.size() == 0) {
668                     return null;
669                 }
670                 else {
671                     return (Subscription)list.get(0);
672                 }
673             }
674             catch (Exception e) {
675                 throw HibernateUtil.processException(e);
676             }
677             finally {
678                 closeSession(session);
679             }
680         }
681         else {
682             List list = (List)result;
683 
684             if (list.size() == 0) {
685                 return null;
686             }
687             else {
688                 return (Subscription)list.get(0);
689             }
690         }
691     }
692 
693     public List findWithDynamicQuery(DynamicQueryInitializer queryInitializer)
694         throws SystemException {
695         Session session = null;
696 
697         try {
698             session = openSession();
699 
700             DynamicQuery query = queryInitializer.initialize(session);
701 
702             return query.list();
703         }
704         catch (Exception e) {
705             throw HibernateUtil.processException(e);
706         }
707         finally {
708             closeSession(session);
709         }
710     }
711 
712     public List findWithDynamicQuery(DynamicQueryInitializer queryInitializer,
713         int begin, int end) throws SystemException {
714         Session session = null;
715 
716         try {
717             session = openSession();
718 
719             DynamicQuery query = queryInitializer.initialize(session);
720             query.setLimit(begin, end);
721 
722             return query.list();
723         }
724         catch (Exception e) {
725             throw HibernateUtil.processException(e);
726         }
727         finally {
728             closeSession(session);
729         }
730     }
731 
732     public List findAll() throws SystemException {
733         return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
734     }
735 
736     public List findAll(int begin, int end) throws SystemException {
737         return findAll(begin, end, null);
738     }
739 
740     public List findAll(int begin, int end, OrderByComparator obc)
741         throws SystemException {
742         String finderClassName = Subscription.class.getName();
743         String finderMethodName = "findAll";
744         String[] finderParams = new String[] {
745                 "java.lang.Integer", "java.lang.Integer",
746                 "com.liferay.portal.kernel.util.OrderByComparator"
747             };
748         Object[] finderArgs = new Object[] {
749                 String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
750             };
751         Object result = FinderCache.getResult(finderClassName,
752                 finderMethodName, finderParams, finderArgs, getSessionFactory());
753 
754         if (result == null) {
755             Session session = null;
756 
757             try {
758                 session = openSession();
759 
760                 StringMaker query = new StringMaker();
761                 query.append("FROM com.liferay.portal.model.Subscription ");
762 
763                 if (obc != null) {
764                     query.append("ORDER BY ");
765                     query.append(obc.getOrderBy());
766                 }
767 
768                 Query q = session.createQuery(query.toString());
769                 List list = QueryUtil.list(q, getDialect(), begin, end);
770 
771                 if (obc == null) {
772                     Collections.sort(list);
773                 }
774 
775                 FinderCache.putResult(finderClassName, finderMethodName,
776                     finderParams, finderArgs, list);
777 
778                 return list;
779             }
780             catch (Exception e) {
781                 throw HibernateUtil.processException(e);
782             }
783             finally {
784                 closeSession(session);
785             }
786         }
787         else {
788             return (List)result;
789         }
790     }
791 
792     public void removeByUserId(long userId) throws SystemException {
793         Iterator itr = findByUserId(userId).iterator();
794 
795         while (itr.hasNext()) {
796             Subscription subscription = (Subscription)itr.next();
797             remove(subscription);
798         }
799     }
800 
801     public void removeByC_C_C(long companyId, long classNameId, long classPK)
802         throws SystemException {
803         Iterator itr = findByC_C_C(companyId, classNameId, classPK).iterator();
804 
805         while (itr.hasNext()) {
806             Subscription subscription = (Subscription)itr.next();
807             remove(subscription);
808         }
809     }
810 
811     public void removeByC_U_C_C(long companyId, long userId, long classNameId,
812         long classPK) throws NoSuchSubscriptionException, SystemException {
813         Subscription subscription = findByC_U_C_C(companyId, userId,
814                 classNameId, classPK);
815         remove(subscription);
816     }
817 
818     public void removeAll() throws SystemException {
819         Iterator itr = findAll().iterator();
820 
821         while (itr.hasNext()) {
822             remove((Subscription)itr.next());
823         }
824     }
825 
826     public int countByUserId(long userId) throws SystemException {
827         String finderClassName = Subscription.class.getName();
828         String finderMethodName = "countByUserId";
829         String[] finderParams = new String[] { Long.class.getName() };
830         Object[] finderArgs = new Object[] { new Long(userId) };
831         Object result = FinderCache.getResult(finderClassName,
832                 finderMethodName, finderParams, finderArgs, getSessionFactory());
833 
834         if (result == null) {
835             Session session = null;
836 
837             try {
838                 session = openSession();
839 
840                 StringMaker query = new StringMaker();
841                 query.append("SELECT COUNT(*) ");
842                 query.append(
843                     "FROM com.liferay.portal.model.Subscription WHERE ");
844                 query.append("userId = ?");
845                 query.append(" ");
846 
847                 Query q = session.createQuery(query.toString());
848                 int queryPos = 0;
849                 q.setLong(queryPos++, userId);
850 
851                 Long count = null;
852                 Iterator itr = q.list().iterator();
853 
854                 if (itr.hasNext()) {
855                     count = (Long)itr.next();
856                 }
857 
858                 if (count == null) {
859                     count = new Long(0);
860                 }
861 
862                 FinderCache.putResult(finderClassName, finderMethodName,
863                     finderParams, finderArgs, count);
864 
865                 return count.intValue();
866             }
867             catch (Exception e) {
868                 throw HibernateUtil.processException(e);
869             }
870             finally {
871                 closeSession(session);
872             }
873         }
874         else {
875             return ((Long)result).intValue();
876         }
877     }
878 
879     public int countByC_C_C(long companyId, long classNameId, long classPK)
880         throws SystemException {
881         String finderClassName = Subscription.class.getName();
882         String finderMethodName = "countByC_C_C";
883         String[] finderParams = new String[] {
884                 Long.class.getName(), Long.class.getName(), Long.class.getName()
885             };
886         Object[] finderArgs = new Object[] {
887                 new Long(companyId), new Long(classNameId), new Long(classPK)
888             };
889         Object result = FinderCache.getResult(finderClassName,
890                 finderMethodName, finderParams, finderArgs, getSessionFactory());
891 
892         if (result == null) {
893             Session session = null;
894 
895             try {
896                 session = openSession();
897 
898                 StringMaker query = new StringMaker();
899                 query.append("SELECT COUNT(*) ");
900                 query.append(
901                     "FROM com.liferay.portal.model.Subscription WHERE ");
902                 query.append("companyId = ?");
903                 query.append(" AND ");
904                 query.append("classNameId = ?");
905                 query.append(" AND ");
906                 query.append("classPK = ?");
907                 query.append(" ");
908 
909                 Query q = session.createQuery(query.toString());
910                 int queryPos = 0;
911                 q.setLong(queryPos++, companyId);
912                 q.setLong(queryPos++, classNameId);
913                 q.setLong(queryPos++, classPK);
914 
915                 Long count = null;
916                 Iterator itr = q.list().iterator();
917 
918                 if (itr.hasNext()) {
919                     count = (Long)itr.next();
920                 }
921 
922                 if (count == null) {
923                     count = new Long(0);
924                 }
925 
926                 FinderCache.putResult(finderClassName, finderMethodName,
927                     finderParams, finderArgs, count);
928 
929                 return count.intValue();
930             }
931             catch (Exception e) {
932                 throw HibernateUtil.processException(e);
933             }
934             finally {
935                 closeSession(session);
936             }
937         }
938         else {
939             return ((Long)result).intValue();
940         }
941     }
942 
943     public int countByC_U_C_C(long companyId, long userId, long classNameId,
944         long classPK) throws SystemException {
945         String finderClassName = Subscription.class.getName();
946         String finderMethodName = "countByC_U_C_C";
947         String[] finderParams = new String[] {
948                 Long.class.getName(), Long.class.getName(), Long.class.getName(),
949                 Long.class.getName()
950             };
951         Object[] finderArgs = new Object[] {
952                 new Long(companyId), new Long(userId), new Long(classNameId),
953                 new Long(classPK)
954             };
955         Object result = FinderCache.getResult(finderClassName,
956                 finderMethodName, finderParams, finderArgs, getSessionFactory());
957 
958         if (result == null) {
959             Session session = null;
960 
961             try {
962                 session = openSession();
963 
964                 StringMaker query = new StringMaker();
965                 query.append("SELECT COUNT(*) ");
966                 query.append(
967                     "FROM com.liferay.portal.model.Subscription WHERE ");
968                 query.append("companyId = ?");
969                 query.append(" AND ");
970                 query.append("userId = ?");
971                 query.append(" AND ");
972                 query.append("classNameId = ?");
973                 query.append(" AND ");
974                 query.append("classPK = ?");
975                 query.append(" ");
976 
977                 Query q = session.createQuery(query.toString());
978                 int queryPos = 0;
979                 q.setLong(queryPos++, companyId);
980                 q.setLong(queryPos++, userId);
981                 q.setLong(queryPos++, classNameId);
982                 q.setLong(queryPos++, classPK);
983 
984                 Long count = null;
985                 Iterator itr = q.list().iterator();
986 
987                 if (itr.hasNext()) {
988                     count = (Long)itr.next();
989                 }
990 
991                 if (count == null) {
992                     count = new Long(0);
993                 }
994 
995                 FinderCache.putResult(finderClassName, finderMethodName,
996                     finderParams, finderArgs, count);
997 
998                 return count.intValue();
999             }
1000            catch (Exception e) {
1001                throw HibernateUtil.processException(e);
1002            }
1003            finally {
1004                closeSession(session);
1005            }
1006        }
1007        else {
1008            return ((Long)result).intValue();
1009        }
1010    }
1011
1012    public int countAll() throws SystemException {
1013        String finderClassName = Subscription.class.getName();
1014        String finderMethodName = "countAll";
1015        String[] finderParams = new String[] {  };
1016        Object[] finderArgs = new Object[] {  };
1017        Object result = FinderCache.getResult(finderClassName,
1018                finderMethodName, finderParams, finderArgs, getSessionFactory());
1019
1020        if (result == null) {
1021            Session session = null;
1022
1023            try {
1024                session = openSession();
1025
1026                StringMaker query = new StringMaker();
1027                query.append("SELECT COUNT(*) ");
1028                query.append("FROM com.liferay.portal.model.Subscription");
1029
1030                Query q = session.createQuery(query.toString());
1031                Long count = null;
1032                Iterator itr = q.list().iterator();
1033
1034                if (itr.hasNext()) {
1035                    count = (Long)itr.next();
1036                }
1037
1038                if (count == null) {
1039                    count = new Long(0);
1040                }
1041
1042                FinderCache.putResult(finderClassName, finderMethodName,
1043                    finderParams, finderArgs, count);
1044
1045                return count.intValue();
1046            }
1047            catch (Exception e) {
1048                throw HibernateUtil.processException(e);
1049            }
1050            finally {
1051                closeSession(session);
1052            }
1053        }
1054        else {
1055            return ((Long)result).intValue();
1056        }
1057    }
1058
1059    protected void initDao() {
1060    }
1061
1062    private static Log _log = LogFactory.getLog(SubscriptionPersistenceImpl.class);
1063}