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.NoSuchRecentLayoutBranchException;
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.RecentLayoutBranch;
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.RecentLayoutBranchPersistence;
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.RecentLayoutBranchImpl;
043 import com.liferay.portal.model.impl.RecentLayoutBranchModelImpl;
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 RecentLayoutBranchPersistenceImpl extends BasePersistenceImpl<RecentLayoutBranch>
069 implements RecentLayoutBranchPersistence {
070
075 public static final String FINDER_CLASS_NAME_ENTITY = RecentLayoutBranchImpl.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(RecentLayoutBranchModelImpl.ENTITY_CACHE_ENABLED,
081 RecentLayoutBranchModelImpl.FINDER_CACHE_ENABLED,
082 RecentLayoutBranchImpl.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(RecentLayoutBranchModelImpl.ENTITY_CACHE_ENABLED,
085 RecentLayoutBranchModelImpl.FINDER_CACHE_ENABLED,
086 RecentLayoutBranchImpl.class,
087 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
088 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(RecentLayoutBranchModelImpl.ENTITY_CACHE_ENABLED,
089 RecentLayoutBranchModelImpl.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(RecentLayoutBranchModelImpl.ENTITY_CACHE_ENABLED,
092 RecentLayoutBranchModelImpl.FINDER_CACHE_ENABLED,
093 RecentLayoutBranchImpl.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(RecentLayoutBranchModelImpl.ENTITY_CACHE_ENABLED,
103 RecentLayoutBranchModelImpl.FINDER_CACHE_ENABLED,
104 RecentLayoutBranchImpl.class,
105 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
106 new String[] { Long.class.getName() },
107 RecentLayoutBranchModelImpl.GROUPID_COLUMN_BITMASK);
108 public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(RecentLayoutBranchModelImpl.ENTITY_CACHE_ENABLED,
109 RecentLayoutBranchModelImpl.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<RecentLayoutBranch> findByGroupId(long groupId) {
121 return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
122 }
123
124
136 @Override
137 public List<RecentLayoutBranch> findByGroupId(long groupId, int start,
138 int end) {
139 return findByGroupId(groupId, start, end, null);
140 }
141
142
155 @Override
156 public List<RecentLayoutBranch> findByGroupId(long groupId, int start,
157 int end, OrderByComparator<RecentLayoutBranch> orderByComparator) {
158 return findByGroupId(groupId, start, end, orderByComparator, true);
159 }
160
161
175 @Override
176 public List<RecentLayoutBranch> findByGroupId(long groupId, int start,
177 int end, OrderByComparator<RecentLayoutBranch> 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<RecentLayoutBranch> list = null;
195
196 if (retrieveFromCache) {
197 list = (List<RecentLayoutBranch>)finderCache.getResult(finderPath,
198 finderArgs, this);
199
200 if ((list != null) && !list.isEmpty()) {
201 for (RecentLayoutBranch recentLayoutBranch : list) {
202 if ((groupId != recentLayoutBranch.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_RECENTLAYOUTBRANCH_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(RecentLayoutBranchModelImpl.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<RecentLayoutBranch>)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<RecentLayoutBranch>)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 RecentLayoutBranch findByGroupId_First(long groupId,
288 OrderByComparator<RecentLayoutBranch> orderByComparator)
289 throws NoSuchRecentLayoutBranchException {
290 RecentLayoutBranch recentLayoutBranch = fetchByGroupId_First(groupId,
291 orderByComparator);
292
293 if (recentLayoutBranch != null) {
294 return recentLayoutBranch;
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 NoSuchRecentLayoutBranchException(msg.toString());
307 }
308
309
316 @Override
317 public RecentLayoutBranch fetchByGroupId_First(long groupId,
318 OrderByComparator<RecentLayoutBranch> orderByComparator) {
319 List<RecentLayoutBranch> 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 RecentLayoutBranch findByGroupId_Last(long groupId,
339 OrderByComparator<RecentLayoutBranch> orderByComparator)
340 throws NoSuchRecentLayoutBranchException {
341 RecentLayoutBranch recentLayoutBranch = fetchByGroupId_Last(groupId,
342 orderByComparator);
343
344 if (recentLayoutBranch != null) {
345 return recentLayoutBranch;
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 NoSuchRecentLayoutBranchException(msg.toString());
358 }
359
360
367 @Override
368 public RecentLayoutBranch fetchByGroupId_Last(long groupId,
369 OrderByComparator<RecentLayoutBranch> orderByComparator) {
370 int count = countByGroupId(groupId);
371
372 if (count == 0) {
373 return null;
374 }
375
376 List<RecentLayoutBranch> 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 RecentLayoutBranch[] findByGroupId_PrevAndNext(
397 long recentLayoutBranchId, long groupId,
398 OrderByComparator<RecentLayoutBranch> orderByComparator)
399 throws NoSuchRecentLayoutBranchException {
400 RecentLayoutBranch recentLayoutBranch = findByPrimaryKey(recentLayoutBranchId);
401
402 Session session = null;
403
404 try {
405 session = openSession();
406
407 RecentLayoutBranch[] array = new RecentLayoutBranchImpl[3];
408
409 array[0] = getByGroupId_PrevAndNext(session, recentLayoutBranch,
410 groupId, orderByComparator, true);
411
412 array[1] = recentLayoutBranch;
413
414 array[2] = getByGroupId_PrevAndNext(session, recentLayoutBranch,
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 RecentLayoutBranch getByGroupId_PrevAndNext(Session session,
428 RecentLayoutBranch recentLayoutBranch, long groupId,
429 OrderByComparator<RecentLayoutBranch> 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_RECENTLAYOUTBRANCH_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(RecentLayoutBranchModelImpl.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(recentLayoutBranch);
518
519 for (Object value : values) {
520 qPos.add(value);
521 }
522 }
523
524 List<RecentLayoutBranch> 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 (RecentLayoutBranch recentLayoutBranch : findByGroupId(groupId,
542 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
543 remove(recentLayoutBranch);
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_RECENTLAYOUTBRANCH_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 = "recentLayoutBranch.groupId = ?";
599 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(RecentLayoutBranchModelImpl.ENTITY_CACHE_ENABLED,
600 RecentLayoutBranchModelImpl.FINDER_CACHE_ENABLED,
601 RecentLayoutBranchImpl.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(RecentLayoutBranchModelImpl.ENTITY_CACHE_ENABLED,
611 RecentLayoutBranchModelImpl.FINDER_CACHE_ENABLED,
612 RecentLayoutBranchImpl.class,
613 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId",
614 new String[] { Long.class.getName() },
615 RecentLayoutBranchModelImpl.USERID_COLUMN_BITMASK);
616 public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(RecentLayoutBranchModelImpl.ENTITY_CACHE_ENABLED,
617 RecentLayoutBranchModelImpl.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<RecentLayoutBranch> findByUserId(long userId) {
629 return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
630 }
631
632
644 @Override
645 public List<RecentLayoutBranch> findByUserId(long userId, int start, int end) {
646 return findByUserId(userId, start, end, null);
647 }
648
649
662 @Override
663 public List<RecentLayoutBranch> findByUserId(long userId, int start,
664 int end, OrderByComparator<RecentLayoutBranch> orderByComparator) {
665 return findByUserId(userId, start, end, orderByComparator, true);
666 }
667
668
682 @Override
683 public List<RecentLayoutBranch> findByUserId(long userId, int start,
684 int end, OrderByComparator<RecentLayoutBranch> orderByComparator,
685 boolean retrieveFromCache) {
686 boolean pagination = true;
687 FinderPath finderPath = null;
688 Object[] finderArgs = null;
689
690 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
691 (orderByComparator == null)) {
692 pagination = false;
693 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
694 finderArgs = new Object[] { userId };
695 }
696 else {
697 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
698 finderArgs = new Object[] { userId, start, end, orderByComparator };
699 }
700
701 List<RecentLayoutBranch> list = null;
702
703 if (retrieveFromCache) {
704 list = (List<RecentLayoutBranch>)finderCache.getResult(finderPath,
705 finderArgs, this);
706
707 if ((list != null) && !list.isEmpty()) {
708 for (RecentLayoutBranch recentLayoutBranch : list) {
709 if ((userId != recentLayoutBranch.getUserId())) {
710 list = null;
711
712 break;
713 }
714 }
715 }
716 }
717
718 if (list == null) {
719 StringBundler query = null;
720
721 if (orderByComparator != null) {
722 query = new StringBundler(3 +
723 (orderByComparator.getOrderByFields().length * 2));
724 }
725 else {
726 query = new StringBundler(3);
727 }
728
729 query.append(_SQL_SELECT_RECENTLAYOUTBRANCH_WHERE);
730
731 query.append(_FINDER_COLUMN_USERID_USERID_2);
732
733 if (orderByComparator != null) {
734 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
735 orderByComparator);
736 }
737 else
738 if (pagination) {
739 query.append(RecentLayoutBranchModelImpl.ORDER_BY_JPQL);
740 }
741
742 String sql = query.toString();
743
744 Session session = null;
745
746 try {
747 session = openSession();
748
749 Query q = session.createQuery(sql);
750
751 QueryPos qPos = QueryPos.getInstance(q);
752
753 qPos.add(userId);
754
755 if (!pagination) {
756 list = (List<RecentLayoutBranch>)QueryUtil.list(q,
757 getDialect(), start, end, false);
758
759 Collections.sort(list);
760
761 list = Collections.unmodifiableList(list);
762 }
763 else {
764 list = (List<RecentLayoutBranch>)QueryUtil.list(q,
765 getDialect(), start, end);
766 }
767
768 cacheResult(list);
769
770 finderCache.putResult(finderPath, finderArgs, list);
771 }
772 catch (Exception e) {
773 finderCache.removeResult(finderPath, finderArgs);
774
775 throw processException(e);
776 }
777 finally {
778 closeSession(session);
779 }
780 }
781
782 return list;
783 }
784
785
793 @Override
794 public RecentLayoutBranch findByUserId_First(long userId,
795 OrderByComparator<RecentLayoutBranch> orderByComparator)
796 throws NoSuchRecentLayoutBranchException {
797 RecentLayoutBranch recentLayoutBranch = fetchByUserId_First(userId,
798 orderByComparator);
799
800 if (recentLayoutBranch != null) {
801 return recentLayoutBranch;
802 }
803
804 StringBundler msg = new StringBundler(4);
805
806 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
807
808 msg.append("userId=");
809 msg.append(userId);
810
811 msg.append(StringPool.CLOSE_CURLY_BRACE);
812
813 throw new NoSuchRecentLayoutBranchException(msg.toString());
814 }
815
816
823 @Override
824 public RecentLayoutBranch fetchByUserId_First(long userId,
825 OrderByComparator<RecentLayoutBranch> orderByComparator) {
826 List<RecentLayoutBranch> list = findByUserId(userId, 0, 1,
827 orderByComparator);
828
829 if (!list.isEmpty()) {
830 return list.get(0);
831 }
832
833 return null;
834 }
835
836
844 @Override
845 public RecentLayoutBranch findByUserId_Last(long userId,
846 OrderByComparator<RecentLayoutBranch> orderByComparator)
847 throws NoSuchRecentLayoutBranchException {
848 RecentLayoutBranch recentLayoutBranch = fetchByUserId_Last(userId,
849 orderByComparator);
850
851 if (recentLayoutBranch != null) {
852 return recentLayoutBranch;
853 }
854
855 StringBundler msg = new StringBundler(4);
856
857 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
858
859 msg.append("userId=");
860 msg.append(userId);
861
862 msg.append(StringPool.CLOSE_CURLY_BRACE);
863
864 throw new NoSuchRecentLayoutBranchException(msg.toString());
865 }
866
867
874 @Override
875 public RecentLayoutBranch fetchByUserId_Last(long userId,
876 OrderByComparator<RecentLayoutBranch> orderByComparator) {
877 int count = countByUserId(userId);
878
879 if (count == 0) {
880 return null;
881 }
882
883 List<RecentLayoutBranch> list = findByUserId(userId, count - 1, count,
884 orderByComparator);
885
886 if (!list.isEmpty()) {
887 return list.get(0);
888 }
889
890 return null;
891 }
892
893
902 @Override
903 public RecentLayoutBranch[] findByUserId_PrevAndNext(
904 long recentLayoutBranchId, long userId,
905 OrderByComparator<RecentLayoutBranch> orderByComparator)
906 throws NoSuchRecentLayoutBranchException {
907 RecentLayoutBranch recentLayoutBranch = findByPrimaryKey(recentLayoutBranchId);
908
909 Session session = null;
910
911 try {
912 session = openSession();
913
914 RecentLayoutBranch[] array = new RecentLayoutBranchImpl[3];
915
916 array[0] = getByUserId_PrevAndNext(session, recentLayoutBranch,
917 userId, orderByComparator, true);
918
919 array[1] = recentLayoutBranch;
920
921 array[2] = getByUserId_PrevAndNext(session, recentLayoutBranch,
922 userId, orderByComparator, false);
923
924 return array;
925 }
926 catch (Exception e) {
927 throw processException(e);
928 }
929 finally {
930 closeSession(session);
931 }
932 }
933
934 protected RecentLayoutBranch getByUserId_PrevAndNext(Session session,
935 RecentLayoutBranch recentLayoutBranch, long userId,
936 OrderByComparator<RecentLayoutBranch> orderByComparator,
937 boolean previous) {
938 StringBundler query = null;
939
940 if (orderByComparator != null) {
941 query = new StringBundler(4 +
942 (orderByComparator.getOrderByConditionFields().length * 3) +
943 (orderByComparator.getOrderByFields().length * 3));
944 }
945 else {
946 query = new StringBundler(3);
947 }
948
949 query.append(_SQL_SELECT_RECENTLAYOUTBRANCH_WHERE);
950
951 query.append(_FINDER_COLUMN_USERID_USERID_2);
952
953 if (orderByComparator != null) {
954 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
955
956 if (orderByConditionFields.length > 0) {
957 query.append(WHERE_AND);
958 }
959
960 for (int i = 0; i < orderByConditionFields.length; i++) {
961 query.append(_ORDER_BY_ENTITY_ALIAS);
962 query.append(orderByConditionFields[i]);
963
964 if ((i + 1) < orderByConditionFields.length) {
965 if (orderByComparator.isAscending() ^ previous) {
966 query.append(WHERE_GREATER_THAN_HAS_NEXT);
967 }
968 else {
969 query.append(WHERE_LESSER_THAN_HAS_NEXT);
970 }
971 }
972 else {
973 if (orderByComparator.isAscending() ^ previous) {
974 query.append(WHERE_GREATER_THAN);
975 }
976 else {
977 query.append(WHERE_LESSER_THAN);
978 }
979 }
980 }
981
982 query.append(ORDER_BY_CLAUSE);
983
984 String[] orderByFields = orderByComparator.getOrderByFields();
985
986 for (int i = 0; i < orderByFields.length; i++) {
987 query.append(_ORDER_BY_ENTITY_ALIAS);
988 query.append(orderByFields[i]);
989
990 if ((i + 1) < orderByFields.length) {
991 if (orderByComparator.isAscending() ^ previous) {
992 query.append(ORDER_BY_ASC_HAS_NEXT);
993 }
994 else {
995 query.append(ORDER_BY_DESC_HAS_NEXT);
996 }
997 }
998 else {
999 if (orderByComparator.isAscending() ^ previous) {
1000 query.append(ORDER_BY_ASC);
1001 }
1002 else {
1003 query.append(ORDER_BY_DESC);
1004 }
1005 }
1006 }
1007 }
1008 else {
1009 query.append(RecentLayoutBranchModelImpl.ORDER_BY_JPQL);
1010 }
1011
1012 String sql = query.toString();
1013
1014 Query q = session.createQuery(sql);
1015
1016 q.setFirstResult(0);
1017 q.setMaxResults(2);
1018
1019 QueryPos qPos = QueryPos.getInstance(q);
1020
1021 qPos.add(userId);
1022
1023 if (orderByComparator != null) {
1024 Object[] values = orderByComparator.getOrderByConditionValues(recentLayoutBranch);
1025
1026 for (Object value : values) {
1027 qPos.add(value);
1028 }
1029 }
1030
1031 List<RecentLayoutBranch> list = q.list();
1032
1033 if (list.size() == 2) {
1034 return list.get(1);
1035 }
1036 else {
1037 return null;
1038 }
1039 }
1040
1041
1046 @Override
1047 public void removeByUserId(long userId) {
1048 for (RecentLayoutBranch recentLayoutBranch : findByUserId(userId,
1049 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1050 remove(recentLayoutBranch);
1051 }
1052 }
1053
1054
1060 @Override
1061 public int countByUserId(long userId) {
1062 FinderPath finderPath = FINDER_PATH_COUNT_BY_USERID;
1063
1064 Object[] finderArgs = new Object[] { userId };
1065
1066 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1067
1068 if (count == null) {
1069 StringBundler query = new StringBundler(2);
1070
1071 query.append(_SQL_COUNT_RECENTLAYOUTBRANCH_WHERE);
1072
1073 query.append(_FINDER_COLUMN_USERID_USERID_2);
1074
1075 String sql = query.toString();
1076
1077 Session session = null;
1078
1079 try {
1080 session = openSession();
1081
1082 Query q = session.createQuery(sql);
1083
1084 QueryPos qPos = QueryPos.getInstance(q);
1085
1086 qPos.add(userId);
1087
1088 count = (Long)q.uniqueResult();
1089
1090 finderCache.putResult(finderPath, finderArgs, count);
1091 }
1092 catch (Exception e) {
1093 finderCache.removeResult(finderPath, finderArgs);
1094
1095 throw processException(e);
1096 }
1097 finally {
1098 closeSession(session);
1099 }
1100 }
1101
1102 return count.intValue();
1103 }
1104
1105 private static final String _FINDER_COLUMN_USERID_USERID_2 = "recentLayoutBranch.userId = ?";
1106 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_LAYOUTBRANCHID =
1107 new FinderPath(RecentLayoutBranchModelImpl.ENTITY_CACHE_ENABLED,
1108 RecentLayoutBranchModelImpl.FINDER_CACHE_ENABLED,
1109 RecentLayoutBranchImpl.class,
1110 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByLayoutBranchId",
1111 new String[] {
1112 Long.class.getName(),
1113
1114 Integer.class.getName(), Integer.class.getName(),
1115 OrderByComparator.class.getName()
1116 });
1117 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LAYOUTBRANCHID =
1118 new FinderPath(RecentLayoutBranchModelImpl.ENTITY_CACHE_ENABLED,
1119 RecentLayoutBranchModelImpl.FINDER_CACHE_ENABLED,
1120 RecentLayoutBranchImpl.class,
1121 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByLayoutBranchId",
1122 new String[] { Long.class.getName() },
1123 RecentLayoutBranchModelImpl.LAYOUTBRANCHID_COLUMN_BITMASK);
1124 public static final FinderPath FINDER_PATH_COUNT_BY_LAYOUTBRANCHID = new FinderPath(RecentLayoutBranchModelImpl.ENTITY_CACHE_ENABLED,
1125 RecentLayoutBranchModelImpl.FINDER_CACHE_ENABLED, Long.class,
1126 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByLayoutBranchId",
1127 new String[] { Long.class.getName() });
1128
1129
1135 @Override
1136 public List<RecentLayoutBranch> findByLayoutBranchId(long layoutBranchId) {
1137 return findByLayoutBranchId(layoutBranchId, QueryUtil.ALL_POS,
1138 QueryUtil.ALL_POS, null);
1139 }
1140
1141
1153 @Override
1154 public List<RecentLayoutBranch> findByLayoutBranchId(long layoutBranchId,
1155 int start, int end) {
1156 return findByLayoutBranchId(layoutBranchId, start, end, null);
1157 }
1158
1159
1172 @Override
1173 public List<RecentLayoutBranch> findByLayoutBranchId(long layoutBranchId,
1174 int start, int end,
1175 OrderByComparator<RecentLayoutBranch> orderByComparator) {
1176 return findByLayoutBranchId(layoutBranchId, start, end,
1177 orderByComparator, true);
1178 }
1179
1180
1194 @Override
1195 public List<RecentLayoutBranch> findByLayoutBranchId(long layoutBranchId,
1196 int start, int end,
1197 OrderByComparator<RecentLayoutBranch> orderByComparator,
1198 boolean retrieveFromCache) {
1199 boolean pagination = true;
1200 FinderPath finderPath = null;
1201 Object[] finderArgs = null;
1202
1203 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1204 (orderByComparator == null)) {
1205 pagination = false;
1206 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LAYOUTBRANCHID;
1207 finderArgs = new Object[] { layoutBranchId };
1208 }
1209 else {
1210 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_LAYOUTBRANCHID;
1211 finderArgs = new Object[] {
1212 layoutBranchId,
1213
1214 start, end, orderByComparator
1215 };
1216 }
1217
1218 List<RecentLayoutBranch> list = null;
1219
1220 if (retrieveFromCache) {
1221 list = (List<RecentLayoutBranch>)finderCache.getResult(finderPath,
1222 finderArgs, this);
1223
1224 if ((list != null) && !list.isEmpty()) {
1225 for (RecentLayoutBranch recentLayoutBranch : list) {
1226 if ((layoutBranchId != recentLayoutBranch.getLayoutBranchId())) {
1227 list = null;
1228
1229 break;
1230 }
1231 }
1232 }
1233 }
1234
1235 if (list == null) {
1236 StringBundler query = null;
1237
1238 if (orderByComparator != null) {
1239 query = new StringBundler(3 +
1240 (orderByComparator.getOrderByFields().length * 2));
1241 }
1242 else {
1243 query = new StringBundler(3);
1244 }
1245
1246 query.append(_SQL_SELECT_RECENTLAYOUTBRANCH_WHERE);
1247
1248 query.append(_FINDER_COLUMN_LAYOUTBRANCHID_LAYOUTBRANCHID_2);
1249
1250 if (orderByComparator != null) {
1251 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1252 orderByComparator);
1253 }
1254 else
1255 if (pagination) {
1256 query.append(RecentLayoutBranchModelImpl.ORDER_BY_JPQL);
1257 }
1258
1259 String sql = query.toString();
1260
1261 Session session = null;
1262
1263 try {
1264 session = openSession();
1265
1266 Query q = session.createQuery(sql);
1267
1268 QueryPos qPos = QueryPos.getInstance(q);
1269
1270 qPos.add(layoutBranchId);
1271
1272 if (!pagination) {
1273 list = (List<RecentLayoutBranch>)QueryUtil.list(q,
1274 getDialect(), start, end, false);
1275
1276 Collections.sort(list);
1277
1278 list = Collections.unmodifiableList(list);
1279 }
1280 else {
1281 list = (List<RecentLayoutBranch>)QueryUtil.list(q,
1282 getDialect(), start, end);
1283 }
1284
1285 cacheResult(list);
1286
1287 finderCache.putResult(finderPath, finderArgs, list);
1288 }
1289 catch (Exception e) {
1290 finderCache.removeResult(finderPath, finderArgs);
1291
1292 throw processException(e);
1293 }
1294 finally {
1295 closeSession(session);
1296 }
1297 }
1298
1299 return list;
1300 }
1301
1302
1310 @Override
1311 public RecentLayoutBranch findByLayoutBranchId_First(long layoutBranchId,
1312 OrderByComparator<RecentLayoutBranch> orderByComparator)
1313 throws NoSuchRecentLayoutBranchException {
1314 RecentLayoutBranch recentLayoutBranch = fetchByLayoutBranchId_First(layoutBranchId,
1315 orderByComparator);
1316
1317 if (recentLayoutBranch != null) {
1318 return recentLayoutBranch;
1319 }
1320
1321 StringBundler msg = new StringBundler(4);
1322
1323 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1324
1325 msg.append("layoutBranchId=");
1326 msg.append(layoutBranchId);
1327
1328 msg.append(StringPool.CLOSE_CURLY_BRACE);
1329
1330 throw new NoSuchRecentLayoutBranchException(msg.toString());
1331 }
1332
1333
1340 @Override
1341 public RecentLayoutBranch fetchByLayoutBranchId_First(long layoutBranchId,
1342 OrderByComparator<RecentLayoutBranch> orderByComparator) {
1343 List<RecentLayoutBranch> list = findByLayoutBranchId(layoutBranchId, 0,
1344 1, orderByComparator);
1345
1346 if (!list.isEmpty()) {
1347 return list.get(0);
1348 }
1349
1350 return null;
1351 }
1352
1353
1361 @Override
1362 public RecentLayoutBranch findByLayoutBranchId_Last(long layoutBranchId,
1363 OrderByComparator<RecentLayoutBranch> orderByComparator)
1364 throws NoSuchRecentLayoutBranchException {
1365 RecentLayoutBranch recentLayoutBranch = fetchByLayoutBranchId_Last(layoutBranchId,
1366 orderByComparator);
1367
1368 if (recentLayoutBranch != null) {
1369 return recentLayoutBranch;
1370 }
1371
1372 StringBundler msg = new StringBundler(4);
1373
1374 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1375
1376 msg.append("layoutBranchId=");
1377 msg.append(layoutBranchId);
1378
1379 msg.append(StringPool.CLOSE_CURLY_BRACE);
1380
1381 throw new NoSuchRecentLayoutBranchException(msg.toString());
1382 }
1383
1384
1391 @Override
1392 public RecentLayoutBranch fetchByLayoutBranchId_Last(long layoutBranchId,
1393 OrderByComparator<RecentLayoutBranch> orderByComparator) {
1394 int count = countByLayoutBranchId(layoutBranchId);
1395
1396 if (count == 0) {
1397 return null;
1398 }
1399
1400 List<RecentLayoutBranch> list = findByLayoutBranchId(layoutBranchId,
1401 count - 1, count, orderByComparator);
1402
1403 if (!list.isEmpty()) {
1404 return list.get(0);
1405 }
1406
1407 return null;
1408 }
1409
1410
1419 @Override
1420 public RecentLayoutBranch[] findByLayoutBranchId_PrevAndNext(
1421 long recentLayoutBranchId, long layoutBranchId,
1422 OrderByComparator<RecentLayoutBranch> orderByComparator)
1423 throws NoSuchRecentLayoutBranchException {
1424 RecentLayoutBranch recentLayoutBranch = findByPrimaryKey(recentLayoutBranchId);
1425
1426 Session session = null;
1427
1428 try {
1429 session = openSession();
1430
1431 RecentLayoutBranch[] array = new RecentLayoutBranchImpl[3];
1432
1433 array[0] = getByLayoutBranchId_PrevAndNext(session,
1434 recentLayoutBranch, layoutBranchId, orderByComparator, true);
1435
1436 array[1] = recentLayoutBranch;
1437
1438 array[2] = getByLayoutBranchId_PrevAndNext(session,
1439 recentLayoutBranch, layoutBranchId, orderByComparator, false);
1440
1441 return array;
1442 }
1443 catch (Exception e) {
1444 throw processException(e);
1445 }
1446 finally {
1447 closeSession(session);
1448 }
1449 }
1450
1451 protected RecentLayoutBranch getByLayoutBranchId_PrevAndNext(
1452 Session session, RecentLayoutBranch recentLayoutBranch,
1453 long layoutBranchId,
1454 OrderByComparator<RecentLayoutBranch> orderByComparator,
1455 boolean previous) {
1456 StringBundler query = null;
1457
1458 if (orderByComparator != null) {
1459 query = new StringBundler(4 +
1460 (orderByComparator.getOrderByConditionFields().length * 3) +
1461 (orderByComparator.getOrderByFields().length * 3));
1462 }
1463 else {
1464 query = new StringBundler(3);
1465 }
1466
1467 query.append(_SQL_SELECT_RECENTLAYOUTBRANCH_WHERE);
1468
1469 query.append(_FINDER_COLUMN_LAYOUTBRANCHID_LAYOUTBRANCHID_2);
1470
1471 if (orderByComparator != null) {
1472 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1473
1474 if (orderByConditionFields.length > 0) {
1475 query.append(WHERE_AND);
1476 }
1477
1478 for (int i = 0; i < orderByConditionFields.length; i++) {
1479 query.append(_ORDER_BY_ENTITY_ALIAS);
1480 query.append(orderByConditionFields[i]);
1481
1482 if ((i + 1) < orderByConditionFields.length) {
1483 if (orderByComparator.isAscending() ^ previous) {
1484 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1485 }
1486 else {
1487 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1488 }
1489 }
1490 else {
1491 if (orderByComparator.isAscending() ^ previous) {
1492 query.append(WHERE_GREATER_THAN);
1493 }
1494 else {
1495 query.append(WHERE_LESSER_THAN);
1496 }
1497 }
1498 }
1499
1500 query.append(ORDER_BY_CLAUSE);
1501
1502 String[] orderByFields = orderByComparator.getOrderByFields();
1503
1504 for (int i = 0; i < orderByFields.length; i++) {
1505 query.append(_ORDER_BY_ENTITY_ALIAS);
1506 query.append(orderByFields[i]);
1507
1508 if ((i + 1) < orderByFields.length) {
1509 if (orderByComparator.isAscending() ^ previous) {
1510 query.append(ORDER_BY_ASC_HAS_NEXT);
1511 }
1512 else {
1513 query.append(ORDER_BY_DESC_HAS_NEXT);
1514 }
1515 }
1516 else {
1517 if (orderByComparator.isAscending() ^ previous) {
1518 query.append(ORDER_BY_ASC);
1519 }
1520 else {
1521 query.append(ORDER_BY_DESC);
1522 }
1523 }
1524 }
1525 }
1526 else {
1527 query.append(RecentLayoutBranchModelImpl.ORDER_BY_JPQL);
1528 }
1529
1530 String sql = query.toString();
1531
1532 Query q = session.createQuery(sql);
1533
1534 q.setFirstResult(0);
1535 q.setMaxResults(2);
1536
1537 QueryPos qPos = QueryPos.getInstance(q);
1538
1539 qPos.add(layoutBranchId);
1540
1541 if (orderByComparator != null) {
1542 Object[] values = orderByComparator.getOrderByConditionValues(recentLayoutBranch);
1543
1544 for (Object value : values) {
1545 qPos.add(value);
1546 }
1547 }
1548
1549 List<RecentLayoutBranch> list = q.list();
1550
1551 if (list.size() == 2) {
1552 return list.get(1);
1553 }
1554 else {
1555 return null;
1556 }
1557 }
1558
1559
1564 @Override
1565 public void removeByLayoutBranchId(long layoutBranchId) {
1566 for (RecentLayoutBranch recentLayoutBranch : findByLayoutBranchId(
1567 layoutBranchId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1568 remove(recentLayoutBranch);
1569 }
1570 }
1571
1572
1578 @Override
1579 public int countByLayoutBranchId(long layoutBranchId) {
1580 FinderPath finderPath = FINDER_PATH_COUNT_BY_LAYOUTBRANCHID;
1581
1582 Object[] finderArgs = new Object[] { layoutBranchId };
1583
1584 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1585
1586 if (count == null) {
1587 StringBundler query = new StringBundler(2);
1588
1589 query.append(_SQL_COUNT_RECENTLAYOUTBRANCH_WHERE);
1590
1591 query.append(_FINDER_COLUMN_LAYOUTBRANCHID_LAYOUTBRANCHID_2);
1592
1593 String sql = query.toString();
1594
1595 Session session = null;
1596
1597 try {
1598 session = openSession();
1599
1600 Query q = session.createQuery(sql);
1601
1602 QueryPos qPos = QueryPos.getInstance(q);
1603
1604 qPos.add(layoutBranchId);
1605
1606 count = (Long)q.uniqueResult();
1607
1608 finderCache.putResult(finderPath, finderArgs, count);
1609 }
1610 catch (Exception e) {
1611 finderCache.removeResult(finderPath, finderArgs);
1612
1613 throw processException(e);
1614 }
1615 finally {
1616 closeSession(session);
1617 }
1618 }
1619
1620 return count.intValue();
1621 }
1622
1623 private static final String _FINDER_COLUMN_LAYOUTBRANCHID_LAYOUTBRANCHID_2 = "recentLayoutBranch.layoutBranchId = ?";
1624 public static final FinderPath FINDER_PATH_FETCH_BY_U_L_P = new FinderPath(RecentLayoutBranchModelImpl.ENTITY_CACHE_ENABLED,
1625 RecentLayoutBranchModelImpl.FINDER_CACHE_ENABLED,
1626 RecentLayoutBranchImpl.class, FINDER_CLASS_NAME_ENTITY,
1627 "fetchByU_L_P",
1628 new String[] {
1629 Long.class.getName(), Long.class.getName(), Long.class.getName()
1630 },
1631 RecentLayoutBranchModelImpl.USERID_COLUMN_BITMASK |
1632 RecentLayoutBranchModelImpl.LAYOUTSETBRANCHID_COLUMN_BITMASK |
1633 RecentLayoutBranchModelImpl.PLID_COLUMN_BITMASK);
1634 public static final FinderPath FINDER_PATH_COUNT_BY_U_L_P = new FinderPath(RecentLayoutBranchModelImpl.ENTITY_CACHE_ENABLED,
1635 RecentLayoutBranchModelImpl.FINDER_CACHE_ENABLED, Long.class,
1636 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_L_P",
1637 new String[] {
1638 Long.class.getName(), Long.class.getName(), Long.class.getName()
1639 });
1640
1641
1650 @Override
1651 public RecentLayoutBranch findByU_L_P(long userId, long layoutSetBranchId,
1652 long plid) throws NoSuchRecentLayoutBranchException {
1653 RecentLayoutBranch recentLayoutBranch = fetchByU_L_P(userId,
1654 layoutSetBranchId, plid);
1655
1656 if (recentLayoutBranch == null) {
1657 StringBundler msg = new StringBundler(8);
1658
1659 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1660
1661 msg.append("userId=");
1662 msg.append(userId);
1663
1664 msg.append(", layoutSetBranchId=");
1665 msg.append(layoutSetBranchId);
1666
1667 msg.append(", plid=");
1668 msg.append(plid);
1669
1670 msg.append(StringPool.CLOSE_CURLY_BRACE);
1671
1672 if (_log.isDebugEnabled()) {
1673 _log.debug(msg.toString());
1674 }
1675
1676 throw new NoSuchRecentLayoutBranchException(msg.toString());
1677 }
1678
1679 return recentLayoutBranch;
1680 }
1681
1682
1690 @Override
1691 public RecentLayoutBranch fetchByU_L_P(long userId, long layoutSetBranchId,
1692 long plid) {
1693 return fetchByU_L_P(userId, layoutSetBranchId, plid, true);
1694 }
1695
1696
1705 @Override
1706 public RecentLayoutBranch fetchByU_L_P(long userId, long layoutSetBranchId,
1707 long plid, boolean retrieveFromCache) {
1708 Object[] finderArgs = new Object[] { userId, layoutSetBranchId, plid };
1709
1710 Object result = null;
1711
1712 if (retrieveFromCache) {
1713 result = finderCache.getResult(FINDER_PATH_FETCH_BY_U_L_P,
1714 finderArgs, this);
1715 }
1716
1717 if (result instanceof RecentLayoutBranch) {
1718 RecentLayoutBranch recentLayoutBranch = (RecentLayoutBranch)result;
1719
1720 if ((userId != recentLayoutBranch.getUserId()) ||
1721 (layoutSetBranchId != recentLayoutBranch.getLayoutSetBranchId()) ||
1722 (plid != recentLayoutBranch.getPlid())) {
1723 result = null;
1724 }
1725 }
1726
1727 if (result == null) {
1728 StringBundler query = new StringBundler(5);
1729
1730 query.append(_SQL_SELECT_RECENTLAYOUTBRANCH_WHERE);
1731
1732 query.append(_FINDER_COLUMN_U_L_P_USERID_2);
1733
1734 query.append(_FINDER_COLUMN_U_L_P_LAYOUTSETBRANCHID_2);
1735
1736 query.append(_FINDER_COLUMN_U_L_P_PLID_2);
1737
1738 String sql = query.toString();
1739
1740 Session session = null;
1741
1742 try {
1743 session = openSession();
1744
1745 Query q = session.createQuery(sql);
1746
1747 QueryPos qPos = QueryPos.getInstance(q);
1748
1749 qPos.add(userId);
1750
1751 qPos.add(layoutSetBranchId);
1752
1753 qPos.add(plid);
1754
1755 List<RecentLayoutBranch> list = q.list();
1756
1757 if (list.isEmpty()) {
1758 finderCache.putResult(FINDER_PATH_FETCH_BY_U_L_P,
1759 finderArgs, list);
1760 }
1761 else {
1762 RecentLayoutBranch recentLayoutBranch = list.get(0);
1763
1764 result = recentLayoutBranch;
1765
1766 cacheResult(recentLayoutBranch);
1767
1768 if ((recentLayoutBranch.getUserId() != userId) ||
1769 (recentLayoutBranch.getLayoutSetBranchId() != layoutSetBranchId) ||
1770 (recentLayoutBranch.getPlid() != plid)) {
1771 finderCache.putResult(FINDER_PATH_FETCH_BY_U_L_P,
1772 finderArgs, recentLayoutBranch);
1773 }
1774 }
1775 }
1776 catch (Exception e) {
1777 finderCache.removeResult(FINDER_PATH_FETCH_BY_U_L_P, finderArgs);
1778
1779 throw processException(e);
1780 }
1781 finally {
1782 closeSession(session);
1783 }
1784 }
1785
1786 if (result instanceof List<?>) {
1787 return null;
1788 }
1789 else {
1790 return (RecentLayoutBranch)result;
1791 }
1792 }
1793
1794
1802 @Override
1803 public RecentLayoutBranch removeByU_L_P(long userId,
1804 long layoutSetBranchId, long plid)
1805 throws NoSuchRecentLayoutBranchException {
1806 RecentLayoutBranch recentLayoutBranch = findByU_L_P(userId,
1807 layoutSetBranchId, plid);
1808
1809 return remove(recentLayoutBranch);
1810 }
1811
1812
1820 @Override
1821 public int countByU_L_P(long userId, long layoutSetBranchId, long plid) {
1822 FinderPath finderPath = FINDER_PATH_COUNT_BY_U_L_P;
1823
1824 Object[] finderArgs = new Object[] { userId, layoutSetBranchId, plid };
1825
1826 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1827
1828 if (count == null) {
1829 StringBundler query = new StringBundler(4);
1830
1831 query.append(_SQL_COUNT_RECENTLAYOUTBRANCH_WHERE);
1832
1833 query.append(_FINDER_COLUMN_U_L_P_USERID_2);
1834
1835 query.append(_FINDER_COLUMN_U_L_P_LAYOUTSETBRANCHID_2);
1836
1837 query.append(_FINDER_COLUMN_U_L_P_PLID_2);
1838
1839 String sql = query.toString();
1840
1841 Session session = null;
1842
1843 try {
1844 session = openSession();
1845
1846 Query q = session.createQuery(sql);
1847
1848 QueryPos qPos = QueryPos.getInstance(q);
1849
1850 qPos.add(userId);
1851
1852 qPos.add(layoutSetBranchId);
1853
1854 qPos.add(plid);
1855
1856 count = (Long)q.uniqueResult();
1857
1858 finderCache.putResult(finderPath, finderArgs, count);
1859 }
1860 catch (Exception e) {
1861 finderCache.removeResult(finderPath, finderArgs);
1862
1863 throw processException(e);
1864 }
1865 finally {
1866 closeSession(session);
1867 }
1868 }
1869
1870 return count.intValue();
1871 }
1872
1873 private static final String _FINDER_COLUMN_U_L_P_USERID_2 = "recentLayoutBranch.userId = ? AND ";
1874 private static final String _FINDER_COLUMN_U_L_P_LAYOUTSETBRANCHID_2 = "recentLayoutBranch.layoutSetBranchId = ? AND ";
1875 private static final String _FINDER_COLUMN_U_L_P_PLID_2 = "recentLayoutBranch.plid = ?";
1876
1877 public RecentLayoutBranchPersistenceImpl() {
1878 setModelClass(RecentLayoutBranch.class);
1879 }
1880
1881
1886 @Override
1887 public void cacheResult(RecentLayoutBranch recentLayoutBranch) {
1888 entityCache.putResult(RecentLayoutBranchModelImpl.ENTITY_CACHE_ENABLED,
1889 RecentLayoutBranchImpl.class, recentLayoutBranch.getPrimaryKey(),
1890 recentLayoutBranch);
1891
1892 finderCache.putResult(FINDER_PATH_FETCH_BY_U_L_P,
1893 new Object[] {
1894 recentLayoutBranch.getUserId(),
1895 recentLayoutBranch.getLayoutSetBranchId(),
1896 recentLayoutBranch.getPlid()
1897 }, recentLayoutBranch);
1898
1899 recentLayoutBranch.resetOriginalValues();
1900 }
1901
1902
1907 @Override
1908 public void cacheResult(List<RecentLayoutBranch> recentLayoutBranchs) {
1909 for (RecentLayoutBranch recentLayoutBranch : recentLayoutBranchs) {
1910 if (entityCache.getResult(
1911 RecentLayoutBranchModelImpl.ENTITY_CACHE_ENABLED,
1912 RecentLayoutBranchImpl.class,
1913 recentLayoutBranch.getPrimaryKey()) == null) {
1914 cacheResult(recentLayoutBranch);
1915 }
1916 else {
1917 recentLayoutBranch.resetOriginalValues();
1918 }
1919 }
1920 }
1921
1922
1929 @Override
1930 public void clearCache() {
1931 entityCache.clearCache(RecentLayoutBranchImpl.class);
1932
1933 finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
1934 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1935 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1936 }
1937
1938
1945 @Override
1946 public void clearCache(RecentLayoutBranch recentLayoutBranch) {
1947 entityCache.removeResult(RecentLayoutBranchModelImpl.ENTITY_CACHE_ENABLED,
1948 RecentLayoutBranchImpl.class, recentLayoutBranch.getPrimaryKey());
1949
1950 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1951 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1952
1953 clearUniqueFindersCache((RecentLayoutBranchModelImpl)recentLayoutBranch);
1954 }
1955
1956 @Override
1957 public void clearCache(List<RecentLayoutBranch> recentLayoutBranchs) {
1958 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1959 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1960
1961 for (RecentLayoutBranch recentLayoutBranch : recentLayoutBranchs) {
1962 entityCache.removeResult(RecentLayoutBranchModelImpl.ENTITY_CACHE_ENABLED,
1963 RecentLayoutBranchImpl.class, recentLayoutBranch.getPrimaryKey());
1964
1965 clearUniqueFindersCache((RecentLayoutBranchModelImpl)recentLayoutBranch);
1966 }
1967 }
1968
1969 protected void cacheUniqueFindersCache(
1970 RecentLayoutBranchModelImpl recentLayoutBranchModelImpl, boolean isNew) {
1971 if (isNew) {
1972 Object[] args = new Object[] {
1973 recentLayoutBranchModelImpl.getUserId(),
1974 recentLayoutBranchModelImpl.getLayoutSetBranchId(),
1975 recentLayoutBranchModelImpl.getPlid()
1976 };
1977
1978 finderCache.putResult(FINDER_PATH_COUNT_BY_U_L_P, args,
1979 Long.valueOf(1));
1980 finderCache.putResult(FINDER_PATH_FETCH_BY_U_L_P, args,
1981 recentLayoutBranchModelImpl);
1982 }
1983 else {
1984 if ((recentLayoutBranchModelImpl.getColumnBitmask() &
1985 FINDER_PATH_FETCH_BY_U_L_P.getColumnBitmask()) != 0) {
1986 Object[] args = new Object[] {
1987 recentLayoutBranchModelImpl.getUserId(),
1988 recentLayoutBranchModelImpl.getLayoutSetBranchId(),
1989 recentLayoutBranchModelImpl.getPlid()
1990 };
1991
1992 finderCache.putResult(FINDER_PATH_COUNT_BY_U_L_P, args,
1993 Long.valueOf(1));
1994 finderCache.putResult(FINDER_PATH_FETCH_BY_U_L_P, args,
1995 recentLayoutBranchModelImpl);
1996 }
1997 }
1998 }
1999
2000 protected void clearUniqueFindersCache(
2001 RecentLayoutBranchModelImpl recentLayoutBranchModelImpl) {
2002 Object[] args = new Object[] {
2003 recentLayoutBranchModelImpl.getUserId(),
2004 recentLayoutBranchModelImpl.getLayoutSetBranchId(),
2005 recentLayoutBranchModelImpl.getPlid()
2006 };
2007
2008 finderCache.removeResult(FINDER_PATH_COUNT_BY_U_L_P, args);
2009 finderCache.removeResult(FINDER_PATH_FETCH_BY_U_L_P, args);
2010
2011 if ((recentLayoutBranchModelImpl.getColumnBitmask() &
2012 FINDER_PATH_FETCH_BY_U_L_P.getColumnBitmask()) != 0) {
2013 args = new Object[] {
2014 recentLayoutBranchModelImpl.getOriginalUserId(),
2015 recentLayoutBranchModelImpl.getOriginalLayoutSetBranchId(),
2016 recentLayoutBranchModelImpl.getOriginalPlid()
2017 };
2018
2019 finderCache.removeResult(FINDER_PATH_COUNT_BY_U_L_P, args);
2020 finderCache.removeResult(FINDER_PATH_FETCH_BY_U_L_P, args);
2021 }
2022 }
2023
2024
2030 @Override
2031 public RecentLayoutBranch create(long recentLayoutBranchId) {
2032 RecentLayoutBranch recentLayoutBranch = new RecentLayoutBranchImpl();
2033
2034 recentLayoutBranch.setNew(true);
2035 recentLayoutBranch.setPrimaryKey(recentLayoutBranchId);
2036
2037 recentLayoutBranch.setCompanyId(companyProvider.getCompanyId());
2038
2039 return recentLayoutBranch;
2040 }
2041
2042
2049 @Override
2050 public RecentLayoutBranch remove(long recentLayoutBranchId)
2051 throws NoSuchRecentLayoutBranchException {
2052 return remove((Serializable)recentLayoutBranchId);
2053 }
2054
2055
2062 @Override
2063 public RecentLayoutBranch remove(Serializable primaryKey)
2064 throws NoSuchRecentLayoutBranchException {
2065 Session session = null;
2066
2067 try {
2068 session = openSession();
2069
2070 RecentLayoutBranch recentLayoutBranch = (RecentLayoutBranch)session.get(RecentLayoutBranchImpl.class,
2071 primaryKey);
2072
2073 if (recentLayoutBranch == null) {
2074 if (_log.isDebugEnabled()) {
2075 _log.debug(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2076 }
2077
2078 throw new NoSuchRecentLayoutBranchException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2079 primaryKey);
2080 }
2081
2082 return remove(recentLayoutBranch);
2083 }
2084 catch (NoSuchRecentLayoutBranchException nsee) {
2085 throw nsee;
2086 }
2087 catch (Exception e) {
2088 throw processException(e);
2089 }
2090 finally {
2091 closeSession(session);
2092 }
2093 }
2094
2095 @Override
2096 protected RecentLayoutBranch removeImpl(
2097 RecentLayoutBranch recentLayoutBranch) {
2098 recentLayoutBranch = toUnwrappedModel(recentLayoutBranch);
2099
2100 Session session = null;
2101
2102 try {
2103 session = openSession();
2104
2105 if (!session.contains(recentLayoutBranch)) {
2106 recentLayoutBranch = (RecentLayoutBranch)session.get(RecentLayoutBranchImpl.class,
2107 recentLayoutBranch.getPrimaryKeyObj());
2108 }
2109
2110 if (recentLayoutBranch != null) {
2111 session.delete(recentLayoutBranch);
2112 }
2113 }
2114 catch (Exception e) {
2115 throw processException(e);
2116 }
2117 finally {
2118 closeSession(session);
2119 }
2120
2121 if (recentLayoutBranch != null) {
2122 clearCache(recentLayoutBranch);
2123 }
2124
2125 return recentLayoutBranch;
2126 }
2127
2128 @Override
2129 public RecentLayoutBranch updateImpl(RecentLayoutBranch recentLayoutBranch) {
2130 recentLayoutBranch = toUnwrappedModel(recentLayoutBranch);
2131
2132 boolean isNew = recentLayoutBranch.isNew();
2133
2134 RecentLayoutBranchModelImpl recentLayoutBranchModelImpl = (RecentLayoutBranchModelImpl)recentLayoutBranch;
2135
2136 Session session = null;
2137
2138 try {
2139 session = openSession();
2140
2141 if (recentLayoutBranch.isNew()) {
2142 session.save(recentLayoutBranch);
2143
2144 recentLayoutBranch.setNew(false);
2145 }
2146 else {
2147 recentLayoutBranch = (RecentLayoutBranch)session.merge(recentLayoutBranch);
2148 }
2149 }
2150 catch (Exception e) {
2151 throw processException(e);
2152 }
2153 finally {
2154 closeSession(session);
2155 }
2156
2157 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2158
2159 if (isNew || !RecentLayoutBranchModelImpl.COLUMN_BITMASK_ENABLED) {
2160 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2161 }
2162
2163 else {
2164 if ((recentLayoutBranchModelImpl.getColumnBitmask() &
2165 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
2166 Object[] args = new Object[] {
2167 recentLayoutBranchModelImpl.getOriginalGroupId()
2168 };
2169
2170 finderCache.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
2171 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
2172 args);
2173
2174 args = new Object[] { recentLayoutBranchModelImpl.getGroupId() };
2175
2176 finderCache.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
2177 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
2178 args);
2179 }
2180
2181 if ((recentLayoutBranchModelImpl.getColumnBitmask() &
2182 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
2183 Object[] args = new Object[] {
2184 recentLayoutBranchModelImpl.getOriginalUserId()
2185 };
2186
2187 finderCache.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
2188 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
2189 args);
2190
2191 args = new Object[] { recentLayoutBranchModelImpl.getUserId() };
2192
2193 finderCache.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
2194 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
2195 args);
2196 }
2197
2198 if ((recentLayoutBranchModelImpl.getColumnBitmask() &
2199 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LAYOUTBRANCHID.getColumnBitmask()) != 0) {
2200 Object[] args = new Object[] {
2201 recentLayoutBranchModelImpl.getOriginalLayoutBranchId()
2202 };
2203
2204 finderCache.removeResult(FINDER_PATH_COUNT_BY_LAYOUTBRANCHID,
2205 args);
2206 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LAYOUTBRANCHID,
2207 args);
2208
2209 args = new Object[] {
2210 recentLayoutBranchModelImpl.getLayoutBranchId()
2211 };
2212
2213 finderCache.removeResult(FINDER_PATH_COUNT_BY_LAYOUTBRANCHID,
2214 args);
2215 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LAYOUTBRANCHID,
2216 args);
2217 }
2218 }
2219
2220 entityCache.putResult(RecentLayoutBranchModelImpl.ENTITY_CACHE_ENABLED,
2221 RecentLayoutBranchImpl.class, recentLayoutBranch.getPrimaryKey(),
2222 recentLayoutBranch, false);
2223
2224 clearUniqueFindersCache(recentLayoutBranchModelImpl);
2225 cacheUniqueFindersCache(recentLayoutBranchModelImpl, isNew);
2226
2227 recentLayoutBranch.resetOriginalValues();
2228
2229 return recentLayoutBranch;
2230 }
2231
2232 protected RecentLayoutBranch toUnwrappedModel(
2233 RecentLayoutBranch recentLayoutBranch) {
2234 if (recentLayoutBranch instanceof RecentLayoutBranchImpl) {
2235 return recentLayoutBranch;
2236 }
2237
2238 RecentLayoutBranchImpl recentLayoutBranchImpl = new RecentLayoutBranchImpl();
2239
2240 recentLayoutBranchImpl.setNew(recentLayoutBranch.isNew());
2241 recentLayoutBranchImpl.setPrimaryKey(recentLayoutBranch.getPrimaryKey());
2242
2243 recentLayoutBranchImpl.setMvccVersion(recentLayoutBranch.getMvccVersion());
2244 recentLayoutBranchImpl.setRecentLayoutBranchId(recentLayoutBranch.getRecentLayoutBranchId());
2245 recentLayoutBranchImpl.setGroupId(recentLayoutBranch.getGroupId());
2246 recentLayoutBranchImpl.setCompanyId(recentLayoutBranch.getCompanyId());
2247 recentLayoutBranchImpl.setUserId(recentLayoutBranch.getUserId());
2248 recentLayoutBranchImpl.setLayoutBranchId(recentLayoutBranch.getLayoutBranchId());
2249 recentLayoutBranchImpl.setLayoutSetBranchId(recentLayoutBranch.getLayoutSetBranchId());
2250 recentLayoutBranchImpl.setPlid(recentLayoutBranch.getPlid());
2251
2252 return recentLayoutBranchImpl;
2253 }
2254
2255
2262 @Override
2263 public RecentLayoutBranch findByPrimaryKey(Serializable primaryKey)
2264 throws NoSuchRecentLayoutBranchException {
2265 RecentLayoutBranch recentLayoutBranch = fetchByPrimaryKey(primaryKey);
2266
2267 if (recentLayoutBranch == null) {
2268 if (_log.isDebugEnabled()) {
2269 _log.debug(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2270 }
2271
2272 throw new NoSuchRecentLayoutBranchException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2273 primaryKey);
2274 }
2275
2276 return recentLayoutBranch;
2277 }
2278
2279
2286 @Override
2287 public RecentLayoutBranch findByPrimaryKey(long recentLayoutBranchId)
2288 throws NoSuchRecentLayoutBranchException {
2289 return findByPrimaryKey((Serializable)recentLayoutBranchId);
2290 }
2291
2292
2298 @Override
2299 public RecentLayoutBranch fetchByPrimaryKey(Serializable primaryKey) {
2300 RecentLayoutBranch recentLayoutBranch = (RecentLayoutBranch)entityCache.getResult(RecentLayoutBranchModelImpl.ENTITY_CACHE_ENABLED,
2301 RecentLayoutBranchImpl.class, primaryKey);
2302
2303 if (recentLayoutBranch == _nullRecentLayoutBranch) {
2304 return null;
2305 }
2306
2307 if (recentLayoutBranch == null) {
2308 Session session = null;
2309
2310 try {
2311 session = openSession();
2312
2313 recentLayoutBranch = (RecentLayoutBranch)session.get(RecentLayoutBranchImpl.class,
2314 primaryKey);
2315
2316 if (recentLayoutBranch != null) {
2317 cacheResult(recentLayoutBranch);
2318 }
2319 else {
2320 entityCache.putResult(RecentLayoutBranchModelImpl.ENTITY_CACHE_ENABLED,
2321 RecentLayoutBranchImpl.class, primaryKey,
2322 _nullRecentLayoutBranch);
2323 }
2324 }
2325 catch (Exception e) {
2326 entityCache.removeResult(RecentLayoutBranchModelImpl.ENTITY_CACHE_ENABLED,
2327 RecentLayoutBranchImpl.class, primaryKey);
2328
2329 throw processException(e);
2330 }
2331 finally {
2332 closeSession(session);
2333 }
2334 }
2335
2336 return recentLayoutBranch;
2337 }
2338
2339
2345 @Override
2346 public RecentLayoutBranch fetchByPrimaryKey(long recentLayoutBranchId) {
2347 return fetchByPrimaryKey((Serializable)recentLayoutBranchId);
2348 }
2349
2350 @Override
2351 public Map<Serializable, RecentLayoutBranch> fetchByPrimaryKeys(
2352 Set<Serializable> primaryKeys) {
2353 if (primaryKeys.isEmpty()) {
2354 return Collections.emptyMap();
2355 }
2356
2357 Map<Serializable, RecentLayoutBranch> map = new HashMap<Serializable, RecentLayoutBranch>();
2358
2359 if (primaryKeys.size() == 1) {
2360 Iterator<Serializable> iterator = primaryKeys.iterator();
2361
2362 Serializable primaryKey = iterator.next();
2363
2364 RecentLayoutBranch recentLayoutBranch = fetchByPrimaryKey(primaryKey);
2365
2366 if (recentLayoutBranch != null) {
2367 map.put(primaryKey, recentLayoutBranch);
2368 }
2369
2370 return map;
2371 }
2372
2373 Set<Serializable> uncachedPrimaryKeys = null;
2374
2375 for (Serializable primaryKey : primaryKeys) {
2376 RecentLayoutBranch recentLayoutBranch = (RecentLayoutBranch)entityCache.getResult(RecentLayoutBranchModelImpl.ENTITY_CACHE_ENABLED,
2377 RecentLayoutBranchImpl.class, primaryKey);
2378
2379 if (recentLayoutBranch == null) {
2380 if (uncachedPrimaryKeys == null) {
2381 uncachedPrimaryKeys = new HashSet<Serializable>();
2382 }
2383
2384 uncachedPrimaryKeys.add(primaryKey);
2385 }
2386 else {
2387 map.put(primaryKey, recentLayoutBranch);
2388 }
2389 }
2390
2391 if (uncachedPrimaryKeys == null) {
2392 return map;
2393 }
2394
2395 StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
2396 1);
2397
2398 query.append(_SQL_SELECT_RECENTLAYOUTBRANCH_WHERE_PKS_IN);
2399
2400 for (Serializable primaryKey : uncachedPrimaryKeys) {
2401 query.append(String.valueOf(primaryKey));
2402
2403 query.append(StringPool.COMMA);
2404 }
2405
2406 query.setIndex(query.index() - 1);
2407
2408 query.append(StringPool.CLOSE_PARENTHESIS);
2409
2410 String sql = query.toString();
2411
2412 Session session = null;
2413
2414 try {
2415 session = openSession();
2416
2417 Query q = session.createQuery(sql);
2418
2419 for (RecentLayoutBranch recentLayoutBranch : (List<RecentLayoutBranch>)q.list()) {
2420 map.put(recentLayoutBranch.getPrimaryKeyObj(),
2421 recentLayoutBranch);
2422
2423 cacheResult(recentLayoutBranch);
2424
2425 uncachedPrimaryKeys.remove(recentLayoutBranch.getPrimaryKeyObj());
2426 }
2427
2428 for (Serializable primaryKey : uncachedPrimaryKeys) {
2429 entityCache.putResult(RecentLayoutBranchModelImpl.ENTITY_CACHE_ENABLED,
2430 RecentLayoutBranchImpl.class, primaryKey,
2431 _nullRecentLayoutBranch);
2432 }
2433 }
2434 catch (Exception e) {
2435 throw processException(e);
2436 }
2437 finally {
2438 closeSession(session);
2439 }
2440
2441 return map;
2442 }
2443
2444
2449 @Override
2450 public List<RecentLayoutBranch> findAll() {
2451 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2452 }
2453
2454
2465 @Override
2466 public List<RecentLayoutBranch> findAll(int start, int end) {
2467 return findAll(start, end, null);
2468 }
2469
2470
2482 @Override
2483 public List<RecentLayoutBranch> findAll(int start, int end,
2484 OrderByComparator<RecentLayoutBranch> orderByComparator) {
2485 return findAll(start, end, orderByComparator, true);
2486 }
2487
2488
2501 @Override
2502 public List<RecentLayoutBranch> findAll(int start, int end,
2503 OrderByComparator<RecentLayoutBranch> orderByComparator,
2504 boolean retrieveFromCache) {
2505 boolean pagination = true;
2506 FinderPath finderPath = null;
2507 Object[] finderArgs = null;
2508
2509 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2510 (orderByComparator == null)) {
2511 pagination = false;
2512 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2513 finderArgs = FINDER_ARGS_EMPTY;
2514 }
2515 else {
2516 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2517 finderArgs = new Object[] { start, end, orderByComparator };
2518 }
2519
2520 List<RecentLayoutBranch> list = null;
2521
2522 if (retrieveFromCache) {
2523 list = (List<RecentLayoutBranch>)finderCache.getResult(finderPath,
2524 finderArgs, this);
2525 }
2526
2527 if (list == null) {
2528 StringBundler query = null;
2529 String sql = null;
2530
2531 if (orderByComparator != null) {
2532 query = new StringBundler(2 +
2533 (orderByComparator.getOrderByFields().length * 2));
2534
2535 query.append(_SQL_SELECT_RECENTLAYOUTBRANCH);
2536
2537 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2538 orderByComparator);
2539
2540 sql = query.toString();
2541 }
2542 else {
2543 sql = _SQL_SELECT_RECENTLAYOUTBRANCH;
2544
2545 if (pagination) {
2546 sql = sql.concat(RecentLayoutBranchModelImpl.ORDER_BY_JPQL);
2547 }
2548 }
2549
2550 Session session = null;
2551
2552 try {
2553 session = openSession();
2554
2555 Query q = session.createQuery(sql);
2556
2557 if (!pagination) {
2558 list = (List<RecentLayoutBranch>)QueryUtil.list(q,
2559 getDialect(), start, end, false);
2560
2561 Collections.sort(list);
2562
2563 list = Collections.unmodifiableList(list);
2564 }
2565 else {
2566 list = (List<RecentLayoutBranch>)QueryUtil.list(q,
2567 getDialect(), start, end);
2568 }
2569
2570 cacheResult(list);
2571
2572 finderCache.putResult(finderPath, finderArgs, list);
2573 }
2574 catch (Exception e) {
2575 finderCache.removeResult(finderPath, finderArgs);
2576
2577 throw processException(e);
2578 }
2579 finally {
2580 closeSession(session);
2581 }
2582 }
2583
2584 return list;
2585 }
2586
2587
2591 @Override
2592 public void removeAll() {
2593 for (RecentLayoutBranch recentLayoutBranch : findAll()) {
2594 remove(recentLayoutBranch);
2595 }
2596 }
2597
2598
2603 @Override
2604 public int countAll() {
2605 Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
2606 FINDER_ARGS_EMPTY, this);
2607
2608 if (count == null) {
2609 Session session = null;
2610
2611 try {
2612 session = openSession();
2613
2614 Query q = session.createQuery(_SQL_COUNT_RECENTLAYOUTBRANCH);
2615
2616 count = (Long)q.uniqueResult();
2617
2618 finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
2619 count);
2620 }
2621 catch (Exception e) {
2622 finderCache.removeResult(FINDER_PATH_COUNT_ALL,
2623 FINDER_ARGS_EMPTY);
2624
2625 throw processException(e);
2626 }
2627 finally {
2628 closeSession(session);
2629 }
2630 }
2631
2632 return count.intValue();
2633 }
2634
2635 @Override
2636 protected Map<String, Integer> getTableColumnsMap() {
2637 return RecentLayoutBranchModelImpl.TABLE_COLUMNS_MAP;
2638 }
2639
2640
2643 public void afterPropertiesSet() {
2644 }
2645
2646 public void destroy() {
2647 entityCache.removeCache(RecentLayoutBranchImpl.class.getName());
2648 finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
2649 finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2650 finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2651 }
2652
2653 @BeanReference(type = CompanyProviderWrapper.class)
2654 protected CompanyProvider companyProvider;
2655 protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
2656 protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
2657 private static final String _SQL_SELECT_RECENTLAYOUTBRANCH = "SELECT recentLayoutBranch FROM RecentLayoutBranch recentLayoutBranch";
2658 private static final String _SQL_SELECT_RECENTLAYOUTBRANCH_WHERE_PKS_IN = "SELECT recentLayoutBranch FROM RecentLayoutBranch recentLayoutBranch WHERE recentLayoutBranchId IN (";
2659 private static final String _SQL_SELECT_RECENTLAYOUTBRANCH_WHERE = "SELECT recentLayoutBranch FROM RecentLayoutBranch recentLayoutBranch WHERE ";
2660 private static final String _SQL_COUNT_RECENTLAYOUTBRANCH = "SELECT COUNT(recentLayoutBranch) FROM RecentLayoutBranch recentLayoutBranch";
2661 private static final String _SQL_COUNT_RECENTLAYOUTBRANCH_WHERE = "SELECT COUNT(recentLayoutBranch) FROM RecentLayoutBranch recentLayoutBranch WHERE ";
2662 private static final String _ORDER_BY_ENTITY_ALIAS = "recentLayoutBranch.";
2663 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No RecentLayoutBranch exists with the primary key ";
2664 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No RecentLayoutBranch exists with the key {";
2665 private static final Log _log = LogFactoryUtil.getLog(RecentLayoutBranchPersistenceImpl.class);
2666 private static final RecentLayoutBranch _nullRecentLayoutBranch = new RecentLayoutBranchImpl() {
2667 @Override
2668 public Object clone() {
2669 return this;
2670 }
2671
2672 @Override
2673 public CacheModel<RecentLayoutBranch> toCacheModel() {
2674 return _nullRecentLayoutBranchCacheModel;
2675 }
2676 };
2677
2678 private static final CacheModel<RecentLayoutBranch> _nullRecentLayoutBranchCacheModel =
2679 new NullCacheModel();
2680
2681 private static class NullCacheModel implements CacheModel<RecentLayoutBranch>,
2682 MVCCModel {
2683 @Override
2684 public long getMvccVersion() {
2685 return -1;
2686 }
2687
2688 @Override
2689 public void setMvccVersion(long mvccVersion) {
2690 }
2691
2692 @Override
2693 public RecentLayoutBranch toEntityModel() {
2694 return _nullRecentLayoutBranch;
2695 }
2696 }
2697 }