1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   * 
13   */
14  
15  package com.liferay.portal.service.persistence;
16  
17  import com.liferay.portal.NoSuchModelException;
18  import com.liferay.portal.NoSuchSubscriptionException;
19  import com.liferay.portal.SystemException;
20  import com.liferay.portal.kernel.annotation.BeanReference;
21  import com.liferay.portal.kernel.cache.CacheRegistry;
22  import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
23  import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
24  import com.liferay.portal.kernel.dao.orm.FinderPath;
25  import com.liferay.portal.kernel.dao.orm.Query;
26  import com.liferay.portal.kernel.dao.orm.QueryPos;
27  import com.liferay.portal.kernel.dao.orm.QueryUtil;
28  import com.liferay.portal.kernel.dao.orm.Session;
29  import com.liferay.portal.kernel.log.Log;
30  import com.liferay.portal.kernel.log.LogFactoryUtil;
31  import com.liferay.portal.kernel.util.GetterUtil;
32  import com.liferay.portal.kernel.util.OrderByComparator;
33  import com.liferay.portal.kernel.util.StringBundler;
34  import com.liferay.portal.kernel.util.StringPool;
35  import com.liferay.portal.kernel.util.StringUtil;
36  import com.liferay.portal.model.ModelListener;
37  import com.liferay.portal.model.Subscription;
38  import com.liferay.portal.model.impl.SubscriptionImpl;
39  import com.liferay.portal.model.impl.SubscriptionModelImpl;
40  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
41  
42  import java.io.Serializable;
43  
44  import java.util.ArrayList;
45  import java.util.Collections;
46  import java.util.List;
47  
48  /**
49   * <a href="SubscriptionPersistenceImpl.java.html"><b><i>View Source</i></b></a>
50   *
51   * <p>
52   * ServiceBuilder generated this class. Modifications in this class will be
53   * overwritten the next time is generated.
54   * </p>
55   *
56   * @author    Brian Wing Shun Chan
57   * @see       SubscriptionPersistence
58   * @see       SubscriptionUtil
59   * @generated
60   */
61  public class SubscriptionPersistenceImpl extends BasePersistenceImpl<Subscription>
62      implements SubscriptionPersistence {
63      public static final String FINDER_CLASS_NAME_ENTITY = SubscriptionImpl.class.getName();
64      public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
65          ".List";
66      public static final FinderPath FINDER_PATH_FIND_BY_USERID = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
67              SubscriptionModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
68              "findByUserId", new String[] { Long.class.getName() });
69      public static final FinderPath FINDER_PATH_FIND_BY_OBC_USERID = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
70              SubscriptionModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
71              "findByUserId",
72              new String[] {
73                  Long.class.getName(),
74                  
75              "java.lang.Integer", "java.lang.Integer",
76                  "com.liferay.portal.kernel.util.OrderByComparator"
77              });
78      public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
79              SubscriptionModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
80              "countByUserId", new String[] { Long.class.getName() });
81      public static final FinderPath FINDER_PATH_FIND_BY_U_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
82              SubscriptionModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
83              "findByU_C",
84              new String[] { Long.class.getName(), Long.class.getName() });
85      public static final FinderPath FINDER_PATH_FIND_BY_OBC_U_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
86              SubscriptionModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
87              "findByU_C",
88              new String[] {
89                  Long.class.getName(), Long.class.getName(),
90                  
91              "java.lang.Integer", "java.lang.Integer",
92                  "com.liferay.portal.kernel.util.OrderByComparator"
93              });
94      public static final FinderPath FINDER_PATH_COUNT_BY_U_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
95              SubscriptionModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
96              "countByU_C",
97              new String[] { Long.class.getName(), Long.class.getName() });
98      public static final FinderPath FINDER_PATH_FIND_BY_C_C_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
99              SubscriptionModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
100             "findByC_C_C",
101             new String[] {
102                 Long.class.getName(), Long.class.getName(), Long.class.getName()
103             });
104     public static final FinderPath FINDER_PATH_FIND_BY_OBC_C_C_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
105             SubscriptionModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
106             "findByC_C_C",
107             new String[] {
108                 Long.class.getName(), Long.class.getName(), Long.class.getName(),
109                 
110             "java.lang.Integer", "java.lang.Integer",
111                 "com.liferay.portal.kernel.util.OrderByComparator"
112             });
113     public static final FinderPath FINDER_PATH_COUNT_BY_C_C_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
114             SubscriptionModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
115             "countByC_C_C",
116             new String[] {
117                 Long.class.getName(), Long.class.getName(), Long.class.getName()
118             });
119     public static final FinderPath FINDER_PATH_FETCH_BY_C_U_C_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
120             SubscriptionModelImpl.FINDER_CACHE_ENABLED,
121             FINDER_CLASS_NAME_ENTITY, "fetchByC_U_C_C",
122             new String[] {
123                 Long.class.getName(), Long.class.getName(), Long.class.getName(),
124                 Long.class.getName()
125             });
126     public static final FinderPath FINDER_PATH_COUNT_BY_C_U_C_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
127             SubscriptionModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
128             "countByC_U_C_C",
129             new String[] {
130                 Long.class.getName(), Long.class.getName(), Long.class.getName(),
131                 Long.class.getName()
132             });
133     public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
134             SubscriptionModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
135             "findAll", new String[0]);
136     public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
137             SubscriptionModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
138             "countAll", new String[0]);
139 
140     public void cacheResult(Subscription subscription) {
141         EntityCacheUtil.putResult(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
142             SubscriptionImpl.class, subscription.getPrimaryKey(), subscription);
143 
144         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_U_C_C,
145             new Object[] {
146                 new Long(subscription.getCompanyId()),
147                 new Long(subscription.getUserId()),
148                 new Long(subscription.getClassNameId()),
149                 new Long(subscription.getClassPK())
150             }, subscription);
151     }
152 
153     public void cacheResult(List<Subscription> subscriptions) {
154         for (Subscription subscription : subscriptions) {
155             if (EntityCacheUtil.getResult(
156                         SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
157                         SubscriptionImpl.class, subscription.getPrimaryKey(),
158                         this) == null) {
159                 cacheResult(subscription);
160             }
161         }
162     }
163 
164     public void clearCache() {
165         CacheRegistry.clear(SubscriptionImpl.class.getName());
166         EntityCacheUtil.clearCache(SubscriptionImpl.class.getName());
167         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
168         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
169     }
170 
171     public Subscription create(long subscriptionId) {
172         Subscription subscription = new SubscriptionImpl();
173 
174         subscription.setNew(true);
175         subscription.setPrimaryKey(subscriptionId);
176 
177         return subscription;
178     }
179 
180     public Subscription remove(Serializable primaryKey)
181         throws NoSuchModelException, SystemException {
182         return remove(((Long)primaryKey).longValue());
183     }
184 
185     public Subscription remove(long subscriptionId)
186         throws NoSuchSubscriptionException, SystemException {
187         Session session = null;
188 
189         try {
190             session = openSession();
191 
192             Subscription subscription = (Subscription)session.get(SubscriptionImpl.class,
193                     new Long(subscriptionId));
194 
195             if (subscription == null) {
196                 if (_log.isWarnEnabled()) {
197                     _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
198                         subscriptionId);
199                 }
200 
201                 throw new NoSuchSubscriptionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
202                     subscriptionId);
203             }
204 
205             return remove(subscription);
206         }
207         catch (NoSuchSubscriptionException nsee) {
208             throw nsee;
209         }
210         catch (Exception e) {
211             throw processException(e);
212         }
213         finally {
214             closeSession(session);
215         }
216     }
217 
218     public Subscription remove(Subscription subscription)
219         throws SystemException {
220         for (ModelListener<Subscription> listener : listeners) {
221             listener.onBeforeRemove(subscription);
222         }
223 
224         subscription = removeImpl(subscription);
225 
226         for (ModelListener<Subscription> listener : listeners) {
227             listener.onAfterRemove(subscription);
228         }
229 
230         return subscription;
231     }
232 
233     protected Subscription removeImpl(Subscription subscription)
234         throws SystemException {
235         subscription = toUnwrappedModel(subscription);
236 
237         Session session = null;
238 
239         try {
240             session = openSession();
241 
242             if (subscription.isCachedModel() || BatchSessionUtil.isEnabled()) {
243                 Object staleObject = session.get(SubscriptionImpl.class,
244                         subscription.getPrimaryKeyObj());
245 
246                 if (staleObject != null) {
247                     session.evict(staleObject);
248                 }
249             }
250 
251             session.delete(subscription);
252 
253             session.flush();
254         }
255         catch (Exception e) {
256             throw processException(e);
257         }
258         finally {
259             closeSession(session);
260         }
261 
262         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
263 
264         SubscriptionModelImpl subscriptionModelImpl = (SubscriptionModelImpl)subscription;
265 
266         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_U_C_C,
267             new Object[] {
268                 new Long(subscriptionModelImpl.getOriginalCompanyId()),
269                 new Long(subscriptionModelImpl.getOriginalUserId()),
270                 new Long(subscriptionModelImpl.getOriginalClassNameId()),
271                 new Long(subscriptionModelImpl.getOriginalClassPK())
272             });
273 
274         EntityCacheUtil.removeResult(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
275             SubscriptionImpl.class, subscription.getPrimaryKey());
276 
277         return subscription;
278     }
279 
280     /**
281      * @deprecated Use {@link BasePersistence#update(com.liferay.portal.model.BaseModel, boolean)}.
282      */
283     public Subscription update(Subscription subscription)
284         throws SystemException {
285         if (_log.isWarnEnabled()) {
286             _log.warn(
287                 "Using the deprecated update(Subscription subscription) method. Use update(Subscription subscription, boolean merge) instead.");
288         }
289 
290         return update(subscription, false);
291     }
292 
293     public Subscription updateImpl(
294         com.liferay.portal.model.Subscription subscription, boolean merge)
295         throws SystemException {
296         subscription = toUnwrappedModel(subscription);
297 
298         boolean isNew = subscription.isNew();
299 
300         SubscriptionModelImpl subscriptionModelImpl = (SubscriptionModelImpl)subscription;
301 
302         Session session = null;
303 
304         try {
305             session = openSession();
306 
307             BatchSessionUtil.update(session, subscription, merge);
308 
309             subscription.setNew(false);
310         }
311         catch (Exception e) {
312             throw processException(e);
313         }
314         finally {
315             closeSession(session);
316         }
317 
318         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
319 
320         EntityCacheUtil.putResult(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
321             SubscriptionImpl.class, subscription.getPrimaryKey(), subscription);
322 
323         if (!isNew &&
324                 ((subscription.getCompanyId() != subscriptionModelImpl.getOriginalCompanyId()) ||
325                 (subscription.getUserId() != subscriptionModelImpl.getOriginalUserId()) ||
326                 (subscription.getClassNameId() != subscriptionModelImpl.getOriginalClassNameId()) ||
327                 (subscription.getClassPK() != subscriptionModelImpl.getOriginalClassPK()))) {
328             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_U_C_C,
329                 new Object[] {
330                     new Long(subscriptionModelImpl.getOriginalCompanyId()),
331                     new Long(subscriptionModelImpl.getOriginalUserId()),
332                     new Long(subscriptionModelImpl.getOriginalClassNameId()),
333                     new Long(subscriptionModelImpl.getOriginalClassPK())
334                 });
335         }
336 
337         if (isNew ||
338                 ((subscription.getCompanyId() != subscriptionModelImpl.getOriginalCompanyId()) ||
339                 (subscription.getUserId() != subscriptionModelImpl.getOriginalUserId()) ||
340                 (subscription.getClassNameId() != subscriptionModelImpl.getOriginalClassNameId()) ||
341                 (subscription.getClassPK() != subscriptionModelImpl.getOriginalClassPK()))) {
342             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_U_C_C,
343                 new Object[] {
344                     new Long(subscription.getCompanyId()),
345                     new Long(subscription.getUserId()),
346                     new Long(subscription.getClassNameId()),
347                     new Long(subscription.getClassPK())
348                 }, subscription);
349         }
350 
351         return subscription;
352     }
353 
354     protected Subscription toUnwrappedModel(Subscription subscription) {
355         if (subscription instanceof SubscriptionImpl) {
356             return subscription;
357         }
358 
359         SubscriptionImpl subscriptionImpl = new SubscriptionImpl();
360 
361         subscriptionImpl.setNew(subscription.isNew());
362         subscriptionImpl.setPrimaryKey(subscription.getPrimaryKey());
363 
364         subscriptionImpl.setSubscriptionId(subscription.getSubscriptionId());
365         subscriptionImpl.setCompanyId(subscription.getCompanyId());
366         subscriptionImpl.setUserId(subscription.getUserId());
367         subscriptionImpl.setUserName(subscription.getUserName());
368         subscriptionImpl.setCreateDate(subscription.getCreateDate());
369         subscriptionImpl.setModifiedDate(subscription.getModifiedDate());
370         subscriptionImpl.setClassNameId(subscription.getClassNameId());
371         subscriptionImpl.setClassPK(subscription.getClassPK());
372         subscriptionImpl.setFrequency(subscription.getFrequency());
373 
374         return subscriptionImpl;
375     }
376 
377     public Subscription findByPrimaryKey(Serializable primaryKey)
378         throws NoSuchModelException, SystemException {
379         return findByPrimaryKey(((Long)primaryKey).longValue());
380     }
381 
382     public Subscription findByPrimaryKey(long subscriptionId)
383         throws NoSuchSubscriptionException, SystemException {
384         Subscription subscription = fetchByPrimaryKey(subscriptionId);
385 
386         if (subscription == null) {
387             if (_log.isWarnEnabled()) {
388                 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + subscriptionId);
389             }
390 
391             throw new NoSuchSubscriptionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
392                 subscriptionId);
393         }
394 
395         return subscription;
396     }
397 
398     public Subscription fetchByPrimaryKey(Serializable primaryKey)
399         throws SystemException {
400         return fetchByPrimaryKey(((Long)primaryKey).longValue());
401     }
402 
403     public Subscription fetchByPrimaryKey(long subscriptionId)
404         throws SystemException {
405         Subscription subscription = (Subscription)EntityCacheUtil.getResult(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
406                 SubscriptionImpl.class, subscriptionId, this);
407 
408         if (subscription == null) {
409             Session session = null;
410 
411             try {
412                 session = openSession();
413 
414                 subscription = (Subscription)session.get(SubscriptionImpl.class,
415                         new Long(subscriptionId));
416             }
417             catch (Exception e) {
418                 throw processException(e);
419             }
420             finally {
421                 if (subscription != null) {
422                     cacheResult(subscription);
423                 }
424 
425                 closeSession(session);
426             }
427         }
428 
429         return subscription;
430     }
431 
432     public List<Subscription> findByUserId(long userId)
433         throws SystemException {
434         Object[] finderArgs = new Object[] { new Long(userId) };
435 
436         List<Subscription> list = (List<Subscription>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_USERID,
437                 finderArgs, this);
438 
439         if (list == null) {
440             Session session = null;
441 
442             try {
443                 session = openSession();
444 
445                 StringBundler query = new StringBundler(2);
446 
447                 query.append(_SQL_SELECT_SUBSCRIPTION_WHERE);
448 
449                 query.append(_FINDER_COLUMN_USERID_USERID_2);
450 
451                 String sql = query.toString();
452 
453                 Query q = session.createQuery(sql);
454 
455                 QueryPos qPos = QueryPos.getInstance(q);
456 
457                 qPos.add(userId);
458 
459                 list = q.list();
460             }
461             catch (Exception e) {
462                 throw processException(e);
463             }
464             finally {
465                 if (list == null) {
466                     list = new ArrayList<Subscription>();
467                 }
468 
469                 cacheResult(list);
470 
471                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_USERID,
472                     finderArgs, list);
473 
474                 closeSession(session);
475             }
476         }
477 
478         return list;
479     }
480 
481     public List<Subscription> findByUserId(long userId, int start, int end)
482         throws SystemException {
483         return findByUserId(userId, start, end, null);
484     }
485 
486     public List<Subscription> findByUserId(long userId, int start, int end,
487         OrderByComparator orderByComparator) throws SystemException {
488         Object[] finderArgs = new Object[] {
489                 new Long(userId),
490                 
491                 String.valueOf(start), String.valueOf(end),
492                 String.valueOf(orderByComparator)
493             };
494 
495         List<Subscription> list = (List<Subscription>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_USERID,
496                 finderArgs, this);
497 
498         if (list == null) {
499             Session session = null;
500 
501             try {
502                 session = openSession();
503 
504                 StringBundler query = null;
505 
506                 if (orderByComparator != null) {
507                     query = new StringBundler(3 +
508                             (orderByComparator.getOrderByFields().length * 3));
509                 }
510                 else {
511                     query = new StringBundler(2);
512                 }
513 
514                 query.append(_SQL_SELECT_SUBSCRIPTION_WHERE);
515 
516                 query.append(_FINDER_COLUMN_USERID_USERID_2);
517 
518                 if (orderByComparator != null) {
519                     appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
520                         orderByComparator);
521                 }
522 
523                 String sql = query.toString();
524 
525                 Query q = session.createQuery(sql);
526 
527                 QueryPos qPos = QueryPos.getInstance(q);
528 
529                 qPos.add(userId);
530 
531                 list = (List<Subscription>)QueryUtil.list(q, getDialect(),
532                         start, end);
533             }
534             catch (Exception e) {
535                 throw processException(e);
536             }
537             finally {
538                 if (list == null) {
539                     list = new ArrayList<Subscription>();
540                 }
541 
542                 cacheResult(list);
543 
544                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_USERID,
545                     finderArgs, list);
546 
547                 closeSession(session);
548             }
549         }
550 
551         return list;
552     }
553 
554     public Subscription findByUserId_First(long userId,
555         OrderByComparator orderByComparator)
556         throws NoSuchSubscriptionException, SystemException {
557         List<Subscription> list = findByUserId(userId, 0, 1, orderByComparator);
558 
559         if (list.isEmpty()) {
560             StringBundler msg = new StringBundler(4);
561 
562             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
563 
564             msg.append("userId=");
565             msg.append(userId);
566 
567             msg.append(StringPool.CLOSE_CURLY_BRACE);
568 
569             throw new NoSuchSubscriptionException(msg.toString());
570         }
571         else {
572             return list.get(0);
573         }
574     }
575 
576     public Subscription findByUserId_Last(long userId,
577         OrderByComparator orderByComparator)
578         throws NoSuchSubscriptionException, SystemException {
579         int count = countByUserId(userId);
580 
581         List<Subscription> list = findByUserId(userId, count - 1, count,
582                 orderByComparator);
583 
584         if (list.isEmpty()) {
585             StringBundler msg = new StringBundler(4);
586 
587             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
588 
589             msg.append("userId=");
590             msg.append(userId);
591 
592             msg.append(StringPool.CLOSE_CURLY_BRACE);
593 
594             throw new NoSuchSubscriptionException(msg.toString());
595         }
596         else {
597             return list.get(0);
598         }
599     }
600 
601     public Subscription[] findByUserId_PrevAndNext(long subscriptionId,
602         long userId, OrderByComparator orderByComparator)
603         throws NoSuchSubscriptionException, SystemException {
604         Subscription subscription = findByPrimaryKey(subscriptionId);
605 
606         int count = countByUserId(userId);
607 
608         Session session = null;
609 
610         try {
611             session = openSession();
612 
613             StringBundler query = null;
614 
615             if (orderByComparator != null) {
616                 query = new StringBundler(3 +
617                         (orderByComparator.getOrderByFields().length * 3));
618             }
619             else {
620                 query = new StringBundler(2);
621             }
622 
623             query.append(_SQL_SELECT_SUBSCRIPTION_WHERE);
624 
625             query.append(_FINDER_COLUMN_USERID_USERID_2);
626 
627             if (orderByComparator != null) {
628                 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
629                     orderByComparator);
630             }
631 
632             String sql = query.toString();
633 
634             Query q = session.createQuery(sql);
635 
636             QueryPos qPos = QueryPos.getInstance(q);
637 
638             qPos.add(userId);
639 
640             Object[] objArray = QueryUtil.getPrevAndNext(q, count,
641                     orderByComparator, subscription);
642 
643             Subscription[] array = new SubscriptionImpl[3];
644 
645             array[0] = (Subscription)objArray[0];
646             array[1] = (Subscription)objArray[1];
647             array[2] = (Subscription)objArray[2];
648 
649             return array;
650         }
651         catch (Exception e) {
652             throw processException(e);
653         }
654         finally {
655             closeSession(session);
656         }
657     }
658 
659     public List<Subscription> findByU_C(long userId, long classNameId)
660         throws SystemException {
661         Object[] finderArgs = new Object[] {
662                 new Long(userId), new Long(classNameId)
663             };
664 
665         List<Subscription> list = (List<Subscription>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_U_C,
666                 finderArgs, this);
667 
668         if (list == null) {
669             Session session = null;
670 
671             try {
672                 session = openSession();
673 
674                 StringBundler query = new StringBundler(3);
675 
676                 query.append(_SQL_SELECT_SUBSCRIPTION_WHERE);
677 
678                 query.append(_FINDER_COLUMN_U_C_USERID_2);
679 
680                 query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
681 
682                 String sql = query.toString();
683 
684                 Query q = session.createQuery(sql);
685 
686                 QueryPos qPos = QueryPos.getInstance(q);
687 
688                 qPos.add(userId);
689 
690                 qPos.add(classNameId);
691 
692                 list = q.list();
693             }
694             catch (Exception e) {
695                 throw processException(e);
696             }
697             finally {
698                 if (list == null) {
699                     list = new ArrayList<Subscription>();
700                 }
701 
702                 cacheResult(list);
703 
704                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_U_C, finderArgs,
705                     list);
706 
707                 closeSession(session);
708             }
709         }
710 
711         return list;
712     }
713 
714     public List<Subscription> findByU_C(long userId, long classNameId,
715         int start, int end) throws SystemException {
716         return findByU_C(userId, classNameId, start, end, null);
717     }
718 
719     public List<Subscription> findByU_C(long userId, long classNameId,
720         int start, int end, OrderByComparator orderByComparator)
721         throws SystemException {
722         Object[] finderArgs = new Object[] {
723                 new Long(userId), new Long(classNameId),
724                 
725                 String.valueOf(start), String.valueOf(end),
726                 String.valueOf(orderByComparator)
727             };
728 
729         List<Subscription> list = (List<Subscription>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_U_C,
730                 finderArgs, this);
731 
732         if (list == null) {
733             Session session = null;
734 
735             try {
736                 session = openSession();
737 
738                 StringBundler query = null;
739 
740                 if (orderByComparator != null) {
741                     query = new StringBundler(4 +
742                             (orderByComparator.getOrderByFields().length * 3));
743                 }
744                 else {
745                     query = new StringBundler(3);
746                 }
747 
748                 query.append(_SQL_SELECT_SUBSCRIPTION_WHERE);
749 
750                 query.append(_FINDER_COLUMN_U_C_USERID_2);
751 
752                 query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
753 
754                 if (orderByComparator != null) {
755                     appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
756                         orderByComparator);
757                 }
758 
759                 String sql = query.toString();
760 
761                 Query q = session.createQuery(sql);
762 
763                 QueryPos qPos = QueryPos.getInstance(q);
764 
765                 qPos.add(userId);
766 
767                 qPos.add(classNameId);
768 
769                 list = (List<Subscription>)QueryUtil.list(q, getDialect(),
770                         start, end);
771             }
772             catch (Exception e) {
773                 throw processException(e);
774             }
775             finally {
776                 if (list == null) {
777                     list = new ArrayList<Subscription>();
778                 }
779 
780                 cacheResult(list);
781 
782                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_U_C,
783                     finderArgs, list);
784 
785                 closeSession(session);
786             }
787         }
788 
789         return list;
790     }
791 
792     public Subscription findByU_C_First(long userId, long classNameId,
793         OrderByComparator orderByComparator)
794         throws NoSuchSubscriptionException, SystemException {
795         List<Subscription> list = findByU_C(userId, classNameId, 0, 1,
796                 orderByComparator);
797 
798         if (list.isEmpty()) {
799             StringBundler msg = new StringBundler(6);
800 
801             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
802 
803             msg.append("userId=");
804             msg.append(userId);
805 
806             msg.append(", classNameId=");
807             msg.append(classNameId);
808 
809             msg.append(StringPool.CLOSE_CURLY_BRACE);
810 
811             throw new NoSuchSubscriptionException(msg.toString());
812         }
813         else {
814             return list.get(0);
815         }
816     }
817 
818     public Subscription findByU_C_Last(long userId, long classNameId,
819         OrderByComparator orderByComparator)
820         throws NoSuchSubscriptionException, SystemException {
821         int count = countByU_C(userId, classNameId);
822 
823         List<Subscription> list = findByU_C(userId, classNameId, count - 1,
824                 count, orderByComparator);
825 
826         if (list.isEmpty()) {
827             StringBundler msg = new StringBundler(6);
828 
829             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
830 
831             msg.append("userId=");
832             msg.append(userId);
833 
834             msg.append(", classNameId=");
835             msg.append(classNameId);
836 
837             msg.append(StringPool.CLOSE_CURLY_BRACE);
838 
839             throw new NoSuchSubscriptionException(msg.toString());
840         }
841         else {
842             return list.get(0);
843         }
844     }
845 
846     public Subscription[] findByU_C_PrevAndNext(long subscriptionId,
847         long userId, long classNameId, OrderByComparator orderByComparator)
848         throws NoSuchSubscriptionException, SystemException {
849         Subscription subscription = findByPrimaryKey(subscriptionId);
850 
851         int count = countByU_C(userId, classNameId);
852 
853         Session session = null;
854 
855         try {
856             session = openSession();
857 
858             StringBundler query = null;
859 
860             if (orderByComparator != null) {
861                 query = new StringBundler(4 +
862                         (orderByComparator.getOrderByFields().length * 3));
863             }
864             else {
865                 query = new StringBundler(3);
866             }
867 
868             query.append(_SQL_SELECT_SUBSCRIPTION_WHERE);
869 
870             query.append(_FINDER_COLUMN_U_C_USERID_2);
871 
872             query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
873 
874             if (orderByComparator != null) {
875                 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
876                     orderByComparator);
877             }
878 
879             String sql = query.toString();
880 
881             Query q = session.createQuery(sql);
882 
883             QueryPos qPos = QueryPos.getInstance(q);
884 
885             qPos.add(userId);
886 
887             qPos.add(classNameId);
888 
889             Object[] objArray = QueryUtil.getPrevAndNext(q, count,
890                     orderByComparator, subscription);
891 
892             Subscription[] array = new SubscriptionImpl[3];
893 
894             array[0] = (Subscription)objArray[0];
895             array[1] = (Subscription)objArray[1];
896             array[2] = (Subscription)objArray[2];
897 
898             return array;
899         }
900         catch (Exception e) {
901             throw processException(e);
902         }
903         finally {
904             closeSession(session);
905         }
906     }
907 
908     public List<Subscription> findByC_C_C(long companyId, long classNameId,
909         long classPK) throws SystemException {
910         Object[] finderArgs = new Object[] {
911                 new Long(companyId), new Long(classNameId), new Long(classPK)
912             };
913 
914         List<Subscription> list = (List<Subscription>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_C_C,
915                 finderArgs, this);
916 
917         if (list == null) {
918             Session session = null;
919 
920             try {
921                 session = openSession();
922 
923                 StringBundler query = new StringBundler(4);
924 
925                 query.append(_SQL_SELECT_SUBSCRIPTION_WHERE);
926 
927                 query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
928 
929                 query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
930 
931                 query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
932 
933                 String sql = query.toString();
934 
935                 Query q = session.createQuery(sql);
936 
937                 QueryPos qPos = QueryPos.getInstance(q);
938 
939                 qPos.add(companyId);
940 
941                 qPos.add(classNameId);
942 
943                 qPos.add(classPK);
944 
945                 list = q.list();
946             }
947             catch (Exception e) {
948                 throw processException(e);
949             }
950             finally {
951                 if (list == null) {
952                     list = new ArrayList<Subscription>();
953                 }
954 
955                 cacheResult(list);
956 
957                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_C_C,
958                     finderArgs, list);
959 
960                 closeSession(session);
961             }
962         }
963 
964         return list;
965     }
966 
967     public List<Subscription> findByC_C_C(long companyId, long classNameId,
968         long classPK, int start, int end) throws SystemException {
969         return findByC_C_C(companyId, classNameId, classPK, start, end, null);
970     }
971 
972     public List<Subscription> findByC_C_C(long companyId, long classNameId,
973         long classPK, int start, int end, OrderByComparator orderByComparator)
974         throws SystemException {
975         Object[] finderArgs = new Object[] {
976                 new Long(companyId), new Long(classNameId), new Long(classPK),
977                 
978                 String.valueOf(start), String.valueOf(end),
979                 String.valueOf(orderByComparator)
980             };
981 
982         List<Subscription> list = (List<Subscription>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_C_C_C,
983                 finderArgs, this);
984 
985         if (list == null) {
986             Session session = null;
987 
988             try {
989                 session = openSession();
990 
991                 StringBundler query = null;
992 
993                 if (orderByComparator != null) {
994                     query = new StringBundler(5 +
995                             (orderByComparator.getOrderByFields().length * 3));
996                 }
997                 else {
998                     query = new StringBundler(4);
999                 }
1000
1001                query.append(_SQL_SELECT_SUBSCRIPTION_WHERE);
1002
1003                query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
1004
1005                query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
1006
1007                query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
1008
1009                if (orderByComparator != null) {
1010                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1011                        orderByComparator);
1012                }
1013
1014                String sql = query.toString();
1015
1016                Query q = session.createQuery(sql);
1017
1018                QueryPos qPos = QueryPos.getInstance(q);
1019
1020                qPos.add(companyId);
1021
1022                qPos.add(classNameId);
1023
1024                qPos.add(classPK);
1025
1026                list = (List<Subscription>)QueryUtil.list(q, getDialect(),
1027                        start, end);
1028            }
1029            catch (Exception e) {
1030                throw processException(e);
1031            }
1032            finally {
1033                if (list == null) {
1034                    list = new ArrayList<Subscription>();
1035                }
1036
1037                cacheResult(list);
1038
1039                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_C_C_C,
1040                    finderArgs, list);
1041
1042                closeSession(session);
1043            }
1044        }
1045
1046        return list;
1047    }
1048
1049    public Subscription findByC_C_C_First(long companyId, long classNameId,
1050        long classPK, OrderByComparator orderByComparator)
1051        throws NoSuchSubscriptionException, SystemException {
1052        List<Subscription> list = findByC_C_C(companyId, classNameId, classPK,
1053                0, 1, orderByComparator);
1054
1055        if (list.isEmpty()) {
1056            StringBundler msg = new StringBundler(8);
1057
1058            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1059
1060            msg.append("companyId=");
1061            msg.append(companyId);
1062
1063            msg.append(", classNameId=");
1064            msg.append(classNameId);
1065
1066            msg.append(", classPK=");
1067            msg.append(classPK);
1068
1069            msg.append(StringPool.CLOSE_CURLY_BRACE);
1070
1071            throw new NoSuchSubscriptionException(msg.toString());
1072        }
1073        else {
1074            return list.get(0);
1075        }
1076    }
1077
1078    public Subscription findByC_C_C_Last(long companyId, long classNameId,
1079        long classPK, OrderByComparator orderByComparator)
1080        throws NoSuchSubscriptionException, SystemException {
1081        int count = countByC_C_C(companyId, classNameId, classPK);
1082
1083        List<Subscription> list = findByC_C_C(companyId, classNameId, classPK,
1084                count - 1, count, orderByComparator);
1085
1086        if (list.isEmpty()) {
1087            StringBundler msg = new StringBundler(8);
1088
1089            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1090
1091            msg.append("companyId=");
1092            msg.append(companyId);
1093
1094            msg.append(", classNameId=");
1095            msg.append(classNameId);
1096
1097            msg.append(", classPK=");
1098            msg.append(classPK);
1099
1100            msg.append(StringPool.CLOSE_CURLY_BRACE);
1101
1102            throw new NoSuchSubscriptionException(msg.toString());
1103        }
1104        else {
1105            return list.get(0);
1106        }
1107    }
1108
1109    public Subscription[] findByC_C_C_PrevAndNext(long subscriptionId,
1110        long companyId, long classNameId, long classPK,
1111        OrderByComparator orderByComparator)
1112        throws NoSuchSubscriptionException, SystemException {
1113        Subscription subscription = findByPrimaryKey(subscriptionId);
1114
1115        int count = countByC_C_C(companyId, classNameId, classPK);
1116
1117        Session session = null;
1118
1119        try {
1120            session = openSession();
1121
1122            StringBundler query = null;
1123
1124            if (orderByComparator != null) {
1125                query = new StringBundler(5 +
1126                        (orderByComparator.getOrderByFields().length * 3));
1127            }
1128            else {
1129                query = new StringBundler(4);
1130            }
1131
1132            query.append(_SQL_SELECT_SUBSCRIPTION_WHERE);
1133
1134            query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
1135
1136            query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
1137
1138            query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
1139
1140            if (orderByComparator != null) {
1141                appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1142                    orderByComparator);
1143            }
1144
1145            String sql = query.toString();
1146
1147            Query q = session.createQuery(sql);
1148
1149            QueryPos qPos = QueryPos.getInstance(q);
1150
1151            qPos.add(companyId);
1152
1153            qPos.add(classNameId);
1154
1155            qPos.add(classPK);
1156
1157            Object[] objArray = QueryUtil.getPrevAndNext(q, count,
1158                    orderByComparator, subscription);
1159
1160            Subscription[] array = new SubscriptionImpl[3];
1161
1162            array[0] = (Subscription)objArray[0];
1163            array[1] = (Subscription)objArray[1];
1164            array[2] = (Subscription)objArray[2];
1165
1166            return array;
1167        }
1168        catch (Exception e) {
1169            throw processException(e);
1170        }
1171        finally {
1172            closeSession(session);
1173        }
1174    }
1175
1176    public Subscription findByC_U_C_C(long companyId, long userId,
1177        long classNameId, long classPK)
1178        throws NoSuchSubscriptionException, SystemException {
1179        Subscription subscription = fetchByC_U_C_C(companyId, userId,
1180                classNameId, classPK);
1181
1182        if (subscription == null) {
1183            StringBundler msg = new StringBundler(10);
1184
1185            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1186
1187            msg.append("companyId=");
1188            msg.append(companyId);
1189
1190            msg.append(", userId=");
1191            msg.append(userId);
1192
1193            msg.append(", classNameId=");
1194            msg.append(classNameId);
1195
1196            msg.append(", classPK=");
1197            msg.append(classPK);
1198
1199            msg.append(StringPool.CLOSE_CURLY_BRACE);
1200
1201            if (_log.isWarnEnabled()) {
1202                _log.warn(msg.toString());
1203            }
1204
1205            throw new NoSuchSubscriptionException(msg.toString());
1206        }
1207
1208        return subscription;
1209    }
1210
1211    public Subscription fetchByC_U_C_C(long companyId, long userId,
1212        long classNameId, long classPK) throws SystemException {
1213        return fetchByC_U_C_C(companyId, userId, classNameId, classPK, true);
1214    }
1215
1216    public Subscription fetchByC_U_C_C(long companyId, long userId,
1217        long classNameId, long classPK, boolean retrieveFromCache)
1218        throws SystemException {
1219        Object[] finderArgs = new Object[] {
1220                new Long(companyId), new Long(userId), new Long(classNameId),
1221                new Long(classPK)
1222            };
1223
1224        Object result = null;
1225
1226        if (retrieveFromCache) {
1227            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_U_C_C,
1228                    finderArgs, this);
1229        }
1230
1231        if (result == null) {
1232            Session session = null;
1233
1234            try {
1235                session = openSession();
1236
1237                StringBundler query = new StringBundler(5);
1238
1239                query.append(_SQL_SELECT_SUBSCRIPTION_WHERE);
1240
1241                query.append(_FINDER_COLUMN_C_U_C_C_COMPANYID_2);
1242
1243                query.append(_FINDER_COLUMN_C_U_C_C_USERID_2);
1244
1245                query.append(_FINDER_COLUMN_C_U_C_C_CLASSNAMEID_2);
1246
1247                query.append(_FINDER_COLUMN_C_U_C_C_CLASSPK_2);
1248
1249                String sql = query.toString();
1250
1251                Query q = session.createQuery(sql);
1252
1253                QueryPos qPos = QueryPos.getInstance(q);
1254
1255                qPos.add(companyId);
1256
1257                qPos.add(userId);
1258
1259                qPos.add(classNameId);
1260
1261                qPos.add(classPK);
1262
1263                List<Subscription> list = q.list();
1264
1265                result = list;
1266
1267                Subscription subscription = null;
1268
1269                if (list.isEmpty()) {
1270                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_U_C_C,
1271                        finderArgs, list);
1272                }
1273                else {
1274                    subscription = list.get(0);
1275
1276                    cacheResult(subscription);
1277
1278                    if ((subscription.getCompanyId() != companyId) ||
1279                            (subscription.getUserId() != userId) ||
1280                            (subscription.getClassNameId() != classNameId) ||
1281                            (subscription.getClassPK() != classPK)) {
1282                        FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_U_C_C,
1283                            finderArgs, subscription);
1284                    }
1285                }
1286
1287                return subscription;
1288            }
1289            catch (Exception e) {
1290                throw processException(e);
1291            }
1292            finally {
1293                if (result == null) {
1294                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_U_C_C,
1295                        finderArgs, new ArrayList<Subscription>());
1296                }
1297
1298                closeSession(session);
1299            }
1300        }
1301        else {
1302            if (result instanceof List<?>) {
1303                return null;
1304            }
1305            else {
1306                return (Subscription)result;
1307            }
1308        }
1309    }
1310
1311    public List<Subscription> findAll() throws SystemException {
1312        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1313    }
1314
1315    public List<Subscription> findAll(int start, int end)
1316        throws SystemException {
1317        return findAll(start, end, null);
1318    }
1319
1320    public List<Subscription> findAll(int start, int end,
1321        OrderByComparator orderByComparator) throws SystemException {
1322        Object[] finderArgs = new Object[] {
1323                String.valueOf(start), String.valueOf(end),
1324                String.valueOf(orderByComparator)
1325            };
1326
1327        List<Subscription> list = (List<Subscription>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1328                finderArgs, this);
1329
1330        if (list == null) {
1331            Session session = null;
1332
1333            try {
1334                session = openSession();
1335
1336                StringBundler query = null;
1337                String sql = null;
1338
1339                if (orderByComparator != null) {
1340                    query = new StringBundler(2 +
1341                            (orderByComparator.getOrderByFields().length * 3));
1342
1343                    query.append(_SQL_SELECT_SUBSCRIPTION);
1344
1345                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1346                        orderByComparator);
1347
1348                    sql = query.toString();
1349                }
1350
1351                sql = _SQL_SELECT_SUBSCRIPTION;
1352
1353                Query q = session.createQuery(sql);
1354
1355                if (orderByComparator == null) {
1356                    list = (List<Subscription>)QueryUtil.list(q, getDialect(),
1357                            start, end, false);
1358
1359                    Collections.sort(list);
1360                }
1361                else {
1362                    list = (List<Subscription>)QueryUtil.list(q, getDialect(),
1363                            start, end);
1364                }
1365            }
1366            catch (Exception e) {
1367                throw processException(e);
1368            }
1369            finally {
1370                if (list == null) {
1371                    list = new ArrayList<Subscription>();
1372                }
1373
1374                cacheResult(list);
1375
1376                FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1377
1378                closeSession(session);
1379            }
1380        }
1381
1382        return list;
1383    }
1384
1385    public void removeByUserId(long userId) throws SystemException {
1386        for (Subscription subscription : findByUserId(userId)) {
1387            remove(subscription);
1388        }
1389    }
1390
1391    public void removeByU_C(long userId, long classNameId)
1392        throws SystemException {
1393        for (Subscription subscription : findByU_C(userId, classNameId)) {
1394            remove(subscription);
1395        }
1396    }
1397
1398    public void removeByC_C_C(long companyId, long classNameId, long classPK)
1399        throws SystemException {
1400        for (Subscription subscription : findByC_C_C(companyId, classNameId,
1401                classPK)) {
1402            remove(subscription);
1403        }
1404    }
1405
1406    public void removeByC_U_C_C(long companyId, long userId, long classNameId,
1407        long classPK) throws NoSuchSubscriptionException, SystemException {
1408        Subscription subscription = findByC_U_C_C(companyId, userId,
1409                classNameId, classPK);
1410
1411        remove(subscription);
1412    }
1413
1414    public void removeAll() throws SystemException {
1415        for (Subscription subscription : findAll()) {
1416            remove(subscription);
1417        }
1418    }
1419
1420    public int countByUserId(long userId) throws SystemException {
1421        Object[] finderArgs = new Object[] { new Long(userId) };
1422
1423        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
1424                finderArgs, this);
1425
1426        if (count == null) {
1427            Session session = null;
1428
1429            try {
1430                session = openSession();
1431
1432                StringBundler query = new StringBundler(2);
1433
1434                query.append(_SQL_COUNT_SUBSCRIPTION_WHERE);
1435
1436                query.append(_FINDER_COLUMN_USERID_USERID_2);
1437
1438                String sql = query.toString();
1439
1440                Query q = session.createQuery(sql);
1441
1442                QueryPos qPos = QueryPos.getInstance(q);
1443
1444                qPos.add(userId);
1445
1446                count = (Long)q.uniqueResult();
1447            }
1448            catch (Exception e) {
1449                throw processException(e);
1450            }
1451            finally {
1452                if (count == null) {
1453                    count = Long.valueOf(0);
1454                }
1455
1456                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
1457                    finderArgs, count);
1458
1459                closeSession(session);
1460            }
1461        }
1462
1463        return count.intValue();
1464    }
1465
1466    public int countByU_C(long userId, long classNameId)
1467        throws SystemException {
1468        Object[] finderArgs = new Object[] {
1469                new Long(userId), new Long(classNameId)
1470            };
1471
1472        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_C,
1473                finderArgs, this);
1474
1475        if (count == null) {
1476            Session session = null;
1477
1478            try {
1479                session = openSession();
1480
1481                StringBundler query = new StringBundler(3);
1482
1483                query.append(_SQL_COUNT_SUBSCRIPTION_WHERE);
1484
1485                query.append(_FINDER_COLUMN_U_C_USERID_2);
1486
1487                query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
1488
1489                String sql = query.toString();
1490
1491                Query q = session.createQuery(sql);
1492
1493                QueryPos qPos = QueryPos.getInstance(q);
1494
1495                qPos.add(userId);
1496
1497                qPos.add(classNameId);
1498
1499                count = (Long)q.uniqueResult();
1500            }
1501            catch (Exception e) {
1502                throw processException(e);
1503            }
1504            finally {
1505                if (count == null) {
1506                    count = Long.valueOf(0);
1507                }
1508
1509                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_C, finderArgs,
1510                    count);
1511
1512                closeSession(session);
1513            }
1514        }
1515
1516        return count.intValue();
1517    }
1518
1519    public int countByC_C_C(long companyId, long classNameId, long classPK)
1520        throws SystemException {
1521        Object[] finderArgs = new Object[] {
1522                new Long(companyId), new Long(classNameId), new Long(classPK)
1523            };
1524
1525        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C_C,
1526                finderArgs, this);
1527
1528        if (count == null) {
1529            Session session = null;
1530
1531            try {
1532                session = openSession();
1533
1534                StringBundler query = new StringBundler(4);
1535
1536                query.append(_SQL_COUNT_SUBSCRIPTION_WHERE);
1537
1538                query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
1539
1540                query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
1541
1542                query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
1543
1544                String sql = query.toString();
1545
1546                Query q = session.createQuery(sql);
1547
1548                QueryPos qPos = QueryPos.getInstance(q);
1549
1550                qPos.add(companyId);
1551
1552                qPos.add(classNameId);
1553
1554                qPos.add(classPK);
1555
1556                count = (Long)q.uniqueResult();
1557            }
1558            catch (Exception e) {
1559                throw processException(e);
1560            }
1561            finally {
1562                if (count == null) {
1563                    count = Long.valueOf(0);
1564                }
1565
1566                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_C,
1567                    finderArgs, count);
1568
1569                closeSession(session);
1570            }
1571        }
1572
1573        return count.intValue();
1574    }
1575
1576    public int countByC_U_C_C(long companyId, long userId, long classNameId,
1577        long classPK) throws SystemException {
1578        Object[] finderArgs = new Object[] {
1579                new Long(companyId), new Long(userId), new Long(classNameId),
1580                new Long(classPK)
1581            };
1582
1583        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_U_C_C,
1584                finderArgs, this);
1585
1586        if (count == null) {
1587            Session session = null;
1588
1589            try {
1590                session = openSession();
1591
1592                StringBundler query = new StringBundler(5);
1593
1594                query.append(_SQL_COUNT_SUBSCRIPTION_WHERE);
1595
1596                query.append(_FINDER_COLUMN_C_U_C_C_COMPANYID_2);
1597
1598                query.append(_FINDER_COLUMN_C_U_C_C_USERID_2);
1599
1600                query.append(_FINDER_COLUMN_C_U_C_C_CLASSNAMEID_2);
1601
1602                query.append(_FINDER_COLUMN_C_U_C_C_CLASSPK_2);
1603
1604                String sql = query.toString();
1605
1606                Query q = session.createQuery(sql);
1607
1608                QueryPos qPos = QueryPos.getInstance(q);
1609
1610                qPos.add(companyId);
1611
1612                qPos.add(userId);
1613
1614                qPos.add(classNameId);
1615
1616                qPos.add(classPK);
1617
1618                count = (Long)q.uniqueResult();
1619            }
1620            catch (Exception e) {
1621                throw processException(e);
1622            }
1623            finally {
1624                if (count == null) {
1625                    count = Long.valueOf(0);
1626                }
1627
1628                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_U_C_C,
1629                    finderArgs, count);
1630
1631                closeSession(session);
1632            }
1633        }
1634
1635        return count.intValue();
1636    }
1637
1638    public int countAll() throws SystemException {
1639        Object[] finderArgs = new Object[0];
1640
1641        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1642                finderArgs, this);
1643
1644        if (count == null) {
1645            Session session = null;
1646
1647            try {
1648                session = openSession();
1649
1650                Query q = session.createQuery(_SQL_COUNT_SUBSCRIPTION);
1651
1652                count = (Long)q.uniqueResult();
1653            }
1654            catch (Exception e) {
1655                throw processException(e);
1656            }
1657            finally {
1658                if (count == null) {
1659                    count = Long.valueOf(0);
1660                }
1661
1662                FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1663                    count);
1664
1665                closeSession(session);
1666            }
1667        }
1668
1669        return count.intValue();
1670    }
1671
1672    public void afterPropertiesSet() {
1673        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1674                    com.liferay.portal.util.PropsUtil.get(
1675                        "value.object.listener.com.liferay.portal.model.Subscription")));
1676
1677        if (listenerClassNames.length > 0) {
1678            try {
1679                List<ModelListener<Subscription>> listenersList = new ArrayList<ModelListener<Subscription>>();
1680
1681                for (String listenerClassName : listenerClassNames) {
1682                    listenersList.add((ModelListener<Subscription>)Class.forName(
1683                            listenerClassName).newInstance());
1684                }
1685
1686                listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1687            }
1688            catch (Exception e) {
1689                _log.error(e);
1690            }
1691        }
1692    }
1693
1694    @BeanReference(type = AccountPersistence.class)
1695    protected AccountPersistence accountPersistence;
1696    @BeanReference(type = AddressPersistence.class)
1697    protected AddressPersistence addressPersistence;
1698    @BeanReference(type = BrowserTrackerPersistence.class)
1699    protected BrowserTrackerPersistence browserTrackerPersistence;
1700    @BeanReference(type = ClassNamePersistence.class)
1701    protected ClassNamePersistence classNamePersistence;
1702    @BeanReference(type = CompanyPersistence.class)
1703    protected CompanyPersistence companyPersistence;
1704    @BeanReference(type = ContactPersistence.class)
1705    protected ContactPersistence contactPersistence;
1706    @BeanReference(type = CountryPersistence.class)
1707    protected CountryPersistence countryPersistence;
1708    @BeanReference(type = EmailAddressPersistence.class)
1709    protected EmailAddressPersistence emailAddressPersistence;
1710    @BeanReference(type = GroupPersistence.class)
1711    protected GroupPersistence groupPersistence;
1712    @BeanReference(type = ImagePersistence.class)
1713    protected ImagePersistence imagePersistence;
1714    @BeanReference(type = LayoutPersistence.class)
1715    protected LayoutPersistence layoutPersistence;
1716    @BeanReference(type = LayoutSetPersistence.class)
1717    protected LayoutSetPersistence layoutSetPersistence;
1718    @BeanReference(type = ListTypePersistence.class)
1719    protected ListTypePersistence listTypePersistence;
1720    @BeanReference(type = LockPersistence.class)
1721    protected LockPersistence lockPersistence;
1722    @BeanReference(type = MembershipRequestPersistence.class)
1723    protected MembershipRequestPersistence membershipRequestPersistence;
1724    @BeanReference(type = OrganizationPersistence.class)
1725    protected OrganizationPersistence organizationPersistence;
1726    @BeanReference(type = OrgGroupPermissionPersistence.class)
1727    protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1728    @BeanReference(type = OrgGroupRolePersistence.class)
1729    protected OrgGroupRolePersistence orgGroupRolePersistence;
1730    @BeanReference(type = OrgLaborPersistence.class)
1731    protected OrgLaborPersistence orgLaborPersistence;
1732    @BeanReference(type = PasswordPolicyPersistence.class)
1733    protected PasswordPolicyPersistence passwordPolicyPersistence;
1734    @BeanReference(type = PasswordPolicyRelPersistence.class)
1735    protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1736    @BeanReference(type = PasswordTrackerPersistence.class)
1737    protected PasswordTrackerPersistence passwordTrackerPersistence;
1738    @BeanReference(type = PermissionPersistence.class)
1739    protected PermissionPersistence permissionPersistence;
1740    @BeanReference(type = PhonePersistence.class)
1741    protected PhonePersistence phonePersistence;
1742    @BeanReference(type = PluginSettingPersistence.class)
1743    protected PluginSettingPersistence pluginSettingPersistence;
1744    @BeanReference(type = PortletPersistence.class)
1745    protected PortletPersistence portletPersistence;
1746    @BeanReference(type = PortletItemPersistence.class)
1747    protected PortletItemPersistence portletItemPersistence;
1748    @BeanReference(type = PortletPreferencesPersistence.class)
1749    protected PortletPreferencesPersistence portletPreferencesPersistence;
1750    @BeanReference(type = RegionPersistence.class)
1751    protected RegionPersistence regionPersistence;
1752    @BeanReference(type = ReleasePersistence.class)
1753    protected ReleasePersistence releasePersistence;
1754    @BeanReference(type = ResourcePersistence.class)
1755    protected ResourcePersistence resourcePersistence;
1756    @BeanReference(type = ResourceActionPersistence.class)
1757    protected ResourceActionPersistence resourceActionPersistence;
1758    @BeanReference(type = ResourceCodePersistence.class)
1759    protected ResourceCodePersistence resourceCodePersistence;
1760    @BeanReference(type = ResourcePermissionPersistence.class)
1761    protected ResourcePermissionPersistence resourcePermissionPersistence;
1762    @BeanReference(type = RolePersistence.class)
1763    protected RolePersistence rolePersistence;
1764    @BeanReference(type = ServiceComponentPersistence.class)
1765    protected ServiceComponentPersistence serviceComponentPersistence;
1766    @BeanReference(type = ShardPersistence.class)
1767    protected ShardPersistence shardPersistence;
1768    @BeanReference(type = SubscriptionPersistence.class)
1769    protected SubscriptionPersistence subscriptionPersistence;
1770    @BeanReference(type = UserPersistence.class)
1771    protected UserPersistence userPersistence;
1772    @BeanReference(type = UserGroupPersistence.class)
1773    protected UserGroupPersistence userGroupPersistence;
1774    @BeanReference(type = UserGroupGroupRolePersistence.class)
1775    protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1776    @BeanReference(type = UserGroupRolePersistence.class)
1777    protected UserGroupRolePersistence userGroupRolePersistence;
1778    @BeanReference(type = UserIdMapperPersistence.class)
1779    protected UserIdMapperPersistence userIdMapperPersistence;
1780    @BeanReference(type = UserTrackerPersistence.class)
1781    protected UserTrackerPersistence userTrackerPersistence;
1782    @BeanReference(type = UserTrackerPathPersistence.class)
1783    protected UserTrackerPathPersistence userTrackerPathPersistence;
1784    @BeanReference(type = WebDAVPropsPersistence.class)
1785    protected WebDAVPropsPersistence webDAVPropsPersistence;
1786    @BeanReference(type = WebsitePersistence.class)
1787    protected WebsitePersistence websitePersistence;
1788    private static final String _SQL_SELECT_SUBSCRIPTION = "SELECT subscription FROM Subscription subscription";
1789    private static final String _SQL_SELECT_SUBSCRIPTION_WHERE = "SELECT subscription FROM Subscription subscription WHERE ";
1790    private static final String _SQL_COUNT_SUBSCRIPTION = "SELECT COUNT(subscription) FROM Subscription subscription";
1791    private static final String _SQL_COUNT_SUBSCRIPTION_WHERE = "SELECT COUNT(subscription) FROM Subscription subscription WHERE ";
1792    private static final String _FINDER_COLUMN_USERID_USERID_2 = "subscription.userId = ?";
1793    private static final String _FINDER_COLUMN_U_C_USERID_2 = "subscription.userId = ? AND ";
1794    private static final String _FINDER_COLUMN_U_C_CLASSNAMEID_2 = "subscription.classNameId = ?";
1795    private static final String _FINDER_COLUMN_C_C_C_COMPANYID_2 = "subscription.companyId = ? AND ";
1796    private static final String _FINDER_COLUMN_C_C_C_CLASSNAMEID_2 = "subscription.classNameId = ? AND ";
1797    private static final String _FINDER_COLUMN_C_C_C_CLASSPK_2 = "subscription.classPK = ?";
1798    private static final String _FINDER_COLUMN_C_U_C_C_COMPANYID_2 = "subscription.companyId = ? AND ";
1799    private static final String _FINDER_COLUMN_C_U_C_C_USERID_2 = "subscription.userId = ? AND ";
1800    private static final String _FINDER_COLUMN_C_U_C_C_CLASSNAMEID_2 = "subscription.classNameId = ? AND ";
1801    private static final String _FINDER_COLUMN_C_U_C_C_CLASSPK_2 = "subscription.classPK = ?";
1802    private static final String _ORDER_BY_ENTITY_ALIAS = "subscription.";
1803    private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Subscription exists with the primary key ";
1804    private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Subscription exists with the key {";
1805    private static Log _log = LogFactoryUtil.getLog(SubscriptionPersistenceImpl.class);
1806}