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.cache.CacheRegistryUtil;
021 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
023 import com.liferay.portal.kernel.dao.orm.FinderPath;
024 import com.liferay.portal.kernel.dao.orm.Query;
025 import com.liferay.portal.kernel.dao.orm.QueryPos;
026 import com.liferay.portal.kernel.dao.orm.QueryUtil;
027 import com.liferay.portal.kernel.dao.orm.Session;
028 import com.liferay.portal.kernel.log.Log;
029 import com.liferay.portal.kernel.log.LogFactoryUtil;
030 import com.liferay.portal.kernel.util.ArrayUtil;
031 import com.liferay.portal.kernel.util.OrderByComparator;
032 import com.liferay.portal.kernel.util.StringBundler;
033 import com.liferay.portal.kernel.util.StringPool;
034 import com.liferay.portal.kernel.util.StringUtil;
035 import com.liferay.portal.model.CacheModel;
036 import com.liferay.portal.model.MVCCModel;
037 import com.liferay.portal.model.Subscription;
038 import com.liferay.portal.model.impl.SubscriptionImpl;
039 import com.liferay.portal.model.impl.SubscriptionModelImpl;
040 import com.liferay.portal.service.persistence.SubscriptionPersistence;
041
042 import java.io.Serializable;
043
044 import java.util.ArrayList;
045 import java.util.Collections;
046 import java.util.HashMap;
047 import java.util.HashSet;
048 import java.util.Iterator;
049 import java.util.List;
050 import java.util.Map;
051 import java.util.Set;
052
053
065 @ProviderType
066 public class SubscriptionPersistenceImpl extends BasePersistenceImpl<Subscription>
067 implements SubscriptionPersistence {
068
073 public static final String FINDER_CLASS_NAME_ENTITY = SubscriptionImpl.class.getName();
074 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
075 ".List1";
076 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
077 ".List2";
078 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
079 SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.class,
080 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
081 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
082 SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.class,
083 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
084 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
085 SubscriptionModelImpl.FINDER_CACHE_ENABLED, Long.class,
086 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
087 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
088 SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.class,
089 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUserId",
090 new String[] {
091 Long.class.getName(),
092
093 Integer.class.getName(), Integer.class.getName(),
094 OrderByComparator.class.getName()
095 });
096 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID =
097 new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
098 SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.class,
099 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId",
100 new String[] { Long.class.getName() },
101 SubscriptionModelImpl.USERID_COLUMN_BITMASK);
102 public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
103 SubscriptionModelImpl.FINDER_CACHE_ENABLED, Long.class,
104 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
105 new String[] { Long.class.getName() });
106
107
113 @Override
114 public List<Subscription> findByUserId(long userId) {
115 return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
116 }
117
118
130 @Override
131 public List<Subscription> findByUserId(long userId, int start, int end) {
132 return findByUserId(userId, start, end, null);
133 }
134
135
148 @Override
149 public List<Subscription> findByUserId(long userId, int start, int end,
150 OrderByComparator<Subscription> orderByComparator) {
151 boolean pagination = true;
152 FinderPath finderPath = null;
153 Object[] finderArgs = null;
154
155 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
156 (orderByComparator == null)) {
157 pagination = false;
158 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
159 finderArgs = new Object[] { userId };
160 }
161 else {
162 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
163 finderArgs = new Object[] { userId, start, end, orderByComparator };
164 }
165
166 List<Subscription> list = (List<Subscription>)FinderCacheUtil.getResult(finderPath,
167 finderArgs, this);
168
169 if ((list != null) && !list.isEmpty()) {
170 for (Subscription subscription : list) {
171 if ((userId != subscription.getUserId())) {
172 list = null;
173
174 break;
175 }
176 }
177 }
178
179 if (list == null) {
180 StringBundler query = null;
181
182 if (orderByComparator != null) {
183 query = new StringBundler(3 +
184 (orderByComparator.getOrderByFields().length * 3));
185 }
186 else {
187 query = new StringBundler(3);
188 }
189
190 query.append(_SQL_SELECT_SUBSCRIPTION_WHERE);
191
192 query.append(_FINDER_COLUMN_USERID_USERID_2);
193
194 if (orderByComparator != null) {
195 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
196 orderByComparator);
197 }
198 else
199 if (pagination) {
200 query.append(SubscriptionModelImpl.ORDER_BY_JPQL);
201 }
202
203 String sql = query.toString();
204
205 Session session = null;
206
207 try {
208 session = openSession();
209
210 Query q = session.createQuery(sql);
211
212 QueryPos qPos = QueryPos.getInstance(q);
213
214 qPos.add(userId);
215
216 if (!pagination) {
217 list = (List<Subscription>)QueryUtil.list(q, getDialect(),
218 start, end, false);
219
220 Collections.sort(list);
221
222 list = Collections.unmodifiableList(list);
223 }
224 else {
225 list = (List<Subscription>)QueryUtil.list(q, getDialect(),
226 start, end);
227 }
228
229 cacheResult(list);
230
231 FinderCacheUtil.putResult(finderPath, finderArgs, list);
232 }
233 catch (Exception e) {
234 FinderCacheUtil.removeResult(finderPath, finderArgs);
235
236 throw processException(e);
237 }
238 finally {
239 closeSession(session);
240 }
241 }
242
243 return list;
244 }
245
246
254 @Override
255 public Subscription findByUserId_First(long userId,
256 OrderByComparator<Subscription> orderByComparator)
257 throws NoSuchSubscriptionException {
258 Subscription subscription = fetchByUserId_First(userId,
259 orderByComparator);
260
261 if (subscription != null) {
262 return subscription;
263 }
264
265 StringBundler msg = new StringBundler(4);
266
267 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
268
269 msg.append("userId=");
270 msg.append(userId);
271
272 msg.append(StringPool.CLOSE_CURLY_BRACE);
273
274 throw new NoSuchSubscriptionException(msg.toString());
275 }
276
277
284 @Override
285 public Subscription fetchByUserId_First(long userId,
286 OrderByComparator<Subscription> orderByComparator) {
287 List<Subscription> list = findByUserId(userId, 0, 1, orderByComparator);
288
289 if (!list.isEmpty()) {
290 return list.get(0);
291 }
292
293 return null;
294 }
295
296
304 @Override
305 public Subscription findByUserId_Last(long userId,
306 OrderByComparator<Subscription> orderByComparator)
307 throws NoSuchSubscriptionException {
308 Subscription subscription = fetchByUserId_Last(userId, orderByComparator);
309
310 if (subscription != null) {
311 return subscription;
312 }
313
314 StringBundler msg = new StringBundler(4);
315
316 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
317
318 msg.append("userId=");
319 msg.append(userId);
320
321 msg.append(StringPool.CLOSE_CURLY_BRACE);
322
323 throw new NoSuchSubscriptionException(msg.toString());
324 }
325
326
333 @Override
334 public Subscription fetchByUserId_Last(long userId,
335 OrderByComparator<Subscription> orderByComparator) {
336 int count = countByUserId(userId);
337
338 if (count == 0) {
339 return null;
340 }
341
342 List<Subscription> list = findByUserId(userId, count - 1, count,
343 orderByComparator);
344
345 if (!list.isEmpty()) {
346 return list.get(0);
347 }
348
349 return null;
350 }
351
352
361 @Override
362 public Subscription[] findByUserId_PrevAndNext(long subscriptionId,
363 long userId, OrderByComparator<Subscription> orderByComparator)
364 throws NoSuchSubscriptionException {
365 Subscription subscription = findByPrimaryKey(subscriptionId);
366
367 Session session = null;
368
369 try {
370 session = openSession();
371
372 Subscription[] array = new SubscriptionImpl[3];
373
374 array[0] = getByUserId_PrevAndNext(session, subscription, userId,
375 orderByComparator, true);
376
377 array[1] = subscription;
378
379 array[2] = getByUserId_PrevAndNext(session, subscription, userId,
380 orderByComparator, false);
381
382 return array;
383 }
384 catch (Exception e) {
385 throw processException(e);
386 }
387 finally {
388 closeSession(session);
389 }
390 }
391
392 protected Subscription getByUserId_PrevAndNext(Session session,
393 Subscription subscription, long userId,
394 OrderByComparator<Subscription> orderByComparator, boolean previous) {
395 StringBundler query = null;
396
397 if (orderByComparator != null) {
398 query = new StringBundler(6 +
399 (orderByComparator.getOrderByFields().length * 6));
400 }
401 else {
402 query = new StringBundler(3);
403 }
404
405 query.append(_SQL_SELECT_SUBSCRIPTION_WHERE);
406
407 query.append(_FINDER_COLUMN_USERID_USERID_2);
408
409 if (orderByComparator != null) {
410 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
411
412 if (orderByConditionFields.length > 0) {
413 query.append(WHERE_AND);
414 }
415
416 for (int i = 0; i < orderByConditionFields.length; i++) {
417 query.append(_ORDER_BY_ENTITY_ALIAS);
418 query.append(orderByConditionFields[i]);
419
420 if ((i + 1) < orderByConditionFields.length) {
421 if (orderByComparator.isAscending() ^ previous) {
422 query.append(WHERE_GREATER_THAN_HAS_NEXT);
423 }
424 else {
425 query.append(WHERE_LESSER_THAN_HAS_NEXT);
426 }
427 }
428 else {
429 if (orderByComparator.isAscending() ^ previous) {
430 query.append(WHERE_GREATER_THAN);
431 }
432 else {
433 query.append(WHERE_LESSER_THAN);
434 }
435 }
436 }
437
438 query.append(ORDER_BY_CLAUSE);
439
440 String[] orderByFields = orderByComparator.getOrderByFields();
441
442 for (int i = 0; i < orderByFields.length; i++) {
443 query.append(_ORDER_BY_ENTITY_ALIAS);
444 query.append(orderByFields[i]);
445
446 if ((i + 1) < orderByFields.length) {
447 if (orderByComparator.isAscending() ^ previous) {
448 query.append(ORDER_BY_ASC_HAS_NEXT);
449 }
450 else {
451 query.append(ORDER_BY_DESC_HAS_NEXT);
452 }
453 }
454 else {
455 if (orderByComparator.isAscending() ^ previous) {
456 query.append(ORDER_BY_ASC);
457 }
458 else {
459 query.append(ORDER_BY_DESC);
460 }
461 }
462 }
463 }
464 else {
465 query.append(SubscriptionModelImpl.ORDER_BY_JPQL);
466 }
467
468 String sql = query.toString();
469
470 Query q = session.createQuery(sql);
471
472 q.setFirstResult(0);
473 q.setMaxResults(2);
474
475 QueryPos qPos = QueryPos.getInstance(q);
476
477 qPos.add(userId);
478
479 if (orderByComparator != null) {
480 Object[] values = orderByComparator.getOrderByConditionValues(subscription);
481
482 for (Object value : values) {
483 qPos.add(value);
484 }
485 }
486
487 List<Subscription> list = q.list();
488
489 if (list.size() == 2) {
490 return list.get(1);
491 }
492 else {
493 return null;
494 }
495 }
496
497
502 @Override
503 public void removeByUserId(long userId) {
504 for (Subscription subscription : findByUserId(userId,
505 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
506 remove(subscription);
507 }
508 }
509
510
516 @Override
517 public int countByUserId(long userId) {
518 FinderPath finderPath = FINDER_PATH_COUNT_BY_USERID;
519
520 Object[] finderArgs = new Object[] { userId };
521
522 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
523 this);
524
525 if (count == null) {
526 StringBundler query = new StringBundler(2);
527
528 query.append(_SQL_COUNT_SUBSCRIPTION_WHERE);
529
530 query.append(_FINDER_COLUMN_USERID_USERID_2);
531
532 String sql = query.toString();
533
534 Session session = null;
535
536 try {
537 session = openSession();
538
539 Query q = session.createQuery(sql);
540
541 QueryPos qPos = QueryPos.getInstance(q);
542
543 qPos.add(userId);
544
545 count = (Long)q.uniqueResult();
546
547 FinderCacheUtil.putResult(finderPath, finderArgs, count);
548 }
549 catch (Exception e) {
550 FinderCacheUtil.removeResult(finderPath, finderArgs);
551
552 throw processException(e);
553 }
554 finally {
555 closeSession(session);
556 }
557 }
558
559 return count.intValue();
560 }
561
562 private static final String _FINDER_COLUMN_USERID_USERID_2 = "subscription.userId = ?";
563 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
564 SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.class,
565 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C",
566 new String[] {
567 Long.class.getName(), Long.class.getName(),
568
569 Integer.class.getName(), Integer.class.getName(),
570 OrderByComparator.class.getName()
571 });
572 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
573 SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.class,
574 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C",
575 new String[] { Long.class.getName(), Long.class.getName() },
576 SubscriptionModelImpl.USERID_COLUMN_BITMASK |
577 SubscriptionModelImpl.CLASSNAMEID_COLUMN_BITMASK);
578 public static final FinderPath FINDER_PATH_COUNT_BY_U_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
579 SubscriptionModelImpl.FINDER_CACHE_ENABLED, Long.class,
580 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C",
581 new String[] { Long.class.getName(), Long.class.getName() });
582
583
590 @Override
591 public List<Subscription> findByU_C(long userId, long classNameId) {
592 return findByU_C(userId, classNameId, QueryUtil.ALL_POS,
593 QueryUtil.ALL_POS, null);
594 }
595
596
609 @Override
610 public List<Subscription> findByU_C(long userId, long classNameId,
611 int start, int end) {
612 return findByU_C(userId, classNameId, start, end, null);
613 }
614
615
629 @Override
630 public List<Subscription> findByU_C(long userId, long classNameId,
631 int start, int end, OrderByComparator<Subscription> orderByComparator) {
632 boolean pagination = true;
633 FinderPath finderPath = null;
634 Object[] finderArgs = null;
635
636 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
637 (orderByComparator == null)) {
638 pagination = false;
639 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C;
640 finderArgs = new Object[] { userId, classNameId };
641 }
642 else {
643 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C;
644 finderArgs = new Object[] {
645 userId, classNameId,
646
647 start, end, orderByComparator
648 };
649 }
650
651 List<Subscription> list = (List<Subscription>)FinderCacheUtil.getResult(finderPath,
652 finderArgs, this);
653
654 if ((list != null) && !list.isEmpty()) {
655 for (Subscription subscription : list) {
656 if ((userId != subscription.getUserId()) ||
657 (classNameId != subscription.getClassNameId())) {
658 list = null;
659
660 break;
661 }
662 }
663 }
664
665 if (list == null) {
666 StringBundler query = null;
667
668 if (orderByComparator != null) {
669 query = new StringBundler(4 +
670 (orderByComparator.getOrderByFields().length * 3));
671 }
672 else {
673 query = new StringBundler(4);
674 }
675
676 query.append(_SQL_SELECT_SUBSCRIPTION_WHERE);
677
678 query.append(_FINDER_COLUMN_U_C_USERID_2);
679
680 query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
681
682 if (orderByComparator != null) {
683 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
684 orderByComparator);
685 }
686 else
687 if (pagination) {
688 query.append(SubscriptionModelImpl.ORDER_BY_JPQL);
689 }
690
691 String sql = query.toString();
692
693 Session session = null;
694
695 try {
696 session = openSession();
697
698 Query q = session.createQuery(sql);
699
700 QueryPos qPos = QueryPos.getInstance(q);
701
702 qPos.add(userId);
703
704 qPos.add(classNameId);
705
706 if (!pagination) {
707 list = (List<Subscription>)QueryUtil.list(q, getDialect(),
708 start, end, false);
709
710 Collections.sort(list);
711
712 list = Collections.unmodifiableList(list);
713 }
714 else {
715 list = (List<Subscription>)QueryUtil.list(q, getDialect(),
716 start, end);
717 }
718
719 cacheResult(list);
720
721 FinderCacheUtil.putResult(finderPath, finderArgs, list);
722 }
723 catch (Exception e) {
724 FinderCacheUtil.removeResult(finderPath, finderArgs);
725
726 throw processException(e);
727 }
728 finally {
729 closeSession(session);
730 }
731 }
732
733 return list;
734 }
735
736
745 @Override
746 public Subscription findByU_C_First(long userId, long classNameId,
747 OrderByComparator<Subscription> orderByComparator)
748 throws NoSuchSubscriptionException {
749 Subscription subscription = fetchByU_C_First(userId, classNameId,
750 orderByComparator);
751
752 if (subscription != null) {
753 return subscription;
754 }
755
756 StringBundler msg = new StringBundler(6);
757
758 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
759
760 msg.append("userId=");
761 msg.append(userId);
762
763 msg.append(", classNameId=");
764 msg.append(classNameId);
765
766 msg.append(StringPool.CLOSE_CURLY_BRACE);
767
768 throw new NoSuchSubscriptionException(msg.toString());
769 }
770
771
779 @Override
780 public Subscription fetchByU_C_First(long userId, long classNameId,
781 OrderByComparator<Subscription> orderByComparator) {
782 List<Subscription> list = findByU_C(userId, classNameId, 0, 1,
783 orderByComparator);
784
785 if (!list.isEmpty()) {
786 return list.get(0);
787 }
788
789 return null;
790 }
791
792
801 @Override
802 public Subscription findByU_C_Last(long userId, long classNameId,
803 OrderByComparator<Subscription> orderByComparator)
804 throws NoSuchSubscriptionException {
805 Subscription subscription = fetchByU_C_Last(userId, classNameId,
806 orderByComparator);
807
808 if (subscription != null) {
809 return subscription;
810 }
811
812 StringBundler msg = new StringBundler(6);
813
814 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
815
816 msg.append("userId=");
817 msg.append(userId);
818
819 msg.append(", classNameId=");
820 msg.append(classNameId);
821
822 msg.append(StringPool.CLOSE_CURLY_BRACE);
823
824 throw new NoSuchSubscriptionException(msg.toString());
825 }
826
827
835 @Override
836 public Subscription fetchByU_C_Last(long userId, long classNameId,
837 OrderByComparator<Subscription> orderByComparator) {
838 int count = countByU_C(userId, classNameId);
839
840 if (count == 0) {
841 return null;
842 }
843
844 List<Subscription> list = findByU_C(userId, classNameId, count - 1,
845 count, orderByComparator);
846
847 if (!list.isEmpty()) {
848 return list.get(0);
849 }
850
851 return null;
852 }
853
854
864 @Override
865 public Subscription[] findByU_C_PrevAndNext(long subscriptionId,
866 long userId, long classNameId,
867 OrderByComparator<Subscription> orderByComparator)
868 throws NoSuchSubscriptionException {
869 Subscription subscription = findByPrimaryKey(subscriptionId);
870
871 Session session = null;
872
873 try {
874 session = openSession();
875
876 Subscription[] array = new SubscriptionImpl[3];
877
878 array[0] = getByU_C_PrevAndNext(session, subscription, userId,
879 classNameId, orderByComparator, true);
880
881 array[1] = subscription;
882
883 array[2] = getByU_C_PrevAndNext(session, subscription, userId,
884 classNameId, orderByComparator, false);
885
886 return array;
887 }
888 catch (Exception e) {
889 throw processException(e);
890 }
891 finally {
892 closeSession(session);
893 }
894 }
895
896 protected Subscription getByU_C_PrevAndNext(Session session,
897 Subscription subscription, long userId, long classNameId,
898 OrderByComparator<Subscription> orderByComparator, boolean previous) {
899 StringBundler query = null;
900
901 if (orderByComparator != null) {
902 query = new StringBundler(6 +
903 (orderByComparator.getOrderByFields().length * 6));
904 }
905 else {
906 query = new StringBundler(3);
907 }
908
909 query.append(_SQL_SELECT_SUBSCRIPTION_WHERE);
910
911 query.append(_FINDER_COLUMN_U_C_USERID_2);
912
913 query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
914
915 if (orderByComparator != null) {
916 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
917
918 if (orderByConditionFields.length > 0) {
919 query.append(WHERE_AND);
920 }
921
922 for (int i = 0; i < orderByConditionFields.length; i++) {
923 query.append(_ORDER_BY_ENTITY_ALIAS);
924 query.append(orderByConditionFields[i]);
925
926 if ((i + 1) < orderByConditionFields.length) {
927 if (orderByComparator.isAscending() ^ previous) {
928 query.append(WHERE_GREATER_THAN_HAS_NEXT);
929 }
930 else {
931 query.append(WHERE_LESSER_THAN_HAS_NEXT);
932 }
933 }
934 else {
935 if (orderByComparator.isAscending() ^ previous) {
936 query.append(WHERE_GREATER_THAN);
937 }
938 else {
939 query.append(WHERE_LESSER_THAN);
940 }
941 }
942 }
943
944 query.append(ORDER_BY_CLAUSE);
945
946 String[] orderByFields = orderByComparator.getOrderByFields();
947
948 for (int i = 0; i < orderByFields.length; i++) {
949 query.append(_ORDER_BY_ENTITY_ALIAS);
950 query.append(orderByFields[i]);
951
952 if ((i + 1) < orderByFields.length) {
953 if (orderByComparator.isAscending() ^ previous) {
954 query.append(ORDER_BY_ASC_HAS_NEXT);
955 }
956 else {
957 query.append(ORDER_BY_DESC_HAS_NEXT);
958 }
959 }
960 else {
961 if (orderByComparator.isAscending() ^ previous) {
962 query.append(ORDER_BY_ASC);
963 }
964 else {
965 query.append(ORDER_BY_DESC);
966 }
967 }
968 }
969 }
970 else {
971 query.append(SubscriptionModelImpl.ORDER_BY_JPQL);
972 }
973
974 String sql = query.toString();
975
976 Query q = session.createQuery(sql);
977
978 q.setFirstResult(0);
979 q.setMaxResults(2);
980
981 QueryPos qPos = QueryPos.getInstance(q);
982
983 qPos.add(userId);
984
985 qPos.add(classNameId);
986
987 if (orderByComparator != null) {
988 Object[] values = orderByComparator.getOrderByConditionValues(subscription);
989
990 for (Object value : values) {
991 qPos.add(value);
992 }
993 }
994
995 List<Subscription> list = q.list();
996
997 if (list.size() == 2) {
998 return list.get(1);
999 }
1000 else {
1001 return null;
1002 }
1003 }
1004
1005
1011 @Override
1012 public void removeByU_C(long userId, long classNameId) {
1013 for (Subscription subscription : findByU_C(userId, classNameId,
1014 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1015 remove(subscription);
1016 }
1017 }
1018
1019
1026 @Override
1027 public int countByU_C(long userId, long classNameId) {
1028 FinderPath finderPath = FINDER_PATH_COUNT_BY_U_C;
1029
1030 Object[] finderArgs = new Object[] { userId, classNameId };
1031
1032 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1033 this);
1034
1035 if (count == null) {
1036 StringBundler query = new StringBundler(3);
1037
1038 query.append(_SQL_COUNT_SUBSCRIPTION_WHERE);
1039
1040 query.append(_FINDER_COLUMN_U_C_USERID_2);
1041
1042 query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
1043
1044 String sql = query.toString();
1045
1046 Session session = null;
1047
1048 try {
1049 session = openSession();
1050
1051 Query q = session.createQuery(sql);
1052
1053 QueryPos qPos = QueryPos.getInstance(q);
1054
1055 qPos.add(userId);
1056
1057 qPos.add(classNameId);
1058
1059 count = (Long)q.uniqueResult();
1060
1061 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1062 }
1063 catch (Exception e) {
1064 FinderCacheUtil.removeResult(finderPath, finderArgs);
1065
1066 throw processException(e);
1067 }
1068 finally {
1069 closeSession(session);
1070 }
1071 }
1072
1073 return count.intValue();
1074 }
1075
1076 private static final String _FINDER_COLUMN_U_C_USERID_2 = "subscription.userId = ? AND ";
1077 private static final String _FINDER_COLUMN_U_C_CLASSNAMEID_2 = "subscription.classNameId = ?";
1078 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
1079 SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.class,
1080 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C_C",
1081 new String[] {
1082 Long.class.getName(), Long.class.getName(), Long.class.getName(),
1083
1084 Integer.class.getName(), Integer.class.getName(),
1085 OrderByComparator.class.getName()
1086 });
1087 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
1088 SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.class,
1089 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C_C",
1090 new String[] {
1091 Long.class.getName(), Long.class.getName(), Long.class.getName()
1092 },
1093 SubscriptionModelImpl.COMPANYID_COLUMN_BITMASK |
1094 SubscriptionModelImpl.CLASSNAMEID_COLUMN_BITMASK |
1095 SubscriptionModelImpl.CLASSPK_COLUMN_BITMASK);
1096 public static final FinderPath FINDER_PATH_COUNT_BY_C_C_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
1097 SubscriptionModelImpl.FINDER_CACHE_ENABLED, Long.class,
1098 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_C",
1099 new String[] {
1100 Long.class.getName(), Long.class.getName(), Long.class.getName()
1101 });
1102
1103
1111 @Override
1112 public List<Subscription> findByC_C_C(long companyId, long classNameId,
1113 long classPK) {
1114 return findByC_C_C(companyId, classNameId, classPK, QueryUtil.ALL_POS,
1115 QueryUtil.ALL_POS, null);
1116 }
1117
1118
1132 @Override
1133 public List<Subscription> findByC_C_C(long companyId, long classNameId,
1134 long classPK, int start, int end) {
1135 return findByC_C_C(companyId, classNameId, classPK, start, end, null);
1136 }
1137
1138
1153 @Override
1154 public List<Subscription> findByC_C_C(long companyId, long classNameId,
1155 long classPK, int start, int end,
1156 OrderByComparator<Subscription> orderByComparator) {
1157 boolean pagination = true;
1158 FinderPath finderPath = null;
1159 Object[] finderArgs = null;
1160
1161 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1162 (orderByComparator == null)) {
1163 pagination = false;
1164 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C;
1165 finderArgs = new Object[] { companyId, classNameId, classPK };
1166 }
1167 else {
1168 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_C;
1169 finderArgs = new Object[] {
1170 companyId, classNameId, classPK,
1171
1172 start, end, orderByComparator
1173 };
1174 }
1175
1176 List<Subscription> list = (List<Subscription>)FinderCacheUtil.getResult(finderPath,
1177 finderArgs, this);
1178
1179 if ((list != null) && !list.isEmpty()) {
1180 for (Subscription subscription : list) {
1181 if ((companyId != subscription.getCompanyId()) ||
1182 (classNameId != subscription.getClassNameId()) ||
1183 (classPK != subscription.getClassPK())) {
1184 list = null;
1185
1186 break;
1187 }
1188 }
1189 }
1190
1191 if (list == null) {
1192 StringBundler query = null;
1193
1194 if (orderByComparator != null) {
1195 query = new StringBundler(5 +
1196 (orderByComparator.getOrderByFields().length * 3));
1197 }
1198 else {
1199 query = new StringBundler(5);
1200 }
1201
1202 query.append(_SQL_SELECT_SUBSCRIPTION_WHERE);
1203
1204 query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
1205
1206 query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
1207
1208 query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
1209
1210 if (orderByComparator != null) {
1211 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1212 orderByComparator);
1213 }
1214 else
1215 if (pagination) {
1216 query.append(SubscriptionModelImpl.ORDER_BY_JPQL);
1217 }
1218
1219 String sql = query.toString();
1220
1221 Session session = null;
1222
1223 try {
1224 session = openSession();
1225
1226 Query q = session.createQuery(sql);
1227
1228 QueryPos qPos = QueryPos.getInstance(q);
1229
1230 qPos.add(companyId);
1231
1232 qPos.add(classNameId);
1233
1234 qPos.add(classPK);
1235
1236 if (!pagination) {
1237 list = (List<Subscription>)QueryUtil.list(q, getDialect(),
1238 start, end, false);
1239
1240 Collections.sort(list);
1241
1242 list = Collections.unmodifiableList(list);
1243 }
1244 else {
1245 list = (List<Subscription>)QueryUtil.list(q, getDialect(),
1246 start, end);
1247 }
1248
1249 cacheResult(list);
1250
1251 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1252 }
1253 catch (Exception e) {
1254 FinderCacheUtil.removeResult(finderPath, finderArgs);
1255
1256 throw processException(e);
1257 }
1258 finally {
1259 closeSession(session);
1260 }
1261 }
1262
1263 return list;
1264 }
1265
1266
1276 @Override
1277 public Subscription findByC_C_C_First(long companyId, long classNameId,
1278 long classPK, OrderByComparator<Subscription> orderByComparator)
1279 throws NoSuchSubscriptionException {
1280 Subscription subscription = fetchByC_C_C_First(companyId, classNameId,
1281 classPK, orderByComparator);
1282
1283 if (subscription != null) {
1284 return subscription;
1285 }
1286
1287 StringBundler msg = new StringBundler(8);
1288
1289 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1290
1291 msg.append("companyId=");
1292 msg.append(companyId);
1293
1294 msg.append(", classNameId=");
1295 msg.append(classNameId);
1296
1297 msg.append(", classPK=");
1298 msg.append(classPK);
1299
1300 msg.append(StringPool.CLOSE_CURLY_BRACE);
1301
1302 throw new NoSuchSubscriptionException(msg.toString());
1303 }
1304
1305
1314 @Override
1315 public Subscription fetchByC_C_C_First(long companyId, long classNameId,
1316 long classPK, OrderByComparator<Subscription> orderByComparator) {
1317 List<Subscription> list = findByC_C_C(companyId, classNameId, classPK,
1318 0, 1, orderByComparator);
1319
1320 if (!list.isEmpty()) {
1321 return list.get(0);
1322 }
1323
1324 return null;
1325 }
1326
1327
1337 @Override
1338 public Subscription findByC_C_C_Last(long companyId, long classNameId,
1339 long classPK, OrderByComparator<Subscription> orderByComparator)
1340 throws NoSuchSubscriptionException {
1341 Subscription subscription = fetchByC_C_C_Last(companyId, classNameId,
1342 classPK, orderByComparator);
1343
1344 if (subscription != null) {
1345 return subscription;
1346 }
1347
1348 StringBundler msg = new StringBundler(8);
1349
1350 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1351
1352 msg.append("companyId=");
1353 msg.append(companyId);
1354
1355 msg.append(", classNameId=");
1356 msg.append(classNameId);
1357
1358 msg.append(", classPK=");
1359 msg.append(classPK);
1360
1361 msg.append(StringPool.CLOSE_CURLY_BRACE);
1362
1363 throw new NoSuchSubscriptionException(msg.toString());
1364 }
1365
1366
1375 @Override
1376 public Subscription fetchByC_C_C_Last(long companyId, long classNameId,
1377 long classPK, OrderByComparator<Subscription> orderByComparator) {
1378 int count = countByC_C_C(companyId, classNameId, classPK);
1379
1380 if (count == 0) {
1381 return null;
1382 }
1383
1384 List<Subscription> list = findByC_C_C(companyId, classNameId, classPK,
1385 count - 1, count, orderByComparator);
1386
1387 if (!list.isEmpty()) {
1388 return list.get(0);
1389 }
1390
1391 return null;
1392 }
1393
1394
1405 @Override
1406 public Subscription[] findByC_C_C_PrevAndNext(long subscriptionId,
1407 long companyId, long classNameId, long classPK,
1408 OrderByComparator<Subscription> orderByComparator)
1409 throws NoSuchSubscriptionException {
1410 Subscription subscription = findByPrimaryKey(subscriptionId);
1411
1412 Session session = null;
1413
1414 try {
1415 session = openSession();
1416
1417 Subscription[] array = new SubscriptionImpl[3];
1418
1419 array[0] = getByC_C_C_PrevAndNext(session, subscription, companyId,
1420 classNameId, classPK, orderByComparator, true);
1421
1422 array[1] = subscription;
1423
1424 array[2] = getByC_C_C_PrevAndNext(session, subscription, companyId,
1425 classNameId, classPK, orderByComparator, false);
1426
1427 return array;
1428 }
1429 catch (Exception e) {
1430 throw processException(e);
1431 }
1432 finally {
1433 closeSession(session);
1434 }
1435 }
1436
1437 protected Subscription getByC_C_C_PrevAndNext(Session session,
1438 Subscription subscription, long companyId, long classNameId,
1439 long classPK, OrderByComparator<Subscription> orderByComparator,
1440 boolean previous) {
1441 StringBundler query = null;
1442
1443 if (orderByComparator != null) {
1444 query = new StringBundler(6 +
1445 (orderByComparator.getOrderByFields().length * 6));
1446 }
1447 else {
1448 query = new StringBundler(3);
1449 }
1450
1451 query.append(_SQL_SELECT_SUBSCRIPTION_WHERE);
1452
1453 query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
1454
1455 query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
1456
1457 query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
1458
1459 if (orderByComparator != null) {
1460 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1461
1462 if (orderByConditionFields.length > 0) {
1463 query.append(WHERE_AND);
1464 }
1465
1466 for (int i = 0; i < orderByConditionFields.length; i++) {
1467 query.append(_ORDER_BY_ENTITY_ALIAS);
1468 query.append(orderByConditionFields[i]);
1469
1470 if ((i + 1) < orderByConditionFields.length) {
1471 if (orderByComparator.isAscending() ^ previous) {
1472 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1473 }
1474 else {
1475 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1476 }
1477 }
1478 else {
1479 if (orderByComparator.isAscending() ^ previous) {
1480 query.append(WHERE_GREATER_THAN);
1481 }
1482 else {
1483 query.append(WHERE_LESSER_THAN);
1484 }
1485 }
1486 }
1487
1488 query.append(ORDER_BY_CLAUSE);
1489
1490 String[] orderByFields = orderByComparator.getOrderByFields();
1491
1492 for (int i = 0; i < orderByFields.length; i++) {
1493 query.append(_ORDER_BY_ENTITY_ALIAS);
1494 query.append(orderByFields[i]);
1495
1496 if ((i + 1) < orderByFields.length) {
1497 if (orderByComparator.isAscending() ^ previous) {
1498 query.append(ORDER_BY_ASC_HAS_NEXT);
1499 }
1500 else {
1501 query.append(ORDER_BY_DESC_HAS_NEXT);
1502 }
1503 }
1504 else {
1505 if (orderByComparator.isAscending() ^ previous) {
1506 query.append(ORDER_BY_ASC);
1507 }
1508 else {
1509 query.append(ORDER_BY_DESC);
1510 }
1511 }
1512 }
1513 }
1514 else {
1515 query.append(SubscriptionModelImpl.ORDER_BY_JPQL);
1516 }
1517
1518 String sql = query.toString();
1519
1520 Query q = session.createQuery(sql);
1521
1522 q.setFirstResult(0);
1523 q.setMaxResults(2);
1524
1525 QueryPos qPos = QueryPos.getInstance(q);
1526
1527 qPos.add(companyId);
1528
1529 qPos.add(classNameId);
1530
1531 qPos.add(classPK);
1532
1533 if (orderByComparator != null) {
1534 Object[] values = orderByComparator.getOrderByConditionValues(subscription);
1535
1536 for (Object value : values) {
1537 qPos.add(value);
1538 }
1539 }
1540
1541 List<Subscription> list = q.list();
1542
1543 if (list.size() == 2) {
1544 return list.get(1);
1545 }
1546 else {
1547 return null;
1548 }
1549 }
1550
1551
1558 @Override
1559 public void removeByC_C_C(long companyId, long classNameId, long classPK) {
1560 for (Subscription subscription : findByC_C_C(companyId, classNameId,
1561 classPK, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1562 remove(subscription);
1563 }
1564 }
1565
1566
1574 @Override
1575 public int countByC_C_C(long companyId, long classNameId, long classPK) {
1576 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C_C;
1577
1578 Object[] finderArgs = new Object[] { companyId, classNameId, classPK };
1579
1580 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1581 this);
1582
1583 if (count == null) {
1584 StringBundler query = new StringBundler(4);
1585
1586 query.append(_SQL_COUNT_SUBSCRIPTION_WHERE);
1587
1588 query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
1589
1590 query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
1591
1592 query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
1593
1594 String sql = query.toString();
1595
1596 Session session = null;
1597
1598 try {
1599 session = openSession();
1600
1601 Query q = session.createQuery(sql);
1602
1603 QueryPos qPos = QueryPos.getInstance(q);
1604
1605 qPos.add(companyId);
1606
1607 qPos.add(classNameId);
1608
1609 qPos.add(classPK);
1610
1611 count = (Long)q.uniqueResult();
1612
1613 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1614 }
1615 catch (Exception e) {
1616 FinderCacheUtil.removeResult(finderPath, finderArgs);
1617
1618 throw processException(e);
1619 }
1620 finally {
1621 closeSession(session);
1622 }
1623 }
1624
1625 return count.intValue();
1626 }
1627
1628 private static final String _FINDER_COLUMN_C_C_C_COMPANYID_2 = "subscription.companyId = ? AND ";
1629 private static final String _FINDER_COLUMN_C_C_C_CLASSNAMEID_2 = "subscription.classNameId = ? AND ";
1630 private static final String _FINDER_COLUMN_C_C_C_CLASSPK_2 = "subscription.classPK = ?";
1631 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_U_C_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
1632 SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.class,
1633 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_U_C_C",
1634 new String[] {
1635 Long.class.getName(), Long.class.getName(), Long.class.getName(),
1636 Long.class.getName(),
1637
1638 Integer.class.getName(), Integer.class.getName(),
1639 OrderByComparator.class.getName()
1640 });
1641 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_U_C_C =
1642 new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
1643 SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.class,
1644 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_U_C_C",
1645 new String[] {
1646 Long.class.getName(), Long.class.getName(), Long.class.getName(),
1647 Long.class.getName()
1648 },
1649 SubscriptionModelImpl.COMPANYID_COLUMN_BITMASK |
1650 SubscriptionModelImpl.USERID_COLUMN_BITMASK |
1651 SubscriptionModelImpl.CLASSNAMEID_COLUMN_BITMASK |
1652 SubscriptionModelImpl.CLASSPK_COLUMN_BITMASK);
1653 public static final FinderPath FINDER_PATH_FETCH_BY_C_U_C_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
1654 SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.class,
1655 FINDER_CLASS_NAME_ENTITY, "fetchByC_U_C_C",
1656 new String[] {
1657 Long.class.getName(), Long.class.getName(), Long.class.getName(),
1658 Long.class.getName()
1659 },
1660 SubscriptionModelImpl.COMPANYID_COLUMN_BITMASK |
1661 SubscriptionModelImpl.USERID_COLUMN_BITMASK |
1662 SubscriptionModelImpl.CLASSNAMEID_COLUMN_BITMASK |
1663 SubscriptionModelImpl.CLASSPK_COLUMN_BITMASK);
1664 public static final FinderPath FINDER_PATH_COUNT_BY_C_U_C_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
1665 SubscriptionModelImpl.FINDER_CACHE_ENABLED, Long.class,
1666 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_U_C_C",
1667 new String[] {
1668 Long.class.getName(), Long.class.getName(), Long.class.getName(),
1669 Long.class.getName()
1670 });
1671 public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_U_C_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
1672 SubscriptionModelImpl.FINDER_CACHE_ENABLED, Long.class,
1673 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByC_U_C_C",
1674 new String[] {
1675 Long.class.getName(), Long.class.getName(), Long.class.getName(),
1676 Long.class.getName()
1677 });
1678
1679
1692 @Override
1693 public List<Subscription> findByC_U_C_C(long companyId, long userId,
1694 long classNameId, long[] classPKs) {
1695 return findByC_U_C_C(companyId, userId, classNameId, classPKs,
1696 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1697 }
1698
1699
1714 @Override
1715 public List<Subscription> findByC_U_C_C(long companyId, long userId,
1716 long classNameId, long[] classPKs, int start, int end) {
1717 return findByC_U_C_C(companyId, userId, classNameId, classPKs, start,
1718 end, null);
1719 }
1720
1721
1737 @Override
1738 public List<Subscription> findByC_U_C_C(long companyId, long userId,
1739 long classNameId, long[] classPKs, int start, int end,
1740 OrderByComparator<Subscription> orderByComparator) {
1741 if (classPKs == null) {
1742 classPKs = new long[0];
1743 }
1744 else {
1745 classPKs = ArrayUtil.unique(classPKs);
1746 }
1747
1748 if (classPKs.length == 1) {
1749 Subscription subscription = fetchByC_U_C_C(companyId, userId,
1750 classNameId, classPKs[0]);
1751
1752 if (subscription == null) {
1753 return Collections.emptyList();
1754 }
1755 else {
1756 List<Subscription> list = new ArrayList<Subscription>(1);
1757
1758 list.add(subscription);
1759
1760 return list;
1761 }
1762 }
1763
1764 boolean pagination = true;
1765 Object[] finderArgs = null;
1766
1767 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1768 (orderByComparator == null)) {
1769 pagination = false;
1770 finderArgs = new Object[] {
1771 companyId, userId, classNameId, StringUtil.merge(classPKs)
1772 };
1773 }
1774 else {
1775 finderArgs = new Object[] {
1776 companyId, userId, classNameId, StringUtil.merge(classPKs),
1777
1778 start, end, orderByComparator
1779 };
1780 }
1781
1782 List<Subscription> list = (List<Subscription>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_C_U_C_C,
1783 finderArgs, this);
1784
1785 if ((list != null) && !list.isEmpty()) {
1786 for (Subscription subscription : list) {
1787 if ((companyId != subscription.getCompanyId()) ||
1788 (userId != subscription.getUserId()) ||
1789 (classNameId != subscription.getClassNameId()) ||
1790 !ArrayUtil.contains(classPKs, subscription.getClassPK())) {
1791 list = null;
1792
1793 break;
1794 }
1795 }
1796 }
1797
1798 if (list == null) {
1799 StringBundler query = new StringBundler();
1800
1801 query.append(_SQL_SELECT_SUBSCRIPTION_WHERE);
1802
1803 query.append(_FINDER_COLUMN_C_U_C_C_COMPANYID_2);
1804
1805 query.append(_FINDER_COLUMN_C_U_C_C_USERID_2);
1806
1807 query.append(_FINDER_COLUMN_C_U_C_C_CLASSNAMEID_2);
1808
1809 if (classPKs.length > 0) {
1810 query.append(StringPool.OPEN_PARENTHESIS);
1811
1812 query.append(_FINDER_COLUMN_C_U_C_C_CLASSPK_7);
1813
1814 query.append(StringUtil.merge(classPKs));
1815
1816 query.append(StringPool.CLOSE_PARENTHESIS);
1817
1818 query.append(StringPool.CLOSE_PARENTHESIS);
1819 }
1820
1821 query.setStringAt(removeConjunction(query.stringAt(query.index() -
1822 1)), query.index() - 1);
1823
1824 if (orderByComparator != null) {
1825 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1826 orderByComparator);
1827 }
1828 else
1829 if (pagination) {
1830 query.append(SubscriptionModelImpl.ORDER_BY_JPQL);
1831 }
1832
1833 String sql = query.toString();
1834
1835 Session session = null;
1836
1837 try {
1838 session = openSession();
1839
1840 Query q = session.createQuery(sql);
1841
1842 QueryPos qPos = QueryPos.getInstance(q);
1843
1844 qPos.add(companyId);
1845
1846 qPos.add(userId);
1847
1848 qPos.add(classNameId);
1849
1850 if (!pagination) {
1851 list = (List<Subscription>)QueryUtil.list(q, getDialect(),
1852 start, end, false);
1853
1854 Collections.sort(list);
1855
1856 list = Collections.unmodifiableList(list);
1857 }
1858 else {
1859 list = (List<Subscription>)QueryUtil.list(q, getDialect(),
1860 start, end);
1861 }
1862
1863 cacheResult(list);
1864
1865 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_C_U_C_C,
1866 finderArgs, list);
1867 }
1868 catch (Exception e) {
1869 FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_C_U_C_C,
1870 finderArgs);
1871
1872 throw processException(e);
1873 }
1874 finally {
1875 closeSession(session);
1876 }
1877 }
1878
1879 return list;
1880 }
1881
1882
1892 @Override
1893 public Subscription findByC_U_C_C(long companyId, long userId,
1894 long classNameId, long classPK) throws NoSuchSubscriptionException {
1895 Subscription subscription = fetchByC_U_C_C(companyId, userId,
1896 classNameId, classPK);
1897
1898 if (subscription == null) {
1899 StringBundler msg = new StringBundler(10);
1900
1901 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1902
1903 msg.append("companyId=");
1904 msg.append(companyId);
1905
1906 msg.append(", userId=");
1907 msg.append(userId);
1908
1909 msg.append(", classNameId=");
1910 msg.append(classNameId);
1911
1912 msg.append(", classPK=");
1913 msg.append(classPK);
1914
1915 msg.append(StringPool.CLOSE_CURLY_BRACE);
1916
1917 if (_log.isWarnEnabled()) {
1918 _log.warn(msg.toString());
1919 }
1920
1921 throw new NoSuchSubscriptionException(msg.toString());
1922 }
1923
1924 return subscription;
1925 }
1926
1927
1936 @Override
1937 public Subscription fetchByC_U_C_C(long companyId, long userId,
1938 long classNameId, long classPK) {
1939 return fetchByC_U_C_C(companyId, userId, classNameId, classPK, true);
1940 }
1941
1942
1952 @Override
1953 public Subscription fetchByC_U_C_C(long companyId, long userId,
1954 long classNameId, long classPK, boolean retrieveFromCache) {
1955 Object[] finderArgs = new Object[] {
1956 companyId, userId, classNameId, classPK
1957 };
1958
1959 Object result = null;
1960
1961 if (retrieveFromCache) {
1962 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_U_C_C,
1963 finderArgs, this);
1964 }
1965
1966 if (result instanceof Subscription) {
1967 Subscription subscription = (Subscription)result;
1968
1969 if ((companyId != subscription.getCompanyId()) ||
1970 (userId != subscription.getUserId()) ||
1971 (classNameId != subscription.getClassNameId()) ||
1972 (classPK != subscription.getClassPK())) {
1973 result = null;
1974 }
1975 }
1976
1977 if (result == null) {
1978 StringBundler query = new StringBundler(6);
1979
1980 query.append(_SQL_SELECT_SUBSCRIPTION_WHERE);
1981
1982 query.append(_FINDER_COLUMN_C_U_C_C_COMPANYID_2);
1983
1984 query.append(_FINDER_COLUMN_C_U_C_C_USERID_2);
1985
1986 query.append(_FINDER_COLUMN_C_U_C_C_CLASSNAMEID_2);
1987
1988 query.append(_FINDER_COLUMN_C_U_C_C_CLASSPK_2);
1989
1990 String sql = query.toString();
1991
1992 Session session = null;
1993
1994 try {
1995 session = openSession();
1996
1997 Query q = session.createQuery(sql);
1998
1999 QueryPos qPos = QueryPos.getInstance(q);
2000
2001 qPos.add(companyId);
2002
2003 qPos.add(userId);
2004
2005 qPos.add(classNameId);
2006
2007 qPos.add(classPK);
2008
2009 List<Subscription> list = q.list();
2010
2011 if (list.isEmpty()) {
2012 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_U_C_C,
2013 finderArgs, list);
2014 }
2015 else {
2016 Subscription subscription = list.get(0);
2017
2018 result = subscription;
2019
2020 cacheResult(subscription);
2021
2022 if ((subscription.getCompanyId() != companyId) ||
2023 (subscription.getUserId() != userId) ||
2024 (subscription.getClassNameId() != classNameId) ||
2025 (subscription.getClassPK() != classPK)) {
2026 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_U_C_C,
2027 finderArgs, subscription);
2028 }
2029 }
2030 }
2031 catch (Exception e) {
2032 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_U_C_C,
2033 finderArgs);
2034
2035 throw processException(e);
2036 }
2037 finally {
2038 closeSession(session);
2039 }
2040 }
2041
2042 if (result instanceof List<?>) {
2043 return null;
2044 }
2045 else {
2046 return (Subscription)result;
2047 }
2048 }
2049
2050
2059 @Override
2060 public Subscription removeByC_U_C_C(long companyId, long userId,
2061 long classNameId, long classPK) throws NoSuchSubscriptionException {
2062 Subscription subscription = findByC_U_C_C(companyId, userId,
2063 classNameId, classPK);
2064
2065 return remove(subscription);
2066 }
2067
2068
2077 @Override
2078 public int countByC_U_C_C(long companyId, long userId, long classNameId,
2079 long classPK) {
2080 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_U_C_C;
2081
2082 Object[] finderArgs = new Object[] {
2083 companyId, userId, classNameId, classPK
2084 };
2085
2086 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2087 this);
2088
2089 if (count == null) {
2090 StringBundler query = new StringBundler(5);
2091
2092 query.append(_SQL_COUNT_SUBSCRIPTION_WHERE);
2093
2094 query.append(_FINDER_COLUMN_C_U_C_C_COMPANYID_2);
2095
2096 query.append(_FINDER_COLUMN_C_U_C_C_USERID_2);
2097
2098 query.append(_FINDER_COLUMN_C_U_C_C_CLASSNAMEID_2);
2099
2100 query.append(_FINDER_COLUMN_C_U_C_C_CLASSPK_2);
2101
2102 String sql = query.toString();
2103
2104 Session session = null;
2105
2106 try {
2107 session = openSession();
2108
2109 Query q = session.createQuery(sql);
2110
2111 QueryPos qPos = QueryPos.getInstance(q);
2112
2113 qPos.add(companyId);
2114
2115 qPos.add(userId);
2116
2117 qPos.add(classNameId);
2118
2119 qPos.add(classPK);
2120
2121 count = (Long)q.uniqueResult();
2122
2123 FinderCacheUtil.putResult(finderPath, finderArgs, count);
2124 }
2125 catch (Exception e) {
2126 FinderCacheUtil.removeResult(finderPath, finderArgs);
2127
2128 throw processException(e);
2129 }
2130 finally {
2131 closeSession(session);
2132 }
2133 }
2134
2135 return count.intValue();
2136 }
2137
2138
2147 @Override
2148 public int countByC_U_C_C(long companyId, long userId, long classNameId,
2149 long[] classPKs) {
2150 if (classPKs == null) {
2151 classPKs = new long[0];
2152 }
2153 else {
2154 classPKs = ArrayUtil.unique(classPKs);
2155 }
2156
2157 Object[] finderArgs = new Object[] {
2158 companyId, userId, classNameId, StringUtil.merge(classPKs)
2159 };
2160
2161 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_U_C_C,
2162 finderArgs, this);
2163
2164 if (count == null) {
2165 StringBundler query = new StringBundler();
2166
2167 query.append(_SQL_COUNT_SUBSCRIPTION_WHERE);
2168
2169 query.append(_FINDER_COLUMN_C_U_C_C_COMPANYID_2);
2170
2171 query.append(_FINDER_COLUMN_C_U_C_C_USERID_2);
2172
2173 query.append(_FINDER_COLUMN_C_U_C_C_CLASSNAMEID_2);
2174
2175 if (classPKs.length > 0) {
2176 query.append(StringPool.OPEN_PARENTHESIS);
2177
2178 query.append(_FINDER_COLUMN_C_U_C_C_CLASSPK_7);
2179
2180 query.append(StringUtil.merge(classPKs));
2181
2182 query.append(StringPool.CLOSE_PARENTHESIS);
2183
2184 query.append(StringPool.CLOSE_PARENTHESIS);
2185 }
2186
2187 query.setStringAt(removeConjunction(query.stringAt(query.index() -
2188 1)), query.index() - 1);
2189
2190 String sql = query.toString();
2191
2192 Session session = null;
2193
2194 try {
2195 session = openSession();
2196
2197 Query q = session.createQuery(sql);
2198
2199 QueryPos qPos = QueryPos.getInstance(q);
2200
2201 qPos.add(companyId);
2202
2203 qPos.add(userId);
2204
2205 qPos.add(classNameId);
2206
2207 count = (Long)q.uniqueResult();
2208
2209 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_U_C_C,
2210 finderArgs, count);
2211 }
2212 catch (Exception e) {
2213 FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_U_C_C,
2214 finderArgs);
2215
2216 throw processException(e);
2217 }
2218 finally {
2219 closeSession(session);
2220 }
2221 }
2222
2223 return count.intValue();
2224 }
2225
2226 private static final String _FINDER_COLUMN_C_U_C_C_COMPANYID_2 = "subscription.companyId = ? AND ";
2227 private static final String _FINDER_COLUMN_C_U_C_C_USERID_2 = "subscription.userId = ? AND ";
2228 private static final String _FINDER_COLUMN_C_U_C_C_CLASSNAMEID_2 = "subscription.classNameId = ? AND ";
2229 private static final String _FINDER_COLUMN_C_U_C_C_CLASSPK_2 = "subscription.classPK = ?";
2230 private static final String _FINDER_COLUMN_C_U_C_C_CLASSPK_7 = "subscription.classPK IN (";
2231
2232 public SubscriptionPersistenceImpl() {
2233 setModelClass(Subscription.class);
2234 }
2235
2236
2241 @Override
2242 public void cacheResult(Subscription subscription) {
2243 EntityCacheUtil.putResult(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
2244 SubscriptionImpl.class, subscription.getPrimaryKey(), subscription);
2245
2246 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_U_C_C,
2247 new Object[] {
2248 subscription.getCompanyId(), subscription.getUserId(),
2249 subscription.getClassNameId(), subscription.getClassPK()
2250 }, subscription);
2251
2252 subscription.resetOriginalValues();
2253 }
2254
2255
2260 @Override
2261 public void cacheResult(List<Subscription> subscriptions) {
2262 for (Subscription subscription : subscriptions) {
2263 if (EntityCacheUtil.getResult(
2264 SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
2265 SubscriptionImpl.class, subscription.getPrimaryKey()) == null) {
2266 cacheResult(subscription);
2267 }
2268 else {
2269 subscription.resetOriginalValues();
2270 }
2271 }
2272 }
2273
2274
2281 @Override
2282 public void clearCache() {
2283 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
2284 CacheRegistryUtil.clear(SubscriptionImpl.class.getName());
2285 }
2286
2287 EntityCacheUtil.clearCache(SubscriptionImpl.class);
2288
2289 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
2290 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2291 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2292 }
2293
2294
2301 @Override
2302 public void clearCache(Subscription subscription) {
2303 EntityCacheUtil.removeResult(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
2304 SubscriptionImpl.class, subscription.getPrimaryKey());
2305
2306 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2307 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2308
2309 clearUniqueFindersCache(subscription);
2310 }
2311
2312 @Override
2313 public void clearCache(List<Subscription> subscriptions) {
2314 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2315 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2316
2317 for (Subscription subscription : subscriptions) {
2318 EntityCacheUtil.removeResult(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
2319 SubscriptionImpl.class, subscription.getPrimaryKey());
2320
2321 clearUniqueFindersCache(subscription);
2322 }
2323 }
2324
2325 protected void cacheUniqueFindersCache(Subscription subscription) {
2326 if (subscription.isNew()) {
2327 Object[] args = new Object[] {
2328 subscription.getCompanyId(), subscription.getUserId(),
2329 subscription.getClassNameId(), subscription.getClassPK()
2330 };
2331
2332 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_U_C_C, args,
2333 Long.valueOf(1));
2334 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_U_C_C, args,
2335 subscription);
2336 }
2337 else {
2338 SubscriptionModelImpl subscriptionModelImpl = (SubscriptionModelImpl)subscription;
2339
2340 if ((subscriptionModelImpl.getColumnBitmask() &
2341 FINDER_PATH_FETCH_BY_C_U_C_C.getColumnBitmask()) != 0) {
2342 Object[] args = new Object[] {
2343 subscription.getCompanyId(), subscription.getUserId(),
2344 subscription.getClassNameId(), subscription.getClassPK()
2345 };
2346
2347 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_U_C_C, args,
2348 Long.valueOf(1));
2349 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_U_C_C, args,
2350 subscription);
2351 }
2352 }
2353 }
2354
2355 protected void clearUniqueFindersCache(Subscription subscription) {
2356 SubscriptionModelImpl subscriptionModelImpl = (SubscriptionModelImpl)subscription;
2357
2358 Object[] args = new Object[] {
2359 subscription.getCompanyId(), subscription.getUserId(),
2360 subscription.getClassNameId(), subscription.getClassPK()
2361 };
2362
2363 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_U_C_C, args);
2364 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_U_C_C, args);
2365
2366 if ((subscriptionModelImpl.getColumnBitmask() &
2367 FINDER_PATH_FETCH_BY_C_U_C_C.getColumnBitmask()) != 0) {
2368 args = new Object[] {
2369 subscriptionModelImpl.getOriginalCompanyId(),
2370 subscriptionModelImpl.getOriginalUserId(),
2371 subscriptionModelImpl.getOriginalClassNameId(),
2372 subscriptionModelImpl.getOriginalClassPK()
2373 };
2374
2375 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_U_C_C, args);
2376 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_U_C_C, args);
2377 }
2378 }
2379
2380
2386 @Override
2387 public Subscription create(long subscriptionId) {
2388 Subscription subscription = new SubscriptionImpl();
2389
2390 subscription.setNew(true);
2391 subscription.setPrimaryKey(subscriptionId);
2392
2393 return subscription;
2394 }
2395
2396
2403 @Override
2404 public Subscription remove(long subscriptionId)
2405 throws NoSuchSubscriptionException {
2406 return remove((Serializable)subscriptionId);
2407 }
2408
2409
2416 @Override
2417 public Subscription remove(Serializable primaryKey)
2418 throws NoSuchSubscriptionException {
2419 Session session = null;
2420
2421 try {
2422 session = openSession();
2423
2424 Subscription subscription = (Subscription)session.get(SubscriptionImpl.class,
2425 primaryKey);
2426
2427 if (subscription == null) {
2428 if (_log.isWarnEnabled()) {
2429 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2430 }
2431
2432 throw new NoSuchSubscriptionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2433 primaryKey);
2434 }
2435
2436 return remove(subscription);
2437 }
2438 catch (NoSuchSubscriptionException nsee) {
2439 throw nsee;
2440 }
2441 catch (Exception e) {
2442 throw processException(e);
2443 }
2444 finally {
2445 closeSession(session);
2446 }
2447 }
2448
2449 @Override
2450 protected Subscription removeImpl(Subscription subscription) {
2451 subscription = toUnwrappedModel(subscription);
2452
2453 Session session = null;
2454
2455 try {
2456 session = openSession();
2457
2458 if (!session.contains(subscription)) {
2459 subscription = (Subscription)session.get(SubscriptionImpl.class,
2460 subscription.getPrimaryKeyObj());
2461 }
2462
2463 if (subscription != null) {
2464 session.delete(subscription);
2465 }
2466 }
2467 catch (Exception e) {
2468 throw processException(e);
2469 }
2470 finally {
2471 closeSession(session);
2472 }
2473
2474 if (subscription != null) {
2475 clearCache(subscription);
2476 }
2477
2478 return subscription;
2479 }
2480
2481 @Override
2482 public Subscription updateImpl(
2483 com.liferay.portal.model.Subscription subscription) {
2484 subscription = toUnwrappedModel(subscription);
2485
2486 boolean isNew = subscription.isNew();
2487
2488 SubscriptionModelImpl subscriptionModelImpl = (SubscriptionModelImpl)subscription;
2489
2490 Session session = null;
2491
2492 try {
2493 session = openSession();
2494
2495 if (subscription.isNew()) {
2496 session.save(subscription);
2497
2498 subscription.setNew(false);
2499 }
2500 else {
2501 session.merge(subscription);
2502 }
2503 }
2504 catch (Exception e) {
2505 throw processException(e);
2506 }
2507 finally {
2508 closeSession(session);
2509 }
2510
2511 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2512
2513 if (isNew || !SubscriptionModelImpl.COLUMN_BITMASK_ENABLED) {
2514 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2515 }
2516
2517 else {
2518 if ((subscriptionModelImpl.getColumnBitmask() &
2519 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
2520 Object[] args = new Object[] {
2521 subscriptionModelImpl.getOriginalUserId()
2522 };
2523
2524 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
2525 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
2526 args);
2527
2528 args = new Object[] { subscriptionModelImpl.getUserId() };
2529
2530 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
2531 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
2532 args);
2533 }
2534
2535 if ((subscriptionModelImpl.getColumnBitmask() &
2536 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C.getColumnBitmask()) != 0) {
2537 Object[] args = new Object[] {
2538 subscriptionModelImpl.getOriginalUserId(),
2539 subscriptionModelImpl.getOriginalClassNameId()
2540 };
2541
2542 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C, args);
2543 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C,
2544 args);
2545
2546 args = new Object[] {
2547 subscriptionModelImpl.getUserId(),
2548 subscriptionModelImpl.getClassNameId()
2549 };
2550
2551 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C, args);
2552 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C,
2553 args);
2554 }
2555
2556 if ((subscriptionModelImpl.getColumnBitmask() &
2557 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C.getColumnBitmask()) != 0) {
2558 Object[] args = new Object[] {
2559 subscriptionModelImpl.getOriginalCompanyId(),
2560 subscriptionModelImpl.getOriginalClassNameId(),
2561 subscriptionModelImpl.getOriginalClassPK()
2562 };
2563
2564 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_C, args);
2565 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C,
2566 args);
2567
2568 args = new Object[] {
2569 subscriptionModelImpl.getCompanyId(),
2570 subscriptionModelImpl.getClassNameId(),
2571 subscriptionModelImpl.getClassPK()
2572 };
2573
2574 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_C, args);
2575 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C,
2576 args);
2577 }
2578
2579 if ((subscriptionModelImpl.getColumnBitmask() &
2580 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_U_C_C.getColumnBitmask()) != 0) {
2581 Object[] args = new Object[] {
2582 subscriptionModelImpl.getOriginalCompanyId(),
2583 subscriptionModelImpl.getOriginalUserId(),
2584 subscriptionModelImpl.getOriginalClassNameId(),
2585 subscriptionModelImpl.getOriginalClassPK()
2586 };
2587
2588 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_U_C_C, args);
2589 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_U_C_C,
2590 args);
2591
2592 args = new Object[] {
2593 subscriptionModelImpl.getCompanyId(),
2594 subscriptionModelImpl.getUserId(),
2595 subscriptionModelImpl.getClassNameId(),
2596 subscriptionModelImpl.getClassPK()
2597 };
2598
2599 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_U_C_C, args);
2600 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_U_C_C,
2601 args);
2602 }
2603 }
2604
2605 EntityCacheUtil.putResult(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
2606 SubscriptionImpl.class, subscription.getPrimaryKey(), subscription,
2607 false);
2608
2609 clearUniqueFindersCache(subscription);
2610 cacheUniqueFindersCache(subscription);
2611
2612 subscription.resetOriginalValues();
2613
2614 return subscription;
2615 }
2616
2617 protected Subscription toUnwrappedModel(Subscription subscription) {
2618 if (subscription instanceof SubscriptionImpl) {
2619 return subscription;
2620 }
2621
2622 SubscriptionImpl subscriptionImpl = new SubscriptionImpl();
2623
2624 subscriptionImpl.setNew(subscription.isNew());
2625 subscriptionImpl.setPrimaryKey(subscription.getPrimaryKey());
2626
2627 subscriptionImpl.setMvccVersion(subscription.getMvccVersion());
2628 subscriptionImpl.setSubscriptionId(subscription.getSubscriptionId());
2629 subscriptionImpl.setCompanyId(subscription.getCompanyId());
2630 subscriptionImpl.setUserId(subscription.getUserId());
2631 subscriptionImpl.setUserName(subscription.getUserName());
2632 subscriptionImpl.setCreateDate(subscription.getCreateDate());
2633 subscriptionImpl.setModifiedDate(subscription.getModifiedDate());
2634 subscriptionImpl.setClassNameId(subscription.getClassNameId());
2635 subscriptionImpl.setClassPK(subscription.getClassPK());
2636 subscriptionImpl.setFrequency(subscription.getFrequency());
2637
2638 return subscriptionImpl;
2639 }
2640
2641
2648 @Override
2649 public Subscription findByPrimaryKey(Serializable primaryKey)
2650 throws NoSuchSubscriptionException {
2651 Subscription subscription = fetchByPrimaryKey(primaryKey);
2652
2653 if (subscription == null) {
2654 if (_log.isWarnEnabled()) {
2655 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2656 }
2657
2658 throw new NoSuchSubscriptionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2659 primaryKey);
2660 }
2661
2662 return subscription;
2663 }
2664
2665
2672 @Override
2673 public Subscription findByPrimaryKey(long subscriptionId)
2674 throws NoSuchSubscriptionException {
2675 return findByPrimaryKey((Serializable)subscriptionId);
2676 }
2677
2678
2684 @Override
2685 public Subscription fetchByPrimaryKey(Serializable primaryKey) {
2686 Subscription subscription = (Subscription)EntityCacheUtil.getResult(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
2687 SubscriptionImpl.class, primaryKey);
2688
2689 if (subscription == _nullSubscription) {
2690 return null;
2691 }
2692
2693 if (subscription == null) {
2694 Session session = null;
2695
2696 try {
2697 session = openSession();
2698
2699 subscription = (Subscription)session.get(SubscriptionImpl.class,
2700 primaryKey);
2701
2702 if (subscription != null) {
2703 cacheResult(subscription);
2704 }
2705 else {
2706 EntityCacheUtil.putResult(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
2707 SubscriptionImpl.class, primaryKey, _nullSubscription);
2708 }
2709 }
2710 catch (Exception e) {
2711 EntityCacheUtil.removeResult(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
2712 SubscriptionImpl.class, primaryKey);
2713
2714 throw processException(e);
2715 }
2716 finally {
2717 closeSession(session);
2718 }
2719 }
2720
2721 return subscription;
2722 }
2723
2724
2730 @Override
2731 public Subscription fetchByPrimaryKey(long subscriptionId) {
2732 return fetchByPrimaryKey((Serializable)subscriptionId);
2733 }
2734
2735 @Override
2736 public Map<Serializable, Subscription> fetchByPrimaryKeys(
2737 Set<Serializable> primaryKeys) {
2738 if (primaryKeys.isEmpty()) {
2739 return Collections.emptyMap();
2740 }
2741
2742 Map<Serializable, Subscription> map = new HashMap<Serializable, Subscription>();
2743
2744 if (primaryKeys.size() == 1) {
2745 Iterator<Serializable> iterator = primaryKeys.iterator();
2746
2747 Serializable primaryKey = iterator.next();
2748
2749 Subscription subscription = fetchByPrimaryKey(primaryKey);
2750
2751 if (subscription != null) {
2752 map.put(primaryKey, subscription);
2753 }
2754
2755 return map;
2756 }
2757
2758 Set<Serializable> uncachedPrimaryKeys = null;
2759
2760 for (Serializable primaryKey : primaryKeys) {
2761 Subscription subscription = (Subscription)EntityCacheUtil.getResult(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
2762 SubscriptionImpl.class, primaryKey);
2763
2764 if (subscription == null) {
2765 if (uncachedPrimaryKeys == null) {
2766 uncachedPrimaryKeys = new HashSet<Serializable>();
2767 }
2768
2769 uncachedPrimaryKeys.add(primaryKey);
2770 }
2771 else {
2772 map.put(primaryKey, subscription);
2773 }
2774 }
2775
2776 if (uncachedPrimaryKeys == null) {
2777 return map;
2778 }
2779
2780 StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
2781 1);
2782
2783 query.append(_SQL_SELECT_SUBSCRIPTION_WHERE_PKS_IN);
2784
2785 for (Serializable primaryKey : uncachedPrimaryKeys) {
2786 query.append(String.valueOf(primaryKey));
2787
2788 query.append(StringPool.COMMA);
2789 }
2790
2791 query.setIndex(query.index() - 1);
2792
2793 query.append(StringPool.CLOSE_PARENTHESIS);
2794
2795 String sql = query.toString();
2796
2797 Session session = null;
2798
2799 try {
2800 session = openSession();
2801
2802 Query q = session.createQuery(sql);
2803
2804 for (Subscription subscription : (List<Subscription>)q.list()) {
2805 map.put(subscription.getPrimaryKeyObj(), subscription);
2806
2807 cacheResult(subscription);
2808
2809 uncachedPrimaryKeys.remove(subscription.getPrimaryKeyObj());
2810 }
2811
2812 for (Serializable primaryKey : uncachedPrimaryKeys) {
2813 EntityCacheUtil.putResult(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
2814 SubscriptionImpl.class, primaryKey, _nullSubscription);
2815 }
2816 }
2817 catch (Exception e) {
2818 throw processException(e);
2819 }
2820 finally {
2821 closeSession(session);
2822 }
2823
2824 return map;
2825 }
2826
2827
2832 @Override
2833 public List<Subscription> findAll() {
2834 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2835 }
2836
2837
2848 @Override
2849 public List<Subscription> findAll(int start, int end) {
2850 return findAll(start, end, null);
2851 }
2852
2853
2865 @Override
2866 public List<Subscription> findAll(int start, int end,
2867 OrderByComparator<Subscription> orderByComparator) {
2868 boolean pagination = true;
2869 FinderPath finderPath = null;
2870 Object[] finderArgs = null;
2871
2872 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2873 (orderByComparator == null)) {
2874 pagination = false;
2875 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2876 finderArgs = FINDER_ARGS_EMPTY;
2877 }
2878 else {
2879 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2880 finderArgs = new Object[] { start, end, orderByComparator };
2881 }
2882
2883 List<Subscription> list = (List<Subscription>)FinderCacheUtil.getResult(finderPath,
2884 finderArgs, this);
2885
2886 if (list == null) {
2887 StringBundler query = null;
2888 String sql = null;
2889
2890 if (orderByComparator != null) {
2891 query = new StringBundler(2 +
2892 (orderByComparator.getOrderByFields().length * 3));
2893
2894 query.append(_SQL_SELECT_SUBSCRIPTION);
2895
2896 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2897 orderByComparator);
2898
2899 sql = query.toString();
2900 }
2901 else {
2902 sql = _SQL_SELECT_SUBSCRIPTION;
2903
2904 if (pagination) {
2905 sql = sql.concat(SubscriptionModelImpl.ORDER_BY_JPQL);
2906 }
2907 }
2908
2909 Session session = null;
2910
2911 try {
2912 session = openSession();
2913
2914 Query q = session.createQuery(sql);
2915
2916 if (!pagination) {
2917 list = (List<Subscription>)QueryUtil.list(q, getDialect(),
2918 start, end, false);
2919
2920 Collections.sort(list);
2921
2922 list = Collections.unmodifiableList(list);
2923 }
2924 else {
2925 list = (List<Subscription>)QueryUtil.list(q, getDialect(),
2926 start, end);
2927 }
2928
2929 cacheResult(list);
2930
2931 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2932 }
2933 catch (Exception e) {
2934 FinderCacheUtil.removeResult(finderPath, finderArgs);
2935
2936 throw processException(e);
2937 }
2938 finally {
2939 closeSession(session);
2940 }
2941 }
2942
2943 return list;
2944 }
2945
2946
2950 @Override
2951 public void removeAll() {
2952 for (Subscription subscription : findAll()) {
2953 remove(subscription);
2954 }
2955 }
2956
2957
2962 @Override
2963 public int countAll() {
2964 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2965 FINDER_ARGS_EMPTY, this);
2966
2967 if (count == null) {
2968 Session session = null;
2969
2970 try {
2971 session = openSession();
2972
2973 Query q = session.createQuery(_SQL_COUNT_SUBSCRIPTION);
2974
2975 count = (Long)q.uniqueResult();
2976
2977 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2978 FINDER_ARGS_EMPTY, count);
2979 }
2980 catch (Exception e) {
2981 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
2982 FINDER_ARGS_EMPTY);
2983
2984 throw processException(e);
2985 }
2986 finally {
2987 closeSession(session);
2988 }
2989 }
2990
2991 return count.intValue();
2992 }
2993
2994
2997 public void afterPropertiesSet() {
2998 }
2999
3000 public void destroy() {
3001 EntityCacheUtil.removeCache(SubscriptionImpl.class.getName());
3002 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
3003 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3004 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3005 }
3006
3007 private static final String _SQL_SELECT_SUBSCRIPTION = "SELECT subscription FROM Subscription subscription";
3008 private static final String _SQL_SELECT_SUBSCRIPTION_WHERE_PKS_IN = "SELECT subscription FROM Subscription subscription WHERE subscriptionId IN (";
3009 private static final String _SQL_SELECT_SUBSCRIPTION_WHERE = "SELECT subscription FROM Subscription subscription WHERE ";
3010 private static final String _SQL_COUNT_SUBSCRIPTION = "SELECT COUNT(subscription) FROM Subscription subscription";
3011 private static final String _SQL_COUNT_SUBSCRIPTION_WHERE = "SELECT COUNT(subscription) FROM Subscription subscription WHERE ";
3012 private static final String _ORDER_BY_ENTITY_ALIAS = "subscription.";
3013 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Subscription exists with the primary key ";
3014 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Subscription exists with the key {";
3015 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
3016 private static final Log _log = LogFactoryUtil.getLog(SubscriptionPersistenceImpl.class);
3017 private static final Subscription _nullSubscription = new SubscriptionImpl() {
3018 @Override
3019 public Object clone() {
3020 return this;
3021 }
3022
3023 @Override
3024 public CacheModel<Subscription> toCacheModel() {
3025 return _nullSubscriptionCacheModel;
3026 }
3027 };
3028
3029 private static final CacheModel<Subscription> _nullSubscriptionCacheModel = new NullCacheModel();
3030
3031 private static class NullCacheModel implements CacheModel<Subscription>,
3032 MVCCModel {
3033 @Override
3034 public long getMvccVersion() {
3035 return -1;
3036 }
3037
3038 @Override
3039 public void setMvccVersion(long mvccVersion) {
3040 }
3041
3042 @Override
3043 public Subscription toEntityModel() {
3044 return _nullSubscription;
3045 }
3046 }
3047 }