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