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 public SubscriptionPersistenceImpl() {
2331 setModelClass(Subscription.class);
2332 }
2333
2334
2339 @Override
2340 public void cacheResult(Subscription subscription) {
2341 EntityCacheUtil.putResult(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
2342 SubscriptionImpl.class, subscription.getPrimaryKey(), subscription);
2343
2344 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_U_C_C,
2345 new Object[] {
2346 subscription.getCompanyId(), subscription.getUserId(),
2347 subscription.getClassNameId(), subscription.getClassPK()
2348 }, subscription);
2349
2350 subscription.resetOriginalValues();
2351 }
2352
2353
2358 @Override
2359 public void cacheResult(List<Subscription> subscriptions) {
2360 for (Subscription subscription : subscriptions) {
2361 if (EntityCacheUtil.getResult(
2362 SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
2363 SubscriptionImpl.class, subscription.getPrimaryKey()) == null) {
2364 cacheResult(subscription);
2365 }
2366 else {
2367 subscription.resetOriginalValues();
2368 }
2369 }
2370 }
2371
2372
2379 @Override
2380 public void clearCache() {
2381 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
2382 CacheRegistryUtil.clear(SubscriptionImpl.class.getName());
2383 }
2384
2385 EntityCacheUtil.clearCache(SubscriptionImpl.class.getName());
2386
2387 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
2388 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2389 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2390 }
2391
2392
2399 @Override
2400 public void clearCache(Subscription subscription) {
2401 EntityCacheUtil.removeResult(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
2402 SubscriptionImpl.class, subscription.getPrimaryKey());
2403
2404 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2405 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2406
2407 clearUniqueFindersCache(subscription);
2408 }
2409
2410 @Override
2411 public void clearCache(List<Subscription> subscriptions) {
2412 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2413 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2414
2415 for (Subscription subscription : subscriptions) {
2416 EntityCacheUtil.removeResult(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
2417 SubscriptionImpl.class, subscription.getPrimaryKey());
2418
2419 clearUniqueFindersCache(subscription);
2420 }
2421 }
2422
2423 protected void cacheUniqueFindersCache(Subscription subscription) {
2424 if (subscription.isNew()) {
2425 Object[] args = new Object[] {
2426 subscription.getCompanyId(), subscription.getUserId(),
2427 subscription.getClassNameId(), subscription.getClassPK()
2428 };
2429
2430 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_U_C_C, args,
2431 Long.valueOf(1));
2432 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_U_C_C, args,
2433 subscription);
2434 }
2435 else {
2436 SubscriptionModelImpl subscriptionModelImpl = (SubscriptionModelImpl)subscription;
2437
2438 if ((subscriptionModelImpl.getColumnBitmask() &
2439 FINDER_PATH_FETCH_BY_C_U_C_C.getColumnBitmask()) != 0) {
2440 Object[] args = new Object[] {
2441 subscription.getCompanyId(), subscription.getUserId(),
2442 subscription.getClassNameId(), subscription.getClassPK()
2443 };
2444
2445 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_U_C_C, args,
2446 Long.valueOf(1));
2447 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_U_C_C, args,
2448 subscription);
2449 }
2450 }
2451 }
2452
2453 protected void clearUniqueFindersCache(Subscription subscription) {
2454 SubscriptionModelImpl subscriptionModelImpl = (SubscriptionModelImpl)subscription;
2455
2456 Object[] args = new Object[] {
2457 subscription.getCompanyId(), subscription.getUserId(),
2458 subscription.getClassNameId(), subscription.getClassPK()
2459 };
2460
2461 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_U_C_C, args);
2462 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_U_C_C, args);
2463
2464 if ((subscriptionModelImpl.getColumnBitmask() &
2465 FINDER_PATH_FETCH_BY_C_U_C_C.getColumnBitmask()) != 0) {
2466 args = new Object[] {
2467 subscriptionModelImpl.getOriginalCompanyId(),
2468 subscriptionModelImpl.getOriginalUserId(),
2469 subscriptionModelImpl.getOriginalClassNameId(),
2470 subscriptionModelImpl.getOriginalClassPK()
2471 };
2472
2473 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_U_C_C, args);
2474 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_U_C_C, args);
2475 }
2476 }
2477
2478
2484 @Override
2485 public Subscription create(long subscriptionId) {
2486 Subscription subscription = new SubscriptionImpl();
2487
2488 subscription.setNew(true);
2489 subscription.setPrimaryKey(subscriptionId);
2490
2491 return subscription;
2492 }
2493
2494
2502 @Override
2503 public Subscription remove(long subscriptionId)
2504 throws NoSuchSubscriptionException, SystemException {
2505 return remove((Serializable)subscriptionId);
2506 }
2507
2508
2516 @Override
2517 public Subscription remove(Serializable primaryKey)
2518 throws NoSuchSubscriptionException, SystemException {
2519 Session session = null;
2520
2521 try {
2522 session = openSession();
2523
2524 Subscription subscription = (Subscription)session.get(SubscriptionImpl.class,
2525 primaryKey);
2526
2527 if (subscription == null) {
2528 if (_log.isWarnEnabled()) {
2529 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2530 }
2531
2532 throw new NoSuchSubscriptionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2533 primaryKey);
2534 }
2535
2536 return remove(subscription);
2537 }
2538 catch (NoSuchSubscriptionException nsee) {
2539 throw nsee;
2540 }
2541 catch (Exception e) {
2542 throw processException(e);
2543 }
2544 finally {
2545 closeSession(session);
2546 }
2547 }
2548
2549 @Override
2550 protected Subscription removeImpl(Subscription subscription)
2551 throws SystemException {
2552 subscription = toUnwrappedModel(subscription);
2553
2554 Session session = null;
2555
2556 try {
2557 session = openSession();
2558
2559 if (!session.contains(subscription)) {
2560 subscription = (Subscription)session.get(SubscriptionImpl.class,
2561 subscription.getPrimaryKeyObj());
2562 }
2563
2564 if (subscription != null) {
2565 session.delete(subscription);
2566 }
2567 }
2568 catch (Exception e) {
2569 throw processException(e);
2570 }
2571 finally {
2572 closeSession(session);
2573 }
2574
2575 if (subscription != null) {
2576 clearCache(subscription);
2577 }
2578
2579 return subscription;
2580 }
2581
2582 @Override
2583 public Subscription updateImpl(
2584 com.liferay.portal.model.Subscription subscription)
2585 throws SystemException {
2586 subscription = toUnwrappedModel(subscription);
2587
2588 boolean isNew = subscription.isNew();
2589
2590 SubscriptionModelImpl subscriptionModelImpl = (SubscriptionModelImpl)subscription;
2591
2592 Session session = null;
2593
2594 try {
2595 session = openSession();
2596
2597 if (subscription.isNew()) {
2598 session.save(subscription);
2599
2600 subscription.setNew(false);
2601 }
2602 else {
2603 session.merge(subscription);
2604 }
2605 }
2606 catch (Exception e) {
2607 throw processException(e);
2608 }
2609 finally {
2610 closeSession(session);
2611 }
2612
2613 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2614
2615 if (isNew || !SubscriptionModelImpl.COLUMN_BITMASK_ENABLED) {
2616 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2617 }
2618
2619 else {
2620 if ((subscriptionModelImpl.getColumnBitmask() &
2621 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
2622 Object[] args = new Object[] {
2623 subscriptionModelImpl.getOriginalUserId()
2624 };
2625
2626 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
2627 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
2628 args);
2629
2630 args = new Object[] { subscriptionModelImpl.getUserId() };
2631
2632 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
2633 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
2634 args);
2635 }
2636
2637 if ((subscriptionModelImpl.getColumnBitmask() &
2638 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C.getColumnBitmask()) != 0) {
2639 Object[] args = new Object[] {
2640 subscriptionModelImpl.getOriginalUserId(),
2641 subscriptionModelImpl.getOriginalClassNameId()
2642 };
2643
2644 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C, args);
2645 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C,
2646 args);
2647
2648 args = new Object[] {
2649 subscriptionModelImpl.getUserId(),
2650 subscriptionModelImpl.getClassNameId()
2651 };
2652
2653 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C, args);
2654 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C,
2655 args);
2656 }
2657
2658 if ((subscriptionModelImpl.getColumnBitmask() &
2659 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C.getColumnBitmask()) != 0) {
2660 Object[] args = new Object[] {
2661 subscriptionModelImpl.getOriginalCompanyId(),
2662 subscriptionModelImpl.getOriginalClassNameId(),
2663 subscriptionModelImpl.getOriginalClassPK()
2664 };
2665
2666 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_C, args);
2667 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C,
2668 args);
2669
2670 args = new Object[] {
2671 subscriptionModelImpl.getCompanyId(),
2672 subscriptionModelImpl.getClassNameId(),
2673 subscriptionModelImpl.getClassPK()
2674 };
2675
2676 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_C, args);
2677 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C,
2678 args);
2679 }
2680
2681 if ((subscriptionModelImpl.getColumnBitmask() &
2682 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_U_C_C.getColumnBitmask()) != 0) {
2683 Object[] args = new Object[] {
2684 subscriptionModelImpl.getOriginalCompanyId(),
2685 subscriptionModelImpl.getOriginalUserId(),
2686 subscriptionModelImpl.getOriginalClassNameId(),
2687 subscriptionModelImpl.getOriginalClassPK()
2688 };
2689
2690 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_U_C_C, args);
2691 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_U_C_C,
2692 args);
2693
2694 args = new Object[] {
2695 subscriptionModelImpl.getCompanyId(),
2696 subscriptionModelImpl.getUserId(),
2697 subscriptionModelImpl.getClassNameId(),
2698 subscriptionModelImpl.getClassPK()
2699 };
2700
2701 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_U_C_C, args);
2702 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_U_C_C,
2703 args);
2704 }
2705 }
2706
2707 EntityCacheUtil.putResult(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
2708 SubscriptionImpl.class, subscription.getPrimaryKey(), subscription);
2709
2710 clearUniqueFindersCache(subscription);
2711 cacheUniqueFindersCache(subscription);
2712
2713 return subscription;
2714 }
2715
2716 protected Subscription toUnwrappedModel(Subscription subscription) {
2717 if (subscription instanceof SubscriptionImpl) {
2718 return subscription;
2719 }
2720
2721 SubscriptionImpl subscriptionImpl = new SubscriptionImpl();
2722
2723 subscriptionImpl.setNew(subscription.isNew());
2724 subscriptionImpl.setPrimaryKey(subscription.getPrimaryKey());
2725
2726 subscriptionImpl.setSubscriptionId(subscription.getSubscriptionId());
2727 subscriptionImpl.setCompanyId(subscription.getCompanyId());
2728 subscriptionImpl.setUserId(subscription.getUserId());
2729 subscriptionImpl.setUserName(subscription.getUserName());
2730 subscriptionImpl.setCreateDate(subscription.getCreateDate());
2731 subscriptionImpl.setModifiedDate(subscription.getModifiedDate());
2732 subscriptionImpl.setClassNameId(subscription.getClassNameId());
2733 subscriptionImpl.setClassPK(subscription.getClassPK());
2734 subscriptionImpl.setFrequency(subscription.getFrequency());
2735
2736 return subscriptionImpl;
2737 }
2738
2739
2747 @Override
2748 public Subscription findByPrimaryKey(Serializable primaryKey)
2749 throws NoSuchSubscriptionException, SystemException {
2750 Subscription subscription = fetchByPrimaryKey(primaryKey);
2751
2752 if (subscription == null) {
2753 if (_log.isWarnEnabled()) {
2754 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2755 }
2756
2757 throw new NoSuchSubscriptionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2758 primaryKey);
2759 }
2760
2761 return subscription;
2762 }
2763
2764
2772 @Override
2773 public Subscription findByPrimaryKey(long subscriptionId)
2774 throws NoSuchSubscriptionException, SystemException {
2775 return findByPrimaryKey((Serializable)subscriptionId);
2776 }
2777
2778
2785 @Override
2786 public Subscription fetchByPrimaryKey(Serializable primaryKey)
2787 throws SystemException {
2788 Subscription subscription = (Subscription)EntityCacheUtil.getResult(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
2789 SubscriptionImpl.class, primaryKey);
2790
2791 if (subscription == _nullSubscription) {
2792 return null;
2793 }
2794
2795 if (subscription == null) {
2796 Session session = null;
2797
2798 try {
2799 session = openSession();
2800
2801 subscription = (Subscription)session.get(SubscriptionImpl.class,
2802 primaryKey);
2803
2804 if (subscription != null) {
2805 cacheResult(subscription);
2806 }
2807 else {
2808 EntityCacheUtil.putResult(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
2809 SubscriptionImpl.class, primaryKey, _nullSubscription);
2810 }
2811 }
2812 catch (Exception e) {
2813 EntityCacheUtil.removeResult(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
2814 SubscriptionImpl.class, primaryKey);
2815
2816 throw processException(e);
2817 }
2818 finally {
2819 closeSession(session);
2820 }
2821 }
2822
2823 return subscription;
2824 }
2825
2826
2833 @Override
2834 public Subscription fetchByPrimaryKey(long subscriptionId)
2835 throws SystemException {
2836 return fetchByPrimaryKey((Serializable)subscriptionId);
2837 }
2838
2839
2845 @Override
2846 public List<Subscription> findAll() throws SystemException {
2847 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2848 }
2849
2850
2862 @Override
2863 public List<Subscription> findAll(int start, int end)
2864 throws SystemException {
2865 return findAll(start, end, null);
2866 }
2867
2868
2881 @Override
2882 public List<Subscription> findAll(int start, int end,
2883 OrderByComparator orderByComparator) throws SystemException {
2884 boolean pagination = true;
2885 FinderPath finderPath = null;
2886 Object[] finderArgs = null;
2887
2888 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2889 (orderByComparator == null)) {
2890 pagination = false;
2891 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2892 finderArgs = FINDER_ARGS_EMPTY;
2893 }
2894 else {
2895 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2896 finderArgs = new Object[] { start, end, orderByComparator };
2897 }
2898
2899 List<Subscription> list = (List<Subscription>)FinderCacheUtil.getResult(finderPath,
2900 finderArgs, this);
2901
2902 if (list == null) {
2903 StringBundler query = null;
2904 String sql = null;
2905
2906 if (orderByComparator != null) {
2907 query = new StringBundler(2 +
2908 (orderByComparator.getOrderByFields().length * 3));
2909
2910 query.append(_SQL_SELECT_SUBSCRIPTION);
2911
2912 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2913 orderByComparator);
2914
2915 sql = query.toString();
2916 }
2917 else {
2918 sql = _SQL_SELECT_SUBSCRIPTION;
2919
2920 if (pagination) {
2921 sql = sql.concat(SubscriptionModelImpl.ORDER_BY_JPQL);
2922 }
2923 }
2924
2925 Session session = null;
2926
2927 try {
2928 session = openSession();
2929
2930 Query q = session.createQuery(sql);
2931
2932 if (!pagination) {
2933 list = (List<Subscription>)QueryUtil.list(q, getDialect(),
2934 start, end, false);
2935
2936 Collections.sort(list);
2937
2938 list = new UnmodifiableList<Subscription>(list);
2939 }
2940 else {
2941 list = (List<Subscription>)QueryUtil.list(q, getDialect(),
2942 start, end);
2943 }
2944
2945 cacheResult(list);
2946
2947 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2948 }
2949 catch (Exception e) {
2950 FinderCacheUtil.removeResult(finderPath, finderArgs);
2951
2952 throw processException(e);
2953 }
2954 finally {
2955 closeSession(session);
2956 }
2957 }
2958
2959 return list;
2960 }
2961
2962
2967 @Override
2968 public void removeAll() throws SystemException {
2969 for (Subscription subscription : findAll()) {
2970 remove(subscription);
2971 }
2972 }
2973
2974
2980 @Override
2981 public int countAll() throws SystemException {
2982 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2983 FINDER_ARGS_EMPTY, this);
2984
2985 if (count == null) {
2986 Session session = null;
2987
2988 try {
2989 session = openSession();
2990
2991 Query q = session.createQuery(_SQL_COUNT_SUBSCRIPTION);
2992
2993 count = (Long)q.uniqueResult();
2994
2995 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2996 FINDER_ARGS_EMPTY, count);
2997 }
2998 catch (Exception e) {
2999 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
3000 FINDER_ARGS_EMPTY);
3001
3002 throw processException(e);
3003 }
3004 finally {
3005 closeSession(session);
3006 }
3007 }
3008
3009 return count.intValue();
3010 }
3011
3012
3015 public void afterPropertiesSet() {
3016 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
3017 com.liferay.portal.util.PropsUtil.get(
3018 "value.object.listener.com.liferay.portal.model.Subscription")));
3019
3020 if (listenerClassNames.length > 0) {
3021 try {
3022 List<ModelListener<Subscription>> listenersList = new ArrayList<ModelListener<Subscription>>();
3023
3024 for (String listenerClassName : listenerClassNames) {
3025 listenersList.add((ModelListener<Subscription>)InstanceFactory.newInstance(
3026 getClassLoader(), listenerClassName));
3027 }
3028
3029 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
3030 }
3031 catch (Exception e) {
3032 _log.error(e);
3033 }
3034 }
3035 }
3036
3037 public void destroy() {
3038 EntityCacheUtil.removeCache(SubscriptionImpl.class.getName());
3039 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
3040 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3041 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3042 }
3043
3044 private static final String _SQL_SELECT_SUBSCRIPTION = "SELECT subscription FROM Subscription subscription";
3045 private static final String _SQL_SELECT_SUBSCRIPTION_WHERE = "SELECT subscription FROM Subscription subscription WHERE ";
3046 private static final String _SQL_COUNT_SUBSCRIPTION = "SELECT COUNT(subscription) FROM Subscription subscription";
3047 private static final String _SQL_COUNT_SUBSCRIPTION_WHERE = "SELECT COUNT(subscription) FROM Subscription subscription WHERE ";
3048 private static final String _ORDER_BY_ENTITY_ALIAS = "subscription.";
3049 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Subscription exists with the primary key ";
3050 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Subscription exists with the key {";
3051 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
3052 private static Log _log = LogFactoryUtil.getLog(SubscriptionPersistenceImpl.class);
3053 private static Subscription _nullSubscription = new SubscriptionImpl() {
3054 @Override
3055 public Object clone() {
3056 return this;
3057 }
3058
3059 @Override
3060 public CacheModel<Subscription> toCacheModel() {
3061 return _nullSubscriptionCacheModel;
3062 }
3063 };
3064
3065 private static CacheModel<Subscription> _nullSubscriptionCacheModel = new CacheModel<Subscription>() {
3066 @Override
3067 public Subscription toEntityModel() {
3068 return _nullSubscription;
3069 }
3070 };
3071 }