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