001
014
015 package com.liferay.portal.service.persistence.impl;
016
017 import aQute.bnd.annotation.ProviderType;
018
019 import com.liferay.portal.kernel.bean.BeanReference;
020 import com.liferay.portal.kernel.dao.orm.EntityCache;
021 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderCache;
023 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
024 import com.liferay.portal.kernel.dao.orm.FinderPath;
025 import com.liferay.portal.kernel.dao.orm.Query;
026 import com.liferay.portal.kernel.dao.orm.QueryPos;
027 import com.liferay.portal.kernel.dao.orm.QueryUtil;
028 import com.liferay.portal.kernel.dao.orm.Session;
029 import com.liferay.portal.kernel.exception.NoSuchRecentLayoutRevisionException;
030 import com.liferay.portal.kernel.log.Log;
031 import com.liferay.portal.kernel.log.LogFactoryUtil;
032 import com.liferay.portal.kernel.model.CacheModel;
033 import com.liferay.portal.kernel.model.MVCCModel;
034 import com.liferay.portal.kernel.model.RecentLayoutRevision;
035 import com.liferay.portal.kernel.service.persistence.CompanyProvider;
036 import com.liferay.portal.kernel.service.persistence.CompanyProviderWrapper;
037 import com.liferay.portal.kernel.service.persistence.RecentLayoutRevisionPersistence;
038 import com.liferay.portal.kernel.service.persistence.impl.BasePersistenceImpl;
039 import com.liferay.portal.kernel.util.OrderByComparator;
040 import com.liferay.portal.kernel.util.StringBundler;
041 import com.liferay.portal.kernel.util.StringPool;
042 import com.liferay.portal.model.impl.RecentLayoutRevisionImpl;
043 import com.liferay.portal.model.impl.RecentLayoutRevisionModelImpl;
044
045 import java.io.Serializable;
046
047 import java.util.Collections;
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 RecentLayoutRevisionPersistenceImpl extends BasePersistenceImpl<RecentLayoutRevision>
069 implements RecentLayoutRevisionPersistence {
070
075 public static final String FINDER_CLASS_NAME_ENTITY = RecentLayoutRevisionImpl.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(RecentLayoutRevisionModelImpl.ENTITY_CACHE_ENABLED,
081 RecentLayoutRevisionModelImpl.FINDER_CACHE_ENABLED,
082 RecentLayoutRevisionImpl.class,
083 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
084 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(RecentLayoutRevisionModelImpl.ENTITY_CACHE_ENABLED,
085 RecentLayoutRevisionModelImpl.FINDER_CACHE_ENABLED,
086 RecentLayoutRevisionImpl.class,
087 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
088 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(RecentLayoutRevisionModelImpl.ENTITY_CACHE_ENABLED,
089 RecentLayoutRevisionModelImpl.FINDER_CACHE_ENABLED, Long.class,
090 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
091 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(RecentLayoutRevisionModelImpl.ENTITY_CACHE_ENABLED,
092 RecentLayoutRevisionModelImpl.FINDER_CACHE_ENABLED,
093 RecentLayoutRevisionImpl.class,
094 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
095 new String[] {
096 Long.class.getName(),
097
098 Integer.class.getName(), Integer.class.getName(),
099 OrderByComparator.class.getName()
100 });
101 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
102 new FinderPath(RecentLayoutRevisionModelImpl.ENTITY_CACHE_ENABLED,
103 RecentLayoutRevisionModelImpl.FINDER_CACHE_ENABLED,
104 RecentLayoutRevisionImpl.class,
105 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
106 new String[] { Long.class.getName() },
107 RecentLayoutRevisionModelImpl.GROUPID_COLUMN_BITMASK);
108 public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(RecentLayoutRevisionModelImpl.ENTITY_CACHE_ENABLED,
109 RecentLayoutRevisionModelImpl.FINDER_CACHE_ENABLED, Long.class,
110 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
111 new String[] { Long.class.getName() });
112
113
119 @Override
120 public List<RecentLayoutRevision> findByGroupId(long groupId) {
121 return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
122 }
123
124
136 @Override
137 public List<RecentLayoutRevision> findByGroupId(long groupId, int start,
138 int end) {
139 return findByGroupId(groupId, start, end, null);
140 }
141
142
155 @Override
156 public List<RecentLayoutRevision> findByGroupId(long groupId, int start,
157 int end, OrderByComparator<RecentLayoutRevision> orderByComparator) {
158 return findByGroupId(groupId, start, end, orderByComparator, true);
159 }
160
161
175 @Override
176 public List<RecentLayoutRevision> findByGroupId(long groupId, int start,
177 int end, OrderByComparator<RecentLayoutRevision> orderByComparator,
178 boolean retrieveFromCache) {
179 boolean pagination = true;
180 FinderPath finderPath = null;
181 Object[] finderArgs = null;
182
183 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
184 (orderByComparator == null)) {
185 pagination = false;
186 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
187 finderArgs = new Object[] { groupId };
188 }
189 else {
190 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
191 finderArgs = new Object[] { groupId, start, end, orderByComparator };
192 }
193
194 List<RecentLayoutRevision> list = null;
195
196 if (retrieveFromCache) {
197 list = (List<RecentLayoutRevision>)finderCache.getResult(finderPath,
198 finderArgs, this);
199
200 if ((list != null) && !list.isEmpty()) {
201 for (RecentLayoutRevision recentLayoutRevision : list) {
202 if ((groupId != recentLayoutRevision.getGroupId())) {
203 list = null;
204
205 break;
206 }
207 }
208 }
209 }
210
211 if (list == null) {
212 StringBundler query = null;
213
214 if (orderByComparator != null) {
215 query = new StringBundler(3 +
216 (orderByComparator.getOrderByFields().length * 2));
217 }
218 else {
219 query = new StringBundler(3);
220 }
221
222 query.append(_SQL_SELECT_RECENTLAYOUTREVISION_WHERE);
223
224 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
225
226 if (orderByComparator != null) {
227 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
228 orderByComparator);
229 }
230 else
231 if (pagination) {
232 query.append(RecentLayoutRevisionModelImpl.ORDER_BY_JPQL);
233 }
234
235 String sql = query.toString();
236
237 Session session = null;
238
239 try {
240 session = openSession();
241
242 Query q = session.createQuery(sql);
243
244 QueryPos qPos = QueryPos.getInstance(q);
245
246 qPos.add(groupId);
247
248 if (!pagination) {
249 list = (List<RecentLayoutRevision>)QueryUtil.list(q,
250 getDialect(), start, end, false);
251
252 Collections.sort(list);
253
254 list = Collections.unmodifiableList(list);
255 }
256 else {
257 list = (List<RecentLayoutRevision>)QueryUtil.list(q,
258 getDialect(), start, end);
259 }
260
261 cacheResult(list);
262
263 finderCache.putResult(finderPath, finderArgs, list);
264 }
265 catch (Exception e) {
266 finderCache.removeResult(finderPath, finderArgs);
267
268 throw processException(e);
269 }
270 finally {
271 closeSession(session);
272 }
273 }
274
275 return list;
276 }
277
278
286 @Override
287 public RecentLayoutRevision findByGroupId_First(long groupId,
288 OrderByComparator<RecentLayoutRevision> orderByComparator)
289 throws NoSuchRecentLayoutRevisionException {
290 RecentLayoutRevision recentLayoutRevision = fetchByGroupId_First(groupId,
291 orderByComparator);
292
293 if (recentLayoutRevision != null) {
294 return recentLayoutRevision;
295 }
296
297 StringBundler msg = new StringBundler(4);
298
299 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
300
301 msg.append("groupId=");
302 msg.append(groupId);
303
304 msg.append(StringPool.CLOSE_CURLY_BRACE);
305
306 throw new NoSuchRecentLayoutRevisionException(msg.toString());
307 }
308
309
316 @Override
317 public RecentLayoutRevision fetchByGroupId_First(long groupId,
318 OrderByComparator<RecentLayoutRevision> orderByComparator) {
319 List<RecentLayoutRevision> list = findByGroupId(groupId, 0, 1,
320 orderByComparator);
321
322 if (!list.isEmpty()) {
323 return list.get(0);
324 }
325
326 return null;
327 }
328
329
337 @Override
338 public RecentLayoutRevision findByGroupId_Last(long groupId,
339 OrderByComparator<RecentLayoutRevision> orderByComparator)
340 throws NoSuchRecentLayoutRevisionException {
341 RecentLayoutRevision recentLayoutRevision = fetchByGroupId_Last(groupId,
342 orderByComparator);
343
344 if (recentLayoutRevision != null) {
345 return recentLayoutRevision;
346 }
347
348 StringBundler msg = new StringBundler(4);
349
350 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
351
352 msg.append("groupId=");
353 msg.append(groupId);
354
355 msg.append(StringPool.CLOSE_CURLY_BRACE);
356
357 throw new NoSuchRecentLayoutRevisionException(msg.toString());
358 }
359
360
367 @Override
368 public RecentLayoutRevision fetchByGroupId_Last(long groupId,
369 OrderByComparator<RecentLayoutRevision> orderByComparator) {
370 int count = countByGroupId(groupId);
371
372 if (count == 0) {
373 return null;
374 }
375
376 List<RecentLayoutRevision> list = findByGroupId(groupId, count - 1,
377 count, orderByComparator);
378
379 if (!list.isEmpty()) {
380 return list.get(0);
381 }
382
383 return null;
384 }
385
386
395 @Override
396 public RecentLayoutRevision[] findByGroupId_PrevAndNext(
397 long recentLayoutRevisionId, long groupId,
398 OrderByComparator<RecentLayoutRevision> orderByComparator)
399 throws NoSuchRecentLayoutRevisionException {
400 RecentLayoutRevision recentLayoutRevision = findByPrimaryKey(recentLayoutRevisionId);
401
402 Session session = null;
403
404 try {
405 session = openSession();
406
407 RecentLayoutRevision[] array = new RecentLayoutRevisionImpl[3];
408
409 array[0] = getByGroupId_PrevAndNext(session, recentLayoutRevision,
410 groupId, orderByComparator, true);
411
412 array[1] = recentLayoutRevision;
413
414 array[2] = getByGroupId_PrevAndNext(session, recentLayoutRevision,
415 groupId, orderByComparator, false);
416
417 return array;
418 }
419 catch (Exception e) {
420 throw processException(e);
421 }
422 finally {
423 closeSession(session);
424 }
425 }
426
427 protected RecentLayoutRevision getByGroupId_PrevAndNext(Session session,
428 RecentLayoutRevision recentLayoutRevision, long groupId,
429 OrderByComparator<RecentLayoutRevision> orderByComparator,
430 boolean previous) {
431 StringBundler query = null;
432
433 if (orderByComparator != null) {
434 query = new StringBundler(4 +
435 (orderByComparator.getOrderByConditionFields().length * 3) +
436 (orderByComparator.getOrderByFields().length * 3));
437 }
438 else {
439 query = new StringBundler(3);
440 }
441
442 query.append(_SQL_SELECT_RECENTLAYOUTREVISION_WHERE);
443
444 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
445
446 if (orderByComparator != null) {
447 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
448
449 if (orderByConditionFields.length > 0) {
450 query.append(WHERE_AND);
451 }
452
453 for (int i = 0; i < orderByConditionFields.length; i++) {
454 query.append(_ORDER_BY_ENTITY_ALIAS);
455 query.append(orderByConditionFields[i]);
456
457 if ((i + 1) < orderByConditionFields.length) {
458 if (orderByComparator.isAscending() ^ previous) {
459 query.append(WHERE_GREATER_THAN_HAS_NEXT);
460 }
461 else {
462 query.append(WHERE_LESSER_THAN_HAS_NEXT);
463 }
464 }
465 else {
466 if (orderByComparator.isAscending() ^ previous) {
467 query.append(WHERE_GREATER_THAN);
468 }
469 else {
470 query.append(WHERE_LESSER_THAN);
471 }
472 }
473 }
474
475 query.append(ORDER_BY_CLAUSE);
476
477 String[] orderByFields = orderByComparator.getOrderByFields();
478
479 for (int i = 0; i < orderByFields.length; i++) {
480 query.append(_ORDER_BY_ENTITY_ALIAS);
481 query.append(orderByFields[i]);
482
483 if ((i + 1) < orderByFields.length) {
484 if (orderByComparator.isAscending() ^ previous) {
485 query.append(ORDER_BY_ASC_HAS_NEXT);
486 }
487 else {
488 query.append(ORDER_BY_DESC_HAS_NEXT);
489 }
490 }
491 else {
492 if (orderByComparator.isAscending() ^ previous) {
493 query.append(ORDER_BY_ASC);
494 }
495 else {
496 query.append(ORDER_BY_DESC);
497 }
498 }
499 }
500 }
501 else {
502 query.append(RecentLayoutRevisionModelImpl.ORDER_BY_JPQL);
503 }
504
505 String sql = query.toString();
506
507 Query q = session.createQuery(sql);
508
509 q.setFirstResult(0);
510 q.setMaxResults(2);
511
512 QueryPos qPos = QueryPos.getInstance(q);
513
514 qPos.add(groupId);
515
516 if (orderByComparator != null) {
517 Object[] values = orderByComparator.getOrderByConditionValues(recentLayoutRevision);
518
519 for (Object value : values) {
520 qPos.add(value);
521 }
522 }
523
524 List<RecentLayoutRevision> list = q.list();
525
526 if (list.size() == 2) {
527 return list.get(1);
528 }
529 else {
530 return null;
531 }
532 }
533
534
539 @Override
540 public void removeByGroupId(long groupId) {
541 for (RecentLayoutRevision recentLayoutRevision : findByGroupId(
542 groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
543 remove(recentLayoutRevision);
544 }
545 }
546
547
553 @Override
554 public int countByGroupId(long groupId) {
555 FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
556
557 Object[] finderArgs = new Object[] { groupId };
558
559 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
560
561 if (count == null) {
562 StringBundler query = new StringBundler(2);
563
564 query.append(_SQL_COUNT_RECENTLAYOUTREVISION_WHERE);
565
566 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
567
568 String sql = query.toString();
569
570 Session session = null;
571
572 try {
573 session = openSession();
574
575 Query q = session.createQuery(sql);
576
577 QueryPos qPos = QueryPos.getInstance(q);
578
579 qPos.add(groupId);
580
581 count = (Long)q.uniqueResult();
582
583 finderCache.putResult(finderPath, finderArgs, count);
584 }
585 catch (Exception e) {
586 finderCache.removeResult(finderPath, finderArgs);
587
588 throw processException(e);
589 }
590 finally {
591 closeSession(session);
592 }
593 }
594
595 return count.intValue();
596 }
597
598 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "recentLayoutRevision.groupId = ?";
599 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(RecentLayoutRevisionModelImpl.ENTITY_CACHE_ENABLED,
600 RecentLayoutRevisionModelImpl.FINDER_CACHE_ENABLED,
601 RecentLayoutRevisionImpl.class,
602 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUserId",
603 new String[] {
604 Long.class.getName(),
605
606 Integer.class.getName(), Integer.class.getName(),
607 OrderByComparator.class.getName()
608 });
609 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID =
610 new FinderPath(RecentLayoutRevisionModelImpl.ENTITY_CACHE_ENABLED,
611 RecentLayoutRevisionModelImpl.FINDER_CACHE_ENABLED,
612 RecentLayoutRevisionImpl.class,
613 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId",
614 new String[] { Long.class.getName() },
615 RecentLayoutRevisionModelImpl.USERID_COLUMN_BITMASK);
616 public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(RecentLayoutRevisionModelImpl.ENTITY_CACHE_ENABLED,
617 RecentLayoutRevisionModelImpl.FINDER_CACHE_ENABLED, Long.class,
618 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
619 new String[] { Long.class.getName() });
620
621
627 @Override
628 public List<RecentLayoutRevision> findByUserId(long userId) {
629 return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
630 }
631
632
644 @Override
645 public List<RecentLayoutRevision> findByUserId(long userId, int start,
646 int end) {
647 return findByUserId(userId, start, end, null);
648 }
649
650
663 @Override
664 public List<RecentLayoutRevision> findByUserId(long userId, int start,
665 int end, OrderByComparator<RecentLayoutRevision> orderByComparator) {
666 return findByUserId(userId, start, end, orderByComparator, true);
667 }
668
669
683 @Override
684 public List<RecentLayoutRevision> findByUserId(long userId, int start,
685 int end, OrderByComparator<RecentLayoutRevision> orderByComparator,
686 boolean retrieveFromCache) {
687 boolean pagination = true;
688 FinderPath finderPath = null;
689 Object[] finderArgs = null;
690
691 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
692 (orderByComparator == null)) {
693 pagination = false;
694 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
695 finderArgs = new Object[] { userId };
696 }
697 else {
698 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
699 finderArgs = new Object[] { userId, start, end, orderByComparator };
700 }
701
702 List<RecentLayoutRevision> list = null;
703
704 if (retrieveFromCache) {
705 list = (List<RecentLayoutRevision>)finderCache.getResult(finderPath,
706 finderArgs, this);
707
708 if ((list != null) && !list.isEmpty()) {
709 for (RecentLayoutRevision recentLayoutRevision : list) {
710 if ((userId != recentLayoutRevision.getUserId())) {
711 list = null;
712
713 break;
714 }
715 }
716 }
717 }
718
719 if (list == null) {
720 StringBundler query = null;
721
722 if (orderByComparator != null) {
723 query = new StringBundler(3 +
724 (orderByComparator.getOrderByFields().length * 2));
725 }
726 else {
727 query = new StringBundler(3);
728 }
729
730 query.append(_SQL_SELECT_RECENTLAYOUTREVISION_WHERE);
731
732 query.append(_FINDER_COLUMN_USERID_USERID_2);
733
734 if (orderByComparator != null) {
735 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
736 orderByComparator);
737 }
738 else
739 if (pagination) {
740 query.append(RecentLayoutRevisionModelImpl.ORDER_BY_JPQL);
741 }
742
743 String sql = query.toString();
744
745 Session session = null;
746
747 try {
748 session = openSession();
749
750 Query q = session.createQuery(sql);
751
752 QueryPos qPos = QueryPos.getInstance(q);
753
754 qPos.add(userId);
755
756 if (!pagination) {
757 list = (List<RecentLayoutRevision>)QueryUtil.list(q,
758 getDialect(), start, end, false);
759
760 Collections.sort(list);
761
762 list = Collections.unmodifiableList(list);
763 }
764 else {
765 list = (List<RecentLayoutRevision>)QueryUtil.list(q,
766 getDialect(), start, end);
767 }
768
769 cacheResult(list);
770
771 finderCache.putResult(finderPath, finderArgs, list);
772 }
773 catch (Exception e) {
774 finderCache.removeResult(finderPath, finderArgs);
775
776 throw processException(e);
777 }
778 finally {
779 closeSession(session);
780 }
781 }
782
783 return list;
784 }
785
786
794 @Override
795 public RecentLayoutRevision findByUserId_First(long userId,
796 OrderByComparator<RecentLayoutRevision> orderByComparator)
797 throws NoSuchRecentLayoutRevisionException {
798 RecentLayoutRevision recentLayoutRevision = fetchByUserId_First(userId,
799 orderByComparator);
800
801 if (recentLayoutRevision != null) {
802 return recentLayoutRevision;
803 }
804
805 StringBundler msg = new StringBundler(4);
806
807 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
808
809 msg.append("userId=");
810 msg.append(userId);
811
812 msg.append(StringPool.CLOSE_CURLY_BRACE);
813
814 throw new NoSuchRecentLayoutRevisionException(msg.toString());
815 }
816
817
824 @Override
825 public RecentLayoutRevision fetchByUserId_First(long userId,
826 OrderByComparator<RecentLayoutRevision> orderByComparator) {
827 List<RecentLayoutRevision> list = findByUserId(userId, 0, 1,
828 orderByComparator);
829
830 if (!list.isEmpty()) {
831 return list.get(0);
832 }
833
834 return null;
835 }
836
837
845 @Override
846 public RecentLayoutRevision findByUserId_Last(long userId,
847 OrderByComparator<RecentLayoutRevision> orderByComparator)
848 throws NoSuchRecentLayoutRevisionException {
849 RecentLayoutRevision recentLayoutRevision = fetchByUserId_Last(userId,
850 orderByComparator);
851
852 if (recentLayoutRevision != null) {
853 return recentLayoutRevision;
854 }
855
856 StringBundler msg = new StringBundler(4);
857
858 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
859
860 msg.append("userId=");
861 msg.append(userId);
862
863 msg.append(StringPool.CLOSE_CURLY_BRACE);
864
865 throw new NoSuchRecentLayoutRevisionException(msg.toString());
866 }
867
868
875 @Override
876 public RecentLayoutRevision fetchByUserId_Last(long userId,
877 OrderByComparator<RecentLayoutRevision> orderByComparator) {
878 int count = countByUserId(userId);
879
880 if (count == 0) {
881 return null;
882 }
883
884 List<RecentLayoutRevision> list = findByUserId(userId, count - 1,
885 count, orderByComparator);
886
887 if (!list.isEmpty()) {
888 return list.get(0);
889 }
890
891 return null;
892 }
893
894
903 @Override
904 public RecentLayoutRevision[] findByUserId_PrevAndNext(
905 long recentLayoutRevisionId, long userId,
906 OrderByComparator<RecentLayoutRevision> orderByComparator)
907 throws NoSuchRecentLayoutRevisionException {
908 RecentLayoutRevision recentLayoutRevision = findByPrimaryKey(recentLayoutRevisionId);
909
910 Session session = null;
911
912 try {
913 session = openSession();
914
915 RecentLayoutRevision[] array = new RecentLayoutRevisionImpl[3];
916
917 array[0] = getByUserId_PrevAndNext(session, recentLayoutRevision,
918 userId, orderByComparator, true);
919
920 array[1] = recentLayoutRevision;
921
922 array[2] = getByUserId_PrevAndNext(session, recentLayoutRevision,
923 userId, orderByComparator, false);
924
925 return array;
926 }
927 catch (Exception e) {
928 throw processException(e);
929 }
930 finally {
931 closeSession(session);
932 }
933 }
934
935 protected RecentLayoutRevision getByUserId_PrevAndNext(Session session,
936 RecentLayoutRevision recentLayoutRevision, long userId,
937 OrderByComparator<RecentLayoutRevision> orderByComparator,
938 boolean previous) {
939 StringBundler query = null;
940
941 if (orderByComparator != null) {
942 query = new StringBundler(4 +
943 (orderByComparator.getOrderByConditionFields().length * 3) +
944 (orderByComparator.getOrderByFields().length * 3));
945 }
946 else {
947 query = new StringBundler(3);
948 }
949
950 query.append(_SQL_SELECT_RECENTLAYOUTREVISION_WHERE);
951
952 query.append(_FINDER_COLUMN_USERID_USERID_2);
953
954 if (orderByComparator != null) {
955 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
956
957 if (orderByConditionFields.length > 0) {
958 query.append(WHERE_AND);
959 }
960
961 for (int i = 0; i < orderByConditionFields.length; i++) {
962 query.append(_ORDER_BY_ENTITY_ALIAS);
963 query.append(orderByConditionFields[i]);
964
965 if ((i + 1) < orderByConditionFields.length) {
966 if (orderByComparator.isAscending() ^ previous) {
967 query.append(WHERE_GREATER_THAN_HAS_NEXT);
968 }
969 else {
970 query.append(WHERE_LESSER_THAN_HAS_NEXT);
971 }
972 }
973 else {
974 if (orderByComparator.isAscending() ^ previous) {
975 query.append(WHERE_GREATER_THAN);
976 }
977 else {
978 query.append(WHERE_LESSER_THAN);
979 }
980 }
981 }
982
983 query.append(ORDER_BY_CLAUSE);
984
985 String[] orderByFields = orderByComparator.getOrderByFields();
986
987 for (int i = 0; i < orderByFields.length; i++) {
988 query.append(_ORDER_BY_ENTITY_ALIAS);
989 query.append(orderByFields[i]);
990
991 if ((i + 1) < orderByFields.length) {
992 if (orderByComparator.isAscending() ^ previous) {
993 query.append(ORDER_BY_ASC_HAS_NEXT);
994 }
995 else {
996 query.append(ORDER_BY_DESC_HAS_NEXT);
997 }
998 }
999 else {
1000 if (orderByComparator.isAscending() ^ previous) {
1001 query.append(ORDER_BY_ASC);
1002 }
1003 else {
1004 query.append(ORDER_BY_DESC);
1005 }
1006 }
1007 }
1008 }
1009 else {
1010 query.append(RecentLayoutRevisionModelImpl.ORDER_BY_JPQL);
1011 }
1012
1013 String sql = query.toString();
1014
1015 Query q = session.createQuery(sql);
1016
1017 q.setFirstResult(0);
1018 q.setMaxResults(2);
1019
1020 QueryPos qPos = QueryPos.getInstance(q);
1021
1022 qPos.add(userId);
1023
1024 if (orderByComparator != null) {
1025 Object[] values = orderByComparator.getOrderByConditionValues(recentLayoutRevision);
1026
1027 for (Object value : values) {
1028 qPos.add(value);
1029 }
1030 }
1031
1032 List<RecentLayoutRevision> list = q.list();
1033
1034 if (list.size() == 2) {
1035 return list.get(1);
1036 }
1037 else {
1038 return null;
1039 }
1040 }
1041
1042
1047 @Override
1048 public void removeByUserId(long userId) {
1049 for (RecentLayoutRevision recentLayoutRevision : findByUserId(userId,
1050 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1051 remove(recentLayoutRevision);
1052 }
1053 }
1054
1055
1061 @Override
1062 public int countByUserId(long userId) {
1063 FinderPath finderPath = FINDER_PATH_COUNT_BY_USERID;
1064
1065 Object[] finderArgs = new Object[] { userId };
1066
1067 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1068
1069 if (count == null) {
1070 StringBundler query = new StringBundler(2);
1071
1072 query.append(_SQL_COUNT_RECENTLAYOUTREVISION_WHERE);
1073
1074 query.append(_FINDER_COLUMN_USERID_USERID_2);
1075
1076 String sql = query.toString();
1077
1078 Session session = null;
1079
1080 try {
1081 session = openSession();
1082
1083 Query q = session.createQuery(sql);
1084
1085 QueryPos qPos = QueryPos.getInstance(q);
1086
1087 qPos.add(userId);
1088
1089 count = (Long)q.uniqueResult();
1090
1091 finderCache.putResult(finderPath, finderArgs, count);
1092 }
1093 catch (Exception e) {
1094 finderCache.removeResult(finderPath, finderArgs);
1095
1096 throw processException(e);
1097 }
1098 finally {
1099 closeSession(session);
1100 }
1101 }
1102
1103 return count.intValue();
1104 }
1105
1106 private static final String _FINDER_COLUMN_USERID_USERID_2 = "recentLayoutRevision.userId = ?";
1107 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_LAYOUTREVISIONID =
1108 new FinderPath(RecentLayoutRevisionModelImpl.ENTITY_CACHE_ENABLED,
1109 RecentLayoutRevisionModelImpl.FINDER_CACHE_ENABLED,
1110 RecentLayoutRevisionImpl.class,
1111 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByLayoutRevisionId",
1112 new String[] {
1113 Long.class.getName(),
1114
1115 Integer.class.getName(), Integer.class.getName(),
1116 OrderByComparator.class.getName()
1117 });
1118 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LAYOUTREVISIONID =
1119 new FinderPath(RecentLayoutRevisionModelImpl.ENTITY_CACHE_ENABLED,
1120 RecentLayoutRevisionModelImpl.FINDER_CACHE_ENABLED,
1121 RecentLayoutRevisionImpl.class,
1122 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
1123 "findByLayoutRevisionId", new String[] { Long.class.getName() },
1124 RecentLayoutRevisionModelImpl.LAYOUTREVISIONID_COLUMN_BITMASK);
1125 public static final FinderPath FINDER_PATH_COUNT_BY_LAYOUTREVISIONID = new FinderPath(RecentLayoutRevisionModelImpl.ENTITY_CACHE_ENABLED,
1126 RecentLayoutRevisionModelImpl.FINDER_CACHE_ENABLED, Long.class,
1127 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
1128 "countByLayoutRevisionId", new String[] { Long.class.getName() });
1129
1130
1136 @Override
1137 public List<RecentLayoutRevision> findByLayoutRevisionId(
1138 long layoutRevisionId) {
1139 return findByLayoutRevisionId(layoutRevisionId, QueryUtil.ALL_POS,
1140 QueryUtil.ALL_POS, null);
1141 }
1142
1143
1155 @Override
1156 public List<RecentLayoutRevision> findByLayoutRevisionId(
1157 long layoutRevisionId, int start, int end) {
1158 return findByLayoutRevisionId(layoutRevisionId, start, end, null);
1159 }
1160
1161
1174 @Override
1175 public List<RecentLayoutRevision> findByLayoutRevisionId(
1176 long layoutRevisionId, int start, int end,
1177 OrderByComparator<RecentLayoutRevision> orderByComparator) {
1178 return findByLayoutRevisionId(layoutRevisionId, start, end,
1179 orderByComparator, true);
1180 }
1181
1182
1196 @Override
1197 public List<RecentLayoutRevision> findByLayoutRevisionId(
1198 long layoutRevisionId, int start, int end,
1199 OrderByComparator<RecentLayoutRevision> orderByComparator,
1200 boolean retrieveFromCache) {
1201 boolean pagination = true;
1202 FinderPath finderPath = null;
1203 Object[] finderArgs = null;
1204
1205 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1206 (orderByComparator == null)) {
1207 pagination = false;
1208 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LAYOUTREVISIONID;
1209 finderArgs = new Object[] { layoutRevisionId };
1210 }
1211 else {
1212 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_LAYOUTREVISIONID;
1213 finderArgs = new Object[] {
1214 layoutRevisionId,
1215
1216 start, end, orderByComparator
1217 };
1218 }
1219
1220 List<RecentLayoutRevision> list = null;
1221
1222 if (retrieveFromCache) {
1223 list = (List<RecentLayoutRevision>)finderCache.getResult(finderPath,
1224 finderArgs, this);
1225
1226 if ((list != null) && !list.isEmpty()) {
1227 for (RecentLayoutRevision recentLayoutRevision : list) {
1228 if ((layoutRevisionId != recentLayoutRevision.getLayoutRevisionId())) {
1229 list = null;
1230
1231 break;
1232 }
1233 }
1234 }
1235 }
1236
1237 if (list == null) {
1238 StringBundler query = null;
1239
1240 if (orderByComparator != null) {
1241 query = new StringBundler(3 +
1242 (orderByComparator.getOrderByFields().length * 2));
1243 }
1244 else {
1245 query = new StringBundler(3);
1246 }
1247
1248 query.append(_SQL_SELECT_RECENTLAYOUTREVISION_WHERE);
1249
1250 query.append(_FINDER_COLUMN_LAYOUTREVISIONID_LAYOUTREVISIONID_2);
1251
1252 if (orderByComparator != null) {
1253 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1254 orderByComparator);
1255 }
1256 else
1257 if (pagination) {
1258 query.append(RecentLayoutRevisionModelImpl.ORDER_BY_JPQL);
1259 }
1260
1261 String sql = query.toString();
1262
1263 Session session = null;
1264
1265 try {
1266 session = openSession();
1267
1268 Query q = session.createQuery(sql);
1269
1270 QueryPos qPos = QueryPos.getInstance(q);
1271
1272 qPos.add(layoutRevisionId);
1273
1274 if (!pagination) {
1275 list = (List<RecentLayoutRevision>)QueryUtil.list(q,
1276 getDialect(), start, end, false);
1277
1278 Collections.sort(list);
1279
1280 list = Collections.unmodifiableList(list);
1281 }
1282 else {
1283 list = (List<RecentLayoutRevision>)QueryUtil.list(q,
1284 getDialect(), start, end);
1285 }
1286
1287 cacheResult(list);
1288
1289 finderCache.putResult(finderPath, finderArgs, list);
1290 }
1291 catch (Exception e) {
1292 finderCache.removeResult(finderPath, finderArgs);
1293
1294 throw processException(e);
1295 }
1296 finally {
1297 closeSession(session);
1298 }
1299 }
1300
1301 return list;
1302 }
1303
1304
1312 @Override
1313 public RecentLayoutRevision findByLayoutRevisionId_First(
1314 long layoutRevisionId,
1315 OrderByComparator<RecentLayoutRevision> orderByComparator)
1316 throws NoSuchRecentLayoutRevisionException {
1317 RecentLayoutRevision recentLayoutRevision = fetchByLayoutRevisionId_First(layoutRevisionId,
1318 orderByComparator);
1319
1320 if (recentLayoutRevision != null) {
1321 return recentLayoutRevision;
1322 }
1323
1324 StringBundler msg = new StringBundler(4);
1325
1326 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1327
1328 msg.append("layoutRevisionId=");
1329 msg.append(layoutRevisionId);
1330
1331 msg.append(StringPool.CLOSE_CURLY_BRACE);
1332
1333 throw new NoSuchRecentLayoutRevisionException(msg.toString());
1334 }
1335
1336
1343 @Override
1344 public RecentLayoutRevision fetchByLayoutRevisionId_First(
1345 long layoutRevisionId,
1346 OrderByComparator<RecentLayoutRevision> orderByComparator) {
1347 List<RecentLayoutRevision> list = findByLayoutRevisionId(layoutRevisionId,
1348 0, 1, orderByComparator);
1349
1350 if (!list.isEmpty()) {
1351 return list.get(0);
1352 }
1353
1354 return null;
1355 }
1356
1357
1365 @Override
1366 public RecentLayoutRevision findByLayoutRevisionId_Last(
1367 long layoutRevisionId,
1368 OrderByComparator<RecentLayoutRevision> orderByComparator)
1369 throws NoSuchRecentLayoutRevisionException {
1370 RecentLayoutRevision recentLayoutRevision = fetchByLayoutRevisionId_Last(layoutRevisionId,
1371 orderByComparator);
1372
1373 if (recentLayoutRevision != null) {
1374 return recentLayoutRevision;
1375 }
1376
1377 StringBundler msg = new StringBundler(4);
1378
1379 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1380
1381 msg.append("layoutRevisionId=");
1382 msg.append(layoutRevisionId);
1383
1384 msg.append(StringPool.CLOSE_CURLY_BRACE);
1385
1386 throw new NoSuchRecentLayoutRevisionException(msg.toString());
1387 }
1388
1389
1396 @Override
1397 public RecentLayoutRevision fetchByLayoutRevisionId_Last(
1398 long layoutRevisionId,
1399 OrderByComparator<RecentLayoutRevision> orderByComparator) {
1400 int count = countByLayoutRevisionId(layoutRevisionId);
1401
1402 if (count == 0) {
1403 return null;
1404 }
1405
1406 List<RecentLayoutRevision> list = findByLayoutRevisionId(layoutRevisionId,
1407 count - 1, count, orderByComparator);
1408
1409 if (!list.isEmpty()) {
1410 return list.get(0);
1411 }
1412
1413 return null;
1414 }
1415
1416
1425 @Override
1426 public RecentLayoutRevision[] findByLayoutRevisionId_PrevAndNext(
1427 long recentLayoutRevisionId, long layoutRevisionId,
1428 OrderByComparator<RecentLayoutRevision> orderByComparator)
1429 throws NoSuchRecentLayoutRevisionException {
1430 RecentLayoutRevision recentLayoutRevision = findByPrimaryKey(recentLayoutRevisionId);
1431
1432 Session session = null;
1433
1434 try {
1435 session = openSession();
1436
1437 RecentLayoutRevision[] array = new RecentLayoutRevisionImpl[3];
1438
1439 array[0] = getByLayoutRevisionId_PrevAndNext(session,
1440 recentLayoutRevision, layoutRevisionId, orderByComparator,
1441 true);
1442
1443 array[1] = recentLayoutRevision;
1444
1445 array[2] = getByLayoutRevisionId_PrevAndNext(session,
1446 recentLayoutRevision, layoutRevisionId, orderByComparator,
1447 false);
1448
1449 return array;
1450 }
1451 catch (Exception e) {
1452 throw processException(e);
1453 }
1454 finally {
1455 closeSession(session);
1456 }
1457 }
1458
1459 protected RecentLayoutRevision getByLayoutRevisionId_PrevAndNext(
1460 Session session, RecentLayoutRevision recentLayoutRevision,
1461 long layoutRevisionId,
1462 OrderByComparator<RecentLayoutRevision> orderByComparator,
1463 boolean previous) {
1464 StringBundler query = null;
1465
1466 if (orderByComparator != null) {
1467 query = new StringBundler(4 +
1468 (orderByComparator.getOrderByConditionFields().length * 3) +
1469 (orderByComparator.getOrderByFields().length * 3));
1470 }
1471 else {
1472 query = new StringBundler(3);
1473 }
1474
1475 query.append(_SQL_SELECT_RECENTLAYOUTREVISION_WHERE);
1476
1477 query.append(_FINDER_COLUMN_LAYOUTREVISIONID_LAYOUTREVISIONID_2);
1478
1479 if (orderByComparator != null) {
1480 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1481
1482 if (orderByConditionFields.length > 0) {
1483 query.append(WHERE_AND);
1484 }
1485
1486 for (int i = 0; i < orderByConditionFields.length; i++) {
1487 query.append(_ORDER_BY_ENTITY_ALIAS);
1488 query.append(orderByConditionFields[i]);
1489
1490 if ((i + 1) < orderByConditionFields.length) {
1491 if (orderByComparator.isAscending() ^ previous) {
1492 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1493 }
1494 else {
1495 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1496 }
1497 }
1498 else {
1499 if (orderByComparator.isAscending() ^ previous) {
1500 query.append(WHERE_GREATER_THAN);
1501 }
1502 else {
1503 query.append(WHERE_LESSER_THAN);
1504 }
1505 }
1506 }
1507
1508 query.append(ORDER_BY_CLAUSE);
1509
1510 String[] orderByFields = orderByComparator.getOrderByFields();
1511
1512 for (int i = 0; i < orderByFields.length; i++) {
1513 query.append(_ORDER_BY_ENTITY_ALIAS);
1514 query.append(orderByFields[i]);
1515
1516 if ((i + 1) < orderByFields.length) {
1517 if (orderByComparator.isAscending() ^ previous) {
1518 query.append(ORDER_BY_ASC_HAS_NEXT);
1519 }
1520 else {
1521 query.append(ORDER_BY_DESC_HAS_NEXT);
1522 }
1523 }
1524 else {
1525 if (orderByComparator.isAscending() ^ previous) {
1526 query.append(ORDER_BY_ASC);
1527 }
1528 else {
1529 query.append(ORDER_BY_DESC);
1530 }
1531 }
1532 }
1533 }
1534 else {
1535 query.append(RecentLayoutRevisionModelImpl.ORDER_BY_JPQL);
1536 }
1537
1538 String sql = query.toString();
1539
1540 Query q = session.createQuery(sql);
1541
1542 q.setFirstResult(0);
1543 q.setMaxResults(2);
1544
1545 QueryPos qPos = QueryPos.getInstance(q);
1546
1547 qPos.add(layoutRevisionId);
1548
1549 if (orderByComparator != null) {
1550 Object[] values = orderByComparator.getOrderByConditionValues(recentLayoutRevision);
1551
1552 for (Object value : values) {
1553 qPos.add(value);
1554 }
1555 }
1556
1557 List<RecentLayoutRevision> list = q.list();
1558
1559 if (list.size() == 2) {
1560 return list.get(1);
1561 }
1562 else {
1563 return null;
1564 }
1565 }
1566
1567
1572 @Override
1573 public void removeByLayoutRevisionId(long layoutRevisionId) {
1574 for (RecentLayoutRevision recentLayoutRevision : findByLayoutRevisionId(
1575 layoutRevisionId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1576 remove(recentLayoutRevision);
1577 }
1578 }
1579
1580
1586 @Override
1587 public int countByLayoutRevisionId(long layoutRevisionId) {
1588 FinderPath finderPath = FINDER_PATH_COUNT_BY_LAYOUTREVISIONID;
1589
1590 Object[] finderArgs = new Object[] { layoutRevisionId };
1591
1592 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1593
1594 if (count == null) {
1595 StringBundler query = new StringBundler(2);
1596
1597 query.append(_SQL_COUNT_RECENTLAYOUTREVISION_WHERE);
1598
1599 query.append(_FINDER_COLUMN_LAYOUTREVISIONID_LAYOUTREVISIONID_2);
1600
1601 String sql = query.toString();
1602
1603 Session session = null;
1604
1605 try {
1606 session = openSession();
1607
1608 Query q = session.createQuery(sql);
1609
1610 QueryPos qPos = QueryPos.getInstance(q);
1611
1612 qPos.add(layoutRevisionId);
1613
1614 count = (Long)q.uniqueResult();
1615
1616 finderCache.putResult(finderPath, finderArgs, count);
1617 }
1618 catch (Exception e) {
1619 finderCache.removeResult(finderPath, finderArgs);
1620
1621 throw processException(e);
1622 }
1623 finally {
1624 closeSession(session);
1625 }
1626 }
1627
1628 return count.intValue();
1629 }
1630
1631 private static final String _FINDER_COLUMN_LAYOUTREVISIONID_LAYOUTREVISIONID_2 =
1632 "recentLayoutRevision.layoutRevisionId = ?";
1633 public static final FinderPath FINDER_PATH_FETCH_BY_U_L_P = new FinderPath(RecentLayoutRevisionModelImpl.ENTITY_CACHE_ENABLED,
1634 RecentLayoutRevisionModelImpl.FINDER_CACHE_ENABLED,
1635 RecentLayoutRevisionImpl.class, FINDER_CLASS_NAME_ENTITY,
1636 "fetchByU_L_P",
1637 new String[] {
1638 Long.class.getName(), Long.class.getName(), Long.class.getName()
1639 },
1640 RecentLayoutRevisionModelImpl.USERID_COLUMN_BITMASK |
1641 RecentLayoutRevisionModelImpl.LAYOUTSETBRANCHID_COLUMN_BITMASK |
1642 RecentLayoutRevisionModelImpl.PLID_COLUMN_BITMASK);
1643 public static final FinderPath FINDER_PATH_COUNT_BY_U_L_P = new FinderPath(RecentLayoutRevisionModelImpl.ENTITY_CACHE_ENABLED,
1644 RecentLayoutRevisionModelImpl.FINDER_CACHE_ENABLED, Long.class,
1645 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_L_P",
1646 new String[] {
1647 Long.class.getName(), Long.class.getName(), Long.class.getName()
1648 });
1649
1650
1659 @Override
1660 public RecentLayoutRevision findByU_L_P(long userId,
1661 long layoutSetBranchId, long plid)
1662 throws NoSuchRecentLayoutRevisionException {
1663 RecentLayoutRevision recentLayoutRevision = fetchByU_L_P(userId,
1664 layoutSetBranchId, plid);
1665
1666 if (recentLayoutRevision == null) {
1667 StringBundler msg = new StringBundler(8);
1668
1669 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1670
1671 msg.append("userId=");
1672 msg.append(userId);
1673
1674 msg.append(", layoutSetBranchId=");
1675 msg.append(layoutSetBranchId);
1676
1677 msg.append(", plid=");
1678 msg.append(plid);
1679
1680 msg.append(StringPool.CLOSE_CURLY_BRACE);
1681
1682 if (_log.isDebugEnabled()) {
1683 _log.debug(msg.toString());
1684 }
1685
1686 throw new NoSuchRecentLayoutRevisionException(msg.toString());
1687 }
1688
1689 return recentLayoutRevision;
1690 }
1691
1692
1700 @Override
1701 public RecentLayoutRevision fetchByU_L_P(long userId,
1702 long layoutSetBranchId, long plid) {
1703 return fetchByU_L_P(userId, layoutSetBranchId, plid, true);
1704 }
1705
1706
1715 @Override
1716 public RecentLayoutRevision fetchByU_L_P(long userId,
1717 long layoutSetBranchId, long plid, boolean retrieveFromCache) {
1718 Object[] finderArgs = new Object[] { userId, layoutSetBranchId, plid };
1719
1720 Object result = null;
1721
1722 if (retrieveFromCache) {
1723 result = finderCache.getResult(FINDER_PATH_FETCH_BY_U_L_P,
1724 finderArgs, this);
1725 }
1726
1727 if (result instanceof RecentLayoutRevision) {
1728 RecentLayoutRevision recentLayoutRevision = (RecentLayoutRevision)result;
1729
1730 if ((userId != recentLayoutRevision.getUserId()) ||
1731 (layoutSetBranchId != recentLayoutRevision.getLayoutSetBranchId()) ||
1732 (plid != recentLayoutRevision.getPlid())) {
1733 result = null;
1734 }
1735 }
1736
1737 if (result == null) {
1738 StringBundler query = new StringBundler(5);
1739
1740 query.append(_SQL_SELECT_RECENTLAYOUTREVISION_WHERE);
1741
1742 query.append(_FINDER_COLUMN_U_L_P_USERID_2);
1743
1744 query.append(_FINDER_COLUMN_U_L_P_LAYOUTSETBRANCHID_2);
1745
1746 query.append(_FINDER_COLUMN_U_L_P_PLID_2);
1747
1748 String sql = query.toString();
1749
1750 Session session = null;
1751
1752 try {
1753 session = openSession();
1754
1755 Query q = session.createQuery(sql);
1756
1757 QueryPos qPos = QueryPos.getInstance(q);
1758
1759 qPos.add(userId);
1760
1761 qPos.add(layoutSetBranchId);
1762
1763 qPos.add(plid);
1764
1765 List<RecentLayoutRevision> list = q.list();
1766
1767 if (list.isEmpty()) {
1768 finderCache.putResult(FINDER_PATH_FETCH_BY_U_L_P,
1769 finderArgs, list);
1770 }
1771 else {
1772 RecentLayoutRevision recentLayoutRevision = list.get(0);
1773
1774 result = recentLayoutRevision;
1775
1776 cacheResult(recentLayoutRevision);
1777
1778 if ((recentLayoutRevision.getUserId() != userId) ||
1779 (recentLayoutRevision.getLayoutSetBranchId() != layoutSetBranchId) ||
1780 (recentLayoutRevision.getPlid() != plid)) {
1781 finderCache.putResult(FINDER_PATH_FETCH_BY_U_L_P,
1782 finderArgs, recentLayoutRevision);
1783 }
1784 }
1785 }
1786 catch (Exception e) {
1787 finderCache.removeResult(FINDER_PATH_FETCH_BY_U_L_P, finderArgs);
1788
1789 throw processException(e);
1790 }
1791 finally {
1792 closeSession(session);
1793 }
1794 }
1795
1796 if (result instanceof List<?>) {
1797 return null;
1798 }
1799 else {
1800 return (RecentLayoutRevision)result;
1801 }
1802 }
1803
1804
1812 @Override
1813 public RecentLayoutRevision removeByU_L_P(long userId,
1814 long layoutSetBranchId, long plid)
1815 throws NoSuchRecentLayoutRevisionException {
1816 RecentLayoutRevision recentLayoutRevision = findByU_L_P(userId,
1817 layoutSetBranchId, plid);
1818
1819 return remove(recentLayoutRevision);
1820 }
1821
1822
1830 @Override
1831 public int countByU_L_P(long userId, long layoutSetBranchId, long plid) {
1832 FinderPath finderPath = FINDER_PATH_COUNT_BY_U_L_P;
1833
1834 Object[] finderArgs = new Object[] { userId, layoutSetBranchId, plid };
1835
1836 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1837
1838 if (count == null) {
1839 StringBundler query = new StringBundler(4);
1840
1841 query.append(_SQL_COUNT_RECENTLAYOUTREVISION_WHERE);
1842
1843 query.append(_FINDER_COLUMN_U_L_P_USERID_2);
1844
1845 query.append(_FINDER_COLUMN_U_L_P_LAYOUTSETBRANCHID_2);
1846
1847 query.append(_FINDER_COLUMN_U_L_P_PLID_2);
1848
1849 String sql = query.toString();
1850
1851 Session session = null;
1852
1853 try {
1854 session = openSession();
1855
1856 Query q = session.createQuery(sql);
1857
1858 QueryPos qPos = QueryPos.getInstance(q);
1859
1860 qPos.add(userId);
1861
1862 qPos.add(layoutSetBranchId);
1863
1864 qPos.add(plid);
1865
1866 count = (Long)q.uniqueResult();
1867
1868 finderCache.putResult(finderPath, finderArgs, count);
1869 }
1870 catch (Exception e) {
1871 finderCache.removeResult(finderPath, finderArgs);
1872
1873 throw processException(e);
1874 }
1875 finally {
1876 closeSession(session);
1877 }
1878 }
1879
1880 return count.intValue();
1881 }
1882
1883 private static final String _FINDER_COLUMN_U_L_P_USERID_2 = "recentLayoutRevision.userId = ? AND ";
1884 private static final String _FINDER_COLUMN_U_L_P_LAYOUTSETBRANCHID_2 = "recentLayoutRevision.layoutSetBranchId = ? AND ";
1885 private static final String _FINDER_COLUMN_U_L_P_PLID_2 = "recentLayoutRevision.plid = ?";
1886
1887 public RecentLayoutRevisionPersistenceImpl() {
1888 setModelClass(RecentLayoutRevision.class);
1889 }
1890
1891
1896 @Override
1897 public void cacheResult(RecentLayoutRevision recentLayoutRevision) {
1898 entityCache.putResult(RecentLayoutRevisionModelImpl.ENTITY_CACHE_ENABLED,
1899 RecentLayoutRevisionImpl.class,
1900 recentLayoutRevision.getPrimaryKey(), recentLayoutRevision);
1901
1902 finderCache.putResult(FINDER_PATH_FETCH_BY_U_L_P,
1903 new Object[] {
1904 recentLayoutRevision.getUserId(),
1905 recentLayoutRevision.getLayoutSetBranchId(),
1906 recentLayoutRevision.getPlid()
1907 }, recentLayoutRevision);
1908
1909 recentLayoutRevision.resetOriginalValues();
1910 }
1911
1912
1917 @Override
1918 public void cacheResult(List<RecentLayoutRevision> recentLayoutRevisions) {
1919 for (RecentLayoutRevision recentLayoutRevision : recentLayoutRevisions) {
1920 if (entityCache.getResult(
1921 RecentLayoutRevisionModelImpl.ENTITY_CACHE_ENABLED,
1922 RecentLayoutRevisionImpl.class,
1923 recentLayoutRevision.getPrimaryKey()) == null) {
1924 cacheResult(recentLayoutRevision);
1925 }
1926 else {
1927 recentLayoutRevision.resetOriginalValues();
1928 }
1929 }
1930 }
1931
1932
1939 @Override
1940 public void clearCache() {
1941 entityCache.clearCache(RecentLayoutRevisionImpl.class);
1942
1943 finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
1944 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1945 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1946 }
1947
1948
1955 @Override
1956 public void clearCache(RecentLayoutRevision recentLayoutRevision) {
1957 entityCache.removeResult(RecentLayoutRevisionModelImpl.ENTITY_CACHE_ENABLED,
1958 RecentLayoutRevisionImpl.class, recentLayoutRevision.getPrimaryKey());
1959
1960 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1961 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1962
1963 clearUniqueFindersCache((RecentLayoutRevisionModelImpl)recentLayoutRevision);
1964 }
1965
1966 @Override
1967 public void clearCache(List<RecentLayoutRevision> recentLayoutRevisions) {
1968 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1969 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1970
1971 for (RecentLayoutRevision recentLayoutRevision : recentLayoutRevisions) {
1972 entityCache.removeResult(RecentLayoutRevisionModelImpl.ENTITY_CACHE_ENABLED,
1973 RecentLayoutRevisionImpl.class,
1974 recentLayoutRevision.getPrimaryKey());
1975
1976 clearUniqueFindersCache((RecentLayoutRevisionModelImpl)recentLayoutRevision);
1977 }
1978 }
1979
1980 protected void cacheUniqueFindersCache(
1981 RecentLayoutRevisionModelImpl recentLayoutRevisionModelImpl,
1982 boolean isNew) {
1983 if (isNew) {
1984 Object[] args = new Object[] {
1985 recentLayoutRevisionModelImpl.getUserId(),
1986 recentLayoutRevisionModelImpl.getLayoutSetBranchId(),
1987 recentLayoutRevisionModelImpl.getPlid()
1988 };
1989
1990 finderCache.putResult(FINDER_PATH_COUNT_BY_U_L_P, args,
1991 Long.valueOf(1));
1992 finderCache.putResult(FINDER_PATH_FETCH_BY_U_L_P, args,
1993 recentLayoutRevisionModelImpl);
1994 }
1995 else {
1996 if ((recentLayoutRevisionModelImpl.getColumnBitmask() &
1997 FINDER_PATH_FETCH_BY_U_L_P.getColumnBitmask()) != 0) {
1998 Object[] args = new Object[] {
1999 recentLayoutRevisionModelImpl.getUserId(),
2000 recentLayoutRevisionModelImpl.getLayoutSetBranchId(),
2001 recentLayoutRevisionModelImpl.getPlid()
2002 };
2003
2004 finderCache.putResult(FINDER_PATH_COUNT_BY_U_L_P, args,
2005 Long.valueOf(1));
2006 finderCache.putResult(FINDER_PATH_FETCH_BY_U_L_P, args,
2007 recentLayoutRevisionModelImpl);
2008 }
2009 }
2010 }
2011
2012 protected void clearUniqueFindersCache(
2013 RecentLayoutRevisionModelImpl recentLayoutRevisionModelImpl) {
2014 Object[] args = new Object[] {
2015 recentLayoutRevisionModelImpl.getUserId(),
2016 recentLayoutRevisionModelImpl.getLayoutSetBranchId(),
2017 recentLayoutRevisionModelImpl.getPlid()
2018 };
2019
2020 finderCache.removeResult(FINDER_PATH_COUNT_BY_U_L_P, args);
2021 finderCache.removeResult(FINDER_PATH_FETCH_BY_U_L_P, args);
2022
2023 if ((recentLayoutRevisionModelImpl.getColumnBitmask() &
2024 FINDER_PATH_FETCH_BY_U_L_P.getColumnBitmask()) != 0) {
2025 args = new Object[] {
2026 recentLayoutRevisionModelImpl.getOriginalUserId(),
2027 recentLayoutRevisionModelImpl.getOriginalLayoutSetBranchId(),
2028 recentLayoutRevisionModelImpl.getOriginalPlid()
2029 };
2030
2031 finderCache.removeResult(FINDER_PATH_COUNT_BY_U_L_P, args);
2032 finderCache.removeResult(FINDER_PATH_FETCH_BY_U_L_P, args);
2033 }
2034 }
2035
2036
2042 @Override
2043 public RecentLayoutRevision create(long recentLayoutRevisionId) {
2044 RecentLayoutRevision recentLayoutRevision = new RecentLayoutRevisionImpl();
2045
2046 recentLayoutRevision.setNew(true);
2047 recentLayoutRevision.setPrimaryKey(recentLayoutRevisionId);
2048
2049 recentLayoutRevision.setCompanyId(companyProvider.getCompanyId());
2050
2051 return recentLayoutRevision;
2052 }
2053
2054
2061 @Override
2062 public RecentLayoutRevision remove(long recentLayoutRevisionId)
2063 throws NoSuchRecentLayoutRevisionException {
2064 return remove((Serializable)recentLayoutRevisionId);
2065 }
2066
2067
2074 @Override
2075 public RecentLayoutRevision remove(Serializable primaryKey)
2076 throws NoSuchRecentLayoutRevisionException {
2077 Session session = null;
2078
2079 try {
2080 session = openSession();
2081
2082 RecentLayoutRevision recentLayoutRevision = (RecentLayoutRevision)session.get(RecentLayoutRevisionImpl.class,
2083 primaryKey);
2084
2085 if (recentLayoutRevision == null) {
2086 if (_log.isDebugEnabled()) {
2087 _log.debug(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2088 }
2089
2090 throw new NoSuchRecentLayoutRevisionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2091 primaryKey);
2092 }
2093
2094 return remove(recentLayoutRevision);
2095 }
2096 catch (NoSuchRecentLayoutRevisionException nsee) {
2097 throw nsee;
2098 }
2099 catch (Exception e) {
2100 throw processException(e);
2101 }
2102 finally {
2103 closeSession(session);
2104 }
2105 }
2106
2107 @Override
2108 protected RecentLayoutRevision removeImpl(
2109 RecentLayoutRevision recentLayoutRevision) {
2110 recentLayoutRevision = toUnwrappedModel(recentLayoutRevision);
2111
2112 Session session = null;
2113
2114 try {
2115 session = openSession();
2116
2117 if (!session.contains(recentLayoutRevision)) {
2118 recentLayoutRevision = (RecentLayoutRevision)session.get(RecentLayoutRevisionImpl.class,
2119 recentLayoutRevision.getPrimaryKeyObj());
2120 }
2121
2122 if (recentLayoutRevision != null) {
2123 session.delete(recentLayoutRevision);
2124 }
2125 }
2126 catch (Exception e) {
2127 throw processException(e);
2128 }
2129 finally {
2130 closeSession(session);
2131 }
2132
2133 if (recentLayoutRevision != null) {
2134 clearCache(recentLayoutRevision);
2135 }
2136
2137 return recentLayoutRevision;
2138 }
2139
2140 @Override
2141 public RecentLayoutRevision updateImpl(
2142 RecentLayoutRevision recentLayoutRevision) {
2143 recentLayoutRevision = toUnwrappedModel(recentLayoutRevision);
2144
2145 boolean isNew = recentLayoutRevision.isNew();
2146
2147 RecentLayoutRevisionModelImpl recentLayoutRevisionModelImpl = (RecentLayoutRevisionModelImpl)recentLayoutRevision;
2148
2149 Session session = null;
2150
2151 try {
2152 session = openSession();
2153
2154 if (recentLayoutRevision.isNew()) {
2155 session.save(recentLayoutRevision);
2156
2157 recentLayoutRevision.setNew(false);
2158 }
2159 else {
2160 recentLayoutRevision = (RecentLayoutRevision)session.merge(recentLayoutRevision);
2161 }
2162 }
2163 catch (Exception e) {
2164 throw processException(e);
2165 }
2166 finally {
2167 closeSession(session);
2168 }
2169
2170 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2171
2172 if (isNew || !RecentLayoutRevisionModelImpl.COLUMN_BITMASK_ENABLED) {
2173 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2174 }
2175
2176 else {
2177 if ((recentLayoutRevisionModelImpl.getColumnBitmask() &
2178 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
2179 Object[] args = new Object[] {
2180 recentLayoutRevisionModelImpl.getOriginalGroupId()
2181 };
2182
2183 finderCache.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
2184 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
2185 args);
2186
2187 args = new Object[] { recentLayoutRevisionModelImpl.getGroupId() };
2188
2189 finderCache.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
2190 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
2191 args);
2192 }
2193
2194 if ((recentLayoutRevisionModelImpl.getColumnBitmask() &
2195 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
2196 Object[] args = new Object[] {
2197 recentLayoutRevisionModelImpl.getOriginalUserId()
2198 };
2199
2200 finderCache.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
2201 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
2202 args);
2203
2204 args = new Object[] { recentLayoutRevisionModelImpl.getUserId() };
2205
2206 finderCache.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
2207 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
2208 args);
2209 }
2210
2211 if ((recentLayoutRevisionModelImpl.getColumnBitmask() &
2212 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LAYOUTREVISIONID.getColumnBitmask()) != 0) {
2213 Object[] args = new Object[] {
2214 recentLayoutRevisionModelImpl.getOriginalLayoutRevisionId()
2215 };
2216
2217 finderCache.removeResult(FINDER_PATH_COUNT_BY_LAYOUTREVISIONID,
2218 args);
2219 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LAYOUTREVISIONID,
2220 args);
2221
2222 args = new Object[] {
2223 recentLayoutRevisionModelImpl.getLayoutRevisionId()
2224 };
2225
2226 finderCache.removeResult(FINDER_PATH_COUNT_BY_LAYOUTREVISIONID,
2227 args);
2228 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LAYOUTREVISIONID,
2229 args);
2230 }
2231 }
2232
2233 entityCache.putResult(RecentLayoutRevisionModelImpl.ENTITY_CACHE_ENABLED,
2234 RecentLayoutRevisionImpl.class,
2235 recentLayoutRevision.getPrimaryKey(), recentLayoutRevision, false);
2236
2237 clearUniqueFindersCache(recentLayoutRevisionModelImpl);
2238 cacheUniqueFindersCache(recentLayoutRevisionModelImpl, isNew);
2239
2240 recentLayoutRevision.resetOriginalValues();
2241
2242 return recentLayoutRevision;
2243 }
2244
2245 protected RecentLayoutRevision toUnwrappedModel(
2246 RecentLayoutRevision recentLayoutRevision) {
2247 if (recentLayoutRevision instanceof RecentLayoutRevisionImpl) {
2248 return recentLayoutRevision;
2249 }
2250
2251 RecentLayoutRevisionImpl recentLayoutRevisionImpl = new RecentLayoutRevisionImpl();
2252
2253 recentLayoutRevisionImpl.setNew(recentLayoutRevision.isNew());
2254 recentLayoutRevisionImpl.setPrimaryKey(recentLayoutRevision.getPrimaryKey());
2255
2256 recentLayoutRevisionImpl.setMvccVersion(recentLayoutRevision.getMvccVersion());
2257 recentLayoutRevisionImpl.setRecentLayoutRevisionId(recentLayoutRevision.getRecentLayoutRevisionId());
2258 recentLayoutRevisionImpl.setGroupId(recentLayoutRevision.getGroupId());
2259 recentLayoutRevisionImpl.setCompanyId(recentLayoutRevision.getCompanyId());
2260 recentLayoutRevisionImpl.setUserId(recentLayoutRevision.getUserId());
2261 recentLayoutRevisionImpl.setLayoutRevisionId(recentLayoutRevision.getLayoutRevisionId());
2262 recentLayoutRevisionImpl.setLayoutSetBranchId(recentLayoutRevision.getLayoutSetBranchId());
2263 recentLayoutRevisionImpl.setPlid(recentLayoutRevision.getPlid());
2264
2265 return recentLayoutRevisionImpl;
2266 }
2267
2268
2275 @Override
2276 public RecentLayoutRevision findByPrimaryKey(Serializable primaryKey)
2277 throws NoSuchRecentLayoutRevisionException {
2278 RecentLayoutRevision recentLayoutRevision = fetchByPrimaryKey(primaryKey);
2279
2280 if (recentLayoutRevision == null) {
2281 if (_log.isDebugEnabled()) {
2282 _log.debug(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2283 }
2284
2285 throw new NoSuchRecentLayoutRevisionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2286 primaryKey);
2287 }
2288
2289 return recentLayoutRevision;
2290 }
2291
2292
2299 @Override
2300 public RecentLayoutRevision findByPrimaryKey(long recentLayoutRevisionId)
2301 throws NoSuchRecentLayoutRevisionException {
2302 return findByPrimaryKey((Serializable)recentLayoutRevisionId);
2303 }
2304
2305
2311 @Override
2312 public RecentLayoutRevision fetchByPrimaryKey(Serializable primaryKey) {
2313 RecentLayoutRevision recentLayoutRevision = (RecentLayoutRevision)entityCache.getResult(RecentLayoutRevisionModelImpl.ENTITY_CACHE_ENABLED,
2314 RecentLayoutRevisionImpl.class, primaryKey);
2315
2316 if (recentLayoutRevision == _nullRecentLayoutRevision) {
2317 return null;
2318 }
2319
2320 if (recentLayoutRevision == null) {
2321 Session session = null;
2322
2323 try {
2324 session = openSession();
2325
2326 recentLayoutRevision = (RecentLayoutRevision)session.get(RecentLayoutRevisionImpl.class,
2327 primaryKey);
2328
2329 if (recentLayoutRevision != null) {
2330 cacheResult(recentLayoutRevision);
2331 }
2332 else {
2333 entityCache.putResult(RecentLayoutRevisionModelImpl.ENTITY_CACHE_ENABLED,
2334 RecentLayoutRevisionImpl.class, primaryKey,
2335 _nullRecentLayoutRevision);
2336 }
2337 }
2338 catch (Exception e) {
2339 entityCache.removeResult(RecentLayoutRevisionModelImpl.ENTITY_CACHE_ENABLED,
2340 RecentLayoutRevisionImpl.class, primaryKey);
2341
2342 throw processException(e);
2343 }
2344 finally {
2345 closeSession(session);
2346 }
2347 }
2348
2349 return recentLayoutRevision;
2350 }
2351
2352
2358 @Override
2359 public RecentLayoutRevision fetchByPrimaryKey(long recentLayoutRevisionId) {
2360 return fetchByPrimaryKey((Serializable)recentLayoutRevisionId);
2361 }
2362
2363 @Override
2364 public Map<Serializable, RecentLayoutRevision> fetchByPrimaryKeys(
2365 Set<Serializable> primaryKeys) {
2366 if (primaryKeys.isEmpty()) {
2367 return Collections.emptyMap();
2368 }
2369
2370 Map<Serializable, RecentLayoutRevision> map = new HashMap<Serializable, RecentLayoutRevision>();
2371
2372 if (primaryKeys.size() == 1) {
2373 Iterator<Serializable> iterator = primaryKeys.iterator();
2374
2375 Serializable primaryKey = iterator.next();
2376
2377 RecentLayoutRevision recentLayoutRevision = fetchByPrimaryKey(primaryKey);
2378
2379 if (recentLayoutRevision != null) {
2380 map.put(primaryKey, recentLayoutRevision);
2381 }
2382
2383 return map;
2384 }
2385
2386 Set<Serializable> uncachedPrimaryKeys = null;
2387
2388 for (Serializable primaryKey : primaryKeys) {
2389 RecentLayoutRevision recentLayoutRevision = (RecentLayoutRevision)entityCache.getResult(RecentLayoutRevisionModelImpl.ENTITY_CACHE_ENABLED,
2390 RecentLayoutRevisionImpl.class, primaryKey);
2391
2392 if (recentLayoutRevision == null) {
2393 if (uncachedPrimaryKeys == null) {
2394 uncachedPrimaryKeys = new HashSet<Serializable>();
2395 }
2396
2397 uncachedPrimaryKeys.add(primaryKey);
2398 }
2399 else {
2400 map.put(primaryKey, recentLayoutRevision);
2401 }
2402 }
2403
2404 if (uncachedPrimaryKeys == null) {
2405 return map;
2406 }
2407
2408 StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
2409 1);
2410
2411 query.append(_SQL_SELECT_RECENTLAYOUTREVISION_WHERE_PKS_IN);
2412
2413 for (Serializable primaryKey : uncachedPrimaryKeys) {
2414 query.append(String.valueOf(primaryKey));
2415
2416 query.append(StringPool.COMMA);
2417 }
2418
2419 query.setIndex(query.index() - 1);
2420
2421 query.append(StringPool.CLOSE_PARENTHESIS);
2422
2423 String sql = query.toString();
2424
2425 Session session = null;
2426
2427 try {
2428 session = openSession();
2429
2430 Query q = session.createQuery(sql);
2431
2432 for (RecentLayoutRevision recentLayoutRevision : (List<RecentLayoutRevision>)q.list()) {
2433 map.put(recentLayoutRevision.getPrimaryKeyObj(),
2434 recentLayoutRevision);
2435
2436 cacheResult(recentLayoutRevision);
2437
2438 uncachedPrimaryKeys.remove(recentLayoutRevision.getPrimaryKeyObj());
2439 }
2440
2441 for (Serializable primaryKey : uncachedPrimaryKeys) {
2442 entityCache.putResult(RecentLayoutRevisionModelImpl.ENTITY_CACHE_ENABLED,
2443 RecentLayoutRevisionImpl.class, primaryKey,
2444 _nullRecentLayoutRevision);
2445 }
2446 }
2447 catch (Exception e) {
2448 throw processException(e);
2449 }
2450 finally {
2451 closeSession(session);
2452 }
2453
2454 return map;
2455 }
2456
2457
2462 @Override
2463 public List<RecentLayoutRevision> findAll() {
2464 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2465 }
2466
2467
2478 @Override
2479 public List<RecentLayoutRevision> findAll(int start, int end) {
2480 return findAll(start, end, null);
2481 }
2482
2483
2495 @Override
2496 public List<RecentLayoutRevision> findAll(int start, int end,
2497 OrderByComparator<RecentLayoutRevision> orderByComparator) {
2498 return findAll(start, end, orderByComparator, true);
2499 }
2500
2501
2514 @Override
2515 public List<RecentLayoutRevision> findAll(int start, int end,
2516 OrderByComparator<RecentLayoutRevision> orderByComparator,
2517 boolean retrieveFromCache) {
2518 boolean pagination = true;
2519 FinderPath finderPath = null;
2520 Object[] finderArgs = null;
2521
2522 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2523 (orderByComparator == null)) {
2524 pagination = false;
2525 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2526 finderArgs = FINDER_ARGS_EMPTY;
2527 }
2528 else {
2529 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2530 finderArgs = new Object[] { start, end, orderByComparator };
2531 }
2532
2533 List<RecentLayoutRevision> list = null;
2534
2535 if (retrieveFromCache) {
2536 list = (List<RecentLayoutRevision>)finderCache.getResult(finderPath,
2537 finderArgs, this);
2538 }
2539
2540 if (list == null) {
2541 StringBundler query = null;
2542 String sql = null;
2543
2544 if (orderByComparator != null) {
2545 query = new StringBundler(2 +
2546 (orderByComparator.getOrderByFields().length * 2));
2547
2548 query.append(_SQL_SELECT_RECENTLAYOUTREVISION);
2549
2550 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2551 orderByComparator);
2552
2553 sql = query.toString();
2554 }
2555 else {
2556 sql = _SQL_SELECT_RECENTLAYOUTREVISION;
2557
2558 if (pagination) {
2559 sql = sql.concat(RecentLayoutRevisionModelImpl.ORDER_BY_JPQL);
2560 }
2561 }
2562
2563 Session session = null;
2564
2565 try {
2566 session = openSession();
2567
2568 Query q = session.createQuery(sql);
2569
2570 if (!pagination) {
2571 list = (List<RecentLayoutRevision>)QueryUtil.list(q,
2572 getDialect(), start, end, false);
2573
2574 Collections.sort(list);
2575
2576 list = Collections.unmodifiableList(list);
2577 }
2578 else {
2579 list = (List<RecentLayoutRevision>)QueryUtil.list(q,
2580 getDialect(), start, end);
2581 }
2582
2583 cacheResult(list);
2584
2585 finderCache.putResult(finderPath, finderArgs, list);
2586 }
2587 catch (Exception e) {
2588 finderCache.removeResult(finderPath, finderArgs);
2589
2590 throw processException(e);
2591 }
2592 finally {
2593 closeSession(session);
2594 }
2595 }
2596
2597 return list;
2598 }
2599
2600
2604 @Override
2605 public void removeAll() {
2606 for (RecentLayoutRevision recentLayoutRevision : findAll()) {
2607 remove(recentLayoutRevision);
2608 }
2609 }
2610
2611
2616 @Override
2617 public int countAll() {
2618 Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
2619 FINDER_ARGS_EMPTY, this);
2620
2621 if (count == null) {
2622 Session session = null;
2623
2624 try {
2625 session = openSession();
2626
2627 Query q = session.createQuery(_SQL_COUNT_RECENTLAYOUTREVISION);
2628
2629 count = (Long)q.uniqueResult();
2630
2631 finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
2632 count);
2633 }
2634 catch (Exception e) {
2635 finderCache.removeResult(FINDER_PATH_COUNT_ALL,
2636 FINDER_ARGS_EMPTY);
2637
2638 throw processException(e);
2639 }
2640 finally {
2641 closeSession(session);
2642 }
2643 }
2644
2645 return count.intValue();
2646 }
2647
2648 @Override
2649 protected Map<String, Integer> getTableColumnsMap() {
2650 return RecentLayoutRevisionModelImpl.TABLE_COLUMNS_MAP;
2651 }
2652
2653
2656 public void afterPropertiesSet() {
2657 }
2658
2659 public void destroy() {
2660 entityCache.removeCache(RecentLayoutRevisionImpl.class.getName());
2661 finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
2662 finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2663 finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2664 }
2665
2666 @BeanReference(type = CompanyProviderWrapper.class)
2667 protected CompanyProvider companyProvider;
2668 protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
2669 protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
2670 private static final String _SQL_SELECT_RECENTLAYOUTREVISION = "SELECT recentLayoutRevision FROM RecentLayoutRevision recentLayoutRevision";
2671 private static final String _SQL_SELECT_RECENTLAYOUTREVISION_WHERE_PKS_IN = "SELECT recentLayoutRevision FROM RecentLayoutRevision recentLayoutRevision WHERE recentLayoutRevisionId IN (";
2672 private static final String _SQL_SELECT_RECENTLAYOUTREVISION_WHERE = "SELECT recentLayoutRevision FROM RecentLayoutRevision recentLayoutRevision WHERE ";
2673 private static final String _SQL_COUNT_RECENTLAYOUTREVISION = "SELECT COUNT(recentLayoutRevision) FROM RecentLayoutRevision recentLayoutRevision";
2674 private static final String _SQL_COUNT_RECENTLAYOUTREVISION_WHERE = "SELECT COUNT(recentLayoutRevision) FROM RecentLayoutRevision recentLayoutRevision WHERE ";
2675 private static final String _ORDER_BY_ENTITY_ALIAS = "recentLayoutRevision.";
2676 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No RecentLayoutRevision exists with the primary key ";
2677 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No RecentLayoutRevision exists with the key {";
2678 private static final Log _log = LogFactoryUtil.getLog(RecentLayoutRevisionPersistenceImpl.class);
2679 private static final RecentLayoutRevision _nullRecentLayoutRevision = new RecentLayoutRevisionImpl() {
2680 @Override
2681 public Object clone() {
2682 return this;
2683 }
2684
2685 @Override
2686 public CacheModel<RecentLayoutRevision> toCacheModel() {
2687 return _nullRecentLayoutRevisionCacheModel;
2688 }
2689 };
2690
2691 private static final CacheModel<RecentLayoutRevision> _nullRecentLayoutRevisionCacheModel =
2692 new NullCacheModel();
2693
2694 private static class NullCacheModel implements CacheModel<RecentLayoutRevision>,
2695 MVCCModel {
2696 @Override
2697 public long getMvccVersion() {
2698 return -1;
2699 }
2700
2701 @Override
2702 public void setMvccVersion(long mvccVersion) {
2703 }
2704
2705 @Override
2706 public RecentLayoutRevision toEntityModel() {
2707 return _nullRecentLayoutRevision;
2708 }
2709 }
2710 }