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