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