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