001
014
015 package com.liferay.portal.service.persistence.impl;
016
017 import aQute.bnd.annotation.ProviderType;
018
019 import com.liferay.portal.exception.NoSuchRecentLayoutBranchException;
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.RecentLayoutBranch;
038 import com.liferay.portal.model.impl.RecentLayoutBranchImpl;
039 import com.liferay.portal.model.impl.RecentLayoutBranchModelImpl;
040 import com.liferay.portal.service.persistence.CompanyProvider;
041 import com.liferay.portal.service.persistence.CompanyProviderWrapper;
042 import com.liferay.portal.service.persistence.RecentLayoutBranchPersistence;
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 RecentLayoutBranchPersistenceImpl extends BasePersistenceImpl<RecentLayoutBranch>
068 implements RecentLayoutBranchPersistence {
069
074 public static final String FINDER_CLASS_NAME_ENTITY = RecentLayoutBranchImpl.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(RecentLayoutBranchModelImpl.ENTITY_CACHE_ENABLED,
080 RecentLayoutBranchModelImpl.FINDER_CACHE_ENABLED,
081 RecentLayoutBranchImpl.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(RecentLayoutBranchModelImpl.ENTITY_CACHE_ENABLED,
084 RecentLayoutBranchModelImpl.FINDER_CACHE_ENABLED,
085 RecentLayoutBranchImpl.class,
086 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
087 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(RecentLayoutBranchModelImpl.ENTITY_CACHE_ENABLED,
088 RecentLayoutBranchModelImpl.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(RecentLayoutBranchModelImpl.ENTITY_CACHE_ENABLED,
091 RecentLayoutBranchModelImpl.FINDER_CACHE_ENABLED,
092 RecentLayoutBranchImpl.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(RecentLayoutBranchModelImpl.ENTITY_CACHE_ENABLED,
102 RecentLayoutBranchModelImpl.FINDER_CACHE_ENABLED,
103 RecentLayoutBranchImpl.class,
104 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
105 new String[] { Long.class.getName() },
106 RecentLayoutBranchModelImpl.GROUPID_COLUMN_BITMASK);
107 public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(RecentLayoutBranchModelImpl.ENTITY_CACHE_ENABLED,
108 RecentLayoutBranchModelImpl.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<RecentLayoutBranch> findByGroupId(long groupId) {
120 return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
121 }
122
123
135 @Override
136 public List<RecentLayoutBranch> findByGroupId(long groupId, int start,
137 int end) {
138 return findByGroupId(groupId, start, end, null);
139 }
140
141
154 @Override
155 public List<RecentLayoutBranch> findByGroupId(long groupId, int start,
156 int end, OrderByComparator<RecentLayoutBranch> orderByComparator) {
157 return findByGroupId(groupId, start, end, orderByComparator, true);
158 }
159
160
174 @Override
175 public List<RecentLayoutBranch> findByGroupId(long groupId, int start,
176 int end, OrderByComparator<RecentLayoutBranch> 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<RecentLayoutBranch> list = null;
194
195 if (retrieveFromCache) {
196 list = (List<RecentLayoutBranch>)finderCache.getResult(finderPath,
197 finderArgs, this);
198
199 if ((list != null) && !list.isEmpty()) {
200 for (RecentLayoutBranch recentLayoutBranch : list) {
201 if ((groupId != recentLayoutBranch.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 * 2));
216 }
217 else {
218 query = new StringBundler(3);
219 }
220
221 query.append(_SQL_SELECT_RECENTLAYOUTBRANCH_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(RecentLayoutBranchModelImpl.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<RecentLayoutBranch>)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<RecentLayoutBranch>)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 RecentLayoutBranch findByGroupId_First(long groupId,
287 OrderByComparator<RecentLayoutBranch> orderByComparator)
288 throws NoSuchRecentLayoutBranchException {
289 RecentLayoutBranch recentLayoutBranch = fetchByGroupId_First(groupId,
290 orderByComparator);
291
292 if (recentLayoutBranch != null) {
293 return recentLayoutBranch;
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 NoSuchRecentLayoutBranchException(msg.toString());
306 }
307
308
315 @Override
316 public RecentLayoutBranch fetchByGroupId_First(long groupId,
317 OrderByComparator<RecentLayoutBranch> orderByComparator) {
318 List<RecentLayoutBranch> 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 RecentLayoutBranch findByGroupId_Last(long groupId,
338 OrderByComparator<RecentLayoutBranch> orderByComparator)
339 throws NoSuchRecentLayoutBranchException {
340 RecentLayoutBranch recentLayoutBranch = fetchByGroupId_Last(groupId,
341 orderByComparator);
342
343 if (recentLayoutBranch != null) {
344 return recentLayoutBranch;
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 NoSuchRecentLayoutBranchException(msg.toString());
357 }
358
359
366 @Override
367 public RecentLayoutBranch fetchByGroupId_Last(long groupId,
368 OrderByComparator<RecentLayoutBranch> orderByComparator) {
369 int count = countByGroupId(groupId);
370
371 if (count == 0) {
372 return null;
373 }
374
375 List<RecentLayoutBranch> 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 RecentLayoutBranch[] findByGroupId_PrevAndNext(
396 long recentLayoutBranchId, long groupId,
397 OrderByComparator<RecentLayoutBranch> orderByComparator)
398 throws NoSuchRecentLayoutBranchException {
399 RecentLayoutBranch recentLayoutBranch = findByPrimaryKey(recentLayoutBranchId);
400
401 Session session = null;
402
403 try {
404 session = openSession();
405
406 RecentLayoutBranch[] array = new RecentLayoutBranchImpl[3];
407
408 array[0] = getByGroupId_PrevAndNext(session, recentLayoutBranch,
409 groupId, orderByComparator, true);
410
411 array[1] = recentLayoutBranch;
412
413 array[2] = getByGroupId_PrevAndNext(session, recentLayoutBranch,
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 RecentLayoutBranch getByGroupId_PrevAndNext(Session session,
427 RecentLayoutBranch recentLayoutBranch, long groupId,
428 OrderByComparator<RecentLayoutBranch> orderByComparator,
429 boolean previous) {
430 StringBundler query = null;
431
432 if (orderByComparator != null) {
433 query = new StringBundler(4 +
434 (orderByComparator.getOrderByConditionFields().length * 3) +
435 (orderByComparator.getOrderByFields().length * 3));
436 }
437 else {
438 query = new StringBundler(3);
439 }
440
441 query.append(_SQL_SELECT_RECENTLAYOUTBRANCH_WHERE);
442
443 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
444
445 if (orderByComparator != null) {
446 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
447
448 if (orderByConditionFields.length > 0) {
449 query.append(WHERE_AND);
450 }
451
452 for (int i = 0; i < orderByConditionFields.length; i++) {
453 query.append(_ORDER_BY_ENTITY_ALIAS);
454 query.append(orderByConditionFields[i]);
455
456 if ((i + 1) < orderByConditionFields.length) {
457 if (orderByComparator.isAscending() ^ previous) {
458 query.append(WHERE_GREATER_THAN_HAS_NEXT);
459 }
460 else {
461 query.append(WHERE_LESSER_THAN_HAS_NEXT);
462 }
463 }
464 else {
465 if (orderByComparator.isAscending() ^ previous) {
466 query.append(WHERE_GREATER_THAN);
467 }
468 else {
469 query.append(WHERE_LESSER_THAN);
470 }
471 }
472 }
473
474 query.append(ORDER_BY_CLAUSE);
475
476 String[] orderByFields = orderByComparator.getOrderByFields();
477
478 for (int i = 0; i < orderByFields.length; i++) {
479 query.append(_ORDER_BY_ENTITY_ALIAS);
480 query.append(orderByFields[i]);
481
482 if ((i + 1) < orderByFields.length) {
483 if (orderByComparator.isAscending() ^ previous) {
484 query.append(ORDER_BY_ASC_HAS_NEXT);
485 }
486 else {
487 query.append(ORDER_BY_DESC_HAS_NEXT);
488 }
489 }
490 else {
491 if (orderByComparator.isAscending() ^ previous) {
492 query.append(ORDER_BY_ASC);
493 }
494 else {
495 query.append(ORDER_BY_DESC);
496 }
497 }
498 }
499 }
500 else {
501 query.append(RecentLayoutBranchModelImpl.ORDER_BY_JPQL);
502 }
503
504 String sql = query.toString();
505
506 Query q = session.createQuery(sql);
507
508 q.setFirstResult(0);
509 q.setMaxResults(2);
510
511 QueryPos qPos = QueryPos.getInstance(q);
512
513 qPos.add(groupId);
514
515 if (orderByComparator != null) {
516 Object[] values = orderByComparator.getOrderByConditionValues(recentLayoutBranch);
517
518 for (Object value : values) {
519 qPos.add(value);
520 }
521 }
522
523 List<RecentLayoutBranch> list = q.list();
524
525 if (list.size() == 2) {
526 return list.get(1);
527 }
528 else {
529 return null;
530 }
531 }
532
533
538 @Override
539 public void removeByGroupId(long groupId) {
540 for (RecentLayoutBranch recentLayoutBranch : findByGroupId(groupId,
541 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
542 remove(recentLayoutBranch);
543 }
544 }
545
546
552 @Override
553 public int countByGroupId(long groupId) {
554 FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
555
556 Object[] finderArgs = new Object[] { groupId };
557
558 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
559
560 if (count == null) {
561 StringBundler query = new StringBundler(2);
562
563 query.append(_SQL_COUNT_RECENTLAYOUTBRANCH_WHERE);
564
565 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
566
567 String sql = query.toString();
568
569 Session session = null;
570
571 try {
572 session = openSession();
573
574 Query q = session.createQuery(sql);
575
576 QueryPos qPos = QueryPos.getInstance(q);
577
578 qPos.add(groupId);
579
580 count = (Long)q.uniqueResult();
581
582 finderCache.putResult(finderPath, finderArgs, count);
583 }
584 catch (Exception e) {
585 finderCache.removeResult(finderPath, finderArgs);
586
587 throw processException(e);
588 }
589 finally {
590 closeSession(session);
591 }
592 }
593
594 return count.intValue();
595 }
596
597 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "recentLayoutBranch.groupId = ?";
598 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(RecentLayoutBranchModelImpl.ENTITY_CACHE_ENABLED,
599 RecentLayoutBranchModelImpl.FINDER_CACHE_ENABLED,
600 RecentLayoutBranchImpl.class,
601 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUserId",
602 new String[] {
603 Long.class.getName(),
604
605 Integer.class.getName(), Integer.class.getName(),
606 OrderByComparator.class.getName()
607 });
608 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID =
609 new FinderPath(RecentLayoutBranchModelImpl.ENTITY_CACHE_ENABLED,
610 RecentLayoutBranchModelImpl.FINDER_CACHE_ENABLED,
611 RecentLayoutBranchImpl.class,
612 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId",
613 new String[] { Long.class.getName() },
614 RecentLayoutBranchModelImpl.USERID_COLUMN_BITMASK);
615 public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(RecentLayoutBranchModelImpl.ENTITY_CACHE_ENABLED,
616 RecentLayoutBranchModelImpl.FINDER_CACHE_ENABLED, Long.class,
617 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
618 new String[] { Long.class.getName() });
619
620
626 @Override
627 public List<RecentLayoutBranch> findByUserId(long userId) {
628 return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
629 }
630
631
643 @Override
644 public List<RecentLayoutBranch> findByUserId(long userId, int start, int end) {
645 return findByUserId(userId, start, end, null);
646 }
647
648
661 @Override
662 public List<RecentLayoutBranch> findByUserId(long userId, int start,
663 int end, OrderByComparator<RecentLayoutBranch> orderByComparator) {
664 return findByUserId(userId, start, end, orderByComparator, true);
665 }
666
667
681 @Override
682 public List<RecentLayoutBranch> findByUserId(long userId, int start,
683 int end, OrderByComparator<RecentLayoutBranch> 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<RecentLayoutBranch> list = null;
701
702 if (retrieveFromCache) {
703 list = (List<RecentLayoutBranch>)finderCache.getResult(finderPath,
704 finderArgs, this);
705
706 if ((list != null) && !list.isEmpty()) {
707 for (RecentLayoutBranch recentLayoutBranch : list) {
708 if ((userId != recentLayoutBranch.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 * 2));
723 }
724 else {
725 query = new StringBundler(3);
726 }
727
728 query.append(_SQL_SELECT_RECENTLAYOUTBRANCH_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(RecentLayoutBranchModelImpl.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<RecentLayoutBranch>)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<RecentLayoutBranch>)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 RecentLayoutBranch findByUserId_First(long userId,
794 OrderByComparator<RecentLayoutBranch> orderByComparator)
795 throws NoSuchRecentLayoutBranchException {
796 RecentLayoutBranch recentLayoutBranch = fetchByUserId_First(userId,
797 orderByComparator);
798
799 if (recentLayoutBranch != null) {
800 return recentLayoutBranch;
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 NoSuchRecentLayoutBranchException(msg.toString());
813 }
814
815
822 @Override
823 public RecentLayoutBranch fetchByUserId_First(long userId,
824 OrderByComparator<RecentLayoutBranch> orderByComparator) {
825 List<RecentLayoutBranch> 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 RecentLayoutBranch findByUserId_Last(long userId,
845 OrderByComparator<RecentLayoutBranch> orderByComparator)
846 throws NoSuchRecentLayoutBranchException {
847 RecentLayoutBranch recentLayoutBranch = fetchByUserId_Last(userId,
848 orderByComparator);
849
850 if (recentLayoutBranch != null) {
851 return recentLayoutBranch;
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 NoSuchRecentLayoutBranchException(msg.toString());
864 }
865
866
873 @Override
874 public RecentLayoutBranch fetchByUserId_Last(long userId,
875 OrderByComparator<RecentLayoutBranch> orderByComparator) {
876 int count = countByUserId(userId);
877
878 if (count == 0) {
879 return null;
880 }
881
882 List<RecentLayoutBranch> list = findByUserId(userId, count - 1, count,
883 orderByComparator);
884
885 if (!list.isEmpty()) {
886 return list.get(0);
887 }
888
889 return null;
890 }
891
892
901 @Override
902 public RecentLayoutBranch[] findByUserId_PrevAndNext(
903 long recentLayoutBranchId, long userId,
904 OrderByComparator<RecentLayoutBranch> orderByComparator)
905 throws NoSuchRecentLayoutBranchException {
906 RecentLayoutBranch recentLayoutBranch = findByPrimaryKey(recentLayoutBranchId);
907
908 Session session = null;
909
910 try {
911 session = openSession();
912
913 RecentLayoutBranch[] array = new RecentLayoutBranchImpl[3];
914
915 array[0] = getByUserId_PrevAndNext(session, recentLayoutBranch,
916 userId, orderByComparator, true);
917
918 array[1] = recentLayoutBranch;
919
920 array[2] = getByUserId_PrevAndNext(session, recentLayoutBranch,
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 RecentLayoutBranch getByUserId_PrevAndNext(Session session,
934 RecentLayoutBranch recentLayoutBranch, long userId,
935 OrderByComparator<RecentLayoutBranch> orderByComparator,
936 boolean previous) {
937 StringBundler query = null;
938
939 if (orderByComparator != null) {
940 query = new StringBundler(4 +
941 (orderByComparator.getOrderByConditionFields().length * 3) +
942 (orderByComparator.getOrderByFields().length * 3));
943 }
944 else {
945 query = new StringBundler(3);
946 }
947
948 query.append(_SQL_SELECT_RECENTLAYOUTBRANCH_WHERE);
949
950 query.append(_FINDER_COLUMN_USERID_USERID_2);
951
952 if (orderByComparator != null) {
953 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
954
955 if (orderByConditionFields.length > 0) {
956 query.append(WHERE_AND);
957 }
958
959 for (int i = 0; i < orderByConditionFields.length; i++) {
960 query.append(_ORDER_BY_ENTITY_ALIAS);
961 query.append(orderByConditionFields[i]);
962
963 if ((i + 1) < orderByConditionFields.length) {
964 if (orderByComparator.isAscending() ^ previous) {
965 query.append(WHERE_GREATER_THAN_HAS_NEXT);
966 }
967 else {
968 query.append(WHERE_LESSER_THAN_HAS_NEXT);
969 }
970 }
971 else {
972 if (orderByComparator.isAscending() ^ previous) {
973 query.append(WHERE_GREATER_THAN);
974 }
975 else {
976 query.append(WHERE_LESSER_THAN);
977 }
978 }
979 }
980
981 query.append(ORDER_BY_CLAUSE);
982
983 String[] orderByFields = orderByComparator.getOrderByFields();
984
985 for (int i = 0; i < orderByFields.length; i++) {
986 query.append(_ORDER_BY_ENTITY_ALIAS);
987 query.append(orderByFields[i]);
988
989 if ((i + 1) < orderByFields.length) {
990 if (orderByComparator.isAscending() ^ previous) {
991 query.append(ORDER_BY_ASC_HAS_NEXT);
992 }
993 else {
994 query.append(ORDER_BY_DESC_HAS_NEXT);
995 }
996 }
997 else {
998 if (orderByComparator.isAscending() ^ previous) {
999 query.append(ORDER_BY_ASC);
1000 }
1001 else {
1002 query.append(ORDER_BY_DESC);
1003 }
1004 }
1005 }
1006 }
1007 else {
1008 query.append(RecentLayoutBranchModelImpl.ORDER_BY_JPQL);
1009 }
1010
1011 String sql = query.toString();
1012
1013 Query q = session.createQuery(sql);
1014
1015 q.setFirstResult(0);
1016 q.setMaxResults(2);
1017
1018 QueryPos qPos = QueryPos.getInstance(q);
1019
1020 qPos.add(userId);
1021
1022 if (orderByComparator != null) {
1023 Object[] values = orderByComparator.getOrderByConditionValues(recentLayoutBranch);
1024
1025 for (Object value : values) {
1026 qPos.add(value);
1027 }
1028 }
1029
1030 List<RecentLayoutBranch> list = q.list();
1031
1032 if (list.size() == 2) {
1033 return list.get(1);
1034 }
1035 else {
1036 return null;
1037 }
1038 }
1039
1040
1045 @Override
1046 public void removeByUserId(long userId) {
1047 for (RecentLayoutBranch recentLayoutBranch : findByUserId(userId,
1048 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1049 remove(recentLayoutBranch);
1050 }
1051 }
1052
1053
1059 @Override
1060 public int countByUserId(long userId) {
1061 FinderPath finderPath = FINDER_PATH_COUNT_BY_USERID;
1062
1063 Object[] finderArgs = new Object[] { userId };
1064
1065 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1066
1067 if (count == null) {
1068 StringBundler query = new StringBundler(2);
1069
1070 query.append(_SQL_COUNT_RECENTLAYOUTBRANCH_WHERE);
1071
1072 query.append(_FINDER_COLUMN_USERID_USERID_2);
1073
1074 String sql = query.toString();
1075
1076 Session session = null;
1077
1078 try {
1079 session = openSession();
1080
1081 Query q = session.createQuery(sql);
1082
1083 QueryPos qPos = QueryPos.getInstance(q);
1084
1085 qPos.add(userId);
1086
1087 count = (Long)q.uniqueResult();
1088
1089 finderCache.putResult(finderPath, finderArgs, count);
1090 }
1091 catch (Exception e) {
1092 finderCache.removeResult(finderPath, finderArgs);
1093
1094 throw processException(e);
1095 }
1096 finally {
1097 closeSession(session);
1098 }
1099 }
1100
1101 return count.intValue();
1102 }
1103
1104 private static final String _FINDER_COLUMN_USERID_USERID_2 = "recentLayoutBranch.userId = ?";
1105 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_LAYOUTBRANCHID =
1106 new FinderPath(RecentLayoutBranchModelImpl.ENTITY_CACHE_ENABLED,
1107 RecentLayoutBranchModelImpl.FINDER_CACHE_ENABLED,
1108 RecentLayoutBranchImpl.class,
1109 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByLayoutBranchId",
1110 new String[] {
1111 Long.class.getName(),
1112
1113 Integer.class.getName(), Integer.class.getName(),
1114 OrderByComparator.class.getName()
1115 });
1116 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LAYOUTBRANCHID =
1117 new FinderPath(RecentLayoutBranchModelImpl.ENTITY_CACHE_ENABLED,
1118 RecentLayoutBranchModelImpl.FINDER_CACHE_ENABLED,
1119 RecentLayoutBranchImpl.class,
1120 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByLayoutBranchId",
1121 new String[] { Long.class.getName() },
1122 RecentLayoutBranchModelImpl.LAYOUTBRANCHID_COLUMN_BITMASK);
1123 public static final FinderPath FINDER_PATH_COUNT_BY_LAYOUTBRANCHID = new FinderPath(RecentLayoutBranchModelImpl.ENTITY_CACHE_ENABLED,
1124 RecentLayoutBranchModelImpl.FINDER_CACHE_ENABLED, Long.class,
1125 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByLayoutBranchId",
1126 new String[] { Long.class.getName() });
1127
1128
1134 @Override
1135 public List<RecentLayoutBranch> findByLayoutBranchId(long layoutBranchId) {
1136 return findByLayoutBranchId(layoutBranchId, QueryUtil.ALL_POS,
1137 QueryUtil.ALL_POS, null);
1138 }
1139
1140
1152 @Override
1153 public List<RecentLayoutBranch> findByLayoutBranchId(long layoutBranchId,
1154 int start, int end) {
1155 return findByLayoutBranchId(layoutBranchId, start, end, null);
1156 }
1157
1158
1171 @Override
1172 public List<RecentLayoutBranch> findByLayoutBranchId(long layoutBranchId,
1173 int start, int end,
1174 OrderByComparator<RecentLayoutBranch> orderByComparator) {
1175 return findByLayoutBranchId(layoutBranchId, start, end,
1176 orderByComparator, true);
1177 }
1178
1179
1193 @Override
1194 public List<RecentLayoutBranch> findByLayoutBranchId(long layoutBranchId,
1195 int start, int end,
1196 OrderByComparator<RecentLayoutBranch> 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_LAYOUTBRANCHID;
1206 finderArgs = new Object[] { layoutBranchId };
1207 }
1208 else {
1209 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_LAYOUTBRANCHID;
1210 finderArgs = new Object[] {
1211 layoutBranchId,
1212
1213 start, end, orderByComparator
1214 };
1215 }
1216
1217 List<RecentLayoutBranch> list = null;
1218
1219 if (retrieveFromCache) {
1220 list = (List<RecentLayoutBranch>)finderCache.getResult(finderPath,
1221 finderArgs, this);
1222
1223 if ((list != null) && !list.isEmpty()) {
1224 for (RecentLayoutBranch recentLayoutBranch : list) {
1225 if ((layoutBranchId != recentLayoutBranch.getLayoutBranchId())) {
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 * 2));
1240 }
1241 else {
1242 query = new StringBundler(3);
1243 }
1244
1245 query.append(_SQL_SELECT_RECENTLAYOUTBRANCH_WHERE);
1246
1247 query.append(_FINDER_COLUMN_LAYOUTBRANCHID_LAYOUTBRANCHID_2);
1248
1249 if (orderByComparator != null) {
1250 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1251 orderByComparator);
1252 }
1253 else
1254 if (pagination) {
1255 query.append(RecentLayoutBranchModelImpl.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(layoutBranchId);
1270
1271 if (!pagination) {
1272 list = (List<RecentLayoutBranch>)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<RecentLayoutBranch>)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 RecentLayoutBranch findByLayoutBranchId_First(long layoutBranchId,
1311 OrderByComparator<RecentLayoutBranch> orderByComparator)
1312 throws NoSuchRecentLayoutBranchException {
1313 RecentLayoutBranch recentLayoutBranch = fetchByLayoutBranchId_First(layoutBranchId,
1314 orderByComparator);
1315
1316 if (recentLayoutBranch != null) {
1317 return recentLayoutBranch;
1318 }
1319
1320 StringBundler msg = new StringBundler(4);
1321
1322 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1323
1324 msg.append("layoutBranchId=");
1325 msg.append(layoutBranchId);
1326
1327 msg.append(StringPool.CLOSE_CURLY_BRACE);
1328
1329 throw new NoSuchRecentLayoutBranchException(msg.toString());
1330 }
1331
1332
1339 @Override
1340 public RecentLayoutBranch fetchByLayoutBranchId_First(long layoutBranchId,
1341 OrderByComparator<RecentLayoutBranch> orderByComparator) {
1342 List<RecentLayoutBranch> list = findByLayoutBranchId(layoutBranchId, 0,
1343 1, orderByComparator);
1344
1345 if (!list.isEmpty()) {
1346 return list.get(0);
1347 }
1348
1349 return null;
1350 }
1351
1352
1360 @Override
1361 public RecentLayoutBranch findByLayoutBranchId_Last(long layoutBranchId,
1362 OrderByComparator<RecentLayoutBranch> orderByComparator)
1363 throws NoSuchRecentLayoutBranchException {
1364 RecentLayoutBranch recentLayoutBranch = fetchByLayoutBranchId_Last(layoutBranchId,
1365 orderByComparator);
1366
1367 if (recentLayoutBranch != null) {
1368 return recentLayoutBranch;
1369 }
1370
1371 StringBundler msg = new StringBundler(4);
1372
1373 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1374
1375 msg.append("layoutBranchId=");
1376 msg.append(layoutBranchId);
1377
1378 msg.append(StringPool.CLOSE_CURLY_BRACE);
1379
1380 throw new NoSuchRecentLayoutBranchException(msg.toString());
1381 }
1382
1383
1390 @Override
1391 public RecentLayoutBranch fetchByLayoutBranchId_Last(long layoutBranchId,
1392 OrderByComparator<RecentLayoutBranch> orderByComparator) {
1393 int count = countByLayoutBranchId(layoutBranchId);
1394
1395 if (count == 0) {
1396 return null;
1397 }
1398
1399 List<RecentLayoutBranch> list = findByLayoutBranchId(layoutBranchId,
1400 count - 1, count, orderByComparator);
1401
1402 if (!list.isEmpty()) {
1403 return list.get(0);
1404 }
1405
1406 return null;
1407 }
1408
1409
1418 @Override
1419 public RecentLayoutBranch[] findByLayoutBranchId_PrevAndNext(
1420 long recentLayoutBranchId, long layoutBranchId,
1421 OrderByComparator<RecentLayoutBranch> orderByComparator)
1422 throws NoSuchRecentLayoutBranchException {
1423 RecentLayoutBranch recentLayoutBranch = findByPrimaryKey(recentLayoutBranchId);
1424
1425 Session session = null;
1426
1427 try {
1428 session = openSession();
1429
1430 RecentLayoutBranch[] array = new RecentLayoutBranchImpl[3];
1431
1432 array[0] = getByLayoutBranchId_PrevAndNext(session,
1433 recentLayoutBranch, layoutBranchId, orderByComparator, true);
1434
1435 array[1] = recentLayoutBranch;
1436
1437 array[2] = getByLayoutBranchId_PrevAndNext(session,
1438 recentLayoutBranch, layoutBranchId, orderByComparator, false);
1439
1440 return array;
1441 }
1442 catch (Exception e) {
1443 throw processException(e);
1444 }
1445 finally {
1446 closeSession(session);
1447 }
1448 }
1449
1450 protected RecentLayoutBranch getByLayoutBranchId_PrevAndNext(
1451 Session session, RecentLayoutBranch recentLayoutBranch,
1452 long layoutBranchId,
1453 OrderByComparator<RecentLayoutBranch> orderByComparator,
1454 boolean previous) {
1455 StringBundler query = null;
1456
1457 if (orderByComparator != null) {
1458 query = new StringBundler(4 +
1459 (orderByComparator.getOrderByConditionFields().length * 3) +
1460 (orderByComparator.getOrderByFields().length * 3));
1461 }
1462 else {
1463 query = new StringBundler(3);
1464 }
1465
1466 query.append(_SQL_SELECT_RECENTLAYOUTBRANCH_WHERE);
1467
1468 query.append(_FINDER_COLUMN_LAYOUTBRANCHID_LAYOUTBRANCHID_2);
1469
1470 if (orderByComparator != null) {
1471 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1472
1473 if (orderByConditionFields.length > 0) {
1474 query.append(WHERE_AND);
1475 }
1476
1477 for (int i = 0; i < orderByConditionFields.length; i++) {
1478 query.append(_ORDER_BY_ENTITY_ALIAS);
1479 query.append(orderByConditionFields[i]);
1480
1481 if ((i + 1) < orderByConditionFields.length) {
1482 if (orderByComparator.isAscending() ^ previous) {
1483 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1484 }
1485 else {
1486 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1487 }
1488 }
1489 else {
1490 if (orderByComparator.isAscending() ^ previous) {
1491 query.append(WHERE_GREATER_THAN);
1492 }
1493 else {
1494 query.append(WHERE_LESSER_THAN);
1495 }
1496 }
1497 }
1498
1499 query.append(ORDER_BY_CLAUSE);
1500
1501 String[] orderByFields = orderByComparator.getOrderByFields();
1502
1503 for (int i = 0; i < orderByFields.length; i++) {
1504 query.append(_ORDER_BY_ENTITY_ALIAS);
1505 query.append(orderByFields[i]);
1506
1507 if ((i + 1) < orderByFields.length) {
1508 if (orderByComparator.isAscending() ^ previous) {
1509 query.append(ORDER_BY_ASC_HAS_NEXT);
1510 }
1511 else {
1512 query.append(ORDER_BY_DESC_HAS_NEXT);
1513 }
1514 }
1515 else {
1516 if (orderByComparator.isAscending() ^ previous) {
1517 query.append(ORDER_BY_ASC);
1518 }
1519 else {
1520 query.append(ORDER_BY_DESC);
1521 }
1522 }
1523 }
1524 }
1525 else {
1526 query.append(RecentLayoutBranchModelImpl.ORDER_BY_JPQL);
1527 }
1528
1529 String sql = query.toString();
1530
1531 Query q = session.createQuery(sql);
1532
1533 q.setFirstResult(0);
1534 q.setMaxResults(2);
1535
1536 QueryPos qPos = QueryPos.getInstance(q);
1537
1538 qPos.add(layoutBranchId);
1539
1540 if (orderByComparator != null) {
1541 Object[] values = orderByComparator.getOrderByConditionValues(recentLayoutBranch);
1542
1543 for (Object value : values) {
1544 qPos.add(value);
1545 }
1546 }
1547
1548 List<RecentLayoutBranch> list = q.list();
1549
1550 if (list.size() == 2) {
1551 return list.get(1);
1552 }
1553 else {
1554 return null;
1555 }
1556 }
1557
1558
1563 @Override
1564 public void removeByLayoutBranchId(long layoutBranchId) {
1565 for (RecentLayoutBranch recentLayoutBranch : findByLayoutBranchId(
1566 layoutBranchId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1567 remove(recentLayoutBranch);
1568 }
1569 }
1570
1571
1577 @Override
1578 public int countByLayoutBranchId(long layoutBranchId) {
1579 FinderPath finderPath = FINDER_PATH_COUNT_BY_LAYOUTBRANCHID;
1580
1581 Object[] finderArgs = new Object[] { layoutBranchId };
1582
1583 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1584
1585 if (count == null) {
1586 StringBundler query = new StringBundler(2);
1587
1588 query.append(_SQL_COUNT_RECENTLAYOUTBRANCH_WHERE);
1589
1590 query.append(_FINDER_COLUMN_LAYOUTBRANCHID_LAYOUTBRANCHID_2);
1591
1592 String sql = query.toString();
1593
1594 Session session = null;
1595
1596 try {
1597 session = openSession();
1598
1599 Query q = session.createQuery(sql);
1600
1601 QueryPos qPos = QueryPos.getInstance(q);
1602
1603 qPos.add(layoutBranchId);
1604
1605 count = (Long)q.uniqueResult();
1606
1607 finderCache.putResult(finderPath, finderArgs, count);
1608 }
1609 catch (Exception e) {
1610 finderCache.removeResult(finderPath, finderArgs);
1611
1612 throw processException(e);
1613 }
1614 finally {
1615 closeSession(session);
1616 }
1617 }
1618
1619 return count.intValue();
1620 }
1621
1622 private static final String _FINDER_COLUMN_LAYOUTBRANCHID_LAYOUTBRANCHID_2 = "recentLayoutBranch.layoutBranchId = ?";
1623 public static final FinderPath FINDER_PATH_FETCH_BY_U_L_P = new FinderPath(RecentLayoutBranchModelImpl.ENTITY_CACHE_ENABLED,
1624 RecentLayoutBranchModelImpl.FINDER_CACHE_ENABLED,
1625 RecentLayoutBranchImpl.class, FINDER_CLASS_NAME_ENTITY,
1626 "fetchByU_L_P",
1627 new String[] {
1628 Long.class.getName(), Long.class.getName(), Long.class.getName()
1629 },
1630 RecentLayoutBranchModelImpl.USERID_COLUMN_BITMASK |
1631 RecentLayoutBranchModelImpl.LAYOUTSETBRANCHID_COLUMN_BITMASK |
1632 RecentLayoutBranchModelImpl.PLID_COLUMN_BITMASK);
1633 public static final FinderPath FINDER_PATH_COUNT_BY_U_L_P = new FinderPath(RecentLayoutBranchModelImpl.ENTITY_CACHE_ENABLED,
1634 RecentLayoutBranchModelImpl.FINDER_CACHE_ENABLED, Long.class,
1635 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_L_P",
1636 new String[] {
1637 Long.class.getName(), Long.class.getName(), Long.class.getName()
1638 });
1639
1640
1649 @Override
1650 public RecentLayoutBranch findByU_L_P(long userId, long layoutSetBranchId,
1651 long plid) throws NoSuchRecentLayoutBranchException {
1652 RecentLayoutBranch recentLayoutBranch = fetchByU_L_P(userId,
1653 layoutSetBranchId, plid);
1654
1655 if (recentLayoutBranch == null) {
1656 StringBundler msg = new StringBundler(8);
1657
1658 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1659
1660 msg.append("userId=");
1661 msg.append(userId);
1662
1663 msg.append(", layoutSetBranchId=");
1664 msg.append(layoutSetBranchId);
1665
1666 msg.append(", plid=");
1667 msg.append(plid);
1668
1669 msg.append(StringPool.CLOSE_CURLY_BRACE);
1670
1671 if (_log.isWarnEnabled()) {
1672 _log.warn(msg.toString());
1673 }
1674
1675 throw new NoSuchRecentLayoutBranchException(msg.toString());
1676 }
1677
1678 return recentLayoutBranch;
1679 }
1680
1681
1689 @Override
1690 public RecentLayoutBranch fetchByU_L_P(long userId, long layoutSetBranchId,
1691 long plid) {
1692 return fetchByU_L_P(userId, layoutSetBranchId, plid, true);
1693 }
1694
1695
1704 @Override
1705 public RecentLayoutBranch fetchByU_L_P(long userId, long layoutSetBranchId,
1706 long plid, boolean retrieveFromCache) {
1707 Object[] finderArgs = new Object[] { userId, layoutSetBranchId, plid };
1708
1709 Object result = null;
1710
1711 if (retrieveFromCache) {
1712 result = finderCache.getResult(FINDER_PATH_FETCH_BY_U_L_P,
1713 finderArgs, this);
1714 }
1715
1716 if (result instanceof RecentLayoutBranch) {
1717 RecentLayoutBranch recentLayoutBranch = (RecentLayoutBranch)result;
1718
1719 if ((userId != recentLayoutBranch.getUserId()) ||
1720 (layoutSetBranchId != recentLayoutBranch.getLayoutSetBranchId()) ||
1721 (plid != recentLayoutBranch.getPlid())) {
1722 result = null;
1723 }
1724 }
1725
1726 if (result == null) {
1727 StringBundler query = new StringBundler(5);
1728
1729 query.append(_SQL_SELECT_RECENTLAYOUTBRANCH_WHERE);
1730
1731 query.append(_FINDER_COLUMN_U_L_P_USERID_2);
1732
1733 query.append(_FINDER_COLUMN_U_L_P_LAYOUTSETBRANCHID_2);
1734
1735 query.append(_FINDER_COLUMN_U_L_P_PLID_2);
1736
1737 String sql = query.toString();
1738
1739 Session session = null;
1740
1741 try {
1742 session = openSession();
1743
1744 Query q = session.createQuery(sql);
1745
1746 QueryPos qPos = QueryPos.getInstance(q);
1747
1748 qPos.add(userId);
1749
1750 qPos.add(layoutSetBranchId);
1751
1752 qPos.add(plid);
1753
1754 List<RecentLayoutBranch> list = q.list();
1755
1756 if (list.isEmpty()) {
1757 finderCache.putResult(FINDER_PATH_FETCH_BY_U_L_P,
1758 finderArgs, list);
1759 }
1760 else {
1761 RecentLayoutBranch recentLayoutBranch = list.get(0);
1762
1763 result = recentLayoutBranch;
1764
1765 cacheResult(recentLayoutBranch);
1766
1767 if ((recentLayoutBranch.getUserId() != userId) ||
1768 (recentLayoutBranch.getLayoutSetBranchId() != layoutSetBranchId) ||
1769 (recentLayoutBranch.getPlid() != plid)) {
1770 finderCache.putResult(FINDER_PATH_FETCH_BY_U_L_P,
1771 finderArgs, recentLayoutBranch);
1772 }
1773 }
1774 }
1775 catch (Exception e) {
1776 finderCache.removeResult(FINDER_PATH_FETCH_BY_U_L_P, finderArgs);
1777
1778 throw processException(e);
1779 }
1780 finally {
1781 closeSession(session);
1782 }
1783 }
1784
1785 if (result instanceof List<?>) {
1786 return null;
1787 }
1788 else {
1789 return (RecentLayoutBranch)result;
1790 }
1791 }
1792
1793
1801 @Override
1802 public RecentLayoutBranch removeByU_L_P(long userId,
1803 long layoutSetBranchId, long plid)
1804 throws NoSuchRecentLayoutBranchException {
1805 RecentLayoutBranch recentLayoutBranch = findByU_L_P(userId,
1806 layoutSetBranchId, plid);
1807
1808 return remove(recentLayoutBranch);
1809 }
1810
1811
1819 @Override
1820 public int countByU_L_P(long userId, long layoutSetBranchId, long plid) {
1821 FinderPath finderPath = FINDER_PATH_COUNT_BY_U_L_P;
1822
1823 Object[] finderArgs = new Object[] { userId, layoutSetBranchId, plid };
1824
1825 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1826
1827 if (count == null) {
1828 StringBundler query = new StringBundler(4);
1829
1830 query.append(_SQL_COUNT_RECENTLAYOUTBRANCH_WHERE);
1831
1832 query.append(_FINDER_COLUMN_U_L_P_USERID_2);
1833
1834 query.append(_FINDER_COLUMN_U_L_P_LAYOUTSETBRANCHID_2);
1835
1836 query.append(_FINDER_COLUMN_U_L_P_PLID_2);
1837
1838 String sql = query.toString();
1839
1840 Session session = null;
1841
1842 try {
1843 session = openSession();
1844
1845 Query q = session.createQuery(sql);
1846
1847 QueryPos qPos = QueryPos.getInstance(q);
1848
1849 qPos.add(userId);
1850
1851 qPos.add(layoutSetBranchId);
1852
1853 qPos.add(plid);
1854
1855 count = (Long)q.uniqueResult();
1856
1857 finderCache.putResult(finderPath, finderArgs, count);
1858 }
1859 catch (Exception e) {
1860 finderCache.removeResult(finderPath, finderArgs);
1861
1862 throw processException(e);
1863 }
1864 finally {
1865 closeSession(session);
1866 }
1867 }
1868
1869 return count.intValue();
1870 }
1871
1872 private static final String _FINDER_COLUMN_U_L_P_USERID_2 = "recentLayoutBranch.userId = ? AND ";
1873 private static final String _FINDER_COLUMN_U_L_P_LAYOUTSETBRANCHID_2 = "recentLayoutBranch.layoutSetBranchId = ? AND ";
1874 private static final String _FINDER_COLUMN_U_L_P_PLID_2 = "recentLayoutBranch.plid = ?";
1875
1876 public RecentLayoutBranchPersistenceImpl() {
1877 setModelClass(RecentLayoutBranch.class);
1878 }
1879
1880
1885 @Override
1886 public void cacheResult(RecentLayoutBranch recentLayoutBranch) {
1887 entityCache.putResult(RecentLayoutBranchModelImpl.ENTITY_CACHE_ENABLED,
1888 RecentLayoutBranchImpl.class, recentLayoutBranch.getPrimaryKey(),
1889 recentLayoutBranch);
1890
1891 finderCache.putResult(FINDER_PATH_FETCH_BY_U_L_P,
1892 new Object[] {
1893 recentLayoutBranch.getUserId(),
1894 recentLayoutBranch.getLayoutSetBranchId(),
1895 recentLayoutBranch.getPlid()
1896 }, recentLayoutBranch);
1897
1898 recentLayoutBranch.resetOriginalValues();
1899 }
1900
1901
1906 @Override
1907 public void cacheResult(List<RecentLayoutBranch> recentLayoutBranchs) {
1908 for (RecentLayoutBranch recentLayoutBranch : recentLayoutBranchs) {
1909 if (entityCache.getResult(
1910 RecentLayoutBranchModelImpl.ENTITY_CACHE_ENABLED,
1911 RecentLayoutBranchImpl.class,
1912 recentLayoutBranch.getPrimaryKey()) == null) {
1913 cacheResult(recentLayoutBranch);
1914 }
1915 else {
1916 recentLayoutBranch.resetOriginalValues();
1917 }
1918 }
1919 }
1920
1921
1928 @Override
1929 public void clearCache() {
1930 entityCache.clearCache(RecentLayoutBranchImpl.class);
1931
1932 finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
1933 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1934 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1935 }
1936
1937
1944 @Override
1945 public void clearCache(RecentLayoutBranch recentLayoutBranch) {
1946 entityCache.removeResult(RecentLayoutBranchModelImpl.ENTITY_CACHE_ENABLED,
1947 RecentLayoutBranchImpl.class, recentLayoutBranch.getPrimaryKey());
1948
1949 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1950 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1951
1952 clearUniqueFindersCache((RecentLayoutBranchModelImpl)recentLayoutBranch);
1953 }
1954
1955 @Override
1956 public void clearCache(List<RecentLayoutBranch> recentLayoutBranchs) {
1957 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1958 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1959
1960 for (RecentLayoutBranch recentLayoutBranch : recentLayoutBranchs) {
1961 entityCache.removeResult(RecentLayoutBranchModelImpl.ENTITY_CACHE_ENABLED,
1962 RecentLayoutBranchImpl.class, recentLayoutBranch.getPrimaryKey());
1963
1964 clearUniqueFindersCache((RecentLayoutBranchModelImpl)recentLayoutBranch);
1965 }
1966 }
1967
1968 protected void cacheUniqueFindersCache(
1969 RecentLayoutBranchModelImpl recentLayoutBranchModelImpl, boolean isNew) {
1970 if (isNew) {
1971 Object[] args = new Object[] {
1972 recentLayoutBranchModelImpl.getUserId(),
1973 recentLayoutBranchModelImpl.getLayoutSetBranchId(),
1974 recentLayoutBranchModelImpl.getPlid()
1975 };
1976
1977 finderCache.putResult(FINDER_PATH_COUNT_BY_U_L_P, args,
1978 Long.valueOf(1));
1979 finderCache.putResult(FINDER_PATH_FETCH_BY_U_L_P, args,
1980 recentLayoutBranchModelImpl);
1981 }
1982 else {
1983 if ((recentLayoutBranchModelImpl.getColumnBitmask() &
1984 FINDER_PATH_FETCH_BY_U_L_P.getColumnBitmask()) != 0) {
1985 Object[] args = new Object[] {
1986 recentLayoutBranchModelImpl.getUserId(),
1987 recentLayoutBranchModelImpl.getLayoutSetBranchId(),
1988 recentLayoutBranchModelImpl.getPlid()
1989 };
1990
1991 finderCache.putResult(FINDER_PATH_COUNT_BY_U_L_P, args,
1992 Long.valueOf(1));
1993 finderCache.putResult(FINDER_PATH_FETCH_BY_U_L_P, args,
1994 recentLayoutBranchModelImpl);
1995 }
1996 }
1997 }
1998
1999 protected void clearUniqueFindersCache(
2000 RecentLayoutBranchModelImpl recentLayoutBranchModelImpl) {
2001 Object[] args = new Object[] {
2002 recentLayoutBranchModelImpl.getUserId(),
2003 recentLayoutBranchModelImpl.getLayoutSetBranchId(),
2004 recentLayoutBranchModelImpl.getPlid()
2005 };
2006
2007 finderCache.removeResult(FINDER_PATH_COUNT_BY_U_L_P, args);
2008 finderCache.removeResult(FINDER_PATH_FETCH_BY_U_L_P, args);
2009
2010 if ((recentLayoutBranchModelImpl.getColumnBitmask() &
2011 FINDER_PATH_FETCH_BY_U_L_P.getColumnBitmask()) != 0) {
2012 args = new Object[] {
2013 recentLayoutBranchModelImpl.getOriginalUserId(),
2014 recentLayoutBranchModelImpl.getOriginalLayoutSetBranchId(),
2015 recentLayoutBranchModelImpl.getOriginalPlid()
2016 };
2017
2018 finderCache.removeResult(FINDER_PATH_COUNT_BY_U_L_P, args);
2019 finderCache.removeResult(FINDER_PATH_FETCH_BY_U_L_P, args);
2020 }
2021 }
2022
2023
2029 @Override
2030 public RecentLayoutBranch create(long recentLayoutBranchId) {
2031 RecentLayoutBranch recentLayoutBranch = new RecentLayoutBranchImpl();
2032
2033 recentLayoutBranch.setNew(true);
2034 recentLayoutBranch.setPrimaryKey(recentLayoutBranchId);
2035
2036 recentLayoutBranch.setCompanyId(companyProvider.getCompanyId());
2037
2038 return recentLayoutBranch;
2039 }
2040
2041
2048 @Override
2049 public RecentLayoutBranch remove(long recentLayoutBranchId)
2050 throws NoSuchRecentLayoutBranchException {
2051 return remove((Serializable)recentLayoutBranchId);
2052 }
2053
2054
2061 @Override
2062 public RecentLayoutBranch remove(Serializable primaryKey)
2063 throws NoSuchRecentLayoutBranchException {
2064 Session session = null;
2065
2066 try {
2067 session = openSession();
2068
2069 RecentLayoutBranch recentLayoutBranch = (RecentLayoutBranch)session.get(RecentLayoutBranchImpl.class,
2070 primaryKey);
2071
2072 if (recentLayoutBranch == null) {
2073 if (_log.isWarnEnabled()) {
2074 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2075 }
2076
2077 throw new NoSuchRecentLayoutBranchException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2078 primaryKey);
2079 }
2080
2081 return remove(recentLayoutBranch);
2082 }
2083 catch (NoSuchRecentLayoutBranchException nsee) {
2084 throw nsee;
2085 }
2086 catch (Exception e) {
2087 throw processException(e);
2088 }
2089 finally {
2090 closeSession(session);
2091 }
2092 }
2093
2094 @Override
2095 protected RecentLayoutBranch removeImpl(
2096 RecentLayoutBranch recentLayoutBranch) {
2097 recentLayoutBranch = toUnwrappedModel(recentLayoutBranch);
2098
2099 Session session = null;
2100
2101 try {
2102 session = openSession();
2103
2104 if (!session.contains(recentLayoutBranch)) {
2105 recentLayoutBranch = (RecentLayoutBranch)session.get(RecentLayoutBranchImpl.class,
2106 recentLayoutBranch.getPrimaryKeyObj());
2107 }
2108
2109 if (recentLayoutBranch != null) {
2110 session.delete(recentLayoutBranch);
2111 }
2112 }
2113 catch (Exception e) {
2114 throw processException(e);
2115 }
2116 finally {
2117 closeSession(session);
2118 }
2119
2120 if (recentLayoutBranch != null) {
2121 clearCache(recentLayoutBranch);
2122 }
2123
2124 return recentLayoutBranch;
2125 }
2126
2127 @Override
2128 public RecentLayoutBranch updateImpl(RecentLayoutBranch recentLayoutBranch) {
2129 recentLayoutBranch = toUnwrappedModel(recentLayoutBranch);
2130
2131 boolean isNew = recentLayoutBranch.isNew();
2132
2133 RecentLayoutBranchModelImpl recentLayoutBranchModelImpl = (RecentLayoutBranchModelImpl)recentLayoutBranch;
2134
2135 Session session = null;
2136
2137 try {
2138 session = openSession();
2139
2140 if (recentLayoutBranch.isNew()) {
2141 session.save(recentLayoutBranch);
2142
2143 recentLayoutBranch.setNew(false);
2144 }
2145 else {
2146 recentLayoutBranch = (RecentLayoutBranch)session.merge(recentLayoutBranch);
2147 }
2148 }
2149 catch (Exception e) {
2150 throw processException(e);
2151 }
2152 finally {
2153 closeSession(session);
2154 }
2155
2156 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2157
2158 if (isNew || !RecentLayoutBranchModelImpl.COLUMN_BITMASK_ENABLED) {
2159 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2160 }
2161
2162 else {
2163 if ((recentLayoutBranchModelImpl.getColumnBitmask() &
2164 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
2165 Object[] args = new Object[] {
2166 recentLayoutBranchModelImpl.getOriginalGroupId()
2167 };
2168
2169 finderCache.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
2170 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
2171 args);
2172
2173 args = new Object[] { recentLayoutBranchModelImpl.getGroupId() };
2174
2175 finderCache.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
2176 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
2177 args);
2178 }
2179
2180 if ((recentLayoutBranchModelImpl.getColumnBitmask() &
2181 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
2182 Object[] args = new Object[] {
2183 recentLayoutBranchModelImpl.getOriginalUserId()
2184 };
2185
2186 finderCache.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
2187 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
2188 args);
2189
2190 args = new Object[] { recentLayoutBranchModelImpl.getUserId() };
2191
2192 finderCache.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
2193 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
2194 args);
2195 }
2196
2197 if ((recentLayoutBranchModelImpl.getColumnBitmask() &
2198 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LAYOUTBRANCHID.getColumnBitmask()) != 0) {
2199 Object[] args = new Object[] {
2200 recentLayoutBranchModelImpl.getOriginalLayoutBranchId()
2201 };
2202
2203 finderCache.removeResult(FINDER_PATH_COUNT_BY_LAYOUTBRANCHID,
2204 args);
2205 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LAYOUTBRANCHID,
2206 args);
2207
2208 args = new Object[] {
2209 recentLayoutBranchModelImpl.getLayoutBranchId()
2210 };
2211
2212 finderCache.removeResult(FINDER_PATH_COUNT_BY_LAYOUTBRANCHID,
2213 args);
2214 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LAYOUTBRANCHID,
2215 args);
2216 }
2217 }
2218
2219 entityCache.putResult(RecentLayoutBranchModelImpl.ENTITY_CACHE_ENABLED,
2220 RecentLayoutBranchImpl.class, recentLayoutBranch.getPrimaryKey(),
2221 recentLayoutBranch, false);
2222
2223 clearUniqueFindersCache(recentLayoutBranchModelImpl);
2224 cacheUniqueFindersCache(recentLayoutBranchModelImpl, isNew);
2225
2226 recentLayoutBranch.resetOriginalValues();
2227
2228 return recentLayoutBranch;
2229 }
2230
2231 protected RecentLayoutBranch toUnwrappedModel(
2232 RecentLayoutBranch recentLayoutBranch) {
2233 if (recentLayoutBranch instanceof RecentLayoutBranchImpl) {
2234 return recentLayoutBranch;
2235 }
2236
2237 RecentLayoutBranchImpl recentLayoutBranchImpl = new RecentLayoutBranchImpl();
2238
2239 recentLayoutBranchImpl.setNew(recentLayoutBranch.isNew());
2240 recentLayoutBranchImpl.setPrimaryKey(recentLayoutBranch.getPrimaryKey());
2241
2242 recentLayoutBranchImpl.setMvccVersion(recentLayoutBranch.getMvccVersion());
2243 recentLayoutBranchImpl.setRecentLayoutBranchId(recentLayoutBranch.getRecentLayoutBranchId());
2244 recentLayoutBranchImpl.setGroupId(recentLayoutBranch.getGroupId());
2245 recentLayoutBranchImpl.setCompanyId(recentLayoutBranch.getCompanyId());
2246 recentLayoutBranchImpl.setUserId(recentLayoutBranch.getUserId());
2247 recentLayoutBranchImpl.setLayoutBranchId(recentLayoutBranch.getLayoutBranchId());
2248 recentLayoutBranchImpl.setLayoutSetBranchId(recentLayoutBranch.getLayoutSetBranchId());
2249 recentLayoutBranchImpl.setPlid(recentLayoutBranch.getPlid());
2250
2251 return recentLayoutBranchImpl;
2252 }
2253
2254
2261 @Override
2262 public RecentLayoutBranch findByPrimaryKey(Serializable primaryKey)
2263 throws NoSuchRecentLayoutBranchException {
2264 RecentLayoutBranch recentLayoutBranch = fetchByPrimaryKey(primaryKey);
2265
2266 if (recentLayoutBranch == null) {
2267 if (_log.isWarnEnabled()) {
2268 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2269 }
2270
2271 throw new NoSuchRecentLayoutBranchException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2272 primaryKey);
2273 }
2274
2275 return recentLayoutBranch;
2276 }
2277
2278
2285 @Override
2286 public RecentLayoutBranch findByPrimaryKey(long recentLayoutBranchId)
2287 throws NoSuchRecentLayoutBranchException {
2288 return findByPrimaryKey((Serializable)recentLayoutBranchId);
2289 }
2290
2291
2297 @Override
2298 public RecentLayoutBranch fetchByPrimaryKey(Serializable primaryKey) {
2299 RecentLayoutBranch recentLayoutBranch = (RecentLayoutBranch)entityCache.getResult(RecentLayoutBranchModelImpl.ENTITY_CACHE_ENABLED,
2300 RecentLayoutBranchImpl.class, primaryKey);
2301
2302 if (recentLayoutBranch == _nullRecentLayoutBranch) {
2303 return null;
2304 }
2305
2306 if (recentLayoutBranch == null) {
2307 Session session = null;
2308
2309 try {
2310 session = openSession();
2311
2312 recentLayoutBranch = (RecentLayoutBranch)session.get(RecentLayoutBranchImpl.class,
2313 primaryKey);
2314
2315 if (recentLayoutBranch != null) {
2316 cacheResult(recentLayoutBranch);
2317 }
2318 else {
2319 entityCache.putResult(RecentLayoutBranchModelImpl.ENTITY_CACHE_ENABLED,
2320 RecentLayoutBranchImpl.class, primaryKey,
2321 _nullRecentLayoutBranch);
2322 }
2323 }
2324 catch (Exception e) {
2325 entityCache.removeResult(RecentLayoutBranchModelImpl.ENTITY_CACHE_ENABLED,
2326 RecentLayoutBranchImpl.class, primaryKey);
2327
2328 throw processException(e);
2329 }
2330 finally {
2331 closeSession(session);
2332 }
2333 }
2334
2335 return recentLayoutBranch;
2336 }
2337
2338
2344 @Override
2345 public RecentLayoutBranch fetchByPrimaryKey(long recentLayoutBranchId) {
2346 return fetchByPrimaryKey((Serializable)recentLayoutBranchId);
2347 }
2348
2349 @Override
2350 public Map<Serializable, RecentLayoutBranch> fetchByPrimaryKeys(
2351 Set<Serializable> primaryKeys) {
2352 if (primaryKeys.isEmpty()) {
2353 return Collections.emptyMap();
2354 }
2355
2356 Map<Serializable, RecentLayoutBranch> map = new HashMap<Serializable, RecentLayoutBranch>();
2357
2358 if (primaryKeys.size() == 1) {
2359 Iterator<Serializable> iterator = primaryKeys.iterator();
2360
2361 Serializable primaryKey = iterator.next();
2362
2363 RecentLayoutBranch recentLayoutBranch = fetchByPrimaryKey(primaryKey);
2364
2365 if (recentLayoutBranch != null) {
2366 map.put(primaryKey, recentLayoutBranch);
2367 }
2368
2369 return map;
2370 }
2371
2372 Set<Serializable> uncachedPrimaryKeys = null;
2373
2374 for (Serializable primaryKey : primaryKeys) {
2375 RecentLayoutBranch recentLayoutBranch = (RecentLayoutBranch)entityCache.getResult(RecentLayoutBranchModelImpl.ENTITY_CACHE_ENABLED,
2376 RecentLayoutBranchImpl.class, primaryKey);
2377
2378 if (recentLayoutBranch == null) {
2379 if (uncachedPrimaryKeys == null) {
2380 uncachedPrimaryKeys = new HashSet<Serializable>();
2381 }
2382
2383 uncachedPrimaryKeys.add(primaryKey);
2384 }
2385 else {
2386 map.put(primaryKey, recentLayoutBranch);
2387 }
2388 }
2389
2390 if (uncachedPrimaryKeys == null) {
2391 return map;
2392 }
2393
2394 StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
2395 1);
2396
2397 query.append(_SQL_SELECT_RECENTLAYOUTBRANCH_WHERE_PKS_IN);
2398
2399 for (Serializable primaryKey : uncachedPrimaryKeys) {
2400 query.append(String.valueOf(primaryKey));
2401
2402 query.append(StringPool.COMMA);
2403 }
2404
2405 query.setIndex(query.index() - 1);
2406
2407 query.append(StringPool.CLOSE_PARENTHESIS);
2408
2409 String sql = query.toString();
2410
2411 Session session = null;
2412
2413 try {
2414 session = openSession();
2415
2416 Query q = session.createQuery(sql);
2417
2418 for (RecentLayoutBranch recentLayoutBranch : (List<RecentLayoutBranch>)q.list()) {
2419 map.put(recentLayoutBranch.getPrimaryKeyObj(),
2420 recentLayoutBranch);
2421
2422 cacheResult(recentLayoutBranch);
2423
2424 uncachedPrimaryKeys.remove(recentLayoutBranch.getPrimaryKeyObj());
2425 }
2426
2427 for (Serializable primaryKey : uncachedPrimaryKeys) {
2428 entityCache.putResult(RecentLayoutBranchModelImpl.ENTITY_CACHE_ENABLED,
2429 RecentLayoutBranchImpl.class, primaryKey,
2430 _nullRecentLayoutBranch);
2431 }
2432 }
2433 catch (Exception e) {
2434 throw processException(e);
2435 }
2436 finally {
2437 closeSession(session);
2438 }
2439
2440 return map;
2441 }
2442
2443
2448 @Override
2449 public List<RecentLayoutBranch> findAll() {
2450 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2451 }
2452
2453
2464 @Override
2465 public List<RecentLayoutBranch> findAll(int start, int end) {
2466 return findAll(start, end, null);
2467 }
2468
2469
2481 @Override
2482 public List<RecentLayoutBranch> findAll(int start, int end,
2483 OrderByComparator<RecentLayoutBranch> orderByComparator) {
2484 return findAll(start, end, orderByComparator, true);
2485 }
2486
2487
2500 @Override
2501 public List<RecentLayoutBranch> findAll(int start, int end,
2502 OrderByComparator<RecentLayoutBranch> orderByComparator,
2503 boolean retrieveFromCache) {
2504 boolean pagination = true;
2505 FinderPath finderPath = null;
2506 Object[] finderArgs = null;
2507
2508 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2509 (orderByComparator == null)) {
2510 pagination = false;
2511 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2512 finderArgs = FINDER_ARGS_EMPTY;
2513 }
2514 else {
2515 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2516 finderArgs = new Object[] { start, end, orderByComparator };
2517 }
2518
2519 List<RecentLayoutBranch> list = null;
2520
2521 if (retrieveFromCache) {
2522 list = (List<RecentLayoutBranch>)finderCache.getResult(finderPath,
2523 finderArgs, this);
2524 }
2525
2526 if (list == null) {
2527 StringBundler query = null;
2528 String sql = null;
2529
2530 if (orderByComparator != null) {
2531 query = new StringBundler(2 +
2532 (orderByComparator.getOrderByFields().length * 2));
2533
2534 query.append(_SQL_SELECT_RECENTLAYOUTBRANCH);
2535
2536 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2537 orderByComparator);
2538
2539 sql = query.toString();
2540 }
2541 else {
2542 sql = _SQL_SELECT_RECENTLAYOUTBRANCH;
2543
2544 if (pagination) {
2545 sql = sql.concat(RecentLayoutBranchModelImpl.ORDER_BY_JPQL);
2546 }
2547 }
2548
2549 Session session = null;
2550
2551 try {
2552 session = openSession();
2553
2554 Query q = session.createQuery(sql);
2555
2556 if (!pagination) {
2557 list = (List<RecentLayoutBranch>)QueryUtil.list(q,
2558 getDialect(), start, end, false);
2559
2560 Collections.sort(list);
2561
2562 list = Collections.unmodifiableList(list);
2563 }
2564 else {
2565 list = (List<RecentLayoutBranch>)QueryUtil.list(q,
2566 getDialect(), start, end);
2567 }
2568
2569 cacheResult(list);
2570
2571 finderCache.putResult(finderPath, finderArgs, list);
2572 }
2573 catch (Exception e) {
2574 finderCache.removeResult(finderPath, finderArgs);
2575
2576 throw processException(e);
2577 }
2578 finally {
2579 closeSession(session);
2580 }
2581 }
2582
2583 return list;
2584 }
2585
2586
2590 @Override
2591 public void removeAll() {
2592 for (RecentLayoutBranch recentLayoutBranch : findAll()) {
2593 remove(recentLayoutBranch);
2594 }
2595 }
2596
2597
2602 @Override
2603 public int countAll() {
2604 Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
2605 FINDER_ARGS_EMPTY, this);
2606
2607 if (count == null) {
2608 Session session = null;
2609
2610 try {
2611 session = openSession();
2612
2613 Query q = session.createQuery(_SQL_COUNT_RECENTLAYOUTBRANCH);
2614
2615 count = (Long)q.uniqueResult();
2616
2617 finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
2618 count);
2619 }
2620 catch (Exception e) {
2621 finderCache.removeResult(FINDER_PATH_COUNT_ALL,
2622 FINDER_ARGS_EMPTY);
2623
2624 throw processException(e);
2625 }
2626 finally {
2627 closeSession(session);
2628 }
2629 }
2630
2631 return count.intValue();
2632 }
2633
2634 @Override
2635 protected Map<String, Integer> getTableColumnsMap() {
2636 return RecentLayoutBranchModelImpl.TABLE_COLUMNS_MAP;
2637 }
2638
2639
2642 public void afterPropertiesSet() {
2643 }
2644
2645 public void destroy() {
2646 entityCache.removeCache(RecentLayoutBranchImpl.class.getName());
2647 finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
2648 finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2649 finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2650 }
2651
2652 @BeanReference(type = CompanyProviderWrapper.class)
2653 protected CompanyProvider companyProvider;
2654 protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
2655 protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
2656 private static final String _SQL_SELECT_RECENTLAYOUTBRANCH = "SELECT recentLayoutBranch FROM RecentLayoutBranch recentLayoutBranch";
2657 private static final String _SQL_SELECT_RECENTLAYOUTBRANCH_WHERE_PKS_IN = "SELECT recentLayoutBranch FROM RecentLayoutBranch recentLayoutBranch WHERE recentLayoutBranchId IN (";
2658 private static final String _SQL_SELECT_RECENTLAYOUTBRANCH_WHERE = "SELECT recentLayoutBranch FROM RecentLayoutBranch recentLayoutBranch WHERE ";
2659 private static final String _SQL_COUNT_RECENTLAYOUTBRANCH = "SELECT COUNT(recentLayoutBranch) FROM RecentLayoutBranch recentLayoutBranch";
2660 private static final String _SQL_COUNT_RECENTLAYOUTBRANCH_WHERE = "SELECT COUNT(recentLayoutBranch) FROM RecentLayoutBranch recentLayoutBranch WHERE ";
2661 private static final String _ORDER_BY_ENTITY_ALIAS = "recentLayoutBranch.";
2662 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No RecentLayoutBranch exists with the primary key ";
2663 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No RecentLayoutBranch exists with the key {";
2664 private static final Log _log = LogFactoryUtil.getLog(RecentLayoutBranchPersistenceImpl.class);
2665 private static final RecentLayoutBranch _nullRecentLayoutBranch = new RecentLayoutBranchImpl() {
2666 @Override
2667 public Object clone() {
2668 return this;
2669 }
2670
2671 @Override
2672 public CacheModel<RecentLayoutBranch> toCacheModel() {
2673 return _nullRecentLayoutBranchCacheModel;
2674 }
2675 };
2676
2677 private static final CacheModel<RecentLayoutBranch> _nullRecentLayoutBranchCacheModel =
2678 new NullCacheModel();
2679
2680 private static class NullCacheModel implements CacheModel<RecentLayoutBranch>,
2681 MVCCModel {
2682 @Override
2683 public long getMvccVersion() {
2684 return -1;
2685 }
2686
2687 @Override
2688 public void setMvccVersion(long mvccVersion) {
2689 }
2690
2691 @Override
2692 public RecentLayoutBranch toEntityModel() {
2693 return _nullRecentLayoutBranch;
2694 }
2695 }
2696 }