001
014
015 package com.liferay.portal.service.persistence;
016
017 import com.liferay.portal.NoSuchSubscriptionException;
018 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
019 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
020 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderPath;
022 import com.liferay.portal.kernel.dao.orm.Query;
023 import com.liferay.portal.kernel.dao.orm.QueryPos;
024 import com.liferay.portal.kernel.dao.orm.QueryUtil;
025 import com.liferay.portal.kernel.dao.orm.Session;
026 import com.liferay.portal.kernel.exception.SystemException;
027 import com.liferay.portal.kernel.log.Log;
028 import com.liferay.portal.kernel.log.LogFactoryUtil;
029 import com.liferay.portal.kernel.util.ArrayUtil;
030 import com.liferay.portal.kernel.util.GetterUtil;
031 import com.liferay.portal.kernel.util.InstanceFactory;
032 import com.liferay.portal.kernel.util.OrderByComparator;
033 import com.liferay.portal.kernel.util.StringBundler;
034 import com.liferay.portal.kernel.util.StringPool;
035 import com.liferay.portal.kernel.util.StringUtil;
036 import com.liferay.portal.kernel.util.UnmodifiableList;
037 import com.liferay.portal.model.CacheModel;
038 import com.liferay.portal.model.ModelListener;
039 import com.liferay.portal.model.Subscription;
040 import com.liferay.portal.model.impl.SubscriptionImpl;
041 import com.liferay.portal.model.impl.SubscriptionModelImpl;
042 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
043
044 import java.io.Serializable;
045
046 import java.util.ArrayList;
047 import java.util.Collections;
048 import java.util.List;
049
050
062 public class SubscriptionPersistenceImpl extends BasePersistenceImpl<Subscription>
063 implements SubscriptionPersistence {
064
069 public static final String FINDER_CLASS_NAME_ENTITY = SubscriptionImpl.class.getName();
070 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
071 ".List1";
072 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
073 ".List2";
074 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
075 SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.class,
076 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
077 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
078 SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.class,
079 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
080 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
081 SubscriptionModelImpl.FINDER_CACHE_ENABLED, Long.class,
082 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
083 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
084 SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.class,
085 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUserId",
086 new String[] {
087 Long.class.getName(),
088
089 Integer.class.getName(), Integer.class.getName(),
090 OrderByComparator.class.getName()
091 });
092 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID =
093 new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
094 SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.class,
095 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId",
096 new String[] { Long.class.getName() },
097 SubscriptionModelImpl.USERID_COLUMN_BITMASK);
098 public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
099 SubscriptionModelImpl.FINDER_CACHE_ENABLED, Long.class,
100 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
101 new String[] { Long.class.getName() });
102
103
110 @Override
111 public List<Subscription> findByUserId(long userId)
112 throws SystemException {
113 return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
114 }
115
116
129 @Override
130 public List<Subscription> findByUserId(long userId, int start, int end)
131 throws SystemException {
132 return findByUserId(userId, start, end, null);
133 }
134
135
149 @Override
150 public List<Subscription> findByUserId(long userId, int start, int end,
151 OrderByComparator orderByComparator) throws SystemException {
152 boolean pagination = true;
153 FinderPath finderPath = null;
154 Object[] finderArgs = null;
155
156 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
157 (orderByComparator == null)) {
158 pagination = false;
159 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
160 finderArgs = new Object[] { userId };
161 }
162 else {
163 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
164 finderArgs = new Object[] { userId, start, end, orderByComparator };
165 }
166
167 List<Subscription> list = (List<Subscription>)FinderCacheUtil.getResult(finderPath,
168 finderArgs, this);
169
170 if ((list != null) && !list.isEmpty()) {
171 for (Subscription subscription : list) {
172 if ((userId != subscription.getUserId())) {
173 list = null;
174
175 break;
176 }
177 }
178 }
179
180 if (list == null) {
181 StringBundler query = null;
182
183 if (orderByComparator != null) {
184 query = new StringBundler(3 +
185 (orderByComparator.getOrderByFields().length * 3));
186 }
187 else {
188 query = new StringBundler(3);
189 }
190
191 query.append(_SQL_SELECT_SUBSCRIPTION_WHERE);
192
193 query.append(_FINDER_COLUMN_USERID_USERID_2);
194
195 if (orderByComparator != null) {
196 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
197 orderByComparator);
198 }
199 else
200 if (pagination) {
201 query.append(SubscriptionModelImpl.ORDER_BY_JPQL);
202 }
203
204 String sql = query.toString();
205
206 Session session = null;
207
208 try {
209 session = openSession();
210
211 Query q = session.createQuery(sql);
212
213 QueryPos qPos = QueryPos.getInstance(q);
214
215 qPos.add(userId);
216
217 if (!pagination) {
218 list = (List<Subscription>)QueryUtil.list(q, getDialect(),
219 start, end, false);
220
221 Collections.sort(list);
222
223 list = new UnmodifiableList<Subscription>(list);
224 }
225 else {
226 list = (List<Subscription>)QueryUtil.list(q, getDialect(),
227 start, end);
228 }
229
230 cacheResult(list);
231
232 FinderCacheUtil.putResult(finderPath, finderArgs, list);
233 }
234 catch (Exception e) {
235 FinderCacheUtil.removeResult(finderPath, finderArgs);
236
237 throw processException(e);
238 }
239 finally {
240 closeSession(session);
241 }
242 }
243
244 return list;
245 }
246
247
256 @Override
257 public Subscription findByUserId_First(long userId,
258 OrderByComparator orderByComparator)
259 throws NoSuchSubscriptionException, SystemException {
260 Subscription subscription = fetchByUserId_First(userId,
261 orderByComparator);
262
263 if (subscription != null) {
264 return subscription;
265 }
266
267 StringBundler msg = new StringBundler(4);
268
269 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
270
271 msg.append("userId=");
272 msg.append(userId);
273
274 msg.append(StringPool.CLOSE_CURLY_BRACE);
275
276 throw new NoSuchSubscriptionException(msg.toString());
277 }
278
279
287 @Override
288 public Subscription fetchByUserId_First(long userId,
289 OrderByComparator orderByComparator) throws SystemException {
290 List<Subscription> list = findByUserId(userId, 0, 1, orderByComparator);
291
292 if (!list.isEmpty()) {
293 return list.get(0);
294 }
295
296 return null;
297 }
298
299
308 @Override
309 public Subscription findByUserId_Last(long userId,
310 OrderByComparator orderByComparator)
311 throws NoSuchSubscriptionException, SystemException {
312 Subscription subscription = fetchByUserId_Last(userId, orderByComparator);
313
314 if (subscription != null) {
315 return subscription;
316 }
317
318 StringBundler msg = new StringBundler(4);
319
320 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
321
322 msg.append("userId=");
323 msg.append(userId);
324
325 msg.append(StringPool.CLOSE_CURLY_BRACE);
326
327 throw new NoSuchSubscriptionException(msg.toString());
328 }
329
330
338 @Override
339 public Subscription fetchByUserId_Last(long userId,
340 OrderByComparator orderByComparator) throws SystemException {
341 int count = countByUserId(userId);
342
343 if (count == 0) {
344 return null;
345 }
346
347 List<Subscription> list = findByUserId(userId, count - 1, count,
348 orderByComparator);
349
350 if (!list.isEmpty()) {
351 return list.get(0);
352 }
353
354 return null;
355 }
356
357
367 @Override
368 public Subscription[] findByUserId_PrevAndNext(long subscriptionId,
369 long userId, OrderByComparator orderByComparator)
370 throws NoSuchSubscriptionException, SystemException {
371 Subscription subscription = findByPrimaryKey(subscriptionId);
372
373 Session session = null;
374
375 try {
376 session = openSession();
377
378 Subscription[] array = new SubscriptionImpl[3];
379
380 array[0] = getByUserId_PrevAndNext(session, subscription, userId,
381 orderByComparator, true);
382
383 array[1] = subscription;
384
385 array[2] = getByUserId_PrevAndNext(session, subscription, userId,
386 orderByComparator, false);
387
388 return array;
389 }
390 catch (Exception e) {
391 throw processException(e);
392 }
393 finally {
394 closeSession(session);
395 }
396 }
397
398 protected Subscription getByUserId_PrevAndNext(Session session,
399 Subscription subscription, long userId,
400 OrderByComparator orderByComparator, boolean previous) {
401 StringBundler query = null;
402
403 if (orderByComparator != null) {
404 query = new StringBundler(6 +
405 (orderByComparator.getOrderByFields().length * 6));
406 }
407 else {
408 query = new StringBundler(3);
409 }
410
411 query.append(_SQL_SELECT_SUBSCRIPTION_WHERE);
412
413 query.append(_FINDER_COLUMN_USERID_USERID_2);
414
415 if (orderByComparator != null) {
416 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
417
418 if (orderByConditionFields.length > 0) {
419 query.append(WHERE_AND);
420 }
421
422 for (int i = 0; i < orderByConditionFields.length; i++) {
423 query.append(_ORDER_BY_ENTITY_ALIAS);
424 query.append(orderByConditionFields[i]);
425
426 if ((i + 1) < orderByConditionFields.length) {
427 if (orderByComparator.isAscending() ^ previous) {
428 query.append(WHERE_GREATER_THAN_HAS_NEXT);
429 }
430 else {
431 query.append(WHERE_LESSER_THAN_HAS_NEXT);
432 }
433 }
434 else {
435 if (orderByComparator.isAscending() ^ previous) {
436 query.append(WHERE_GREATER_THAN);
437 }
438 else {
439 query.append(WHERE_LESSER_THAN);
440 }
441 }
442 }
443
444 query.append(ORDER_BY_CLAUSE);
445
446 String[] orderByFields = orderByComparator.getOrderByFields();
447
448 for (int i = 0; i < orderByFields.length; i++) {
449 query.append(_ORDER_BY_ENTITY_ALIAS);
450 query.append(orderByFields[i]);
451
452 if ((i + 1) < orderByFields.length) {
453 if (orderByComparator.isAscending() ^ previous) {
454 query.append(ORDER_BY_ASC_HAS_NEXT);
455 }
456 else {
457 query.append(ORDER_BY_DESC_HAS_NEXT);
458 }
459 }
460 else {
461 if (orderByComparator.isAscending() ^ previous) {
462 query.append(ORDER_BY_ASC);
463 }
464 else {
465 query.append(ORDER_BY_DESC);
466 }
467 }
468 }
469 }
470 else {
471 query.append(SubscriptionModelImpl.ORDER_BY_JPQL);
472 }
473
474 String sql = query.toString();
475
476 Query q = session.createQuery(sql);
477
478 q.setFirstResult(0);
479 q.setMaxResults(2);
480
481 QueryPos qPos = QueryPos.getInstance(q);
482
483 qPos.add(userId);
484
485 if (orderByComparator != null) {
486 Object[] values = orderByComparator.getOrderByConditionValues(subscription);
487
488 for (Object value : values) {
489 qPos.add(value);
490 }
491 }
492
493 List<Subscription> list = q.list();
494
495 if (list.size() == 2) {
496 return list.get(1);
497 }
498 else {
499 return null;
500 }
501 }
502
503
509 @Override
510 public void removeByUserId(long userId) throws SystemException {
511 for (Subscription subscription : findByUserId(userId,
512 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
513 remove(subscription);
514 }
515 }
516
517
524 @Override
525 public int countByUserId(long userId) throws SystemException {
526 FinderPath finderPath = FINDER_PATH_COUNT_BY_USERID;
527
528 Object[] finderArgs = new Object[] { userId };
529
530 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
531 this);
532
533 if (count == null) {
534 StringBundler query = new StringBundler(2);
535
536 query.append(_SQL_COUNT_SUBSCRIPTION_WHERE);
537
538 query.append(_FINDER_COLUMN_USERID_USERID_2);
539
540 String sql = query.toString();
541
542 Session session = null;
543
544 try {
545 session = openSession();
546
547 Query q = session.createQuery(sql);
548
549 QueryPos qPos = QueryPos.getInstance(q);
550
551 qPos.add(userId);
552
553 count = (Long)q.uniqueResult();
554
555 FinderCacheUtil.putResult(finderPath, finderArgs, count);
556 }
557 catch (Exception e) {
558 FinderCacheUtil.removeResult(finderPath, finderArgs);
559
560 throw processException(e);
561 }
562 finally {
563 closeSession(session);
564 }
565 }
566
567 return count.intValue();
568 }
569
570 private static final String _FINDER_COLUMN_USERID_USERID_2 = "subscription.userId = ?";
571 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
572 SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.class,
573 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C",
574 new String[] {
575 Long.class.getName(), Long.class.getName(),
576
577 Integer.class.getName(), Integer.class.getName(),
578 OrderByComparator.class.getName()
579 });
580 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
581 SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.class,
582 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C",
583 new String[] { Long.class.getName(), Long.class.getName() },
584 SubscriptionModelImpl.USERID_COLUMN_BITMASK |
585 SubscriptionModelImpl.CLASSNAMEID_COLUMN_BITMASK);
586 public static final FinderPath FINDER_PATH_COUNT_BY_U_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
587 SubscriptionModelImpl.FINDER_CACHE_ENABLED, Long.class,
588 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C",
589 new String[] { Long.class.getName(), Long.class.getName() });
590
591
599 @Override
600 public List<Subscription> findByU_C(long userId, long classNameId)
601 throws SystemException {
602 return findByU_C(userId, classNameId, QueryUtil.ALL_POS,
603 QueryUtil.ALL_POS, null);
604 }
605
606
620 @Override
621 public List<Subscription> findByU_C(long userId, long classNameId,
622 int start, int end) throws SystemException {
623 return findByU_C(userId, classNameId, start, end, null);
624 }
625
626
641 @Override
642 public List<Subscription> findByU_C(long userId, long classNameId,
643 int start, int end, OrderByComparator orderByComparator)
644 throws SystemException {
645 boolean pagination = true;
646 FinderPath finderPath = null;
647 Object[] finderArgs = null;
648
649 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
650 (orderByComparator == null)) {
651 pagination = false;
652 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C;
653 finderArgs = new Object[] { userId, classNameId };
654 }
655 else {
656 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C;
657 finderArgs = new Object[] {
658 userId, classNameId,
659
660 start, end, orderByComparator
661 };
662 }
663
664 List<Subscription> list = (List<Subscription>)FinderCacheUtil.getResult(finderPath,
665 finderArgs, this);
666
667 if ((list != null) && !list.isEmpty()) {
668 for (Subscription subscription : list) {
669 if ((userId != subscription.getUserId()) ||
670 (classNameId != subscription.getClassNameId())) {
671 list = null;
672
673 break;
674 }
675 }
676 }
677
678 if (list == null) {
679 StringBundler query = null;
680
681 if (orderByComparator != null) {
682 query = new StringBundler(4 +
683 (orderByComparator.getOrderByFields().length * 3));
684 }
685 else {
686 query = new StringBundler(4);
687 }
688
689 query.append(_SQL_SELECT_SUBSCRIPTION_WHERE);
690
691 query.append(_FINDER_COLUMN_U_C_USERID_2);
692
693 query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
694
695 if (orderByComparator != null) {
696 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
697 orderByComparator);
698 }
699 else
700 if (pagination) {
701 query.append(SubscriptionModelImpl.ORDER_BY_JPQL);
702 }
703
704 String sql = query.toString();
705
706 Session session = null;
707
708 try {
709 session = openSession();
710
711 Query q = session.createQuery(sql);
712
713 QueryPos qPos = QueryPos.getInstance(q);
714
715 qPos.add(userId);
716
717 qPos.add(classNameId);
718
719 if (!pagination) {
720 list = (List<Subscription>)QueryUtil.list(q, getDialect(),
721 start, end, false);
722
723 Collections.sort(list);
724
725 list = new UnmodifiableList<Subscription>(list);
726 }
727 else {
728 list = (List<Subscription>)QueryUtil.list(q, getDialect(),
729 start, end);
730 }
731
732 cacheResult(list);
733
734 FinderCacheUtil.putResult(finderPath, finderArgs, list);
735 }
736 catch (Exception e) {
737 FinderCacheUtil.removeResult(finderPath, finderArgs);
738
739 throw processException(e);
740 }
741 finally {
742 closeSession(session);
743 }
744 }
745
746 return list;
747 }
748
749
759 @Override
760 public Subscription findByU_C_First(long userId, long classNameId,
761 OrderByComparator orderByComparator)
762 throws NoSuchSubscriptionException, SystemException {
763 Subscription subscription = fetchByU_C_First(userId, classNameId,
764 orderByComparator);
765
766 if (subscription != null) {
767 return subscription;
768 }
769
770 StringBundler msg = new StringBundler(6);
771
772 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
773
774 msg.append("userId=");
775 msg.append(userId);
776
777 msg.append(", classNameId=");
778 msg.append(classNameId);
779
780 msg.append(StringPool.CLOSE_CURLY_BRACE);
781
782 throw new NoSuchSubscriptionException(msg.toString());
783 }
784
785
794 @Override
795 public Subscription fetchByU_C_First(long userId, long classNameId,
796 OrderByComparator orderByComparator) throws SystemException {
797 List<Subscription> list = findByU_C(userId, classNameId, 0, 1,
798 orderByComparator);
799
800 if (!list.isEmpty()) {
801 return list.get(0);
802 }
803
804 return null;
805 }
806
807
817 @Override
818 public Subscription findByU_C_Last(long userId, long classNameId,
819 OrderByComparator orderByComparator)
820 throws NoSuchSubscriptionException, SystemException {
821 Subscription subscription = fetchByU_C_Last(userId, classNameId,
822 orderByComparator);
823
824 if (subscription != null) {
825 return subscription;
826 }
827
828 StringBundler msg = new StringBundler(6);
829
830 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
831
832 msg.append("userId=");
833 msg.append(userId);
834
835 msg.append(", classNameId=");
836 msg.append(classNameId);
837
838 msg.append(StringPool.CLOSE_CURLY_BRACE);
839
840 throw new NoSuchSubscriptionException(msg.toString());
841 }
842
843
852 @Override
853 public Subscription fetchByU_C_Last(long userId, long classNameId,
854 OrderByComparator orderByComparator) throws SystemException {
855 int count = countByU_C(userId, classNameId);
856
857 if (count == 0) {
858 return null;
859 }
860
861 List<Subscription> list = findByU_C(userId, classNameId, count - 1,
862 count, orderByComparator);
863
864 if (!list.isEmpty()) {
865 return list.get(0);
866 }
867
868 return null;
869 }
870
871
882 @Override
883 public Subscription[] findByU_C_PrevAndNext(long subscriptionId,
884 long userId, long classNameId, OrderByComparator orderByComparator)
885 throws NoSuchSubscriptionException, SystemException {
886 Subscription subscription = findByPrimaryKey(subscriptionId);
887
888 Session session = null;
889
890 try {
891 session = openSession();
892
893 Subscription[] array = new SubscriptionImpl[3];
894
895 array[0] = getByU_C_PrevAndNext(session, subscription, userId,
896 classNameId, orderByComparator, true);
897
898 array[1] = subscription;
899
900 array[2] = getByU_C_PrevAndNext(session, subscription, userId,
901 classNameId, orderByComparator, false);
902
903 return array;
904 }
905 catch (Exception e) {
906 throw processException(e);
907 }
908 finally {
909 closeSession(session);
910 }
911 }
912
913 protected Subscription getByU_C_PrevAndNext(Session session,
914 Subscription subscription, long userId, long classNameId,
915 OrderByComparator orderByComparator, boolean previous) {
916 StringBundler query = null;
917
918 if (orderByComparator != null) {
919 query = new StringBundler(6 +
920 (orderByComparator.getOrderByFields().length * 6));
921 }
922 else {
923 query = new StringBundler(3);
924 }
925
926 query.append(_SQL_SELECT_SUBSCRIPTION_WHERE);
927
928 query.append(_FINDER_COLUMN_U_C_USERID_2);
929
930 query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
931
932 if (orderByComparator != null) {
933 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
934
935 if (orderByConditionFields.length > 0) {
936 query.append(WHERE_AND);
937 }
938
939 for (int i = 0; i < orderByConditionFields.length; i++) {
940 query.append(_ORDER_BY_ENTITY_ALIAS);
941 query.append(orderByConditionFields[i]);
942
943 if ((i + 1) < orderByConditionFields.length) {
944 if (orderByComparator.isAscending() ^ previous) {
945 query.append(WHERE_GREATER_THAN_HAS_NEXT);
946 }
947 else {
948 query.append(WHERE_LESSER_THAN_HAS_NEXT);
949 }
950 }
951 else {
952 if (orderByComparator.isAscending() ^ previous) {
953 query.append(WHERE_GREATER_THAN);
954 }
955 else {
956 query.append(WHERE_LESSER_THAN);
957 }
958 }
959 }
960
961 query.append(ORDER_BY_CLAUSE);
962
963 String[] orderByFields = orderByComparator.getOrderByFields();
964
965 for (int i = 0; i < orderByFields.length; i++) {
966 query.append(_ORDER_BY_ENTITY_ALIAS);
967 query.append(orderByFields[i]);
968
969 if ((i + 1) < orderByFields.length) {
970 if (orderByComparator.isAscending() ^ previous) {
971 query.append(ORDER_BY_ASC_HAS_NEXT);
972 }
973 else {
974 query.append(ORDER_BY_DESC_HAS_NEXT);
975 }
976 }
977 else {
978 if (orderByComparator.isAscending() ^ previous) {
979 query.append(ORDER_BY_ASC);
980 }
981 else {
982 query.append(ORDER_BY_DESC);
983 }
984 }
985 }
986 }
987 else {
988 query.append(SubscriptionModelImpl.ORDER_BY_JPQL);
989 }
990
991 String sql = query.toString();
992
993 Query q = session.createQuery(sql);
994
995 q.setFirstResult(0);
996 q.setMaxResults(2);
997
998 QueryPos qPos = QueryPos.getInstance(q);
999
1000 qPos.add(userId);
1001
1002 qPos.add(classNameId);
1003
1004 if (orderByComparator != null) {
1005 Object[] values = orderByComparator.getOrderByConditionValues(subscription);
1006
1007 for (Object value : values) {
1008 qPos.add(value);
1009 }
1010 }
1011
1012 List<Subscription> list = q.list();
1013
1014 if (list.size() == 2) {
1015 return list.get(1);
1016 }
1017 else {
1018 return null;
1019 }
1020 }
1021
1022
1029 @Override
1030 public void removeByU_C(long userId, long classNameId)
1031 throws SystemException {
1032 for (Subscription subscription : findByU_C(userId, classNameId,
1033 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1034 remove(subscription);
1035 }
1036 }
1037
1038
1046 @Override
1047 public int countByU_C(long userId, long classNameId)
1048 throws SystemException {
1049 FinderPath finderPath = FINDER_PATH_COUNT_BY_U_C;
1050
1051 Object[] finderArgs = new Object[] { userId, classNameId };
1052
1053 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1054 this);
1055
1056 if (count == null) {
1057 StringBundler query = new StringBundler(3);
1058
1059 query.append(_SQL_COUNT_SUBSCRIPTION_WHERE);
1060
1061 query.append(_FINDER_COLUMN_U_C_USERID_2);
1062
1063 query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
1064
1065 String sql = query.toString();
1066
1067 Session session = null;
1068
1069 try {
1070 session = openSession();
1071
1072 Query q = session.createQuery(sql);
1073
1074 QueryPos qPos = QueryPos.getInstance(q);
1075
1076 qPos.add(userId);
1077
1078 qPos.add(classNameId);
1079
1080 count = (Long)q.uniqueResult();
1081
1082 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1083 }
1084 catch (Exception e) {
1085 FinderCacheUtil.removeResult(finderPath, finderArgs);
1086
1087 throw processException(e);
1088 }
1089 finally {
1090 closeSession(session);
1091 }
1092 }
1093
1094 return count.intValue();
1095 }
1096
1097 private static final String _FINDER_COLUMN_U_C_USERID_2 = "subscription.userId = ? AND ";
1098 private static final String _FINDER_COLUMN_U_C_CLASSNAMEID_2 = "subscription.classNameId = ?";
1099 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
1100 SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.class,
1101 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C_C",
1102 new String[] {
1103 Long.class.getName(), Long.class.getName(), Long.class.getName(),
1104
1105 Integer.class.getName(), Integer.class.getName(),
1106 OrderByComparator.class.getName()
1107 });
1108 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
1109 SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.class,
1110 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C_C",
1111 new String[] {
1112 Long.class.getName(), Long.class.getName(), Long.class.getName()
1113 },
1114 SubscriptionModelImpl.COMPANYID_COLUMN_BITMASK |
1115 SubscriptionModelImpl.CLASSNAMEID_COLUMN_BITMASK |
1116 SubscriptionModelImpl.CLASSPK_COLUMN_BITMASK);
1117 public static final FinderPath FINDER_PATH_COUNT_BY_C_C_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
1118 SubscriptionModelImpl.FINDER_CACHE_ENABLED, Long.class,
1119 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_C",
1120 new String[] {
1121 Long.class.getName(), Long.class.getName(), Long.class.getName()
1122 });
1123
1124
1133 @Override
1134 public List<Subscription> findByC_C_C(long companyId, long classNameId,
1135 long classPK) throws SystemException {
1136 return findByC_C_C(companyId, classNameId, classPK, QueryUtil.ALL_POS,
1137 QueryUtil.ALL_POS, null);
1138 }
1139
1140
1155 @Override
1156 public List<Subscription> findByC_C_C(long companyId, long classNameId,
1157 long classPK, int start, int end) throws SystemException {
1158 return findByC_C_C(companyId, classNameId, classPK, start, end, null);
1159 }
1160
1161
1177 @Override
1178 public List<Subscription> findByC_C_C(long companyId, long classNameId,
1179 long classPK, int start, int end, OrderByComparator orderByComparator)
1180 throws SystemException {
1181 boolean pagination = true;
1182 FinderPath finderPath = null;
1183 Object[] finderArgs = null;
1184
1185 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1186 (orderByComparator == null)) {
1187 pagination = false;
1188 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C;
1189 finderArgs = new Object[] { companyId, classNameId, classPK };
1190 }
1191 else {
1192 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_C;
1193 finderArgs = new Object[] {
1194 companyId, classNameId, classPK,
1195
1196 start, end, orderByComparator
1197 };
1198 }
1199
1200 List<Subscription> list = (List<Subscription>)FinderCacheUtil.getResult(finderPath,
1201 finderArgs, this);
1202
1203 if ((list != null) && !list.isEmpty()) {
1204 for (Subscription subscription : list) {
1205 if ((companyId != subscription.getCompanyId()) ||
1206 (classNameId != subscription.getClassNameId()) ||
1207 (classPK != subscription.getClassPK())) {
1208 list = null;
1209
1210 break;
1211 }
1212 }
1213 }
1214
1215 if (list == null) {
1216 StringBundler query = null;
1217
1218 if (orderByComparator != null) {
1219 query = new StringBundler(5 +
1220 (orderByComparator.getOrderByFields().length * 3));
1221 }
1222 else {
1223 query = new StringBundler(5);
1224 }
1225
1226 query.append(_SQL_SELECT_SUBSCRIPTION_WHERE);
1227
1228 query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
1229
1230 query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
1231
1232 query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
1233
1234 if (orderByComparator != null) {
1235 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1236 orderByComparator);
1237 }
1238 else
1239 if (pagination) {
1240 query.append(SubscriptionModelImpl.ORDER_BY_JPQL);
1241 }
1242
1243 String sql = query.toString();
1244
1245 Session session = null;
1246
1247 try {
1248 session = openSession();
1249
1250 Query q = session.createQuery(sql);
1251
1252 QueryPos qPos = QueryPos.getInstance(q);
1253
1254 qPos.add(companyId);
1255
1256 qPos.add(classNameId);
1257
1258 qPos.add(classPK);
1259
1260 if (!pagination) {
1261 list = (List<Subscription>)QueryUtil.list(q, getDialect(),
1262 start, end, false);
1263
1264 Collections.sort(list);
1265
1266 list = new UnmodifiableList<Subscription>(list);
1267 }
1268 else {
1269 list = (List<Subscription>)QueryUtil.list(q, getDialect(),
1270 start, end);
1271 }
1272
1273 cacheResult(list);
1274
1275 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1276 }
1277 catch (Exception e) {
1278 FinderCacheUtil.removeResult(finderPath, finderArgs);
1279
1280 throw processException(e);
1281 }
1282 finally {
1283 closeSession(session);
1284 }
1285 }
1286
1287 return list;
1288 }
1289
1290
1301 @Override
1302 public Subscription findByC_C_C_First(long companyId, long classNameId,
1303 long classPK, OrderByComparator orderByComparator)
1304 throws NoSuchSubscriptionException, SystemException {
1305 Subscription subscription = fetchByC_C_C_First(companyId, classNameId,
1306 classPK, orderByComparator);
1307
1308 if (subscription != null) {
1309 return subscription;
1310 }
1311
1312 StringBundler msg = new StringBundler(8);
1313
1314 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1315
1316 msg.append("companyId=");
1317 msg.append(companyId);
1318
1319 msg.append(", classNameId=");
1320 msg.append(classNameId);
1321
1322 msg.append(", classPK=");
1323 msg.append(classPK);
1324
1325 msg.append(StringPool.CLOSE_CURLY_BRACE);
1326
1327 throw new NoSuchSubscriptionException(msg.toString());
1328 }
1329
1330
1340 @Override
1341 public Subscription fetchByC_C_C_First(long companyId, long classNameId,
1342 long classPK, OrderByComparator orderByComparator)
1343 throws SystemException {
1344 List<Subscription> list = findByC_C_C(companyId, classNameId, classPK,
1345 0, 1, orderByComparator);
1346
1347 if (!list.isEmpty()) {
1348 return list.get(0);
1349 }
1350
1351 return null;
1352 }
1353
1354
1365 @Override
1366 public Subscription findByC_C_C_Last(long companyId, long classNameId,
1367 long classPK, OrderByComparator orderByComparator)
1368 throws NoSuchSubscriptionException, SystemException {
1369 Subscription subscription = fetchByC_C_C_Last(companyId, classNameId,
1370 classPK, orderByComparator);
1371
1372 if (subscription != null) {
1373 return subscription;
1374 }
1375
1376 StringBundler msg = new StringBundler(8);
1377
1378 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1379
1380 msg.append("companyId=");
1381 msg.append(companyId);
1382
1383 msg.append(", classNameId=");
1384 msg.append(classNameId);
1385
1386 msg.append(", classPK=");
1387 msg.append(classPK);
1388
1389 msg.append(StringPool.CLOSE_CURLY_BRACE);
1390
1391 throw new NoSuchSubscriptionException(msg.toString());
1392 }
1393
1394
1404 @Override
1405 public Subscription fetchByC_C_C_Last(long companyId, long classNameId,
1406 long classPK, OrderByComparator orderByComparator)
1407 throws SystemException {
1408 int count = countByC_C_C(companyId, classNameId, classPK);
1409
1410 if (count == 0) {
1411 return null;
1412 }
1413
1414 List<Subscription> list = findByC_C_C(companyId, classNameId, classPK,
1415 count - 1, count, orderByComparator);
1416
1417 if (!list.isEmpty()) {
1418 return list.get(0);
1419 }
1420
1421 return null;
1422 }
1423
1424
1436 @Override
1437 public Subscription[] findByC_C_C_PrevAndNext(long subscriptionId,
1438 long companyId, long classNameId, long classPK,
1439 OrderByComparator orderByComparator)
1440 throws NoSuchSubscriptionException, SystemException {
1441 Subscription subscription = findByPrimaryKey(subscriptionId);
1442
1443 Session session = null;
1444
1445 try {
1446 session = openSession();
1447
1448 Subscription[] array = new SubscriptionImpl[3];
1449
1450 array[0] = getByC_C_C_PrevAndNext(session, subscription, companyId,
1451 classNameId, classPK, orderByComparator, true);
1452
1453 array[1] = subscription;
1454
1455 array[2] = getByC_C_C_PrevAndNext(session, subscription, companyId,
1456 classNameId, classPK, orderByComparator, false);
1457
1458 return array;
1459 }
1460 catch (Exception e) {
1461 throw processException(e);
1462 }
1463 finally {
1464 closeSession(session);
1465 }
1466 }
1467
1468 protected Subscription getByC_C_C_PrevAndNext(Session session,
1469 Subscription subscription, long companyId, long classNameId,
1470 long classPK, OrderByComparator orderByComparator, boolean previous) {
1471 StringBundler query = null;
1472
1473 if (orderByComparator != null) {
1474 query = new StringBundler(6 +
1475 (orderByComparator.getOrderByFields().length * 6));
1476 }
1477 else {
1478 query = new StringBundler(3);
1479 }
1480
1481 query.append(_SQL_SELECT_SUBSCRIPTION_WHERE);
1482
1483 query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
1484
1485 query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
1486
1487 query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
1488
1489 if (orderByComparator != null) {
1490 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1491
1492 if (orderByConditionFields.length > 0) {
1493 query.append(WHERE_AND);
1494 }
1495
1496 for (int i = 0; i < orderByConditionFields.length; i++) {
1497 query.append(_ORDER_BY_ENTITY_ALIAS);
1498 query.append(orderByConditionFields[i]);
1499
1500 if ((i + 1) < orderByConditionFields.length) {
1501 if (orderByComparator.isAscending() ^ previous) {
1502 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1503 }
1504 else {
1505 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1506 }
1507 }
1508 else {
1509 if (orderByComparator.isAscending() ^ previous) {
1510 query.append(WHERE_GREATER_THAN);
1511 }
1512 else {
1513 query.append(WHERE_LESSER_THAN);
1514 }
1515 }
1516 }
1517
1518 query.append(ORDER_BY_CLAUSE);
1519
1520 String[] orderByFields = orderByComparator.getOrderByFields();
1521
1522 for (int i = 0; i < orderByFields.length; i++) {
1523 query.append(_ORDER_BY_ENTITY_ALIAS);
1524 query.append(orderByFields[i]);
1525
1526 if ((i + 1) < orderByFields.length) {
1527 if (orderByComparator.isAscending() ^ previous) {
1528 query.append(ORDER_BY_ASC_HAS_NEXT);
1529 }
1530 else {
1531 query.append(ORDER_BY_DESC_HAS_NEXT);
1532 }
1533 }
1534 else {
1535 if (orderByComparator.isAscending() ^ previous) {
1536 query.append(ORDER_BY_ASC);
1537 }
1538 else {
1539 query.append(ORDER_BY_DESC);
1540 }
1541 }
1542 }
1543 }
1544 else {
1545 query.append(SubscriptionModelImpl.ORDER_BY_JPQL);
1546 }
1547
1548 String sql = query.toString();
1549
1550 Query q = session.createQuery(sql);
1551
1552 q.setFirstResult(0);
1553 q.setMaxResults(2);
1554
1555 QueryPos qPos = QueryPos.getInstance(q);
1556
1557 qPos.add(companyId);
1558
1559 qPos.add(classNameId);
1560
1561 qPos.add(classPK);
1562
1563 if (orderByComparator != null) {
1564 Object[] values = orderByComparator.getOrderByConditionValues(subscription);
1565
1566 for (Object value : values) {
1567 qPos.add(value);
1568 }
1569 }
1570
1571 List<Subscription> list = q.list();
1572
1573 if (list.size() == 2) {
1574 return list.get(1);
1575 }
1576 else {
1577 return null;
1578 }
1579 }
1580
1581
1589 @Override
1590 public void removeByC_C_C(long companyId, long classNameId, long classPK)
1591 throws SystemException {
1592 for (Subscription subscription : findByC_C_C(companyId, classNameId,
1593 classPK, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1594 remove(subscription);
1595 }
1596 }
1597
1598
1607 @Override
1608 public int countByC_C_C(long companyId, long classNameId, long classPK)
1609 throws SystemException {
1610 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C_C;
1611
1612 Object[] finderArgs = new Object[] { companyId, classNameId, classPK };
1613
1614 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1615 this);
1616
1617 if (count == null) {
1618 StringBundler query = new StringBundler(4);
1619
1620 query.append(_SQL_COUNT_SUBSCRIPTION_WHERE);
1621
1622 query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
1623
1624 query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
1625
1626 query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
1627
1628 String sql = query.toString();
1629
1630 Session session = null;
1631
1632 try {
1633 session = openSession();
1634
1635 Query q = session.createQuery(sql);
1636
1637 QueryPos qPos = QueryPos.getInstance(q);
1638
1639 qPos.add(companyId);
1640
1641 qPos.add(classNameId);
1642
1643 qPos.add(classPK);
1644
1645 count = (Long)q.uniqueResult();
1646
1647 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1648 }
1649 catch (Exception e) {
1650 FinderCacheUtil.removeResult(finderPath, finderArgs);
1651
1652 throw processException(e);
1653 }
1654 finally {
1655 closeSession(session);
1656 }
1657 }
1658
1659 return count.intValue();
1660 }
1661
1662 private static final String _FINDER_COLUMN_C_C_C_COMPANYID_2 = "subscription.companyId = ? AND ";
1663 private static final String _FINDER_COLUMN_C_C_C_CLASSNAMEID_2 = "subscription.classNameId = ? AND ";
1664 private static final String _FINDER_COLUMN_C_C_C_CLASSPK_2 = "subscription.classPK = ?";
1665 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_U_C_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
1666 SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.class,
1667 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_U_C_C",
1668 new String[] {
1669 Long.class.getName(), Long.class.getName(), Long.class.getName(),
1670 Long.class.getName(),
1671
1672 Integer.class.getName(), Integer.class.getName(),
1673 OrderByComparator.class.getName()
1674 });
1675 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_U_C_C =
1676 new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
1677 SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.class,
1678 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_U_C_C",
1679 new String[] {
1680 Long.class.getName(), Long.class.getName(), Long.class.getName(),
1681 Long.class.getName()
1682 },
1683 SubscriptionModelImpl.COMPANYID_COLUMN_BITMASK |
1684 SubscriptionModelImpl.USERID_COLUMN_BITMASK |
1685 SubscriptionModelImpl.CLASSNAMEID_COLUMN_BITMASK |
1686 SubscriptionModelImpl.CLASSPK_COLUMN_BITMASK);
1687 public static final FinderPath FINDER_PATH_FETCH_BY_C_U_C_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
1688 SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.class,
1689 FINDER_CLASS_NAME_ENTITY, "fetchByC_U_C_C",
1690 new String[] {
1691 Long.class.getName(), Long.class.getName(), Long.class.getName(),
1692 Long.class.getName()
1693 },
1694 SubscriptionModelImpl.COMPANYID_COLUMN_BITMASK |
1695 SubscriptionModelImpl.USERID_COLUMN_BITMASK |
1696 SubscriptionModelImpl.CLASSNAMEID_COLUMN_BITMASK |
1697 SubscriptionModelImpl.CLASSPK_COLUMN_BITMASK);
1698 public static final FinderPath FINDER_PATH_COUNT_BY_C_U_C_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
1699 SubscriptionModelImpl.FINDER_CACHE_ENABLED, Long.class,
1700 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_U_C_C",
1701 new String[] {
1702 Long.class.getName(), Long.class.getName(), Long.class.getName(),
1703 Long.class.getName()
1704 });
1705 public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_U_C_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
1706 SubscriptionModelImpl.FINDER_CACHE_ENABLED, Long.class,
1707 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByC_U_C_C",
1708 new String[] {
1709 Long.class.getName(), Long.class.getName(), Long.class.getName(),
1710 Long.class.getName()
1711 });
1712
1713
1727 @Override
1728 public List<Subscription> findByC_U_C_C(long companyId, long userId,
1729 long classNameId, long[] classPKs) throws SystemException {
1730 return findByC_U_C_C(companyId, userId, classNameId, classPKs,
1731 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1732 }
1733
1734
1750 @Override
1751 public List<Subscription> findByC_U_C_C(long companyId, long userId,
1752 long classNameId, long[] classPKs, int start, int end)
1753 throws SystemException {
1754 return findByC_U_C_C(companyId, userId, classNameId, classPKs, start,
1755 end, null);
1756 }
1757
1758
1775 @Override
1776 public List<Subscription> findByC_U_C_C(long companyId, long userId,
1777 long classNameId, long[] classPKs, int start, int end,
1778 OrderByComparator orderByComparator) throws SystemException {
1779 if ((classPKs != null) && (classPKs.length == 1)) {
1780 Subscription subscription = fetchByC_U_C_C(companyId, userId,
1781 classNameId, classPKs[0]);
1782
1783 if (subscription == null) {
1784 return Collections.emptyList();
1785 }
1786 else {
1787 List<Subscription> list = new ArrayList<Subscription>(1);
1788
1789 list.add(subscription);
1790
1791 return list;
1792 }
1793 }
1794
1795 boolean pagination = true;
1796 Object[] finderArgs = null;
1797
1798 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1799 (orderByComparator == null)) {
1800 pagination = false;
1801 finderArgs = new Object[] {
1802 companyId, userId, classNameId, StringUtil.merge(classPKs)
1803 };
1804 }
1805 else {
1806 finderArgs = new Object[] {
1807 companyId, userId, classNameId, StringUtil.merge(classPKs),
1808
1809 start, end, orderByComparator
1810 };
1811 }
1812
1813 List<Subscription> list = (List<Subscription>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_C_U_C_C,
1814 finderArgs, this);
1815
1816 if ((list != null) && !list.isEmpty()) {
1817 for (Subscription subscription : list) {
1818 if ((companyId != subscription.getCompanyId()) ||
1819 (userId != subscription.getUserId()) ||
1820 (classNameId != subscription.getClassNameId()) ||
1821 !ArrayUtil.contains(classPKs, subscription.getClassPK())) {
1822 list = null;
1823
1824 break;
1825 }
1826 }
1827 }
1828
1829 if (list == null) {
1830 StringBundler query = new StringBundler();
1831
1832 query.append(_SQL_SELECT_SUBSCRIPTION_WHERE);
1833
1834 boolean conjunctionable = false;
1835
1836 if (conjunctionable) {
1837 query.append(WHERE_AND);
1838 }
1839
1840 query.append(_FINDER_COLUMN_C_U_C_C_COMPANYID_5);
1841
1842 conjunctionable = true;
1843
1844 if (conjunctionable) {
1845 query.append(WHERE_AND);
1846 }
1847
1848 query.append(_FINDER_COLUMN_C_U_C_C_USERID_5);
1849
1850 conjunctionable = true;
1851
1852 if (conjunctionable) {
1853 query.append(WHERE_AND);
1854 }
1855
1856 query.append(_FINDER_COLUMN_C_U_C_C_CLASSNAMEID_5);
1857
1858 conjunctionable = true;
1859
1860 if ((classPKs == null) || (classPKs.length > 0)) {
1861 if (conjunctionable) {
1862 query.append(WHERE_AND);
1863 }
1864
1865 query.append(StringPool.OPEN_PARENTHESIS);
1866
1867 for (int i = 0; i < classPKs.length; i++) {
1868 query.append(_FINDER_COLUMN_C_U_C_C_CLASSPK_5);
1869
1870 if ((i + 1) < classPKs.length) {
1871 query.append(WHERE_OR);
1872 }
1873 }
1874
1875 query.append(StringPool.CLOSE_PARENTHESIS);
1876
1877 conjunctionable = true;
1878 }
1879
1880 if (orderByComparator != null) {
1881 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1882 orderByComparator);
1883 }
1884 else
1885 if (pagination) {
1886 query.append(SubscriptionModelImpl.ORDER_BY_JPQL);
1887 }
1888
1889 String sql = query.toString();
1890
1891 Session session = null;
1892
1893 try {
1894 session = openSession();
1895
1896 Query q = session.createQuery(sql);
1897
1898 QueryPos qPos = QueryPos.getInstance(q);
1899
1900 qPos.add(companyId);
1901
1902 qPos.add(userId);
1903
1904 qPos.add(classNameId);
1905
1906 if (classPKs != null) {
1907 qPos.add(classPKs);
1908 }
1909
1910 if (!pagination) {
1911 list = (List<Subscription>)QueryUtil.list(q, getDialect(),
1912 start, end, false);
1913
1914 Collections.sort(list);
1915
1916 list = new UnmodifiableList<Subscription>(list);
1917 }
1918 else {
1919 list = (List<Subscription>)QueryUtil.list(q, getDialect(),
1920 start, end);
1921 }
1922
1923 cacheResult(list);
1924
1925 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_C_U_C_C,
1926 finderArgs, list);
1927 }
1928 catch (Exception e) {
1929 FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_C_U_C_C,
1930 finderArgs);
1931
1932 throw processException(e);
1933 }
1934 finally {
1935 closeSession(session);
1936 }
1937 }
1938
1939 return list;
1940 }
1941
1942
1953 @Override
1954 public Subscription findByC_U_C_C(long companyId, long userId,
1955 long classNameId, long classPK)
1956 throws NoSuchSubscriptionException, SystemException {
1957 Subscription subscription = fetchByC_U_C_C(companyId, userId,
1958 classNameId, classPK);
1959
1960 if (subscription == null) {
1961 StringBundler msg = new StringBundler(10);
1962
1963 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1964
1965 msg.append("companyId=");
1966 msg.append(companyId);
1967
1968 msg.append(", userId=");
1969 msg.append(userId);
1970
1971 msg.append(", classNameId=");
1972 msg.append(classNameId);
1973
1974 msg.append(", classPK=");
1975 msg.append(classPK);
1976
1977 msg.append(StringPool.CLOSE_CURLY_BRACE);
1978
1979 if (_log.isWarnEnabled()) {
1980 _log.warn(msg.toString());
1981 }
1982
1983 throw new NoSuchSubscriptionException(msg.toString());
1984 }
1985
1986 return subscription;
1987 }
1988
1989
1999 @Override
2000 public Subscription fetchByC_U_C_C(long companyId, long userId,
2001 long classNameId, long classPK) throws SystemException {
2002 return fetchByC_U_C_C(companyId, userId, classNameId, classPK, true);
2003 }
2004
2005
2016 @Override
2017 public Subscription fetchByC_U_C_C(long companyId, long userId,
2018 long classNameId, long classPK, boolean retrieveFromCache)
2019 throws SystemException {
2020 Object[] finderArgs = new Object[] {
2021 companyId, userId, classNameId, classPK
2022 };
2023
2024 Object result = null;
2025
2026 if (retrieveFromCache) {
2027 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_U_C_C,
2028 finderArgs, this);
2029 }
2030
2031 if (result instanceof Subscription) {
2032 Subscription subscription = (Subscription)result;
2033
2034 if ((companyId != subscription.getCompanyId()) ||
2035 (userId != subscription.getUserId()) ||
2036 (classNameId != subscription.getClassNameId()) ||
2037 (classPK != subscription.getClassPK())) {
2038 result = null;
2039 }
2040 }
2041
2042 if (result == null) {
2043 StringBundler query = new StringBundler(6);
2044
2045 query.append(_SQL_SELECT_SUBSCRIPTION_WHERE);
2046
2047 query.append(_FINDER_COLUMN_C_U_C_C_COMPANYID_2);
2048
2049 query.append(_FINDER_COLUMN_C_U_C_C_USERID_2);
2050
2051 query.append(_FINDER_COLUMN_C_U_C_C_CLASSNAMEID_2);
2052
2053 query.append(_FINDER_COLUMN_C_U_C_C_CLASSPK_2);
2054
2055 String sql = query.toString();
2056
2057 Session session = null;
2058
2059 try {
2060 session = openSession();
2061
2062 Query q = session.createQuery(sql);
2063
2064 QueryPos qPos = QueryPos.getInstance(q);
2065
2066 qPos.add(companyId);
2067
2068 qPos.add(userId);
2069
2070 qPos.add(classNameId);
2071
2072 qPos.add(classPK);
2073
2074 List<Subscription> list = q.list();
2075
2076 if (list.isEmpty()) {
2077 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_U_C_C,
2078 finderArgs, list);
2079 }
2080 else {
2081 Subscription subscription = list.get(0);
2082
2083 result = subscription;
2084
2085 cacheResult(subscription);
2086
2087 if ((subscription.getCompanyId() != companyId) ||
2088 (subscription.getUserId() != userId) ||
2089 (subscription.getClassNameId() != classNameId) ||
2090 (subscription.getClassPK() != classPK)) {
2091 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_U_C_C,
2092 finderArgs, subscription);
2093 }
2094 }
2095 }
2096 catch (Exception e) {
2097 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_U_C_C,
2098 finderArgs);
2099
2100 throw processException(e);
2101 }
2102 finally {
2103 closeSession(session);
2104 }
2105 }
2106
2107 if (result instanceof List<?>) {
2108 return null;
2109 }
2110 else {
2111 return (Subscription)result;
2112 }
2113 }
2114
2115
2125 @Override
2126 public Subscription removeByC_U_C_C(long companyId, long userId,
2127 long classNameId, long classPK)
2128 throws NoSuchSubscriptionException, SystemException {
2129 Subscription subscription = findByC_U_C_C(companyId, userId,
2130 classNameId, classPK);
2131
2132 return remove(subscription);
2133 }
2134
2135
2145 @Override
2146 public int countByC_U_C_C(long companyId, long userId, long classNameId,
2147 long classPK) throws SystemException {
2148 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_U_C_C;
2149
2150 Object[] finderArgs = new Object[] {
2151 companyId, userId, classNameId, classPK
2152 };
2153
2154 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2155 this);
2156
2157 if (count == null) {
2158 StringBundler query = new StringBundler(5);
2159
2160 query.append(_SQL_COUNT_SUBSCRIPTION_WHERE);
2161
2162 query.append(_FINDER_COLUMN_C_U_C_C_COMPANYID_2);
2163
2164 query.append(_FINDER_COLUMN_C_U_C_C_USERID_2);
2165
2166 query.append(_FINDER_COLUMN_C_U_C_C_CLASSNAMEID_2);
2167
2168 query.append(_FINDER_COLUMN_C_U_C_C_CLASSPK_2);
2169
2170 String sql = query.toString();
2171
2172 Session session = null;
2173
2174 try {
2175 session = openSession();
2176
2177 Query q = session.createQuery(sql);
2178
2179 QueryPos qPos = QueryPos.getInstance(q);
2180
2181 qPos.add(companyId);
2182
2183 qPos.add(userId);
2184
2185 qPos.add(classNameId);
2186
2187 qPos.add(classPK);
2188
2189 count = (Long)q.uniqueResult();
2190
2191 FinderCacheUtil.putResult(finderPath, finderArgs, count);
2192 }
2193 catch (Exception e) {
2194 FinderCacheUtil.removeResult(finderPath, finderArgs);
2195
2196 throw processException(e);
2197 }
2198 finally {
2199 closeSession(session);
2200 }
2201 }
2202
2203 return count.intValue();
2204 }
2205
2206
2216 @Override
2217 public int countByC_U_C_C(long companyId, long userId, long classNameId,
2218 long[] classPKs) throws SystemException {
2219 Object[] finderArgs = new Object[] {
2220 companyId, userId, classNameId, StringUtil.merge(classPKs)
2221 };
2222
2223 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_U_C_C,
2224 finderArgs, this);
2225
2226 if (count == null) {
2227 StringBundler query = new StringBundler();
2228
2229 query.append(_SQL_COUNT_SUBSCRIPTION_WHERE);
2230
2231 boolean conjunctionable = false;
2232
2233 if (conjunctionable) {
2234 query.append(WHERE_AND);
2235 }
2236
2237 query.append(_FINDER_COLUMN_C_U_C_C_COMPANYID_5);
2238
2239 conjunctionable = true;
2240
2241 if (conjunctionable) {
2242 query.append(WHERE_AND);
2243 }
2244
2245 query.append(_FINDER_COLUMN_C_U_C_C_USERID_5);
2246
2247 conjunctionable = true;
2248
2249 if (conjunctionable) {
2250 query.append(WHERE_AND);
2251 }
2252
2253 query.append(_FINDER_COLUMN_C_U_C_C_CLASSNAMEID_5);
2254
2255 conjunctionable = true;
2256
2257 if ((classPKs == null) || (classPKs.length > 0)) {
2258 if (conjunctionable) {
2259 query.append(WHERE_AND);
2260 }
2261
2262 query.append(StringPool.OPEN_PARENTHESIS);
2263
2264 for (int i = 0; i < classPKs.length; i++) {
2265 query.append(_FINDER_COLUMN_C_U_C_C_CLASSPK_5);
2266
2267 if ((i + 1) < classPKs.length) {
2268 query.append(WHERE_OR);
2269 }
2270 }
2271
2272 query.append(StringPool.CLOSE_PARENTHESIS);
2273
2274 conjunctionable = true;
2275 }
2276
2277 String sql = query.toString();
2278
2279 Session session = null;
2280
2281 try {
2282 session = openSession();
2283
2284 Query q = session.createQuery(sql);
2285
2286 QueryPos qPos = QueryPos.getInstance(q);
2287
2288 qPos.add(companyId);
2289
2290 qPos.add(userId);
2291
2292 qPos.add(classNameId);
2293
2294 if (classPKs != null) {
2295 qPos.add(classPKs);
2296 }
2297
2298 count = (Long)q.uniqueResult();
2299
2300 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_U_C_C,
2301 finderArgs, count);
2302 }
2303 catch (Exception e) {
2304 FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_U_C_C,
2305 finderArgs);
2306
2307 throw processException(e);
2308 }
2309 finally {
2310 closeSession(session);
2311 }
2312 }
2313
2314 return count.intValue();
2315 }
2316
2317 private static final String _FINDER_COLUMN_C_U_C_C_COMPANYID_2 = "subscription.companyId = ? AND ";
2318 private static final String _FINDER_COLUMN_C_U_C_C_COMPANYID_5 = "(" +
2319 removeConjunction(_FINDER_COLUMN_C_U_C_C_COMPANYID_2) + ")";
2320 private static final String _FINDER_COLUMN_C_U_C_C_USERID_2 = "subscription.userId = ? AND ";
2321 private static final String _FINDER_COLUMN_C_U_C_C_USERID_5 = "(" +
2322 removeConjunction(_FINDER_COLUMN_C_U_C_C_USERID_2) + ")";
2323 private static final String _FINDER_COLUMN_C_U_C_C_CLASSNAMEID_2 = "subscription.classNameId = ? AND ";
2324 private static final String _FINDER_COLUMN_C_U_C_C_CLASSNAMEID_5 = "(" +
2325 removeConjunction(_FINDER_COLUMN_C_U_C_C_CLASSNAMEID_2) + ")";
2326 private static final String _FINDER_COLUMN_C_U_C_C_CLASSPK_2 = "subscription.classPK = ?";
2327 private static final String _FINDER_COLUMN_C_U_C_C_CLASSPK_5 = "(" +
2328 removeConjunction(_FINDER_COLUMN_C_U_C_C_CLASSPK_2) + ")";
2329
2330
2335 @Override
2336 public void cacheResult(Subscription subscription) {
2337 EntityCacheUtil.putResult(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
2338 SubscriptionImpl.class, subscription.getPrimaryKey(), subscription);
2339
2340 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_U_C_C,
2341 new Object[] {
2342 subscription.getCompanyId(), subscription.getUserId(),
2343 subscription.getClassNameId(), subscription.getClassPK()
2344 }, subscription);
2345
2346 subscription.resetOriginalValues();
2347 }
2348
2349
2354 @Override
2355 public void cacheResult(List<Subscription> subscriptions) {
2356 for (Subscription subscription : subscriptions) {
2357 if (EntityCacheUtil.getResult(
2358 SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
2359 SubscriptionImpl.class, subscription.getPrimaryKey()) == null) {
2360 cacheResult(subscription);
2361 }
2362 else {
2363 subscription.resetOriginalValues();
2364 }
2365 }
2366 }
2367
2368
2375 @Override
2376 public void clearCache() {
2377 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
2378 CacheRegistryUtil.clear(SubscriptionImpl.class.getName());
2379 }
2380
2381 EntityCacheUtil.clearCache(SubscriptionImpl.class.getName());
2382
2383 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
2384 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2385 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2386 }
2387
2388
2395 @Override
2396 public void clearCache(Subscription subscription) {
2397 EntityCacheUtil.removeResult(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
2398 SubscriptionImpl.class, subscription.getPrimaryKey());
2399
2400 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2401 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2402
2403 clearUniqueFindersCache(subscription);
2404 }
2405
2406 @Override
2407 public void clearCache(List<Subscription> subscriptions) {
2408 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2409 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2410
2411 for (Subscription subscription : subscriptions) {
2412 EntityCacheUtil.removeResult(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
2413 SubscriptionImpl.class, subscription.getPrimaryKey());
2414
2415 clearUniqueFindersCache(subscription);
2416 }
2417 }
2418
2419 protected void cacheUniqueFindersCache(Subscription subscription) {
2420 if (subscription.isNew()) {
2421 Object[] args = new Object[] {
2422 subscription.getCompanyId(), subscription.getUserId(),
2423 subscription.getClassNameId(), subscription.getClassPK()
2424 };
2425
2426 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_U_C_C, args,
2427 Long.valueOf(1));
2428 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_U_C_C, args,
2429 subscription);
2430 }
2431 else {
2432 SubscriptionModelImpl subscriptionModelImpl = (SubscriptionModelImpl)subscription;
2433
2434 if ((subscriptionModelImpl.getColumnBitmask() &
2435 FINDER_PATH_FETCH_BY_C_U_C_C.getColumnBitmask()) != 0) {
2436 Object[] args = new Object[] {
2437 subscription.getCompanyId(), subscription.getUserId(),
2438 subscription.getClassNameId(), subscription.getClassPK()
2439 };
2440
2441 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_U_C_C, args,
2442 Long.valueOf(1));
2443 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_U_C_C, args,
2444 subscription);
2445 }
2446 }
2447 }
2448
2449 protected void clearUniqueFindersCache(Subscription subscription) {
2450 SubscriptionModelImpl subscriptionModelImpl = (SubscriptionModelImpl)subscription;
2451
2452 Object[] args = new Object[] {
2453 subscription.getCompanyId(), subscription.getUserId(),
2454 subscription.getClassNameId(), subscription.getClassPK()
2455 };
2456
2457 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_U_C_C, args);
2458 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_U_C_C, args);
2459
2460 if ((subscriptionModelImpl.getColumnBitmask() &
2461 FINDER_PATH_FETCH_BY_C_U_C_C.getColumnBitmask()) != 0) {
2462 args = new Object[] {
2463 subscriptionModelImpl.getOriginalCompanyId(),
2464 subscriptionModelImpl.getOriginalUserId(),
2465 subscriptionModelImpl.getOriginalClassNameId(),
2466 subscriptionModelImpl.getOriginalClassPK()
2467 };
2468
2469 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_U_C_C, args);
2470 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_U_C_C, args);
2471 }
2472 }
2473
2474
2480 @Override
2481 public Subscription create(long subscriptionId) {
2482 Subscription subscription = new SubscriptionImpl();
2483
2484 subscription.setNew(true);
2485 subscription.setPrimaryKey(subscriptionId);
2486
2487 return subscription;
2488 }
2489
2490
2498 @Override
2499 public Subscription remove(long subscriptionId)
2500 throws NoSuchSubscriptionException, SystemException {
2501 return remove((Serializable)subscriptionId);
2502 }
2503
2504
2512 @Override
2513 public Subscription remove(Serializable primaryKey)
2514 throws NoSuchSubscriptionException, SystemException {
2515 Session session = null;
2516
2517 try {
2518 session = openSession();
2519
2520 Subscription subscription = (Subscription)session.get(SubscriptionImpl.class,
2521 primaryKey);
2522
2523 if (subscription == null) {
2524 if (_log.isWarnEnabled()) {
2525 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2526 }
2527
2528 throw new NoSuchSubscriptionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2529 primaryKey);
2530 }
2531
2532 return remove(subscription);
2533 }
2534 catch (NoSuchSubscriptionException nsee) {
2535 throw nsee;
2536 }
2537 catch (Exception e) {
2538 throw processException(e);
2539 }
2540 finally {
2541 closeSession(session);
2542 }
2543 }
2544
2545 @Override
2546 protected Subscription removeImpl(Subscription subscription)
2547 throws SystemException {
2548 subscription = toUnwrappedModel(subscription);
2549
2550 Session session = null;
2551
2552 try {
2553 session = openSession();
2554
2555 if (!session.contains(subscription)) {
2556 subscription = (Subscription)session.get(SubscriptionImpl.class,
2557 subscription.getPrimaryKeyObj());
2558 }
2559
2560 if (subscription != null) {
2561 session.delete(subscription);
2562 }
2563 }
2564 catch (Exception e) {
2565 throw processException(e);
2566 }
2567 finally {
2568 closeSession(session);
2569 }
2570
2571 if (subscription != null) {
2572 clearCache(subscription);
2573 }
2574
2575 return subscription;
2576 }
2577
2578 @Override
2579 public Subscription updateImpl(
2580 com.liferay.portal.model.Subscription subscription)
2581 throws SystemException {
2582 subscription = toUnwrappedModel(subscription);
2583
2584 boolean isNew = subscription.isNew();
2585
2586 SubscriptionModelImpl subscriptionModelImpl = (SubscriptionModelImpl)subscription;
2587
2588 Session session = null;
2589
2590 try {
2591 session = openSession();
2592
2593 if (subscription.isNew()) {
2594 session.save(subscription);
2595
2596 subscription.setNew(false);
2597 }
2598 else {
2599 session.merge(subscription);
2600 }
2601 }
2602 catch (Exception e) {
2603 throw processException(e);
2604 }
2605 finally {
2606 closeSession(session);
2607 }
2608
2609 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2610
2611 if (isNew || !SubscriptionModelImpl.COLUMN_BITMASK_ENABLED) {
2612 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2613 }
2614
2615 else {
2616 if ((subscriptionModelImpl.getColumnBitmask() &
2617 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
2618 Object[] args = new Object[] {
2619 subscriptionModelImpl.getOriginalUserId()
2620 };
2621
2622 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
2623 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
2624 args);
2625
2626 args = new Object[] { subscriptionModelImpl.getUserId() };
2627
2628 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
2629 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
2630 args);
2631 }
2632
2633 if ((subscriptionModelImpl.getColumnBitmask() &
2634 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C.getColumnBitmask()) != 0) {
2635 Object[] args = new Object[] {
2636 subscriptionModelImpl.getOriginalUserId(),
2637 subscriptionModelImpl.getOriginalClassNameId()
2638 };
2639
2640 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C, args);
2641 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C,
2642 args);
2643
2644 args = new Object[] {
2645 subscriptionModelImpl.getUserId(),
2646 subscriptionModelImpl.getClassNameId()
2647 };
2648
2649 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C, args);
2650 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C,
2651 args);
2652 }
2653
2654 if ((subscriptionModelImpl.getColumnBitmask() &
2655 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C.getColumnBitmask()) != 0) {
2656 Object[] args = new Object[] {
2657 subscriptionModelImpl.getOriginalCompanyId(),
2658 subscriptionModelImpl.getOriginalClassNameId(),
2659 subscriptionModelImpl.getOriginalClassPK()
2660 };
2661
2662 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_C, args);
2663 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C,
2664 args);
2665
2666 args = new Object[] {
2667 subscriptionModelImpl.getCompanyId(),
2668 subscriptionModelImpl.getClassNameId(),
2669 subscriptionModelImpl.getClassPK()
2670 };
2671
2672 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_C, args);
2673 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C,
2674 args);
2675 }
2676
2677 if ((subscriptionModelImpl.getColumnBitmask() &
2678 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_U_C_C.getColumnBitmask()) != 0) {
2679 Object[] args = new Object[] {
2680 subscriptionModelImpl.getOriginalCompanyId(),
2681 subscriptionModelImpl.getOriginalUserId(),
2682 subscriptionModelImpl.getOriginalClassNameId(),
2683 subscriptionModelImpl.getOriginalClassPK()
2684 };
2685
2686 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_U_C_C, args);
2687 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_U_C_C,
2688 args);
2689
2690 args = new Object[] {
2691 subscriptionModelImpl.getCompanyId(),
2692 subscriptionModelImpl.getUserId(),
2693 subscriptionModelImpl.getClassNameId(),
2694 subscriptionModelImpl.getClassPK()
2695 };
2696
2697 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_U_C_C, args);
2698 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_U_C_C,
2699 args);
2700 }
2701 }
2702
2703 EntityCacheUtil.putResult(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
2704 SubscriptionImpl.class, subscription.getPrimaryKey(), subscription);
2705
2706 clearUniqueFindersCache(subscription);
2707 cacheUniqueFindersCache(subscription);
2708
2709 return subscription;
2710 }
2711
2712 protected Subscription toUnwrappedModel(Subscription subscription) {
2713 if (subscription instanceof SubscriptionImpl) {
2714 return subscription;
2715 }
2716
2717 SubscriptionImpl subscriptionImpl = new SubscriptionImpl();
2718
2719 subscriptionImpl.setNew(subscription.isNew());
2720 subscriptionImpl.setPrimaryKey(subscription.getPrimaryKey());
2721
2722 subscriptionImpl.setSubscriptionId(subscription.getSubscriptionId());
2723 subscriptionImpl.setCompanyId(subscription.getCompanyId());
2724 subscriptionImpl.setUserId(subscription.getUserId());
2725 subscriptionImpl.setUserName(subscription.getUserName());
2726 subscriptionImpl.setCreateDate(subscription.getCreateDate());
2727 subscriptionImpl.setModifiedDate(subscription.getModifiedDate());
2728 subscriptionImpl.setClassNameId(subscription.getClassNameId());
2729 subscriptionImpl.setClassPK(subscription.getClassPK());
2730 subscriptionImpl.setFrequency(subscription.getFrequency());
2731
2732 return subscriptionImpl;
2733 }
2734
2735
2743 @Override
2744 public Subscription findByPrimaryKey(Serializable primaryKey)
2745 throws NoSuchSubscriptionException, SystemException {
2746 Subscription subscription = fetchByPrimaryKey(primaryKey);
2747
2748 if (subscription == null) {
2749 if (_log.isWarnEnabled()) {
2750 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2751 }
2752
2753 throw new NoSuchSubscriptionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2754 primaryKey);
2755 }
2756
2757 return subscription;
2758 }
2759
2760
2768 @Override
2769 public Subscription findByPrimaryKey(long subscriptionId)
2770 throws NoSuchSubscriptionException, SystemException {
2771 return findByPrimaryKey((Serializable)subscriptionId);
2772 }
2773
2774
2781 @Override
2782 public Subscription fetchByPrimaryKey(Serializable primaryKey)
2783 throws SystemException {
2784 Subscription subscription = (Subscription)EntityCacheUtil.getResult(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
2785 SubscriptionImpl.class, primaryKey);
2786
2787 if (subscription == _nullSubscription) {
2788 return null;
2789 }
2790
2791 if (subscription == null) {
2792 Session session = null;
2793
2794 try {
2795 session = openSession();
2796
2797 subscription = (Subscription)session.get(SubscriptionImpl.class,
2798 primaryKey);
2799
2800 if (subscription != null) {
2801 cacheResult(subscription);
2802 }
2803 else {
2804 EntityCacheUtil.putResult(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
2805 SubscriptionImpl.class, primaryKey, _nullSubscription);
2806 }
2807 }
2808 catch (Exception e) {
2809 EntityCacheUtil.removeResult(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
2810 SubscriptionImpl.class, primaryKey);
2811
2812 throw processException(e);
2813 }
2814 finally {
2815 closeSession(session);
2816 }
2817 }
2818
2819 return subscription;
2820 }
2821
2822
2829 @Override
2830 public Subscription fetchByPrimaryKey(long subscriptionId)
2831 throws SystemException {
2832 return fetchByPrimaryKey((Serializable)subscriptionId);
2833 }
2834
2835
2841 @Override
2842 public List<Subscription> findAll() throws SystemException {
2843 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2844 }
2845
2846
2858 @Override
2859 public List<Subscription> findAll(int start, int end)
2860 throws SystemException {
2861 return findAll(start, end, null);
2862 }
2863
2864
2877 @Override
2878 public List<Subscription> findAll(int start, int end,
2879 OrderByComparator orderByComparator) throws SystemException {
2880 boolean pagination = true;
2881 FinderPath finderPath = null;
2882 Object[] finderArgs = null;
2883
2884 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2885 (orderByComparator == null)) {
2886 pagination = false;
2887 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2888 finderArgs = FINDER_ARGS_EMPTY;
2889 }
2890 else {
2891 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2892 finderArgs = new Object[] { start, end, orderByComparator };
2893 }
2894
2895 List<Subscription> list = (List<Subscription>)FinderCacheUtil.getResult(finderPath,
2896 finderArgs, this);
2897
2898 if (list == null) {
2899 StringBundler query = null;
2900 String sql = null;
2901
2902 if (orderByComparator != null) {
2903 query = new StringBundler(2 +
2904 (orderByComparator.getOrderByFields().length * 3));
2905
2906 query.append(_SQL_SELECT_SUBSCRIPTION);
2907
2908 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2909 orderByComparator);
2910
2911 sql = query.toString();
2912 }
2913 else {
2914 sql = _SQL_SELECT_SUBSCRIPTION;
2915
2916 if (pagination) {
2917 sql = sql.concat(SubscriptionModelImpl.ORDER_BY_JPQL);
2918 }
2919 }
2920
2921 Session session = null;
2922
2923 try {
2924 session = openSession();
2925
2926 Query q = session.createQuery(sql);
2927
2928 if (!pagination) {
2929 list = (List<Subscription>)QueryUtil.list(q, getDialect(),
2930 start, end, false);
2931
2932 Collections.sort(list);
2933
2934 list = new UnmodifiableList<Subscription>(list);
2935 }
2936 else {
2937 list = (List<Subscription>)QueryUtil.list(q, getDialect(),
2938 start, end);
2939 }
2940
2941 cacheResult(list);
2942
2943 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2944 }
2945 catch (Exception e) {
2946 FinderCacheUtil.removeResult(finderPath, finderArgs);
2947
2948 throw processException(e);
2949 }
2950 finally {
2951 closeSession(session);
2952 }
2953 }
2954
2955 return list;
2956 }
2957
2958
2963 @Override
2964 public void removeAll() throws SystemException {
2965 for (Subscription subscription : findAll()) {
2966 remove(subscription);
2967 }
2968 }
2969
2970
2976 @Override
2977 public int countAll() throws SystemException {
2978 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2979 FINDER_ARGS_EMPTY, this);
2980
2981 if (count == null) {
2982 Session session = null;
2983
2984 try {
2985 session = openSession();
2986
2987 Query q = session.createQuery(_SQL_COUNT_SUBSCRIPTION);
2988
2989 count = (Long)q.uniqueResult();
2990
2991 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2992 FINDER_ARGS_EMPTY, count);
2993 }
2994 catch (Exception e) {
2995 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
2996 FINDER_ARGS_EMPTY);
2997
2998 throw processException(e);
2999 }
3000 finally {
3001 closeSession(session);
3002 }
3003 }
3004
3005 return count.intValue();
3006 }
3007
3008
3011 public void afterPropertiesSet() {
3012 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
3013 com.liferay.portal.util.PropsUtil.get(
3014 "value.object.listener.com.liferay.portal.model.Subscription")));
3015
3016 if (listenerClassNames.length > 0) {
3017 try {
3018 List<ModelListener<Subscription>> listenersList = new ArrayList<ModelListener<Subscription>>();
3019
3020 for (String listenerClassName : listenerClassNames) {
3021 listenersList.add((ModelListener<Subscription>)InstanceFactory.newInstance(
3022 getClassLoader(), listenerClassName));
3023 }
3024
3025 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
3026 }
3027 catch (Exception e) {
3028 _log.error(e);
3029 }
3030 }
3031 }
3032
3033 public void destroy() {
3034 EntityCacheUtil.removeCache(SubscriptionImpl.class.getName());
3035 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
3036 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3037 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3038 }
3039
3040 private static final String _SQL_SELECT_SUBSCRIPTION = "SELECT subscription FROM Subscription subscription";
3041 private static final String _SQL_SELECT_SUBSCRIPTION_WHERE = "SELECT subscription FROM Subscription subscription WHERE ";
3042 private static final String _SQL_COUNT_SUBSCRIPTION = "SELECT COUNT(subscription) FROM Subscription subscription";
3043 private static final String _SQL_COUNT_SUBSCRIPTION_WHERE = "SELECT COUNT(subscription) FROM Subscription subscription WHERE ";
3044 private static final String _ORDER_BY_ENTITY_ALIAS = "subscription.";
3045 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Subscription exists with the primary key ";
3046 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Subscription exists with the key {";
3047 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
3048 private static Log _log = LogFactoryUtil.getLog(SubscriptionPersistenceImpl.class);
3049 private static Subscription _nullSubscription = new SubscriptionImpl() {
3050 @Override
3051 public Object clone() {
3052 return this;
3053 }
3054
3055 @Override
3056 public CacheModel<Subscription> toCacheModel() {
3057 return _nullSubscriptionCacheModel;
3058 }
3059 };
3060
3061 private static CacheModel<Subscription> _nullSubscriptionCacheModel = new CacheModel<Subscription>() {
3062 @Override
3063 public Subscription toEntityModel() {
3064 return _nullSubscription;
3065 }
3066 };
3067 }