001
014
015 package com.liferay.portal.service.persistence.impl;
016
017 import aQute.bnd.annotation.ProviderType;
018
019 import com.liferay.portal.NoSuchSubscriptionException;
020 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderPath;
023 import com.liferay.portal.kernel.dao.orm.Query;
024 import com.liferay.portal.kernel.dao.orm.QueryPos;
025 import com.liferay.portal.kernel.dao.orm.QueryUtil;
026 import com.liferay.portal.kernel.dao.orm.Session;
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.OrderByComparator;
031 import com.liferay.portal.kernel.util.StringBundler;
032 import com.liferay.portal.kernel.util.StringPool;
033 import com.liferay.portal.kernel.util.StringUtil;
034 import com.liferay.portal.model.CacheModel;
035 import com.liferay.portal.model.MVCCModel;
036 import com.liferay.portal.model.Subscription;
037 import com.liferay.portal.model.impl.SubscriptionImpl;
038 import com.liferay.portal.model.impl.SubscriptionModelImpl;
039 import com.liferay.portal.service.ServiceContext;
040 import com.liferay.portal.service.ServiceContextThreadLocal;
041 import com.liferay.portal.service.persistence.SubscriptionPersistence;
042
043 import java.io.Serializable;
044
045 import java.util.ArrayList;
046 import java.util.Collections;
047 import java.util.Date;
048 import java.util.HashMap;
049 import java.util.HashSet;
050 import java.util.Iterator;
051 import java.util.List;
052 import java.util.Map;
053 import java.util.Set;
054
055
067 @ProviderType
068 public class SubscriptionPersistenceImpl extends BasePersistenceImpl<Subscription>
069 implements SubscriptionPersistence {
070
075 public static final String FINDER_CLASS_NAME_ENTITY = SubscriptionImpl.class.getName();
076 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
077 ".List1";
078 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
079 ".List2";
080 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
081 SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.class,
082 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
083 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
084 SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.class,
085 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
086 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
087 SubscriptionModelImpl.FINDER_CACHE_ENABLED, Long.class,
088 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
089 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
090 SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.class,
091 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUserId",
092 new String[] {
093 Long.class.getName(),
094
095 Integer.class.getName(), Integer.class.getName(),
096 OrderByComparator.class.getName()
097 });
098 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID =
099 new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
100 SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.class,
101 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId",
102 new String[] { Long.class.getName() },
103 SubscriptionModelImpl.USERID_COLUMN_BITMASK);
104 public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
105 SubscriptionModelImpl.FINDER_CACHE_ENABLED, Long.class,
106 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
107 new String[] { Long.class.getName() });
108
109
115 @Override
116 public List<Subscription> findByUserId(long userId) {
117 return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
118 }
119
120
132 @Override
133 public List<Subscription> findByUserId(long userId, int start, int end) {
134 return findByUserId(userId, start, end, null);
135 }
136
137
150 @Override
151 public List<Subscription> findByUserId(long userId, int start, int end,
152 OrderByComparator<Subscription> orderByComparator) {
153 boolean pagination = true;
154 FinderPath finderPath = null;
155 Object[] finderArgs = null;
156
157 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
158 (orderByComparator == null)) {
159 pagination = false;
160 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
161 finderArgs = new Object[] { userId };
162 }
163 else {
164 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
165 finderArgs = new Object[] { userId, start, end, orderByComparator };
166 }
167
168 List<Subscription> list = (List<Subscription>)FinderCacheUtil.getResult(finderPath,
169 finderArgs, this);
170
171 if ((list != null) && !list.isEmpty()) {
172 for (Subscription subscription : list) {
173 if ((userId != subscription.getUserId())) {
174 list = null;
175
176 break;
177 }
178 }
179 }
180
181 if (list == null) {
182 StringBundler query = null;
183
184 if (orderByComparator != null) {
185 query = new StringBundler(3 +
186 (orderByComparator.getOrderByFields().length * 3));
187 }
188 else {
189 query = new StringBundler(3);
190 }
191
192 query.append(_SQL_SELECT_SUBSCRIPTION_WHERE);
193
194 query.append(_FINDER_COLUMN_USERID_USERID_2);
195
196 if (orderByComparator != null) {
197 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
198 orderByComparator);
199 }
200 else
201 if (pagination) {
202 query.append(SubscriptionModelImpl.ORDER_BY_JPQL);
203 }
204
205 String sql = query.toString();
206
207 Session session = null;
208
209 try {
210 session = openSession();
211
212 Query q = session.createQuery(sql);
213
214 QueryPos qPos = QueryPos.getInstance(q);
215
216 qPos.add(userId);
217
218 if (!pagination) {
219 list = (List<Subscription>)QueryUtil.list(q, getDialect(),
220 start, end, false);
221
222 Collections.sort(list);
223
224 list = Collections.unmodifiableList(list);
225 }
226 else {
227 list = (List<Subscription>)QueryUtil.list(q, getDialect(),
228 start, end);
229 }
230
231 cacheResult(list);
232
233 FinderCacheUtil.putResult(finderPath, finderArgs, list);
234 }
235 catch (Exception e) {
236 FinderCacheUtil.removeResult(finderPath, finderArgs);
237
238 throw processException(e);
239 }
240 finally {
241 closeSession(session);
242 }
243 }
244
245 return list;
246 }
247
248
256 @Override
257 public Subscription findByUserId_First(long userId,
258 OrderByComparator<Subscription> orderByComparator)
259 throws NoSuchSubscriptionException {
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
286 @Override
287 public Subscription fetchByUserId_First(long userId,
288 OrderByComparator<Subscription> orderByComparator) {
289 List<Subscription> list = findByUserId(userId, 0, 1, orderByComparator);
290
291 if (!list.isEmpty()) {
292 return list.get(0);
293 }
294
295 return null;
296 }
297
298
306 @Override
307 public Subscription findByUserId_Last(long userId,
308 OrderByComparator<Subscription> orderByComparator)
309 throws NoSuchSubscriptionException {
310 Subscription subscription = fetchByUserId_Last(userId, orderByComparator);
311
312 if (subscription != null) {
313 return subscription;
314 }
315
316 StringBundler msg = new StringBundler(4);
317
318 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
319
320 msg.append("userId=");
321 msg.append(userId);
322
323 msg.append(StringPool.CLOSE_CURLY_BRACE);
324
325 throw new NoSuchSubscriptionException(msg.toString());
326 }
327
328
335 @Override
336 public Subscription fetchByUserId_Last(long userId,
337 OrderByComparator<Subscription> orderByComparator) {
338 int count = countByUserId(userId);
339
340 if (count == 0) {
341 return null;
342 }
343
344 List<Subscription> list = findByUserId(userId, count - 1, count,
345 orderByComparator);
346
347 if (!list.isEmpty()) {
348 return list.get(0);
349 }
350
351 return null;
352 }
353
354
363 @Override
364 public Subscription[] findByUserId_PrevAndNext(long subscriptionId,
365 long userId, OrderByComparator<Subscription> orderByComparator)
366 throws NoSuchSubscriptionException {
367 Subscription subscription = findByPrimaryKey(subscriptionId);
368
369 Session session = null;
370
371 try {
372 session = openSession();
373
374 Subscription[] array = new SubscriptionImpl[3];
375
376 array[0] = getByUserId_PrevAndNext(session, subscription, userId,
377 orderByComparator, true);
378
379 array[1] = subscription;
380
381 array[2] = getByUserId_PrevAndNext(session, subscription, userId,
382 orderByComparator, false);
383
384 return array;
385 }
386 catch (Exception e) {
387 throw processException(e);
388 }
389 finally {
390 closeSession(session);
391 }
392 }
393
394 protected Subscription getByUserId_PrevAndNext(Session session,
395 Subscription subscription, long userId,
396 OrderByComparator<Subscription> orderByComparator, boolean previous) {
397 StringBundler query = null;
398
399 if (orderByComparator != null) {
400 query = new StringBundler(6 +
401 (orderByComparator.getOrderByFields().length * 6));
402 }
403 else {
404 query = new StringBundler(3);
405 }
406
407 query.append(_SQL_SELECT_SUBSCRIPTION_WHERE);
408
409 query.append(_FINDER_COLUMN_USERID_USERID_2);
410
411 if (orderByComparator != null) {
412 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
413
414 if (orderByConditionFields.length > 0) {
415 query.append(WHERE_AND);
416 }
417
418 for (int i = 0; i < orderByConditionFields.length; i++) {
419 query.append(_ORDER_BY_ENTITY_ALIAS);
420 query.append(orderByConditionFields[i]);
421
422 if ((i + 1) < orderByConditionFields.length) {
423 if (orderByComparator.isAscending() ^ previous) {
424 query.append(WHERE_GREATER_THAN_HAS_NEXT);
425 }
426 else {
427 query.append(WHERE_LESSER_THAN_HAS_NEXT);
428 }
429 }
430 else {
431 if (orderByComparator.isAscending() ^ previous) {
432 query.append(WHERE_GREATER_THAN);
433 }
434 else {
435 query.append(WHERE_LESSER_THAN);
436 }
437 }
438 }
439
440 query.append(ORDER_BY_CLAUSE);
441
442 String[] orderByFields = orderByComparator.getOrderByFields();
443
444 for (int i = 0; i < orderByFields.length; i++) {
445 query.append(_ORDER_BY_ENTITY_ALIAS);
446 query.append(orderByFields[i]);
447
448 if ((i + 1) < orderByFields.length) {
449 if (orderByComparator.isAscending() ^ previous) {
450 query.append(ORDER_BY_ASC_HAS_NEXT);
451 }
452 else {
453 query.append(ORDER_BY_DESC_HAS_NEXT);
454 }
455 }
456 else {
457 if (orderByComparator.isAscending() ^ previous) {
458 query.append(ORDER_BY_ASC);
459 }
460 else {
461 query.append(ORDER_BY_DESC);
462 }
463 }
464 }
465 }
466 else {
467 query.append(SubscriptionModelImpl.ORDER_BY_JPQL);
468 }
469
470 String sql = query.toString();
471
472 Query q = session.createQuery(sql);
473
474 q.setFirstResult(0);
475 q.setMaxResults(2);
476
477 QueryPos qPos = QueryPos.getInstance(q);
478
479 qPos.add(userId);
480
481 if (orderByComparator != null) {
482 Object[] values = orderByComparator.getOrderByConditionValues(subscription);
483
484 for (Object value : values) {
485 qPos.add(value);
486 }
487 }
488
489 List<Subscription> list = q.list();
490
491 if (list.size() == 2) {
492 return list.get(1);
493 }
494 else {
495 return null;
496 }
497 }
498
499
504 @Override
505 public void removeByUserId(long userId) {
506 for (Subscription subscription : findByUserId(userId,
507 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
508 remove(subscription);
509 }
510 }
511
512
518 @Override
519 public int countByUserId(long userId) {
520 FinderPath finderPath = FINDER_PATH_COUNT_BY_USERID;
521
522 Object[] finderArgs = new Object[] { userId };
523
524 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
525 this);
526
527 if (count == null) {
528 StringBundler query = new StringBundler(2);
529
530 query.append(_SQL_COUNT_SUBSCRIPTION_WHERE);
531
532 query.append(_FINDER_COLUMN_USERID_USERID_2);
533
534 String sql = query.toString();
535
536 Session session = null;
537
538 try {
539 session = openSession();
540
541 Query q = session.createQuery(sql);
542
543 QueryPos qPos = QueryPos.getInstance(q);
544
545 qPos.add(userId);
546
547 count = (Long)q.uniqueResult();
548
549 FinderCacheUtil.putResult(finderPath, finderArgs, count);
550 }
551 catch (Exception e) {
552 FinderCacheUtil.removeResult(finderPath, finderArgs);
553
554 throw processException(e);
555 }
556 finally {
557 closeSession(session);
558 }
559 }
560
561 return count.intValue();
562 }
563
564 private static final String _FINDER_COLUMN_USERID_USERID_2 = "subscription.userId = ?";
565 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
566 SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.class,
567 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_U",
568 new String[] {
569 Long.class.getName(), Long.class.getName(),
570
571 Integer.class.getName(), Integer.class.getName(),
572 OrderByComparator.class.getName()
573 });
574 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
575 SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.class,
576 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_U",
577 new String[] { Long.class.getName(), Long.class.getName() },
578 SubscriptionModelImpl.GROUPID_COLUMN_BITMASK |
579 SubscriptionModelImpl.USERID_COLUMN_BITMASK);
580 public static final FinderPath FINDER_PATH_COUNT_BY_G_U = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
581 SubscriptionModelImpl.FINDER_CACHE_ENABLED, Long.class,
582 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_U",
583 new String[] { Long.class.getName(), Long.class.getName() });
584
585
592 @Override
593 public List<Subscription> findByG_U(long groupId, long userId) {
594 return findByG_U(groupId, userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
595 null);
596 }
597
598
611 @Override
612 public List<Subscription> findByG_U(long groupId, long userId, int start,
613 int end) {
614 return findByG_U(groupId, userId, start, end, null);
615 }
616
617
631 @Override
632 public List<Subscription> findByG_U(long groupId, long userId, int start,
633 int end, OrderByComparator<Subscription> orderByComparator) {
634 boolean pagination = true;
635 FinderPath finderPath = null;
636 Object[] finderArgs = null;
637
638 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
639 (orderByComparator == null)) {
640 pagination = false;
641 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U;
642 finderArgs = new Object[] { groupId, userId };
643 }
644 else {
645 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U;
646 finderArgs = new Object[] {
647 groupId, userId,
648
649 start, end, orderByComparator
650 };
651 }
652
653 List<Subscription> list = (List<Subscription>)FinderCacheUtil.getResult(finderPath,
654 finderArgs, this);
655
656 if ((list != null) && !list.isEmpty()) {
657 for (Subscription subscription : list) {
658 if ((groupId != subscription.getGroupId()) ||
659 (userId != subscription.getUserId())) {
660 list = null;
661
662 break;
663 }
664 }
665 }
666
667 if (list == null) {
668 StringBundler query = null;
669
670 if (orderByComparator != null) {
671 query = new StringBundler(4 +
672 (orderByComparator.getOrderByFields().length * 3));
673 }
674 else {
675 query = new StringBundler(4);
676 }
677
678 query.append(_SQL_SELECT_SUBSCRIPTION_WHERE);
679
680 query.append(_FINDER_COLUMN_G_U_GROUPID_2);
681
682 query.append(_FINDER_COLUMN_G_U_USERID_2);
683
684 if (orderByComparator != null) {
685 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
686 orderByComparator);
687 }
688 else
689 if (pagination) {
690 query.append(SubscriptionModelImpl.ORDER_BY_JPQL);
691 }
692
693 String sql = query.toString();
694
695 Session session = null;
696
697 try {
698 session = openSession();
699
700 Query q = session.createQuery(sql);
701
702 QueryPos qPos = QueryPos.getInstance(q);
703
704 qPos.add(groupId);
705
706 qPos.add(userId);
707
708 if (!pagination) {
709 list = (List<Subscription>)QueryUtil.list(q, getDialect(),
710 start, end, false);
711
712 Collections.sort(list);
713
714 list = Collections.unmodifiableList(list);
715 }
716 else {
717 list = (List<Subscription>)QueryUtil.list(q, getDialect(),
718 start, end);
719 }
720
721 cacheResult(list);
722
723 FinderCacheUtil.putResult(finderPath, finderArgs, list);
724 }
725 catch (Exception e) {
726 FinderCacheUtil.removeResult(finderPath, finderArgs);
727
728 throw processException(e);
729 }
730 finally {
731 closeSession(session);
732 }
733 }
734
735 return list;
736 }
737
738
747 @Override
748 public Subscription findByG_U_First(long groupId, long userId,
749 OrderByComparator<Subscription> orderByComparator)
750 throws NoSuchSubscriptionException {
751 Subscription subscription = fetchByG_U_First(groupId, userId,
752 orderByComparator);
753
754 if (subscription != null) {
755 return subscription;
756 }
757
758 StringBundler msg = new StringBundler(6);
759
760 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
761
762 msg.append("groupId=");
763 msg.append(groupId);
764
765 msg.append(", userId=");
766 msg.append(userId);
767
768 msg.append(StringPool.CLOSE_CURLY_BRACE);
769
770 throw new NoSuchSubscriptionException(msg.toString());
771 }
772
773
781 @Override
782 public Subscription fetchByG_U_First(long groupId, long userId,
783 OrderByComparator<Subscription> orderByComparator) {
784 List<Subscription> list = findByG_U(groupId, userId, 0, 1,
785 orderByComparator);
786
787 if (!list.isEmpty()) {
788 return list.get(0);
789 }
790
791 return null;
792 }
793
794
803 @Override
804 public Subscription findByG_U_Last(long groupId, long userId,
805 OrderByComparator<Subscription> orderByComparator)
806 throws NoSuchSubscriptionException {
807 Subscription subscription = fetchByG_U_Last(groupId, userId,
808 orderByComparator);
809
810 if (subscription != null) {
811 return subscription;
812 }
813
814 StringBundler msg = new StringBundler(6);
815
816 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
817
818 msg.append("groupId=");
819 msg.append(groupId);
820
821 msg.append(", userId=");
822 msg.append(userId);
823
824 msg.append(StringPool.CLOSE_CURLY_BRACE);
825
826 throw new NoSuchSubscriptionException(msg.toString());
827 }
828
829
837 @Override
838 public Subscription fetchByG_U_Last(long groupId, long userId,
839 OrderByComparator<Subscription> orderByComparator) {
840 int count = countByG_U(groupId, userId);
841
842 if (count == 0) {
843 return null;
844 }
845
846 List<Subscription> list = findByG_U(groupId, userId, count - 1, count,
847 orderByComparator);
848
849 if (!list.isEmpty()) {
850 return list.get(0);
851 }
852
853 return null;
854 }
855
856
866 @Override
867 public Subscription[] findByG_U_PrevAndNext(long subscriptionId,
868 long groupId, long userId,
869 OrderByComparator<Subscription> orderByComparator)
870 throws NoSuchSubscriptionException {
871 Subscription subscription = findByPrimaryKey(subscriptionId);
872
873 Session session = null;
874
875 try {
876 session = openSession();
877
878 Subscription[] array = new SubscriptionImpl[3];
879
880 array[0] = getByG_U_PrevAndNext(session, subscription, groupId,
881 userId, orderByComparator, true);
882
883 array[1] = subscription;
884
885 array[2] = getByG_U_PrevAndNext(session, subscription, groupId,
886 userId, orderByComparator, false);
887
888 return array;
889 }
890 catch (Exception e) {
891 throw processException(e);
892 }
893 finally {
894 closeSession(session);
895 }
896 }
897
898 protected Subscription getByG_U_PrevAndNext(Session session,
899 Subscription subscription, long groupId, long userId,
900 OrderByComparator<Subscription> orderByComparator, boolean previous) {
901 StringBundler query = null;
902
903 if (orderByComparator != null) {
904 query = new StringBundler(6 +
905 (orderByComparator.getOrderByFields().length * 6));
906 }
907 else {
908 query = new StringBundler(3);
909 }
910
911 query.append(_SQL_SELECT_SUBSCRIPTION_WHERE);
912
913 query.append(_FINDER_COLUMN_G_U_GROUPID_2);
914
915 query.append(_FINDER_COLUMN_G_U_USERID_2);
916
917 if (orderByComparator != null) {
918 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
919
920 if (orderByConditionFields.length > 0) {
921 query.append(WHERE_AND);
922 }
923
924 for (int i = 0; i < orderByConditionFields.length; i++) {
925 query.append(_ORDER_BY_ENTITY_ALIAS);
926 query.append(orderByConditionFields[i]);
927
928 if ((i + 1) < orderByConditionFields.length) {
929 if (orderByComparator.isAscending() ^ previous) {
930 query.append(WHERE_GREATER_THAN_HAS_NEXT);
931 }
932 else {
933 query.append(WHERE_LESSER_THAN_HAS_NEXT);
934 }
935 }
936 else {
937 if (orderByComparator.isAscending() ^ previous) {
938 query.append(WHERE_GREATER_THAN);
939 }
940 else {
941 query.append(WHERE_LESSER_THAN);
942 }
943 }
944 }
945
946 query.append(ORDER_BY_CLAUSE);
947
948 String[] orderByFields = orderByComparator.getOrderByFields();
949
950 for (int i = 0; i < orderByFields.length; i++) {
951 query.append(_ORDER_BY_ENTITY_ALIAS);
952 query.append(orderByFields[i]);
953
954 if ((i + 1) < orderByFields.length) {
955 if (orderByComparator.isAscending() ^ previous) {
956 query.append(ORDER_BY_ASC_HAS_NEXT);
957 }
958 else {
959 query.append(ORDER_BY_DESC_HAS_NEXT);
960 }
961 }
962 else {
963 if (orderByComparator.isAscending() ^ previous) {
964 query.append(ORDER_BY_ASC);
965 }
966 else {
967 query.append(ORDER_BY_DESC);
968 }
969 }
970 }
971 }
972 else {
973 query.append(SubscriptionModelImpl.ORDER_BY_JPQL);
974 }
975
976 String sql = query.toString();
977
978 Query q = session.createQuery(sql);
979
980 q.setFirstResult(0);
981 q.setMaxResults(2);
982
983 QueryPos qPos = QueryPos.getInstance(q);
984
985 qPos.add(groupId);
986
987 qPos.add(userId);
988
989 if (orderByComparator != null) {
990 Object[] values = orderByComparator.getOrderByConditionValues(subscription);
991
992 for (Object value : values) {
993 qPos.add(value);
994 }
995 }
996
997 List<Subscription> list = q.list();
998
999 if (list.size() == 2) {
1000 return list.get(1);
1001 }
1002 else {
1003 return null;
1004 }
1005 }
1006
1007
1013 @Override
1014 public void removeByG_U(long groupId, long userId) {
1015 for (Subscription subscription : findByG_U(groupId, userId,
1016 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1017 remove(subscription);
1018 }
1019 }
1020
1021
1028 @Override
1029 public int countByG_U(long groupId, long userId) {
1030 FinderPath finderPath = FINDER_PATH_COUNT_BY_G_U;
1031
1032 Object[] finderArgs = new Object[] { groupId, userId };
1033
1034 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1035 this);
1036
1037 if (count == null) {
1038 StringBundler query = new StringBundler(3);
1039
1040 query.append(_SQL_COUNT_SUBSCRIPTION_WHERE);
1041
1042 query.append(_FINDER_COLUMN_G_U_GROUPID_2);
1043
1044 query.append(_FINDER_COLUMN_G_U_USERID_2);
1045
1046 String sql = query.toString();
1047
1048 Session session = null;
1049
1050 try {
1051 session = openSession();
1052
1053 Query q = session.createQuery(sql);
1054
1055 QueryPos qPos = QueryPos.getInstance(q);
1056
1057 qPos.add(groupId);
1058
1059 qPos.add(userId);
1060
1061 count = (Long)q.uniqueResult();
1062
1063 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1064 }
1065 catch (Exception e) {
1066 FinderCacheUtil.removeResult(finderPath, finderArgs);
1067
1068 throw processException(e);
1069 }
1070 finally {
1071 closeSession(session);
1072 }
1073 }
1074
1075 return count.intValue();
1076 }
1077
1078 private static final String _FINDER_COLUMN_G_U_GROUPID_2 = "subscription.groupId = ? AND ";
1079 private static final String _FINDER_COLUMN_G_U_USERID_2 = "subscription.userId = ?";
1080 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
1081 SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.class,
1082 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C",
1083 new String[] {
1084 Long.class.getName(), Long.class.getName(),
1085
1086 Integer.class.getName(), Integer.class.getName(),
1087 OrderByComparator.class.getName()
1088 });
1089 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
1090 SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.class,
1091 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C",
1092 new String[] { Long.class.getName(), Long.class.getName() },
1093 SubscriptionModelImpl.USERID_COLUMN_BITMASK |
1094 SubscriptionModelImpl.CLASSNAMEID_COLUMN_BITMASK);
1095 public static final FinderPath FINDER_PATH_COUNT_BY_U_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
1096 SubscriptionModelImpl.FINDER_CACHE_ENABLED, Long.class,
1097 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C",
1098 new String[] { Long.class.getName(), Long.class.getName() });
1099
1100
1107 @Override
1108 public List<Subscription> findByU_C(long userId, long classNameId) {
1109 return findByU_C(userId, classNameId, QueryUtil.ALL_POS,
1110 QueryUtil.ALL_POS, null);
1111 }
1112
1113
1126 @Override
1127 public List<Subscription> findByU_C(long userId, long classNameId,
1128 int start, int end) {
1129 return findByU_C(userId, classNameId, start, end, null);
1130 }
1131
1132
1146 @Override
1147 public List<Subscription> findByU_C(long userId, long classNameId,
1148 int start, int end, OrderByComparator<Subscription> orderByComparator) {
1149 boolean pagination = true;
1150 FinderPath finderPath = null;
1151 Object[] finderArgs = null;
1152
1153 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1154 (orderByComparator == null)) {
1155 pagination = false;
1156 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C;
1157 finderArgs = new Object[] { userId, classNameId };
1158 }
1159 else {
1160 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C;
1161 finderArgs = new Object[] {
1162 userId, classNameId,
1163
1164 start, end, orderByComparator
1165 };
1166 }
1167
1168 List<Subscription> list = (List<Subscription>)FinderCacheUtil.getResult(finderPath,
1169 finderArgs, this);
1170
1171 if ((list != null) && !list.isEmpty()) {
1172 for (Subscription subscription : list) {
1173 if ((userId != subscription.getUserId()) ||
1174 (classNameId != subscription.getClassNameId())) {
1175 list = null;
1176
1177 break;
1178 }
1179 }
1180 }
1181
1182 if (list == null) {
1183 StringBundler query = null;
1184
1185 if (orderByComparator != null) {
1186 query = new StringBundler(4 +
1187 (orderByComparator.getOrderByFields().length * 3));
1188 }
1189 else {
1190 query = new StringBundler(4);
1191 }
1192
1193 query.append(_SQL_SELECT_SUBSCRIPTION_WHERE);
1194
1195 query.append(_FINDER_COLUMN_U_C_USERID_2);
1196
1197 query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
1198
1199 if (orderByComparator != null) {
1200 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1201 orderByComparator);
1202 }
1203 else
1204 if (pagination) {
1205 query.append(SubscriptionModelImpl.ORDER_BY_JPQL);
1206 }
1207
1208 String sql = query.toString();
1209
1210 Session session = null;
1211
1212 try {
1213 session = openSession();
1214
1215 Query q = session.createQuery(sql);
1216
1217 QueryPos qPos = QueryPos.getInstance(q);
1218
1219 qPos.add(userId);
1220
1221 qPos.add(classNameId);
1222
1223 if (!pagination) {
1224 list = (List<Subscription>)QueryUtil.list(q, getDialect(),
1225 start, end, false);
1226
1227 Collections.sort(list);
1228
1229 list = Collections.unmodifiableList(list);
1230 }
1231 else {
1232 list = (List<Subscription>)QueryUtil.list(q, getDialect(),
1233 start, end);
1234 }
1235
1236 cacheResult(list);
1237
1238 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1239 }
1240 catch (Exception e) {
1241 FinderCacheUtil.removeResult(finderPath, finderArgs);
1242
1243 throw processException(e);
1244 }
1245 finally {
1246 closeSession(session);
1247 }
1248 }
1249
1250 return list;
1251 }
1252
1253
1262 @Override
1263 public Subscription findByU_C_First(long userId, long classNameId,
1264 OrderByComparator<Subscription> orderByComparator)
1265 throws NoSuchSubscriptionException {
1266 Subscription subscription = fetchByU_C_First(userId, classNameId,
1267 orderByComparator);
1268
1269 if (subscription != null) {
1270 return subscription;
1271 }
1272
1273 StringBundler msg = new StringBundler(6);
1274
1275 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1276
1277 msg.append("userId=");
1278 msg.append(userId);
1279
1280 msg.append(", classNameId=");
1281 msg.append(classNameId);
1282
1283 msg.append(StringPool.CLOSE_CURLY_BRACE);
1284
1285 throw new NoSuchSubscriptionException(msg.toString());
1286 }
1287
1288
1296 @Override
1297 public Subscription fetchByU_C_First(long userId, long classNameId,
1298 OrderByComparator<Subscription> orderByComparator) {
1299 List<Subscription> list = findByU_C(userId, classNameId, 0, 1,
1300 orderByComparator);
1301
1302 if (!list.isEmpty()) {
1303 return list.get(0);
1304 }
1305
1306 return null;
1307 }
1308
1309
1318 @Override
1319 public Subscription findByU_C_Last(long userId, long classNameId,
1320 OrderByComparator<Subscription> orderByComparator)
1321 throws NoSuchSubscriptionException {
1322 Subscription subscription = fetchByU_C_Last(userId, classNameId,
1323 orderByComparator);
1324
1325 if (subscription != null) {
1326 return subscription;
1327 }
1328
1329 StringBundler msg = new StringBundler(6);
1330
1331 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1332
1333 msg.append("userId=");
1334 msg.append(userId);
1335
1336 msg.append(", classNameId=");
1337 msg.append(classNameId);
1338
1339 msg.append(StringPool.CLOSE_CURLY_BRACE);
1340
1341 throw new NoSuchSubscriptionException(msg.toString());
1342 }
1343
1344
1352 @Override
1353 public Subscription fetchByU_C_Last(long userId, long classNameId,
1354 OrderByComparator<Subscription> orderByComparator) {
1355 int count = countByU_C(userId, classNameId);
1356
1357 if (count == 0) {
1358 return null;
1359 }
1360
1361 List<Subscription> list = findByU_C(userId, classNameId, count - 1,
1362 count, orderByComparator);
1363
1364 if (!list.isEmpty()) {
1365 return list.get(0);
1366 }
1367
1368 return null;
1369 }
1370
1371
1381 @Override
1382 public Subscription[] findByU_C_PrevAndNext(long subscriptionId,
1383 long userId, long classNameId,
1384 OrderByComparator<Subscription> orderByComparator)
1385 throws NoSuchSubscriptionException {
1386 Subscription subscription = findByPrimaryKey(subscriptionId);
1387
1388 Session session = null;
1389
1390 try {
1391 session = openSession();
1392
1393 Subscription[] array = new SubscriptionImpl[3];
1394
1395 array[0] = getByU_C_PrevAndNext(session, subscription, userId,
1396 classNameId, orderByComparator, true);
1397
1398 array[1] = subscription;
1399
1400 array[2] = getByU_C_PrevAndNext(session, subscription, userId,
1401 classNameId, orderByComparator, false);
1402
1403 return array;
1404 }
1405 catch (Exception e) {
1406 throw processException(e);
1407 }
1408 finally {
1409 closeSession(session);
1410 }
1411 }
1412
1413 protected Subscription getByU_C_PrevAndNext(Session session,
1414 Subscription subscription, long userId, long classNameId,
1415 OrderByComparator<Subscription> orderByComparator, boolean previous) {
1416 StringBundler query = null;
1417
1418 if (orderByComparator != null) {
1419 query = new StringBundler(6 +
1420 (orderByComparator.getOrderByFields().length * 6));
1421 }
1422 else {
1423 query = new StringBundler(3);
1424 }
1425
1426 query.append(_SQL_SELECT_SUBSCRIPTION_WHERE);
1427
1428 query.append(_FINDER_COLUMN_U_C_USERID_2);
1429
1430 query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
1431
1432 if (orderByComparator != null) {
1433 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1434
1435 if (orderByConditionFields.length > 0) {
1436 query.append(WHERE_AND);
1437 }
1438
1439 for (int i = 0; i < orderByConditionFields.length; i++) {
1440 query.append(_ORDER_BY_ENTITY_ALIAS);
1441 query.append(orderByConditionFields[i]);
1442
1443 if ((i + 1) < orderByConditionFields.length) {
1444 if (orderByComparator.isAscending() ^ previous) {
1445 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1446 }
1447 else {
1448 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1449 }
1450 }
1451 else {
1452 if (orderByComparator.isAscending() ^ previous) {
1453 query.append(WHERE_GREATER_THAN);
1454 }
1455 else {
1456 query.append(WHERE_LESSER_THAN);
1457 }
1458 }
1459 }
1460
1461 query.append(ORDER_BY_CLAUSE);
1462
1463 String[] orderByFields = orderByComparator.getOrderByFields();
1464
1465 for (int i = 0; i < orderByFields.length; i++) {
1466 query.append(_ORDER_BY_ENTITY_ALIAS);
1467 query.append(orderByFields[i]);
1468
1469 if ((i + 1) < orderByFields.length) {
1470 if (orderByComparator.isAscending() ^ previous) {
1471 query.append(ORDER_BY_ASC_HAS_NEXT);
1472 }
1473 else {
1474 query.append(ORDER_BY_DESC_HAS_NEXT);
1475 }
1476 }
1477 else {
1478 if (orderByComparator.isAscending() ^ previous) {
1479 query.append(ORDER_BY_ASC);
1480 }
1481 else {
1482 query.append(ORDER_BY_DESC);
1483 }
1484 }
1485 }
1486 }
1487 else {
1488 query.append(SubscriptionModelImpl.ORDER_BY_JPQL);
1489 }
1490
1491 String sql = query.toString();
1492
1493 Query q = session.createQuery(sql);
1494
1495 q.setFirstResult(0);
1496 q.setMaxResults(2);
1497
1498 QueryPos qPos = QueryPos.getInstance(q);
1499
1500 qPos.add(userId);
1501
1502 qPos.add(classNameId);
1503
1504 if (orderByComparator != null) {
1505 Object[] values = orderByComparator.getOrderByConditionValues(subscription);
1506
1507 for (Object value : values) {
1508 qPos.add(value);
1509 }
1510 }
1511
1512 List<Subscription> list = q.list();
1513
1514 if (list.size() == 2) {
1515 return list.get(1);
1516 }
1517 else {
1518 return null;
1519 }
1520 }
1521
1522
1528 @Override
1529 public void removeByU_C(long userId, long classNameId) {
1530 for (Subscription subscription : findByU_C(userId, classNameId,
1531 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1532 remove(subscription);
1533 }
1534 }
1535
1536
1543 @Override
1544 public int countByU_C(long userId, long classNameId) {
1545 FinderPath finderPath = FINDER_PATH_COUNT_BY_U_C;
1546
1547 Object[] finderArgs = new Object[] { userId, classNameId };
1548
1549 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1550 this);
1551
1552 if (count == null) {
1553 StringBundler query = new StringBundler(3);
1554
1555 query.append(_SQL_COUNT_SUBSCRIPTION_WHERE);
1556
1557 query.append(_FINDER_COLUMN_U_C_USERID_2);
1558
1559 query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
1560
1561 String sql = query.toString();
1562
1563 Session session = null;
1564
1565 try {
1566 session = openSession();
1567
1568 Query q = session.createQuery(sql);
1569
1570 QueryPos qPos = QueryPos.getInstance(q);
1571
1572 qPos.add(userId);
1573
1574 qPos.add(classNameId);
1575
1576 count = (Long)q.uniqueResult();
1577
1578 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1579 }
1580 catch (Exception e) {
1581 FinderCacheUtil.removeResult(finderPath, finderArgs);
1582
1583 throw processException(e);
1584 }
1585 finally {
1586 closeSession(session);
1587 }
1588 }
1589
1590 return count.intValue();
1591 }
1592
1593 private static final String _FINDER_COLUMN_U_C_USERID_2 = "subscription.userId = ? AND ";
1594 private static final String _FINDER_COLUMN_U_C_CLASSNAMEID_2 = "subscription.classNameId = ?";
1595 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
1596 SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.class,
1597 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C_C",
1598 new String[] {
1599 Long.class.getName(), Long.class.getName(), Long.class.getName(),
1600
1601 Integer.class.getName(), Integer.class.getName(),
1602 OrderByComparator.class.getName()
1603 });
1604 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
1605 SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.class,
1606 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C_C",
1607 new String[] {
1608 Long.class.getName(), Long.class.getName(), Long.class.getName()
1609 },
1610 SubscriptionModelImpl.COMPANYID_COLUMN_BITMASK |
1611 SubscriptionModelImpl.CLASSNAMEID_COLUMN_BITMASK |
1612 SubscriptionModelImpl.CLASSPK_COLUMN_BITMASK);
1613 public static final FinderPath FINDER_PATH_COUNT_BY_C_C_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
1614 SubscriptionModelImpl.FINDER_CACHE_ENABLED, Long.class,
1615 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_C",
1616 new String[] {
1617 Long.class.getName(), Long.class.getName(), Long.class.getName()
1618 });
1619
1620
1628 @Override
1629 public List<Subscription> findByC_C_C(long companyId, long classNameId,
1630 long classPK) {
1631 return findByC_C_C(companyId, classNameId, classPK, QueryUtil.ALL_POS,
1632 QueryUtil.ALL_POS, null);
1633 }
1634
1635
1649 @Override
1650 public List<Subscription> findByC_C_C(long companyId, long classNameId,
1651 long classPK, int start, int end) {
1652 return findByC_C_C(companyId, classNameId, classPK, start, end, null);
1653 }
1654
1655
1670 @Override
1671 public List<Subscription> findByC_C_C(long companyId, long classNameId,
1672 long classPK, int start, int end,
1673 OrderByComparator<Subscription> orderByComparator) {
1674 boolean pagination = true;
1675 FinderPath finderPath = null;
1676 Object[] finderArgs = null;
1677
1678 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1679 (orderByComparator == null)) {
1680 pagination = false;
1681 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C;
1682 finderArgs = new Object[] { companyId, classNameId, classPK };
1683 }
1684 else {
1685 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_C;
1686 finderArgs = new Object[] {
1687 companyId, classNameId, classPK,
1688
1689 start, end, orderByComparator
1690 };
1691 }
1692
1693 List<Subscription> list = (List<Subscription>)FinderCacheUtil.getResult(finderPath,
1694 finderArgs, this);
1695
1696 if ((list != null) && !list.isEmpty()) {
1697 for (Subscription subscription : list) {
1698 if ((companyId != subscription.getCompanyId()) ||
1699 (classNameId != subscription.getClassNameId()) ||
1700 (classPK != subscription.getClassPK())) {
1701 list = null;
1702
1703 break;
1704 }
1705 }
1706 }
1707
1708 if (list == null) {
1709 StringBundler query = null;
1710
1711 if (orderByComparator != null) {
1712 query = new StringBundler(5 +
1713 (orderByComparator.getOrderByFields().length * 3));
1714 }
1715 else {
1716 query = new StringBundler(5);
1717 }
1718
1719 query.append(_SQL_SELECT_SUBSCRIPTION_WHERE);
1720
1721 query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
1722
1723 query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
1724
1725 query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
1726
1727 if (orderByComparator != null) {
1728 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1729 orderByComparator);
1730 }
1731 else
1732 if (pagination) {
1733 query.append(SubscriptionModelImpl.ORDER_BY_JPQL);
1734 }
1735
1736 String sql = query.toString();
1737
1738 Session session = null;
1739
1740 try {
1741 session = openSession();
1742
1743 Query q = session.createQuery(sql);
1744
1745 QueryPos qPos = QueryPos.getInstance(q);
1746
1747 qPos.add(companyId);
1748
1749 qPos.add(classNameId);
1750
1751 qPos.add(classPK);
1752
1753 if (!pagination) {
1754 list = (List<Subscription>)QueryUtil.list(q, getDialect(),
1755 start, end, false);
1756
1757 Collections.sort(list);
1758
1759 list = Collections.unmodifiableList(list);
1760 }
1761 else {
1762 list = (List<Subscription>)QueryUtil.list(q, getDialect(),
1763 start, end);
1764 }
1765
1766 cacheResult(list);
1767
1768 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1769 }
1770 catch (Exception e) {
1771 FinderCacheUtil.removeResult(finderPath, finderArgs);
1772
1773 throw processException(e);
1774 }
1775 finally {
1776 closeSession(session);
1777 }
1778 }
1779
1780 return list;
1781 }
1782
1783
1793 @Override
1794 public Subscription findByC_C_C_First(long companyId, long classNameId,
1795 long classPK, OrderByComparator<Subscription> orderByComparator)
1796 throws NoSuchSubscriptionException {
1797 Subscription subscription = fetchByC_C_C_First(companyId, classNameId,
1798 classPK, orderByComparator);
1799
1800 if (subscription != null) {
1801 return subscription;
1802 }
1803
1804 StringBundler msg = new StringBundler(8);
1805
1806 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1807
1808 msg.append("companyId=");
1809 msg.append(companyId);
1810
1811 msg.append(", classNameId=");
1812 msg.append(classNameId);
1813
1814 msg.append(", classPK=");
1815 msg.append(classPK);
1816
1817 msg.append(StringPool.CLOSE_CURLY_BRACE);
1818
1819 throw new NoSuchSubscriptionException(msg.toString());
1820 }
1821
1822
1831 @Override
1832 public Subscription fetchByC_C_C_First(long companyId, long classNameId,
1833 long classPK, OrderByComparator<Subscription> orderByComparator) {
1834 List<Subscription> list = findByC_C_C(companyId, classNameId, classPK,
1835 0, 1, orderByComparator);
1836
1837 if (!list.isEmpty()) {
1838 return list.get(0);
1839 }
1840
1841 return null;
1842 }
1843
1844
1854 @Override
1855 public Subscription findByC_C_C_Last(long companyId, long classNameId,
1856 long classPK, OrderByComparator<Subscription> orderByComparator)
1857 throws NoSuchSubscriptionException {
1858 Subscription subscription = fetchByC_C_C_Last(companyId, classNameId,
1859 classPK, orderByComparator);
1860
1861 if (subscription != null) {
1862 return subscription;
1863 }
1864
1865 StringBundler msg = new StringBundler(8);
1866
1867 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1868
1869 msg.append("companyId=");
1870 msg.append(companyId);
1871
1872 msg.append(", classNameId=");
1873 msg.append(classNameId);
1874
1875 msg.append(", classPK=");
1876 msg.append(classPK);
1877
1878 msg.append(StringPool.CLOSE_CURLY_BRACE);
1879
1880 throw new NoSuchSubscriptionException(msg.toString());
1881 }
1882
1883
1892 @Override
1893 public Subscription fetchByC_C_C_Last(long companyId, long classNameId,
1894 long classPK, OrderByComparator<Subscription> orderByComparator) {
1895 int count = countByC_C_C(companyId, classNameId, classPK);
1896
1897 if (count == 0) {
1898 return null;
1899 }
1900
1901 List<Subscription> list = findByC_C_C(companyId, classNameId, classPK,
1902 count - 1, count, orderByComparator);
1903
1904 if (!list.isEmpty()) {
1905 return list.get(0);
1906 }
1907
1908 return null;
1909 }
1910
1911
1922 @Override
1923 public Subscription[] findByC_C_C_PrevAndNext(long subscriptionId,
1924 long companyId, long classNameId, long classPK,
1925 OrderByComparator<Subscription> orderByComparator)
1926 throws NoSuchSubscriptionException {
1927 Subscription subscription = findByPrimaryKey(subscriptionId);
1928
1929 Session session = null;
1930
1931 try {
1932 session = openSession();
1933
1934 Subscription[] array = new SubscriptionImpl[3];
1935
1936 array[0] = getByC_C_C_PrevAndNext(session, subscription, companyId,
1937 classNameId, classPK, orderByComparator, true);
1938
1939 array[1] = subscription;
1940
1941 array[2] = getByC_C_C_PrevAndNext(session, subscription, companyId,
1942 classNameId, classPK, orderByComparator, false);
1943
1944 return array;
1945 }
1946 catch (Exception e) {
1947 throw processException(e);
1948 }
1949 finally {
1950 closeSession(session);
1951 }
1952 }
1953
1954 protected Subscription getByC_C_C_PrevAndNext(Session session,
1955 Subscription subscription, long companyId, long classNameId,
1956 long classPK, OrderByComparator<Subscription> orderByComparator,
1957 boolean previous) {
1958 StringBundler query = null;
1959
1960 if (orderByComparator != null) {
1961 query = new StringBundler(6 +
1962 (orderByComparator.getOrderByFields().length * 6));
1963 }
1964 else {
1965 query = new StringBundler(3);
1966 }
1967
1968 query.append(_SQL_SELECT_SUBSCRIPTION_WHERE);
1969
1970 query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
1971
1972 query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
1973
1974 query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
1975
1976 if (orderByComparator != null) {
1977 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1978
1979 if (orderByConditionFields.length > 0) {
1980 query.append(WHERE_AND);
1981 }
1982
1983 for (int i = 0; i < orderByConditionFields.length; i++) {
1984 query.append(_ORDER_BY_ENTITY_ALIAS);
1985 query.append(orderByConditionFields[i]);
1986
1987 if ((i + 1) < orderByConditionFields.length) {
1988 if (orderByComparator.isAscending() ^ previous) {
1989 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1990 }
1991 else {
1992 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1993 }
1994 }
1995 else {
1996 if (orderByComparator.isAscending() ^ previous) {
1997 query.append(WHERE_GREATER_THAN);
1998 }
1999 else {
2000 query.append(WHERE_LESSER_THAN);
2001 }
2002 }
2003 }
2004
2005 query.append(ORDER_BY_CLAUSE);
2006
2007 String[] orderByFields = orderByComparator.getOrderByFields();
2008
2009 for (int i = 0; i < orderByFields.length; i++) {
2010 query.append(_ORDER_BY_ENTITY_ALIAS);
2011 query.append(orderByFields[i]);
2012
2013 if ((i + 1) < orderByFields.length) {
2014 if (orderByComparator.isAscending() ^ previous) {
2015 query.append(ORDER_BY_ASC_HAS_NEXT);
2016 }
2017 else {
2018 query.append(ORDER_BY_DESC_HAS_NEXT);
2019 }
2020 }
2021 else {
2022 if (orderByComparator.isAscending() ^ previous) {
2023 query.append(ORDER_BY_ASC);
2024 }
2025 else {
2026 query.append(ORDER_BY_DESC);
2027 }
2028 }
2029 }
2030 }
2031 else {
2032 query.append(SubscriptionModelImpl.ORDER_BY_JPQL);
2033 }
2034
2035 String sql = query.toString();
2036
2037 Query q = session.createQuery(sql);
2038
2039 q.setFirstResult(0);
2040 q.setMaxResults(2);
2041
2042 QueryPos qPos = QueryPos.getInstance(q);
2043
2044 qPos.add(companyId);
2045
2046 qPos.add(classNameId);
2047
2048 qPos.add(classPK);
2049
2050 if (orderByComparator != null) {
2051 Object[] values = orderByComparator.getOrderByConditionValues(subscription);
2052
2053 for (Object value : values) {
2054 qPos.add(value);
2055 }
2056 }
2057
2058 List<Subscription> list = q.list();
2059
2060 if (list.size() == 2) {
2061 return list.get(1);
2062 }
2063 else {
2064 return null;
2065 }
2066 }
2067
2068
2075 @Override
2076 public void removeByC_C_C(long companyId, long classNameId, long classPK) {
2077 for (Subscription subscription : findByC_C_C(companyId, classNameId,
2078 classPK, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2079 remove(subscription);
2080 }
2081 }
2082
2083
2091 @Override
2092 public int countByC_C_C(long companyId, long classNameId, long classPK) {
2093 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C_C;
2094
2095 Object[] finderArgs = new Object[] { companyId, classNameId, classPK };
2096
2097 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2098 this);
2099
2100 if (count == null) {
2101 StringBundler query = new StringBundler(4);
2102
2103 query.append(_SQL_COUNT_SUBSCRIPTION_WHERE);
2104
2105 query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
2106
2107 query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
2108
2109 query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
2110
2111 String sql = query.toString();
2112
2113 Session session = null;
2114
2115 try {
2116 session = openSession();
2117
2118 Query q = session.createQuery(sql);
2119
2120 QueryPos qPos = QueryPos.getInstance(q);
2121
2122 qPos.add(companyId);
2123
2124 qPos.add(classNameId);
2125
2126 qPos.add(classPK);
2127
2128 count = (Long)q.uniqueResult();
2129
2130 FinderCacheUtil.putResult(finderPath, finderArgs, count);
2131 }
2132 catch (Exception e) {
2133 FinderCacheUtil.removeResult(finderPath, finderArgs);
2134
2135 throw processException(e);
2136 }
2137 finally {
2138 closeSession(session);
2139 }
2140 }
2141
2142 return count.intValue();
2143 }
2144
2145 private static final String _FINDER_COLUMN_C_C_C_COMPANYID_2 = "subscription.companyId = ? AND ";
2146 private static final String _FINDER_COLUMN_C_C_C_CLASSNAMEID_2 = "subscription.classNameId = ? AND ";
2147 private static final String _FINDER_COLUMN_C_C_C_CLASSPK_2 = "subscription.classPK = ?";
2148 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_U_C_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
2149 SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.class,
2150 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_U_C_C",
2151 new String[] {
2152 Long.class.getName(), Long.class.getName(), Long.class.getName(),
2153 Long.class.getName(),
2154
2155 Integer.class.getName(), Integer.class.getName(),
2156 OrderByComparator.class.getName()
2157 });
2158 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_U_C_C =
2159 new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
2160 SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.class,
2161 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_U_C_C",
2162 new String[] {
2163 Long.class.getName(), Long.class.getName(), Long.class.getName(),
2164 Long.class.getName()
2165 },
2166 SubscriptionModelImpl.COMPANYID_COLUMN_BITMASK |
2167 SubscriptionModelImpl.USERID_COLUMN_BITMASK |
2168 SubscriptionModelImpl.CLASSNAMEID_COLUMN_BITMASK |
2169 SubscriptionModelImpl.CLASSPK_COLUMN_BITMASK);
2170 public static final FinderPath FINDER_PATH_FETCH_BY_C_U_C_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
2171 SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.class,
2172 FINDER_CLASS_NAME_ENTITY, "fetchByC_U_C_C",
2173 new String[] {
2174 Long.class.getName(), Long.class.getName(), Long.class.getName(),
2175 Long.class.getName()
2176 },
2177 SubscriptionModelImpl.COMPANYID_COLUMN_BITMASK |
2178 SubscriptionModelImpl.USERID_COLUMN_BITMASK |
2179 SubscriptionModelImpl.CLASSNAMEID_COLUMN_BITMASK |
2180 SubscriptionModelImpl.CLASSPK_COLUMN_BITMASK);
2181 public static final FinderPath FINDER_PATH_COUNT_BY_C_U_C_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
2182 SubscriptionModelImpl.FINDER_CACHE_ENABLED, Long.class,
2183 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_U_C_C",
2184 new String[] {
2185 Long.class.getName(), Long.class.getName(), Long.class.getName(),
2186 Long.class.getName()
2187 });
2188 public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_U_C_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
2189 SubscriptionModelImpl.FINDER_CACHE_ENABLED, Long.class,
2190 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByC_U_C_C",
2191 new String[] {
2192 Long.class.getName(), Long.class.getName(), Long.class.getName(),
2193 Long.class.getName()
2194 });
2195
2196
2209 @Override
2210 public List<Subscription> findByC_U_C_C(long companyId, long userId,
2211 long classNameId, long[] classPKs) {
2212 return findByC_U_C_C(companyId, userId, classNameId, classPKs,
2213 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2214 }
2215
2216
2231 @Override
2232 public List<Subscription> findByC_U_C_C(long companyId, long userId,
2233 long classNameId, long[] classPKs, int start, int end) {
2234 return findByC_U_C_C(companyId, userId, classNameId, classPKs, start,
2235 end, null);
2236 }
2237
2238
2254 @Override
2255 public List<Subscription> findByC_U_C_C(long companyId, long userId,
2256 long classNameId, long[] classPKs, int start, int end,
2257 OrderByComparator<Subscription> orderByComparator) {
2258 if (classPKs == null) {
2259 classPKs = new long[0];
2260 }
2261 else {
2262 classPKs = ArrayUtil.unique(classPKs);
2263 }
2264
2265 if (classPKs.length == 1) {
2266 Subscription subscription = fetchByC_U_C_C(companyId, userId,
2267 classNameId, classPKs[0]);
2268
2269 if (subscription == null) {
2270 return Collections.emptyList();
2271 }
2272 else {
2273 List<Subscription> list = new ArrayList<Subscription>(1);
2274
2275 list.add(subscription);
2276
2277 return list;
2278 }
2279 }
2280
2281 boolean pagination = true;
2282 Object[] finderArgs = null;
2283
2284 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2285 (orderByComparator == null)) {
2286 pagination = false;
2287 finderArgs = new Object[] {
2288 companyId, userId, classNameId, StringUtil.merge(classPKs)
2289 };
2290 }
2291 else {
2292 finderArgs = new Object[] {
2293 companyId, userId, classNameId, StringUtil.merge(classPKs),
2294
2295 start, end, orderByComparator
2296 };
2297 }
2298
2299 List<Subscription> list = (List<Subscription>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_C_U_C_C,
2300 finderArgs, this);
2301
2302 if ((list != null) && !list.isEmpty()) {
2303 for (Subscription subscription : list) {
2304 if ((companyId != subscription.getCompanyId()) ||
2305 (userId != subscription.getUserId()) ||
2306 (classNameId != subscription.getClassNameId()) ||
2307 !ArrayUtil.contains(classPKs, subscription.getClassPK())) {
2308 list = null;
2309
2310 break;
2311 }
2312 }
2313 }
2314
2315 if (list == null) {
2316 StringBundler query = new StringBundler();
2317
2318 query.append(_SQL_SELECT_SUBSCRIPTION_WHERE);
2319
2320 query.append(_FINDER_COLUMN_C_U_C_C_COMPANYID_2);
2321
2322 query.append(_FINDER_COLUMN_C_U_C_C_USERID_2);
2323
2324 query.append(_FINDER_COLUMN_C_U_C_C_CLASSNAMEID_2);
2325
2326 if (classPKs.length > 0) {
2327 query.append(StringPool.OPEN_PARENTHESIS);
2328
2329 query.append(_FINDER_COLUMN_C_U_C_C_CLASSPK_7);
2330
2331 query.append(StringUtil.merge(classPKs));
2332
2333 query.append(StringPool.CLOSE_PARENTHESIS);
2334
2335 query.append(StringPool.CLOSE_PARENTHESIS);
2336 }
2337
2338 query.setStringAt(removeConjunction(query.stringAt(query.index() -
2339 1)), query.index() - 1);
2340
2341 if (orderByComparator != null) {
2342 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2343 orderByComparator);
2344 }
2345 else
2346 if (pagination) {
2347 query.append(SubscriptionModelImpl.ORDER_BY_JPQL);
2348 }
2349
2350 String sql = query.toString();
2351
2352 Session session = null;
2353
2354 try {
2355 session = openSession();
2356
2357 Query q = session.createQuery(sql);
2358
2359 QueryPos qPos = QueryPos.getInstance(q);
2360
2361 qPos.add(companyId);
2362
2363 qPos.add(userId);
2364
2365 qPos.add(classNameId);
2366
2367 if (!pagination) {
2368 list = (List<Subscription>)QueryUtil.list(q, getDialect(),
2369 start, end, false);
2370
2371 Collections.sort(list);
2372
2373 list = Collections.unmodifiableList(list);
2374 }
2375 else {
2376 list = (List<Subscription>)QueryUtil.list(q, getDialect(),
2377 start, end);
2378 }
2379
2380 cacheResult(list);
2381
2382 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_C_U_C_C,
2383 finderArgs, list);
2384 }
2385 catch (Exception e) {
2386 FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_C_U_C_C,
2387 finderArgs);
2388
2389 throw processException(e);
2390 }
2391 finally {
2392 closeSession(session);
2393 }
2394 }
2395
2396 return list;
2397 }
2398
2399
2409 @Override
2410 public Subscription findByC_U_C_C(long companyId, long userId,
2411 long classNameId, long classPK) throws NoSuchSubscriptionException {
2412 Subscription subscription = fetchByC_U_C_C(companyId, userId,
2413 classNameId, classPK);
2414
2415 if (subscription == null) {
2416 StringBundler msg = new StringBundler(10);
2417
2418 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2419
2420 msg.append("companyId=");
2421 msg.append(companyId);
2422
2423 msg.append(", userId=");
2424 msg.append(userId);
2425
2426 msg.append(", classNameId=");
2427 msg.append(classNameId);
2428
2429 msg.append(", classPK=");
2430 msg.append(classPK);
2431
2432 msg.append(StringPool.CLOSE_CURLY_BRACE);
2433
2434 if (_log.isWarnEnabled()) {
2435 _log.warn(msg.toString());
2436 }
2437
2438 throw new NoSuchSubscriptionException(msg.toString());
2439 }
2440
2441 return subscription;
2442 }
2443
2444
2453 @Override
2454 public Subscription fetchByC_U_C_C(long companyId, long userId,
2455 long classNameId, long classPK) {
2456 return fetchByC_U_C_C(companyId, userId, classNameId, classPK, true);
2457 }
2458
2459
2469 @Override
2470 public Subscription fetchByC_U_C_C(long companyId, long userId,
2471 long classNameId, long classPK, boolean retrieveFromCache) {
2472 Object[] finderArgs = new Object[] {
2473 companyId, userId, classNameId, classPK
2474 };
2475
2476 Object result = null;
2477
2478 if (retrieveFromCache) {
2479 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_U_C_C,
2480 finderArgs, this);
2481 }
2482
2483 if (result instanceof Subscription) {
2484 Subscription subscription = (Subscription)result;
2485
2486 if ((companyId != subscription.getCompanyId()) ||
2487 (userId != subscription.getUserId()) ||
2488 (classNameId != subscription.getClassNameId()) ||
2489 (classPK != subscription.getClassPK())) {
2490 result = null;
2491 }
2492 }
2493
2494 if (result == null) {
2495 StringBundler query = new StringBundler(6);
2496
2497 query.append(_SQL_SELECT_SUBSCRIPTION_WHERE);
2498
2499 query.append(_FINDER_COLUMN_C_U_C_C_COMPANYID_2);
2500
2501 query.append(_FINDER_COLUMN_C_U_C_C_USERID_2);
2502
2503 query.append(_FINDER_COLUMN_C_U_C_C_CLASSNAMEID_2);
2504
2505 query.append(_FINDER_COLUMN_C_U_C_C_CLASSPK_2);
2506
2507 String sql = query.toString();
2508
2509 Session session = null;
2510
2511 try {
2512 session = openSession();
2513
2514 Query q = session.createQuery(sql);
2515
2516 QueryPos qPos = QueryPos.getInstance(q);
2517
2518 qPos.add(companyId);
2519
2520 qPos.add(userId);
2521
2522 qPos.add(classNameId);
2523
2524 qPos.add(classPK);
2525
2526 List<Subscription> list = q.list();
2527
2528 if (list.isEmpty()) {
2529 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_U_C_C,
2530 finderArgs, list);
2531 }
2532 else {
2533 Subscription subscription = list.get(0);
2534
2535 result = subscription;
2536
2537 cacheResult(subscription);
2538
2539 if ((subscription.getCompanyId() != companyId) ||
2540 (subscription.getUserId() != userId) ||
2541 (subscription.getClassNameId() != classNameId) ||
2542 (subscription.getClassPK() != classPK)) {
2543 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_U_C_C,
2544 finderArgs, subscription);
2545 }
2546 }
2547 }
2548 catch (Exception e) {
2549 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_U_C_C,
2550 finderArgs);
2551
2552 throw processException(e);
2553 }
2554 finally {
2555 closeSession(session);
2556 }
2557 }
2558
2559 if (result instanceof List<?>) {
2560 return null;
2561 }
2562 else {
2563 return (Subscription)result;
2564 }
2565 }
2566
2567
2576 @Override
2577 public Subscription removeByC_U_C_C(long companyId, long userId,
2578 long classNameId, long classPK) throws NoSuchSubscriptionException {
2579 Subscription subscription = findByC_U_C_C(companyId, userId,
2580 classNameId, classPK);
2581
2582 return remove(subscription);
2583 }
2584
2585
2594 @Override
2595 public int countByC_U_C_C(long companyId, long userId, long classNameId,
2596 long classPK) {
2597 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_U_C_C;
2598
2599 Object[] finderArgs = new Object[] {
2600 companyId, userId, classNameId, classPK
2601 };
2602
2603 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2604 this);
2605
2606 if (count == null) {
2607 StringBundler query = new StringBundler(5);
2608
2609 query.append(_SQL_COUNT_SUBSCRIPTION_WHERE);
2610
2611 query.append(_FINDER_COLUMN_C_U_C_C_COMPANYID_2);
2612
2613 query.append(_FINDER_COLUMN_C_U_C_C_USERID_2);
2614
2615 query.append(_FINDER_COLUMN_C_U_C_C_CLASSNAMEID_2);
2616
2617 query.append(_FINDER_COLUMN_C_U_C_C_CLASSPK_2);
2618
2619 String sql = query.toString();
2620
2621 Session session = null;
2622
2623 try {
2624 session = openSession();
2625
2626 Query q = session.createQuery(sql);
2627
2628 QueryPos qPos = QueryPos.getInstance(q);
2629
2630 qPos.add(companyId);
2631
2632 qPos.add(userId);
2633
2634 qPos.add(classNameId);
2635
2636 qPos.add(classPK);
2637
2638 count = (Long)q.uniqueResult();
2639
2640 FinderCacheUtil.putResult(finderPath, finderArgs, count);
2641 }
2642 catch (Exception e) {
2643 FinderCacheUtil.removeResult(finderPath, finderArgs);
2644
2645 throw processException(e);
2646 }
2647 finally {
2648 closeSession(session);
2649 }
2650 }
2651
2652 return count.intValue();
2653 }
2654
2655
2664 @Override
2665 public int countByC_U_C_C(long companyId, long userId, long classNameId,
2666 long[] classPKs) {
2667 if (classPKs == null) {
2668 classPKs = new long[0];
2669 }
2670 else {
2671 classPKs = ArrayUtil.unique(classPKs);
2672 }
2673
2674 Object[] finderArgs = new Object[] {
2675 companyId, userId, classNameId, StringUtil.merge(classPKs)
2676 };
2677
2678 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_U_C_C,
2679 finderArgs, this);
2680
2681 if (count == null) {
2682 StringBundler query = new StringBundler();
2683
2684 query.append(_SQL_COUNT_SUBSCRIPTION_WHERE);
2685
2686 query.append(_FINDER_COLUMN_C_U_C_C_COMPANYID_2);
2687
2688 query.append(_FINDER_COLUMN_C_U_C_C_USERID_2);
2689
2690 query.append(_FINDER_COLUMN_C_U_C_C_CLASSNAMEID_2);
2691
2692 if (classPKs.length > 0) {
2693 query.append(StringPool.OPEN_PARENTHESIS);
2694
2695 query.append(_FINDER_COLUMN_C_U_C_C_CLASSPK_7);
2696
2697 query.append(StringUtil.merge(classPKs));
2698
2699 query.append(StringPool.CLOSE_PARENTHESIS);
2700
2701 query.append(StringPool.CLOSE_PARENTHESIS);
2702 }
2703
2704 query.setStringAt(removeConjunction(query.stringAt(query.index() -
2705 1)), query.index() - 1);
2706
2707 String sql = query.toString();
2708
2709 Session session = null;
2710
2711 try {
2712 session = openSession();
2713
2714 Query q = session.createQuery(sql);
2715
2716 QueryPos qPos = QueryPos.getInstance(q);
2717
2718 qPos.add(companyId);
2719
2720 qPos.add(userId);
2721
2722 qPos.add(classNameId);
2723
2724 count = (Long)q.uniqueResult();
2725
2726 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_U_C_C,
2727 finderArgs, count);
2728 }
2729 catch (Exception e) {
2730 FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_U_C_C,
2731 finderArgs);
2732
2733 throw processException(e);
2734 }
2735 finally {
2736 closeSession(session);
2737 }
2738 }
2739
2740 return count.intValue();
2741 }
2742
2743 private static final String _FINDER_COLUMN_C_U_C_C_COMPANYID_2 = "subscription.companyId = ? AND ";
2744 private static final String _FINDER_COLUMN_C_U_C_C_USERID_2 = "subscription.userId = ? AND ";
2745 private static final String _FINDER_COLUMN_C_U_C_C_CLASSNAMEID_2 = "subscription.classNameId = ? AND ";
2746 private static final String _FINDER_COLUMN_C_U_C_C_CLASSPK_2 = "subscription.classPK = ?";
2747 private static final String _FINDER_COLUMN_C_U_C_C_CLASSPK_7 = "subscription.classPK IN (";
2748
2749 public SubscriptionPersistenceImpl() {
2750 setModelClass(Subscription.class);
2751 }
2752
2753
2758 @Override
2759 public void cacheResult(Subscription subscription) {
2760 EntityCacheUtil.putResult(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
2761 SubscriptionImpl.class, subscription.getPrimaryKey(), subscription);
2762
2763 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_U_C_C,
2764 new Object[] {
2765 subscription.getCompanyId(), subscription.getUserId(),
2766 subscription.getClassNameId(), subscription.getClassPK()
2767 }, subscription);
2768
2769 subscription.resetOriginalValues();
2770 }
2771
2772
2777 @Override
2778 public void cacheResult(List<Subscription> subscriptions) {
2779 for (Subscription subscription : subscriptions) {
2780 if (EntityCacheUtil.getResult(
2781 SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
2782 SubscriptionImpl.class, subscription.getPrimaryKey()) == null) {
2783 cacheResult(subscription);
2784 }
2785 else {
2786 subscription.resetOriginalValues();
2787 }
2788 }
2789 }
2790
2791
2798 @Override
2799 public void clearCache() {
2800 EntityCacheUtil.clearCache(SubscriptionImpl.class);
2801
2802 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
2803 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2804 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2805 }
2806
2807
2814 @Override
2815 public void clearCache(Subscription subscription) {
2816 EntityCacheUtil.removeResult(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
2817 SubscriptionImpl.class, subscription.getPrimaryKey());
2818
2819 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2820 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2821
2822 clearUniqueFindersCache(subscription);
2823 }
2824
2825 @Override
2826 public void clearCache(List<Subscription> subscriptions) {
2827 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2828 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2829
2830 for (Subscription subscription : subscriptions) {
2831 EntityCacheUtil.removeResult(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
2832 SubscriptionImpl.class, subscription.getPrimaryKey());
2833
2834 clearUniqueFindersCache(subscription);
2835 }
2836 }
2837
2838 protected void cacheUniqueFindersCache(Subscription subscription) {
2839 if (subscription.isNew()) {
2840 Object[] args = new Object[] {
2841 subscription.getCompanyId(), subscription.getUserId(),
2842 subscription.getClassNameId(), subscription.getClassPK()
2843 };
2844
2845 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_U_C_C, args,
2846 Long.valueOf(1));
2847 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_U_C_C, args,
2848 subscription);
2849 }
2850 else {
2851 SubscriptionModelImpl subscriptionModelImpl = (SubscriptionModelImpl)subscription;
2852
2853 if ((subscriptionModelImpl.getColumnBitmask() &
2854 FINDER_PATH_FETCH_BY_C_U_C_C.getColumnBitmask()) != 0) {
2855 Object[] args = new Object[] {
2856 subscription.getCompanyId(), subscription.getUserId(),
2857 subscription.getClassNameId(), subscription.getClassPK()
2858 };
2859
2860 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_U_C_C, args,
2861 Long.valueOf(1));
2862 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_U_C_C, args,
2863 subscription);
2864 }
2865 }
2866 }
2867
2868 protected void clearUniqueFindersCache(Subscription subscription) {
2869 SubscriptionModelImpl subscriptionModelImpl = (SubscriptionModelImpl)subscription;
2870
2871 Object[] args = new Object[] {
2872 subscription.getCompanyId(), subscription.getUserId(),
2873 subscription.getClassNameId(), subscription.getClassPK()
2874 };
2875
2876 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_U_C_C, args);
2877 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_U_C_C, args);
2878
2879 if ((subscriptionModelImpl.getColumnBitmask() &
2880 FINDER_PATH_FETCH_BY_C_U_C_C.getColumnBitmask()) != 0) {
2881 args = new Object[] {
2882 subscriptionModelImpl.getOriginalCompanyId(),
2883 subscriptionModelImpl.getOriginalUserId(),
2884 subscriptionModelImpl.getOriginalClassNameId(),
2885 subscriptionModelImpl.getOriginalClassPK()
2886 };
2887
2888 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_U_C_C, args);
2889 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_U_C_C, args);
2890 }
2891 }
2892
2893
2899 @Override
2900 public Subscription create(long subscriptionId) {
2901 Subscription subscription = new SubscriptionImpl();
2902
2903 subscription.setNew(true);
2904 subscription.setPrimaryKey(subscriptionId);
2905
2906 return subscription;
2907 }
2908
2909
2916 @Override
2917 public Subscription remove(long subscriptionId)
2918 throws NoSuchSubscriptionException {
2919 return remove((Serializable)subscriptionId);
2920 }
2921
2922
2929 @Override
2930 public Subscription remove(Serializable primaryKey)
2931 throws NoSuchSubscriptionException {
2932 Session session = null;
2933
2934 try {
2935 session = openSession();
2936
2937 Subscription subscription = (Subscription)session.get(SubscriptionImpl.class,
2938 primaryKey);
2939
2940 if (subscription == null) {
2941 if (_log.isWarnEnabled()) {
2942 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2943 }
2944
2945 throw new NoSuchSubscriptionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2946 primaryKey);
2947 }
2948
2949 return remove(subscription);
2950 }
2951 catch (NoSuchSubscriptionException nsee) {
2952 throw nsee;
2953 }
2954 catch (Exception e) {
2955 throw processException(e);
2956 }
2957 finally {
2958 closeSession(session);
2959 }
2960 }
2961
2962 @Override
2963 protected Subscription removeImpl(Subscription subscription) {
2964 subscription = toUnwrappedModel(subscription);
2965
2966 Session session = null;
2967
2968 try {
2969 session = openSession();
2970
2971 if (!session.contains(subscription)) {
2972 subscription = (Subscription)session.get(SubscriptionImpl.class,
2973 subscription.getPrimaryKeyObj());
2974 }
2975
2976 if (subscription != null) {
2977 session.delete(subscription);
2978 }
2979 }
2980 catch (Exception e) {
2981 throw processException(e);
2982 }
2983 finally {
2984 closeSession(session);
2985 }
2986
2987 if (subscription != null) {
2988 clearCache(subscription);
2989 }
2990
2991 return subscription;
2992 }
2993
2994 @Override
2995 public Subscription updateImpl(Subscription subscription) {
2996 subscription = toUnwrappedModel(subscription);
2997
2998 boolean isNew = subscription.isNew();
2999
3000 SubscriptionModelImpl subscriptionModelImpl = (SubscriptionModelImpl)subscription;
3001
3002 ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();
3003
3004 Date now = new Date();
3005
3006 if (isNew && (subscription.getCreateDate() == null)) {
3007 if (serviceContext == null) {
3008 subscription.setCreateDate(now);
3009 }
3010 else {
3011 subscription.setCreateDate(serviceContext.getCreateDate(now));
3012 }
3013 }
3014
3015 if (!subscriptionModelImpl.hasSetModifiedDate()) {
3016 if (serviceContext == null) {
3017 subscription.setModifiedDate(now);
3018 }
3019 else {
3020 subscription.setModifiedDate(serviceContext.getModifiedDate(now));
3021 }
3022 }
3023
3024 Session session = null;
3025
3026 try {
3027 session = openSession();
3028
3029 if (subscription.isNew()) {
3030 session.save(subscription);
3031
3032 subscription.setNew(false);
3033 }
3034 else {
3035 session.merge(subscription);
3036 }
3037 }
3038 catch (Exception e) {
3039 throw processException(e);
3040 }
3041 finally {
3042 closeSession(session);
3043 }
3044
3045 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3046
3047 if (isNew || !SubscriptionModelImpl.COLUMN_BITMASK_ENABLED) {
3048 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3049 }
3050
3051 else {
3052 if ((subscriptionModelImpl.getColumnBitmask() &
3053 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
3054 Object[] args = new Object[] {
3055 subscriptionModelImpl.getOriginalUserId()
3056 };
3057
3058 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
3059 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
3060 args);
3061
3062 args = new Object[] { subscriptionModelImpl.getUserId() };
3063
3064 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
3065 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
3066 args);
3067 }
3068
3069 if ((subscriptionModelImpl.getColumnBitmask() &
3070 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U.getColumnBitmask()) != 0) {
3071 Object[] args = new Object[] {
3072 subscriptionModelImpl.getOriginalGroupId(),
3073 subscriptionModelImpl.getOriginalUserId()
3074 };
3075
3076 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U, args);
3077 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U,
3078 args);
3079
3080 args = new Object[] {
3081 subscriptionModelImpl.getGroupId(),
3082 subscriptionModelImpl.getUserId()
3083 };
3084
3085 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U, args);
3086 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U,
3087 args);
3088 }
3089
3090 if ((subscriptionModelImpl.getColumnBitmask() &
3091 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C.getColumnBitmask()) != 0) {
3092 Object[] args = new Object[] {
3093 subscriptionModelImpl.getOriginalUserId(),
3094 subscriptionModelImpl.getOriginalClassNameId()
3095 };
3096
3097 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C, args);
3098 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C,
3099 args);
3100
3101 args = new Object[] {
3102 subscriptionModelImpl.getUserId(),
3103 subscriptionModelImpl.getClassNameId()
3104 };
3105
3106 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C, args);
3107 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C,
3108 args);
3109 }
3110
3111 if ((subscriptionModelImpl.getColumnBitmask() &
3112 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C.getColumnBitmask()) != 0) {
3113 Object[] args = new Object[] {
3114 subscriptionModelImpl.getOriginalCompanyId(),
3115 subscriptionModelImpl.getOriginalClassNameId(),
3116 subscriptionModelImpl.getOriginalClassPK()
3117 };
3118
3119 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_C, args);
3120 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C,
3121 args);
3122
3123 args = new Object[] {
3124 subscriptionModelImpl.getCompanyId(),
3125 subscriptionModelImpl.getClassNameId(),
3126 subscriptionModelImpl.getClassPK()
3127 };
3128
3129 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_C, args);
3130 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C,
3131 args);
3132 }
3133
3134 if ((subscriptionModelImpl.getColumnBitmask() &
3135 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_U_C_C.getColumnBitmask()) != 0) {
3136 Object[] args = new Object[] {
3137 subscriptionModelImpl.getOriginalCompanyId(),
3138 subscriptionModelImpl.getOriginalUserId(),
3139 subscriptionModelImpl.getOriginalClassNameId(),
3140 subscriptionModelImpl.getOriginalClassPK()
3141 };
3142
3143 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_U_C_C, args);
3144 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_U_C_C,
3145 args);
3146
3147 args = new Object[] {
3148 subscriptionModelImpl.getCompanyId(),
3149 subscriptionModelImpl.getUserId(),
3150 subscriptionModelImpl.getClassNameId(),
3151 subscriptionModelImpl.getClassPK()
3152 };
3153
3154 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_U_C_C, args);
3155 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_U_C_C,
3156 args);
3157 }
3158 }
3159
3160 EntityCacheUtil.putResult(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
3161 SubscriptionImpl.class, subscription.getPrimaryKey(), subscription,
3162 false);
3163
3164 clearUniqueFindersCache(subscription);
3165 cacheUniqueFindersCache(subscription);
3166
3167 subscription.resetOriginalValues();
3168
3169 return subscription;
3170 }
3171
3172 protected Subscription toUnwrappedModel(Subscription subscription) {
3173 if (subscription instanceof SubscriptionImpl) {
3174 return subscription;
3175 }
3176
3177 SubscriptionImpl subscriptionImpl = new SubscriptionImpl();
3178
3179 subscriptionImpl.setNew(subscription.isNew());
3180 subscriptionImpl.setPrimaryKey(subscription.getPrimaryKey());
3181
3182 subscriptionImpl.setMvccVersion(subscription.getMvccVersion());
3183 subscriptionImpl.setSubscriptionId(subscription.getSubscriptionId());
3184 subscriptionImpl.setGroupId(subscription.getGroupId());
3185 subscriptionImpl.setCompanyId(subscription.getCompanyId());
3186 subscriptionImpl.setUserId(subscription.getUserId());
3187 subscriptionImpl.setUserName(subscription.getUserName());
3188 subscriptionImpl.setCreateDate(subscription.getCreateDate());
3189 subscriptionImpl.setModifiedDate(subscription.getModifiedDate());
3190 subscriptionImpl.setClassNameId(subscription.getClassNameId());
3191 subscriptionImpl.setClassPK(subscription.getClassPK());
3192 subscriptionImpl.setFrequency(subscription.getFrequency());
3193
3194 return subscriptionImpl;
3195 }
3196
3197
3204 @Override
3205 public Subscription findByPrimaryKey(Serializable primaryKey)
3206 throws NoSuchSubscriptionException {
3207 Subscription subscription = fetchByPrimaryKey(primaryKey);
3208
3209 if (subscription == null) {
3210 if (_log.isWarnEnabled()) {
3211 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
3212 }
3213
3214 throw new NoSuchSubscriptionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
3215 primaryKey);
3216 }
3217
3218 return subscription;
3219 }
3220
3221
3228 @Override
3229 public Subscription findByPrimaryKey(long subscriptionId)
3230 throws NoSuchSubscriptionException {
3231 return findByPrimaryKey((Serializable)subscriptionId);
3232 }
3233
3234
3240 @Override
3241 public Subscription fetchByPrimaryKey(Serializable primaryKey) {
3242 Subscription subscription = (Subscription)EntityCacheUtil.getResult(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
3243 SubscriptionImpl.class, primaryKey);
3244
3245 if (subscription == _nullSubscription) {
3246 return null;
3247 }
3248
3249 if (subscription == null) {
3250 Session session = null;
3251
3252 try {
3253 session = openSession();
3254
3255 subscription = (Subscription)session.get(SubscriptionImpl.class,
3256 primaryKey);
3257
3258 if (subscription != null) {
3259 cacheResult(subscription);
3260 }
3261 else {
3262 EntityCacheUtil.putResult(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
3263 SubscriptionImpl.class, primaryKey, _nullSubscription);
3264 }
3265 }
3266 catch (Exception e) {
3267 EntityCacheUtil.removeResult(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
3268 SubscriptionImpl.class, primaryKey);
3269
3270 throw processException(e);
3271 }
3272 finally {
3273 closeSession(session);
3274 }
3275 }
3276
3277 return subscription;
3278 }
3279
3280
3286 @Override
3287 public Subscription fetchByPrimaryKey(long subscriptionId) {
3288 return fetchByPrimaryKey((Serializable)subscriptionId);
3289 }
3290
3291 @Override
3292 public Map<Serializable, Subscription> fetchByPrimaryKeys(
3293 Set<Serializable> primaryKeys) {
3294 if (primaryKeys.isEmpty()) {
3295 return Collections.emptyMap();
3296 }
3297
3298 Map<Serializable, Subscription> map = new HashMap<Serializable, Subscription>();
3299
3300 if (primaryKeys.size() == 1) {
3301 Iterator<Serializable> iterator = primaryKeys.iterator();
3302
3303 Serializable primaryKey = iterator.next();
3304
3305 Subscription subscription = fetchByPrimaryKey(primaryKey);
3306
3307 if (subscription != null) {
3308 map.put(primaryKey, subscription);
3309 }
3310
3311 return map;
3312 }
3313
3314 Set<Serializable> uncachedPrimaryKeys = null;
3315
3316 for (Serializable primaryKey : primaryKeys) {
3317 Subscription subscription = (Subscription)EntityCacheUtil.getResult(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
3318 SubscriptionImpl.class, primaryKey);
3319
3320 if (subscription == null) {
3321 if (uncachedPrimaryKeys == null) {
3322 uncachedPrimaryKeys = new HashSet<Serializable>();
3323 }
3324
3325 uncachedPrimaryKeys.add(primaryKey);
3326 }
3327 else {
3328 map.put(primaryKey, subscription);
3329 }
3330 }
3331
3332 if (uncachedPrimaryKeys == null) {
3333 return map;
3334 }
3335
3336 StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
3337 1);
3338
3339 query.append(_SQL_SELECT_SUBSCRIPTION_WHERE_PKS_IN);
3340
3341 for (Serializable primaryKey : uncachedPrimaryKeys) {
3342 query.append(String.valueOf(primaryKey));
3343
3344 query.append(StringPool.COMMA);
3345 }
3346
3347 query.setIndex(query.index() - 1);
3348
3349 query.append(StringPool.CLOSE_PARENTHESIS);
3350
3351 String sql = query.toString();
3352
3353 Session session = null;
3354
3355 try {
3356 session = openSession();
3357
3358 Query q = session.createQuery(sql);
3359
3360 for (Subscription subscription : (List<Subscription>)q.list()) {
3361 map.put(subscription.getPrimaryKeyObj(), subscription);
3362
3363 cacheResult(subscription);
3364
3365 uncachedPrimaryKeys.remove(subscription.getPrimaryKeyObj());
3366 }
3367
3368 for (Serializable primaryKey : uncachedPrimaryKeys) {
3369 EntityCacheUtil.putResult(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
3370 SubscriptionImpl.class, primaryKey, _nullSubscription);
3371 }
3372 }
3373 catch (Exception e) {
3374 throw processException(e);
3375 }
3376 finally {
3377 closeSession(session);
3378 }
3379
3380 return map;
3381 }
3382
3383
3388 @Override
3389 public List<Subscription> findAll() {
3390 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3391 }
3392
3393
3404 @Override
3405 public List<Subscription> findAll(int start, int end) {
3406 return findAll(start, end, null);
3407 }
3408
3409
3421 @Override
3422 public List<Subscription> findAll(int start, int end,
3423 OrderByComparator<Subscription> orderByComparator) {
3424 boolean pagination = true;
3425 FinderPath finderPath = null;
3426 Object[] finderArgs = null;
3427
3428 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3429 (orderByComparator == null)) {
3430 pagination = false;
3431 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
3432 finderArgs = FINDER_ARGS_EMPTY;
3433 }
3434 else {
3435 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
3436 finderArgs = new Object[] { start, end, orderByComparator };
3437 }
3438
3439 List<Subscription> list = (List<Subscription>)FinderCacheUtil.getResult(finderPath,
3440 finderArgs, this);
3441
3442 if (list == null) {
3443 StringBundler query = null;
3444 String sql = null;
3445
3446 if (orderByComparator != null) {
3447 query = new StringBundler(2 +
3448 (orderByComparator.getOrderByFields().length * 3));
3449
3450 query.append(_SQL_SELECT_SUBSCRIPTION);
3451
3452 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3453 orderByComparator);
3454
3455 sql = query.toString();
3456 }
3457 else {
3458 sql = _SQL_SELECT_SUBSCRIPTION;
3459
3460 if (pagination) {
3461 sql = sql.concat(SubscriptionModelImpl.ORDER_BY_JPQL);
3462 }
3463 }
3464
3465 Session session = null;
3466
3467 try {
3468 session = openSession();
3469
3470 Query q = session.createQuery(sql);
3471
3472 if (!pagination) {
3473 list = (List<Subscription>)QueryUtil.list(q, getDialect(),
3474 start, end, false);
3475
3476 Collections.sort(list);
3477
3478 list = Collections.unmodifiableList(list);
3479 }
3480 else {
3481 list = (List<Subscription>)QueryUtil.list(q, getDialect(),
3482 start, end);
3483 }
3484
3485 cacheResult(list);
3486
3487 FinderCacheUtil.putResult(finderPath, finderArgs, list);
3488 }
3489 catch (Exception e) {
3490 FinderCacheUtil.removeResult(finderPath, finderArgs);
3491
3492 throw processException(e);
3493 }
3494 finally {
3495 closeSession(session);
3496 }
3497 }
3498
3499 return list;
3500 }
3501
3502
3506 @Override
3507 public void removeAll() {
3508 for (Subscription subscription : findAll()) {
3509 remove(subscription);
3510 }
3511 }
3512
3513
3518 @Override
3519 public int countAll() {
3520 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
3521 FINDER_ARGS_EMPTY, this);
3522
3523 if (count == null) {
3524 Session session = null;
3525
3526 try {
3527 session = openSession();
3528
3529 Query q = session.createQuery(_SQL_COUNT_SUBSCRIPTION);
3530
3531 count = (Long)q.uniqueResult();
3532
3533 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
3534 FINDER_ARGS_EMPTY, count);
3535 }
3536 catch (Exception e) {
3537 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
3538 FINDER_ARGS_EMPTY);
3539
3540 throw processException(e);
3541 }
3542 finally {
3543 closeSession(session);
3544 }
3545 }
3546
3547 return count.intValue();
3548 }
3549
3550
3553 public void afterPropertiesSet() {
3554 }
3555
3556 public void destroy() {
3557 EntityCacheUtil.removeCache(SubscriptionImpl.class.getName());
3558 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
3559 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3560 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3561 }
3562
3563 private static final String _SQL_SELECT_SUBSCRIPTION = "SELECT subscription FROM Subscription subscription";
3564 private static final String _SQL_SELECT_SUBSCRIPTION_WHERE_PKS_IN = "SELECT subscription FROM Subscription subscription WHERE subscriptionId IN (";
3565 private static final String _SQL_SELECT_SUBSCRIPTION_WHERE = "SELECT subscription FROM Subscription subscription WHERE ";
3566 private static final String _SQL_COUNT_SUBSCRIPTION = "SELECT COUNT(subscription) FROM Subscription subscription";
3567 private static final String _SQL_COUNT_SUBSCRIPTION_WHERE = "SELECT COUNT(subscription) FROM Subscription subscription WHERE ";
3568 private static final String _ORDER_BY_ENTITY_ALIAS = "subscription.";
3569 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Subscription exists with the primary key ";
3570 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Subscription exists with the key {";
3571 private static final Log _log = LogFactoryUtil.getLog(SubscriptionPersistenceImpl.class);
3572 private static final Subscription _nullSubscription = new SubscriptionImpl() {
3573 @Override
3574 public Object clone() {
3575 return this;
3576 }
3577
3578 @Override
3579 public CacheModel<Subscription> toCacheModel() {
3580 return _nullSubscriptionCacheModel;
3581 }
3582 };
3583
3584 private static final CacheModel<Subscription> _nullSubscriptionCacheModel = new NullCacheModel();
3585
3586 private static class NullCacheModel implements CacheModel<Subscription>,
3587 MVCCModel {
3588 @Override
3589 public long getMvccVersion() {
3590 return -1;
3591 }
3592
3593 @Override
3594 public void setMvccVersion(long mvccVersion) {
3595 }
3596
3597 @Override
3598 public Subscription toEntityModel() {
3599 return _nullSubscription;
3600 }
3601 }
3602 }