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