001
014
015 package com.liferay.portal.service.persistence;
016
017 import com.liferay.portal.NoSuchLayoutPrototypeException;
018 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
019 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
020 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderPath;
022 import com.liferay.portal.kernel.dao.orm.Query;
023 import com.liferay.portal.kernel.dao.orm.QueryPos;
024 import com.liferay.portal.kernel.dao.orm.QueryUtil;
025 import com.liferay.portal.kernel.dao.orm.SQLQuery;
026 import com.liferay.portal.kernel.dao.orm.Session;
027 import com.liferay.portal.kernel.exception.SystemException;
028 import com.liferay.portal.kernel.log.Log;
029 import com.liferay.portal.kernel.log.LogFactoryUtil;
030 import com.liferay.portal.kernel.util.GetterUtil;
031 import com.liferay.portal.kernel.util.InstanceFactory;
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.kernel.util.StringUtil;
036 import com.liferay.portal.kernel.util.UnmodifiableList;
037 import com.liferay.portal.kernel.util.Validator;
038 import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
039 import com.liferay.portal.model.CacheModel;
040 import com.liferay.portal.model.LayoutPrototype;
041 import com.liferay.portal.model.ModelListener;
042 import com.liferay.portal.model.impl.LayoutPrototypeImpl;
043 import com.liferay.portal.model.impl.LayoutPrototypeModelImpl;
044 import com.liferay.portal.security.permission.InlineSQLHelperUtil;
045 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
046
047 import java.io.Serializable;
048
049 import java.util.ArrayList;
050 import java.util.Collections;
051 import java.util.List;
052
053
065 public class LayoutPrototypePersistenceImpl extends BasePersistenceImpl<LayoutPrototype>
066 implements LayoutPrototypePersistence {
067
072 public static final String FINDER_CLASS_NAME_ENTITY = LayoutPrototypeImpl.class.getName();
073 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
074 ".List1";
075 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
076 ".List2";
077 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(LayoutPrototypeModelImpl.ENTITY_CACHE_ENABLED,
078 LayoutPrototypeModelImpl.FINDER_CACHE_ENABLED,
079 LayoutPrototypeImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
080 "findAll", new String[0]);
081 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(LayoutPrototypeModelImpl.ENTITY_CACHE_ENABLED,
082 LayoutPrototypeModelImpl.FINDER_CACHE_ENABLED,
083 LayoutPrototypeImpl.class,
084 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
085 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(LayoutPrototypeModelImpl.ENTITY_CACHE_ENABLED,
086 LayoutPrototypeModelImpl.FINDER_CACHE_ENABLED, Long.class,
087 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
088 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(LayoutPrototypeModelImpl.ENTITY_CACHE_ENABLED,
089 LayoutPrototypeModelImpl.FINDER_CACHE_ENABLED,
090 LayoutPrototypeImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
091 "findByUuid",
092 new String[] {
093 String.class.getName(),
094
095 Integer.class.getName(), Integer.class.getName(),
096 OrderByComparator.class.getName()
097 });
098 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(LayoutPrototypeModelImpl.ENTITY_CACHE_ENABLED,
099 LayoutPrototypeModelImpl.FINDER_CACHE_ENABLED,
100 LayoutPrototypeImpl.class,
101 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
102 new String[] { String.class.getName() },
103 LayoutPrototypeModelImpl.UUID_COLUMN_BITMASK);
104 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(LayoutPrototypeModelImpl.ENTITY_CACHE_ENABLED,
105 LayoutPrototypeModelImpl.FINDER_CACHE_ENABLED, Long.class,
106 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
107 new String[] { String.class.getName() });
108
109
116 public List<LayoutPrototype> findByUuid(String uuid)
117 throws SystemException {
118 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
119 }
120
121
134 public List<LayoutPrototype> findByUuid(String uuid, int start, int end)
135 throws SystemException {
136 return findByUuid(uuid, start, end, null);
137 }
138
139
153 public List<LayoutPrototype> findByUuid(String uuid, int start, int end,
154 OrderByComparator orderByComparator) throws SystemException {
155 boolean pagination = true;
156 FinderPath finderPath = null;
157 Object[] finderArgs = null;
158
159 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
160 (orderByComparator == null)) {
161 pagination = false;
162 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
163 finderArgs = new Object[] { uuid };
164 }
165 else {
166 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
167 finderArgs = new Object[] { uuid, start, end, orderByComparator };
168 }
169
170 List<LayoutPrototype> list = (List<LayoutPrototype>)FinderCacheUtil.getResult(finderPath,
171 finderArgs, this);
172
173 if ((list != null) && !list.isEmpty()) {
174 for (LayoutPrototype layoutPrototype : list) {
175 if (!Validator.equals(uuid, layoutPrototype.getUuid())) {
176 list = null;
177
178 break;
179 }
180 }
181 }
182
183 if (list == null) {
184 StringBundler query = null;
185
186 if (orderByComparator != null) {
187 query = new StringBundler(3 +
188 (orderByComparator.getOrderByFields().length * 3));
189 }
190 else {
191 query = new StringBundler(3);
192 }
193
194 query.append(_SQL_SELECT_LAYOUTPROTOTYPE_WHERE);
195
196 boolean bindUuid = false;
197
198 if (uuid == null) {
199 query.append(_FINDER_COLUMN_UUID_UUID_1);
200 }
201 else if (uuid.equals(StringPool.BLANK)) {
202 query.append(_FINDER_COLUMN_UUID_UUID_3);
203 }
204 else {
205 bindUuid = true;
206
207 query.append(_FINDER_COLUMN_UUID_UUID_2);
208 }
209
210 if (orderByComparator != null) {
211 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
212 orderByComparator);
213 }
214 else
215 if (pagination) {
216 query.append(LayoutPrototypeModelImpl.ORDER_BY_JPQL);
217 }
218
219 String sql = query.toString();
220
221 Session session = null;
222
223 try {
224 session = openSession();
225
226 Query q = session.createQuery(sql);
227
228 QueryPos qPos = QueryPos.getInstance(q);
229
230 if (bindUuid) {
231 qPos.add(uuid);
232 }
233
234 if (!pagination) {
235 list = (List<LayoutPrototype>)QueryUtil.list(q,
236 getDialect(), start, end, false);
237
238 Collections.sort(list);
239
240 list = new UnmodifiableList<LayoutPrototype>(list);
241 }
242 else {
243 list = (List<LayoutPrototype>)QueryUtil.list(q,
244 getDialect(), start, end);
245 }
246
247 cacheResult(list);
248
249 FinderCacheUtil.putResult(finderPath, finderArgs, list);
250 }
251 catch (Exception e) {
252 FinderCacheUtil.removeResult(finderPath, finderArgs);
253
254 throw processException(e);
255 }
256 finally {
257 closeSession(session);
258 }
259 }
260
261 return list;
262 }
263
264
273 public LayoutPrototype findByUuid_First(String uuid,
274 OrderByComparator orderByComparator)
275 throws NoSuchLayoutPrototypeException, SystemException {
276 LayoutPrototype layoutPrototype = fetchByUuid_First(uuid,
277 orderByComparator);
278
279 if (layoutPrototype != null) {
280 return layoutPrototype;
281 }
282
283 StringBundler msg = new StringBundler(4);
284
285 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
286
287 msg.append("uuid=");
288 msg.append(uuid);
289
290 msg.append(StringPool.CLOSE_CURLY_BRACE);
291
292 throw new NoSuchLayoutPrototypeException(msg.toString());
293 }
294
295
303 public LayoutPrototype fetchByUuid_First(String uuid,
304 OrderByComparator orderByComparator) throws SystemException {
305 List<LayoutPrototype> list = findByUuid(uuid, 0, 1, orderByComparator);
306
307 if (!list.isEmpty()) {
308 return list.get(0);
309 }
310
311 return null;
312 }
313
314
323 public LayoutPrototype findByUuid_Last(String uuid,
324 OrderByComparator orderByComparator)
325 throws NoSuchLayoutPrototypeException, SystemException {
326 LayoutPrototype layoutPrototype = fetchByUuid_Last(uuid,
327 orderByComparator);
328
329 if (layoutPrototype != null) {
330 return layoutPrototype;
331 }
332
333 StringBundler msg = new StringBundler(4);
334
335 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
336
337 msg.append("uuid=");
338 msg.append(uuid);
339
340 msg.append(StringPool.CLOSE_CURLY_BRACE);
341
342 throw new NoSuchLayoutPrototypeException(msg.toString());
343 }
344
345
353 public LayoutPrototype fetchByUuid_Last(String uuid,
354 OrderByComparator orderByComparator) throws SystemException {
355 int count = countByUuid(uuid);
356
357 List<LayoutPrototype> list = findByUuid(uuid, count - 1, count,
358 orderByComparator);
359
360 if (!list.isEmpty()) {
361 return list.get(0);
362 }
363
364 return null;
365 }
366
367
377 public LayoutPrototype[] findByUuid_PrevAndNext(long layoutPrototypeId,
378 String uuid, OrderByComparator orderByComparator)
379 throws NoSuchLayoutPrototypeException, SystemException {
380 LayoutPrototype layoutPrototype = findByPrimaryKey(layoutPrototypeId);
381
382 Session session = null;
383
384 try {
385 session = openSession();
386
387 LayoutPrototype[] array = new LayoutPrototypeImpl[3];
388
389 array[0] = getByUuid_PrevAndNext(session, layoutPrototype, uuid,
390 orderByComparator, true);
391
392 array[1] = layoutPrototype;
393
394 array[2] = getByUuid_PrevAndNext(session, layoutPrototype, uuid,
395 orderByComparator, false);
396
397 return array;
398 }
399 catch (Exception e) {
400 throw processException(e);
401 }
402 finally {
403 closeSession(session);
404 }
405 }
406
407 protected LayoutPrototype getByUuid_PrevAndNext(Session session,
408 LayoutPrototype layoutPrototype, String uuid,
409 OrderByComparator orderByComparator, boolean previous) {
410 StringBundler query = null;
411
412 if (orderByComparator != null) {
413 query = new StringBundler(6 +
414 (orderByComparator.getOrderByFields().length * 6));
415 }
416 else {
417 query = new StringBundler(3);
418 }
419
420 query.append(_SQL_SELECT_LAYOUTPROTOTYPE_WHERE);
421
422 boolean bindUuid = false;
423
424 if (uuid == null) {
425 query.append(_FINDER_COLUMN_UUID_UUID_1);
426 }
427 else if (uuid.equals(StringPool.BLANK)) {
428 query.append(_FINDER_COLUMN_UUID_UUID_3);
429 }
430 else {
431 bindUuid = true;
432
433 query.append(_FINDER_COLUMN_UUID_UUID_2);
434 }
435
436 if (orderByComparator != null) {
437 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
438
439 if (orderByConditionFields.length > 0) {
440 query.append(WHERE_AND);
441 }
442
443 for (int i = 0; i < orderByConditionFields.length; i++) {
444 query.append(_ORDER_BY_ENTITY_ALIAS);
445 query.append(orderByConditionFields[i]);
446
447 if ((i + 1) < orderByConditionFields.length) {
448 if (orderByComparator.isAscending() ^ previous) {
449 query.append(WHERE_GREATER_THAN_HAS_NEXT);
450 }
451 else {
452 query.append(WHERE_LESSER_THAN_HAS_NEXT);
453 }
454 }
455 else {
456 if (orderByComparator.isAscending() ^ previous) {
457 query.append(WHERE_GREATER_THAN);
458 }
459 else {
460 query.append(WHERE_LESSER_THAN);
461 }
462 }
463 }
464
465 query.append(ORDER_BY_CLAUSE);
466
467 String[] orderByFields = orderByComparator.getOrderByFields();
468
469 for (int i = 0; i < orderByFields.length; i++) {
470 query.append(_ORDER_BY_ENTITY_ALIAS);
471 query.append(orderByFields[i]);
472
473 if ((i + 1) < orderByFields.length) {
474 if (orderByComparator.isAscending() ^ previous) {
475 query.append(ORDER_BY_ASC_HAS_NEXT);
476 }
477 else {
478 query.append(ORDER_BY_DESC_HAS_NEXT);
479 }
480 }
481 else {
482 if (orderByComparator.isAscending() ^ previous) {
483 query.append(ORDER_BY_ASC);
484 }
485 else {
486 query.append(ORDER_BY_DESC);
487 }
488 }
489 }
490 }
491 else {
492 query.append(LayoutPrototypeModelImpl.ORDER_BY_JPQL);
493 }
494
495 String sql = query.toString();
496
497 Query q = session.createQuery(sql);
498
499 q.setFirstResult(0);
500 q.setMaxResults(2);
501
502 QueryPos qPos = QueryPos.getInstance(q);
503
504 if (bindUuid) {
505 qPos.add(uuid);
506 }
507
508 if (orderByComparator != null) {
509 Object[] values = orderByComparator.getOrderByConditionValues(layoutPrototype);
510
511 for (Object value : values) {
512 qPos.add(value);
513 }
514 }
515
516 List<LayoutPrototype> list = q.list();
517
518 if (list.size() == 2) {
519 return list.get(1);
520 }
521 else {
522 return null;
523 }
524 }
525
526
533 public List<LayoutPrototype> filterFindByUuid(String uuid)
534 throws SystemException {
535 return filterFindByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
536 }
537
538
551 public List<LayoutPrototype> filterFindByUuid(String uuid, int start,
552 int end) throws SystemException {
553 return filterFindByUuid(uuid, start, end, null);
554 }
555
556
570 public List<LayoutPrototype> filterFindByUuid(String uuid, int start,
571 int end, OrderByComparator orderByComparator) throws SystemException {
572 if (!InlineSQLHelperUtil.isEnabled()) {
573 return findByUuid(uuid, start, end, orderByComparator);
574 }
575
576 StringBundler query = null;
577
578 if (orderByComparator != null) {
579 query = new StringBundler(3 +
580 (orderByComparator.getOrderByFields().length * 3));
581 }
582 else {
583 query = new StringBundler(3);
584 }
585
586 if (getDB().isSupportsInlineDistinct()) {
587 query.append(_FILTER_SQL_SELECT_LAYOUTPROTOTYPE_WHERE);
588 }
589 else {
590 query.append(_FILTER_SQL_SELECT_LAYOUTPROTOTYPE_NO_INLINE_DISTINCT_WHERE_1);
591 }
592
593 boolean bindUuid = false;
594
595 if (uuid == null) {
596 query.append(_FINDER_COLUMN_UUID_UUID_1);
597 }
598 else if (uuid.equals(StringPool.BLANK)) {
599 query.append(_FINDER_COLUMN_UUID_UUID_3);
600 }
601 else {
602 bindUuid = true;
603
604 query.append(_FINDER_COLUMN_UUID_UUID_2);
605 }
606
607 if (!getDB().isSupportsInlineDistinct()) {
608 query.append(_FILTER_SQL_SELECT_LAYOUTPROTOTYPE_NO_INLINE_DISTINCT_WHERE_2);
609 }
610
611 if (orderByComparator != null) {
612 if (getDB().isSupportsInlineDistinct()) {
613 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
614 orderByComparator);
615 }
616 else {
617 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
618 orderByComparator);
619 }
620 }
621 else {
622 if (getDB().isSupportsInlineDistinct()) {
623 query.append(LayoutPrototypeModelImpl.ORDER_BY_JPQL);
624 }
625 else {
626 query.append(LayoutPrototypeModelImpl.ORDER_BY_SQL);
627 }
628 }
629
630 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
631 LayoutPrototype.class.getName(),
632 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
633
634 Session session = null;
635
636 try {
637 session = openSession();
638
639 SQLQuery q = session.createSQLQuery(sql);
640
641 if (getDB().isSupportsInlineDistinct()) {
642 q.addEntity(_FILTER_ENTITY_ALIAS, LayoutPrototypeImpl.class);
643 }
644 else {
645 q.addEntity(_FILTER_ENTITY_TABLE, LayoutPrototypeImpl.class);
646 }
647
648 QueryPos qPos = QueryPos.getInstance(q);
649
650 if (bindUuid) {
651 qPos.add(uuid);
652 }
653
654 return (List<LayoutPrototype>)QueryUtil.list(q, getDialect(),
655 start, end);
656 }
657 catch (Exception e) {
658 throw processException(e);
659 }
660 finally {
661 closeSession(session);
662 }
663 }
664
665
675 public LayoutPrototype[] filterFindByUuid_PrevAndNext(
676 long layoutPrototypeId, String uuid, OrderByComparator orderByComparator)
677 throws NoSuchLayoutPrototypeException, SystemException {
678 if (!InlineSQLHelperUtil.isEnabled()) {
679 return findByUuid_PrevAndNext(layoutPrototypeId, uuid,
680 orderByComparator);
681 }
682
683 LayoutPrototype layoutPrototype = findByPrimaryKey(layoutPrototypeId);
684
685 Session session = null;
686
687 try {
688 session = openSession();
689
690 LayoutPrototype[] array = new LayoutPrototypeImpl[3];
691
692 array[0] = filterGetByUuid_PrevAndNext(session, layoutPrototype,
693 uuid, orderByComparator, true);
694
695 array[1] = layoutPrototype;
696
697 array[2] = filterGetByUuid_PrevAndNext(session, layoutPrototype,
698 uuid, orderByComparator, false);
699
700 return array;
701 }
702 catch (Exception e) {
703 throw processException(e);
704 }
705 finally {
706 closeSession(session);
707 }
708 }
709
710 protected LayoutPrototype filterGetByUuid_PrevAndNext(Session session,
711 LayoutPrototype layoutPrototype, String uuid,
712 OrderByComparator orderByComparator, boolean previous) {
713 StringBundler query = null;
714
715 if (orderByComparator != null) {
716 query = new StringBundler(6 +
717 (orderByComparator.getOrderByFields().length * 6));
718 }
719 else {
720 query = new StringBundler(3);
721 }
722
723 if (getDB().isSupportsInlineDistinct()) {
724 query.append(_FILTER_SQL_SELECT_LAYOUTPROTOTYPE_WHERE);
725 }
726 else {
727 query.append(_FILTER_SQL_SELECT_LAYOUTPROTOTYPE_NO_INLINE_DISTINCT_WHERE_1);
728 }
729
730 boolean bindUuid = false;
731
732 if (uuid == null) {
733 query.append(_FINDER_COLUMN_UUID_UUID_1);
734 }
735 else if (uuid.equals(StringPool.BLANK)) {
736 query.append(_FINDER_COLUMN_UUID_UUID_3);
737 }
738 else {
739 bindUuid = true;
740
741 query.append(_FINDER_COLUMN_UUID_UUID_2);
742 }
743
744 if (!getDB().isSupportsInlineDistinct()) {
745 query.append(_FILTER_SQL_SELECT_LAYOUTPROTOTYPE_NO_INLINE_DISTINCT_WHERE_2);
746 }
747
748 if (orderByComparator != null) {
749 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
750
751 if (orderByConditionFields.length > 0) {
752 query.append(WHERE_AND);
753 }
754
755 for (int i = 0; i < orderByConditionFields.length; i++) {
756 if (getDB().isSupportsInlineDistinct()) {
757 query.append(_ORDER_BY_ENTITY_ALIAS);
758 }
759 else {
760 query.append(_ORDER_BY_ENTITY_TABLE);
761 }
762
763 query.append(orderByConditionFields[i]);
764
765 if ((i + 1) < orderByConditionFields.length) {
766 if (orderByComparator.isAscending() ^ previous) {
767 query.append(WHERE_GREATER_THAN_HAS_NEXT);
768 }
769 else {
770 query.append(WHERE_LESSER_THAN_HAS_NEXT);
771 }
772 }
773 else {
774 if (orderByComparator.isAscending() ^ previous) {
775 query.append(WHERE_GREATER_THAN);
776 }
777 else {
778 query.append(WHERE_LESSER_THAN);
779 }
780 }
781 }
782
783 query.append(ORDER_BY_CLAUSE);
784
785 String[] orderByFields = orderByComparator.getOrderByFields();
786
787 for (int i = 0; i < orderByFields.length; i++) {
788 if (getDB().isSupportsInlineDistinct()) {
789 query.append(_ORDER_BY_ENTITY_ALIAS);
790 }
791 else {
792 query.append(_ORDER_BY_ENTITY_TABLE);
793 }
794
795 query.append(orderByFields[i]);
796
797 if ((i + 1) < orderByFields.length) {
798 if (orderByComparator.isAscending() ^ previous) {
799 query.append(ORDER_BY_ASC_HAS_NEXT);
800 }
801 else {
802 query.append(ORDER_BY_DESC_HAS_NEXT);
803 }
804 }
805 else {
806 if (orderByComparator.isAscending() ^ previous) {
807 query.append(ORDER_BY_ASC);
808 }
809 else {
810 query.append(ORDER_BY_DESC);
811 }
812 }
813 }
814 }
815 else {
816 if (getDB().isSupportsInlineDistinct()) {
817 query.append(LayoutPrototypeModelImpl.ORDER_BY_JPQL);
818 }
819 else {
820 query.append(LayoutPrototypeModelImpl.ORDER_BY_SQL);
821 }
822 }
823
824 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
825 LayoutPrototype.class.getName(),
826 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
827
828 SQLQuery q = session.createSQLQuery(sql);
829
830 q.setFirstResult(0);
831 q.setMaxResults(2);
832
833 if (getDB().isSupportsInlineDistinct()) {
834 q.addEntity(_FILTER_ENTITY_ALIAS, LayoutPrototypeImpl.class);
835 }
836 else {
837 q.addEntity(_FILTER_ENTITY_TABLE, LayoutPrototypeImpl.class);
838 }
839
840 QueryPos qPos = QueryPos.getInstance(q);
841
842 if (bindUuid) {
843 qPos.add(uuid);
844 }
845
846 if (orderByComparator != null) {
847 Object[] values = orderByComparator.getOrderByConditionValues(layoutPrototype);
848
849 for (Object value : values) {
850 qPos.add(value);
851 }
852 }
853
854 List<LayoutPrototype> list = q.list();
855
856 if (list.size() == 2) {
857 return list.get(1);
858 }
859 else {
860 return null;
861 }
862 }
863
864
870 public void removeByUuid(String uuid) throws SystemException {
871 for (LayoutPrototype layoutPrototype : findByUuid(uuid,
872 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
873 remove(layoutPrototype);
874 }
875 }
876
877
884 public int countByUuid(String uuid) throws SystemException {
885 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
886
887 Object[] finderArgs = new Object[] { uuid };
888
889 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
890 this);
891
892 if (count == null) {
893 StringBundler query = new StringBundler(2);
894
895 query.append(_SQL_COUNT_LAYOUTPROTOTYPE_WHERE);
896
897 boolean bindUuid = false;
898
899 if (uuid == null) {
900 query.append(_FINDER_COLUMN_UUID_UUID_1);
901 }
902 else if (uuid.equals(StringPool.BLANK)) {
903 query.append(_FINDER_COLUMN_UUID_UUID_3);
904 }
905 else {
906 bindUuid = true;
907
908 query.append(_FINDER_COLUMN_UUID_UUID_2);
909 }
910
911 String sql = query.toString();
912
913 Session session = null;
914
915 try {
916 session = openSession();
917
918 Query q = session.createQuery(sql);
919
920 QueryPos qPos = QueryPos.getInstance(q);
921
922 if (bindUuid) {
923 qPos.add(uuid);
924 }
925
926 count = (Long)q.uniqueResult();
927
928 FinderCacheUtil.putResult(finderPath, finderArgs, count);
929 }
930 catch (Exception e) {
931 FinderCacheUtil.removeResult(finderPath, finderArgs);
932
933 throw processException(e);
934 }
935 finally {
936 closeSession(session);
937 }
938 }
939
940 return count.intValue();
941 }
942
943
950 public int filterCountByUuid(String uuid) throws SystemException {
951 if (!InlineSQLHelperUtil.isEnabled()) {
952 return countByUuid(uuid);
953 }
954
955 StringBundler query = new StringBundler(2);
956
957 query.append(_FILTER_SQL_COUNT_LAYOUTPROTOTYPE_WHERE);
958
959 boolean bindUuid = false;
960
961 if (uuid == null) {
962 query.append(_FINDER_COLUMN_UUID_UUID_1);
963 }
964 else if (uuid.equals(StringPool.BLANK)) {
965 query.append(_FINDER_COLUMN_UUID_UUID_3);
966 }
967 else {
968 bindUuid = true;
969
970 query.append(_FINDER_COLUMN_UUID_UUID_2);
971 }
972
973 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
974 LayoutPrototype.class.getName(),
975 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
976
977 Session session = null;
978
979 try {
980 session = openSession();
981
982 SQLQuery q = session.createSQLQuery(sql);
983
984 q.addScalar(COUNT_COLUMN_NAME,
985 com.liferay.portal.kernel.dao.orm.Type.LONG);
986
987 QueryPos qPos = QueryPos.getInstance(q);
988
989 if (bindUuid) {
990 qPos.add(uuid);
991 }
992
993 Long count = (Long)q.uniqueResult();
994
995 return count.intValue();
996 }
997 catch (Exception e) {
998 throw processException(e);
999 }
1000 finally {
1001 closeSession(session);
1002 }
1003 }
1004
1005 private static final String _FINDER_COLUMN_UUID_UUID_1 = "layoutPrototype.uuid IS NULL";
1006 private static final String _FINDER_COLUMN_UUID_UUID_2 = "layoutPrototype.uuid = ?";
1007 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(layoutPrototype.uuid IS NULL OR layoutPrototype.uuid = '')";
1008 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(LayoutPrototypeModelImpl.ENTITY_CACHE_ENABLED,
1009 LayoutPrototypeModelImpl.FINDER_CACHE_ENABLED,
1010 LayoutPrototypeImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
1011 "findByUuid_C",
1012 new String[] {
1013 String.class.getName(), Long.class.getName(),
1014
1015 Integer.class.getName(), Integer.class.getName(),
1016 OrderByComparator.class.getName()
1017 });
1018 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
1019 new FinderPath(LayoutPrototypeModelImpl.ENTITY_CACHE_ENABLED,
1020 LayoutPrototypeModelImpl.FINDER_CACHE_ENABLED,
1021 LayoutPrototypeImpl.class,
1022 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
1023 new String[] { String.class.getName(), Long.class.getName() },
1024 LayoutPrototypeModelImpl.UUID_COLUMN_BITMASK |
1025 LayoutPrototypeModelImpl.COMPANYID_COLUMN_BITMASK);
1026 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(LayoutPrototypeModelImpl.ENTITY_CACHE_ENABLED,
1027 LayoutPrototypeModelImpl.FINDER_CACHE_ENABLED, Long.class,
1028 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
1029 new String[] { String.class.getName(), Long.class.getName() });
1030
1031
1039 public List<LayoutPrototype> findByUuid_C(String uuid, long companyId)
1040 throws SystemException {
1041 return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
1042 QueryUtil.ALL_POS, null);
1043 }
1044
1045
1059 public List<LayoutPrototype> findByUuid_C(String uuid, long companyId,
1060 int start, int end) throws SystemException {
1061 return findByUuid_C(uuid, companyId, start, end, null);
1062 }
1063
1064
1079 public List<LayoutPrototype> findByUuid_C(String uuid, long companyId,
1080 int start, int end, OrderByComparator orderByComparator)
1081 throws SystemException {
1082 boolean pagination = true;
1083 FinderPath finderPath = null;
1084 Object[] finderArgs = null;
1085
1086 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1087 (orderByComparator == null)) {
1088 pagination = false;
1089 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
1090 finderArgs = new Object[] { uuid, companyId };
1091 }
1092 else {
1093 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
1094 finderArgs = new Object[] {
1095 uuid, companyId,
1096
1097 start, end, orderByComparator
1098 };
1099 }
1100
1101 List<LayoutPrototype> list = (List<LayoutPrototype>)FinderCacheUtil.getResult(finderPath,
1102 finderArgs, this);
1103
1104 if ((list != null) && !list.isEmpty()) {
1105 for (LayoutPrototype layoutPrototype : list) {
1106 if (!Validator.equals(uuid, layoutPrototype.getUuid()) ||
1107 (companyId != layoutPrototype.getCompanyId())) {
1108 list = null;
1109
1110 break;
1111 }
1112 }
1113 }
1114
1115 if (list == null) {
1116 StringBundler query = null;
1117
1118 if (orderByComparator != null) {
1119 query = new StringBundler(4 +
1120 (orderByComparator.getOrderByFields().length * 3));
1121 }
1122 else {
1123 query = new StringBundler(4);
1124 }
1125
1126 query.append(_SQL_SELECT_LAYOUTPROTOTYPE_WHERE);
1127
1128 boolean bindUuid = false;
1129
1130 if (uuid == null) {
1131 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1132 }
1133 else if (uuid.equals(StringPool.BLANK)) {
1134 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1135 }
1136 else {
1137 bindUuid = true;
1138
1139 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1140 }
1141
1142 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1143
1144 if (orderByComparator != null) {
1145 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1146 orderByComparator);
1147 }
1148 else
1149 if (pagination) {
1150 query.append(LayoutPrototypeModelImpl.ORDER_BY_JPQL);
1151 }
1152
1153 String sql = query.toString();
1154
1155 Session session = null;
1156
1157 try {
1158 session = openSession();
1159
1160 Query q = session.createQuery(sql);
1161
1162 QueryPos qPos = QueryPos.getInstance(q);
1163
1164 if (bindUuid) {
1165 qPos.add(uuid);
1166 }
1167
1168 qPos.add(companyId);
1169
1170 if (!pagination) {
1171 list = (List<LayoutPrototype>)QueryUtil.list(q,
1172 getDialect(), start, end, false);
1173
1174 Collections.sort(list);
1175
1176 list = new UnmodifiableList<LayoutPrototype>(list);
1177 }
1178 else {
1179 list = (List<LayoutPrototype>)QueryUtil.list(q,
1180 getDialect(), start, end);
1181 }
1182
1183 cacheResult(list);
1184
1185 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1186 }
1187 catch (Exception e) {
1188 FinderCacheUtil.removeResult(finderPath, finderArgs);
1189
1190 throw processException(e);
1191 }
1192 finally {
1193 closeSession(session);
1194 }
1195 }
1196
1197 return list;
1198 }
1199
1200
1210 public LayoutPrototype findByUuid_C_First(String uuid, long companyId,
1211 OrderByComparator orderByComparator)
1212 throws NoSuchLayoutPrototypeException, SystemException {
1213 LayoutPrototype layoutPrototype = fetchByUuid_C_First(uuid, companyId,
1214 orderByComparator);
1215
1216 if (layoutPrototype != null) {
1217 return layoutPrototype;
1218 }
1219
1220 StringBundler msg = new StringBundler(6);
1221
1222 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1223
1224 msg.append("uuid=");
1225 msg.append(uuid);
1226
1227 msg.append(", companyId=");
1228 msg.append(companyId);
1229
1230 msg.append(StringPool.CLOSE_CURLY_BRACE);
1231
1232 throw new NoSuchLayoutPrototypeException(msg.toString());
1233 }
1234
1235
1244 public LayoutPrototype fetchByUuid_C_First(String uuid, long companyId,
1245 OrderByComparator orderByComparator) throws SystemException {
1246 List<LayoutPrototype> list = findByUuid_C(uuid, companyId, 0, 1,
1247 orderByComparator);
1248
1249 if (!list.isEmpty()) {
1250 return list.get(0);
1251 }
1252
1253 return null;
1254 }
1255
1256
1266 public LayoutPrototype findByUuid_C_Last(String uuid, long companyId,
1267 OrderByComparator orderByComparator)
1268 throws NoSuchLayoutPrototypeException, SystemException {
1269 LayoutPrototype layoutPrototype = fetchByUuid_C_Last(uuid, companyId,
1270 orderByComparator);
1271
1272 if (layoutPrototype != null) {
1273 return layoutPrototype;
1274 }
1275
1276 StringBundler msg = new StringBundler(6);
1277
1278 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1279
1280 msg.append("uuid=");
1281 msg.append(uuid);
1282
1283 msg.append(", companyId=");
1284 msg.append(companyId);
1285
1286 msg.append(StringPool.CLOSE_CURLY_BRACE);
1287
1288 throw new NoSuchLayoutPrototypeException(msg.toString());
1289 }
1290
1291
1300 public LayoutPrototype fetchByUuid_C_Last(String uuid, long companyId,
1301 OrderByComparator orderByComparator) throws SystemException {
1302 int count = countByUuid_C(uuid, companyId);
1303
1304 List<LayoutPrototype> list = findByUuid_C(uuid, companyId, count - 1,
1305 count, orderByComparator);
1306
1307 if (!list.isEmpty()) {
1308 return list.get(0);
1309 }
1310
1311 return null;
1312 }
1313
1314
1325 public LayoutPrototype[] findByUuid_C_PrevAndNext(long layoutPrototypeId,
1326 String uuid, long companyId, OrderByComparator orderByComparator)
1327 throws NoSuchLayoutPrototypeException, SystemException {
1328 LayoutPrototype layoutPrototype = findByPrimaryKey(layoutPrototypeId);
1329
1330 Session session = null;
1331
1332 try {
1333 session = openSession();
1334
1335 LayoutPrototype[] array = new LayoutPrototypeImpl[3];
1336
1337 array[0] = getByUuid_C_PrevAndNext(session, layoutPrototype, uuid,
1338 companyId, orderByComparator, true);
1339
1340 array[1] = layoutPrototype;
1341
1342 array[2] = getByUuid_C_PrevAndNext(session, layoutPrototype, uuid,
1343 companyId, orderByComparator, false);
1344
1345 return array;
1346 }
1347 catch (Exception e) {
1348 throw processException(e);
1349 }
1350 finally {
1351 closeSession(session);
1352 }
1353 }
1354
1355 protected LayoutPrototype getByUuid_C_PrevAndNext(Session session,
1356 LayoutPrototype layoutPrototype, String uuid, long companyId,
1357 OrderByComparator orderByComparator, boolean previous) {
1358 StringBundler query = null;
1359
1360 if (orderByComparator != null) {
1361 query = new StringBundler(6 +
1362 (orderByComparator.getOrderByFields().length * 6));
1363 }
1364 else {
1365 query = new StringBundler(3);
1366 }
1367
1368 query.append(_SQL_SELECT_LAYOUTPROTOTYPE_WHERE);
1369
1370 boolean bindUuid = false;
1371
1372 if (uuid == null) {
1373 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1374 }
1375 else if (uuid.equals(StringPool.BLANK)) {
1376 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1377 }
1378 else {
1379 bindUuid = true;
1380
1381 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1382 }
1383
1384 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1385
1386 if (orderByComparator != null) {
1387 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1388
1389 if (orderByConditionFields.length > 0) {
1390 query.append(WHERE_AND);
1391 }
1392
1393 for (int i = 0; i < orderByConditionFields.length; i++) {
1394 query.append(_ORDER_BY_ENTITY_ALIAS);
1395 query.append(orderByConditionFields[i]);
1396
1397 if ((i + 1) < orderByConditionFields.length) {
1398 if (orderByComparator.isAscending() ^ previous) {
1399 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1400 }
1401 else {
1402 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1403 }
1404 }
1405 else {
1406 if (orderByComparator.isAscending() ^ previous) {
1407 query.append(WHERE_GREATER_THAN);
1408 }
1409 else {
1410 query.append(WHERE_LESSER_THAN);
1411 }
1412 }
1413 }
1414
1415 query.append(ORDER_BY_CLAUSE);
1416
1417 String[] orderByFields = orderByComparator.getOrderByFields();
1418
1419 for (int i = 0; i < orderByFields.length; i++) {
1420 query.append(_ORDER_BY_ENTITY_ALIAS);
1421 query.append(orderByFields[i]);
1422
1423 if ((i + 1) < orderByFields.length) {
1424 if (orderByComparator.isAscending() ^ previous) {
1425 query.append(ORDER_BY_ASC_HAS_NEXT);
1426 }
1427 else {
1428 query.append(ORDER_BY_DESC_HAS_NEXT);
1429 }
1430 }
1431 else {
1432 if (orderByComparator.isAscending() ^ previous) {
1433 query.append(ORDER_BY_ASC);
1434 }
1435 else {
1436 query.append(ORDER_BY_DESC);
1437 }
1438 }
1439 }
1440 }
1441 else {
1442 query.append(LayoutPrototypeModelImpl.ORDER_BY_JPQL);
1443 }
1444
1445 String sql = query.toString();
1446
1447 Query q = session.createQuery(sql);
1448
1449 q.setFirstResult(0);
1450 q.setMaxResults(2);
1451
1452 QueryPos qPos = QueryPos.getInstance(q);
1453
1454 if (bindUuid) {
1455 qPos.add(uuid);
1456 }
1457
1458 qPos.add(companyId);
1459
1460 if (orderByComparator != null) {
1461 Object[] values = orderByComparator.getOrderByConditionValues(layoutPrototype);
1462
1463 for (Object value : values) {
1464 qPos.add(value);
1465 }
1466 }
1467
1468 List<LayoutPrototype> list = q.list();
1469
1470 if (list.size() == 2) {
1471 return list.get(1);
1472 }
1473 else {
1474 return null;
1475 }
1476 }
1477
1478
1486 public List<LayoutPrototype> filterFindByUuid_C(String uuid, long companyId)
1487 throws SystemException {
1488 return filterFindByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
1489 QueryUtil.ALL_POS, null);
1490 }
1491
1492
1506 public List<LayoutPrototype> filterFindByUuid_C(String uuid,
1507 long companyId, int start, int end) throws SystemException {
1508 return filterFindByUuid_C(uuid, companyId, start, end, null);
1509 }
1510
1511
1526 public List<LayoutPrototype> filterFindByUuid_C(String uuid,
1527 long companyId, int start, int end, OrderByComparator orderByComparator)
1528 throws SystemException {
1529 if (!InlineSQLHelperUtil.isEnabled()) {
1530 return findByUuid_C(uuid, companyId, start, end, orderByComparator);
1531 }
1532
1533 StringBundler query = null;
1534
1535 if (orderByComparator != null) {
1536 query = new StringBundler(4 +
1537 (orderByComparator.getOrderByFields().length * 3));
1538 }
1539 else {
1540 query = new StringBundler(4);
1541 }
1542
1543 if (getDB().isSupportsInlineDistinct()) {
1544 query.append(_FILTER_SQL_SELECT_LAYOUTPROTOTYPE_WHERE);
1545 }
1546 else {
1547 query.append(_FILTER_SQL_SELECT_LAYOUTPROTOTYPE_NO_INLINE_DISTINCT_WHERE_1);
1548 }
1549
1550 boolean bindUuid = false;
1551
1552 if (uuid == null) {
1553 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1554 }
1555 else if (uuid.equals(StringPool.BLANK)) {
1556 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1557 }
1558 else {
1559 bindUuid = true;
1560
1561 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1562 }
1563
1564 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1565
1566 if (!getDB().isSupportsInlineDistinct()) {
1567 query.append(_FILTER_SQL_SELECT_LAYOUTPROTOTYPE_NO_INLINE_DISTINCT_WHERE_2);
1568 }
1569
1570 if (orderByComparator != null) {
1571 if (getDB().isSupportsInlineDistinct()) {
1572 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1573 orderByComparator);
1574 }
1575 else {
1576 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1577 orderByComparator);
1578 }
1579 }
1580 else {
1581 if (getDB().isSupportsInlineDistinct()) {
1582 query.append(LayoutPrototypeModelImpl.ORDER_BY_JPQL);
1583 }
1584 else {
1585 query.append(LayoutPrototypeModelImpl.ORDER_BY_SQL);
1586 }
1587 }
1588
1589 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1590 LayoutPrototype.class.getName(),
1591 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1592
1593 Session session = null;
1594
1595 try {
1596 session = openSession();
1597
1598 SQLQuery q = session.createSQLQuery(sql);
1599
1600 if (getDB().isSupportsInlineDistinct()) {
1601 q.addEntity(_FILTER_ENTITY_ALIAS, LayoutPrototypeImpl.class);
1602 }
1603 else {
1604 q.addEntity(_FILTER_ENTITY_TABLE, LayoutPrototypeImpl.class);
1605 }
1606
1607 QueryPos qPos = QueryPos.getInstance(q);
1608
1609 if (bindUuid) {
1610 qPos.add(uuid);
1611 }
1612
1613 qPos.add(companyId);
1614
1615 return (List<LayoutPrototype>)QueryUtil.list(q, getDialect(),
1616 start, end);
1617 }
1618 catch (Exception e) {
1619 throw processException(e);
1620 }
1621 finally {
1622 closeSession(session);
1623 }
1624 }
1625
1626
1637 public LayoutPrototype[] filterFindByUuid_C_PrevAndNext(
1638 long layoutPrototypeId, String uuid, long companyId,
1639 OrderByComparator orderByComparator)
1640 throws NoSuchLayoutPrototypeException, SystemException {
1641 if (!InlineSQLHelperUtil.isEnabled()) {
1642 return findByUuid_C_PrevAndNext(layoutPrototypeId, uuid, companyId,
1643 orderByComparator);
1644 }
1645
1646 LayoutPrototype layoutPrototype = findByPrimaryKey(layoutPrototypeId);
1647
1648 Session session = null;
1649
1650 try {
1651 session = openSession();
1652
1653 LayoutPrototype[] array = new LayoutPrototypeImpl[3];
1654
1655 array[0] = filterGetByUuid_C_PrevAndNext(session, layoutPrototype,
1656 uuid, companyId, orderByComparator, true);
1657
1658 array[1] = layoutPrototype;
1659
1660 array[2] = filterGetByUuid_C_PrevAndNext(session, layoutPrototype,
1661 uuid, companyId, orderByComparator, false);
1662
1663 return array;
1664 }
1665 catch (Exception e) {
1666 throw processException(e);
1667 }
1668 finally {
1669 closeSession(session);
1670 }
1671 }
1672
1673 protected LayoutPrototype filterGetByUuid_C_PrevAndNext(Session session,
1674 LayoutPrototype layoutPrototype, String uuid, long companyId,
1675 OrderByComparator orderByComparator, boolean previous) {
1676 StringBundler query = null;
1677
1678 if (orderByComparator != null) {
1679 query = new StringBundler(6 +
1680 (orderByComparator.getOrderByFields().length * 6));
1681 }
1682 else {
1683 query = new StringBundler(3);
1684 }
1685
1686 if (getDB().isSupportsInlineDistinct()) {
1687 query.append(_FILTER_SQL_SELECT_LAYOUTPROTOTYPE_WHERE);
1688 }
1689 else {
1690 query.append(_FILTER_SQL_SELECT_LAYOUTPROTOTYPE_NO_INLINE_DISTINCT_WHERE_1);
1691 }
1692
1693 boolean bindUuid = false;
1694
1695 if (uuid == null) {
1696 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1697 }
1698 else if (uuid.equals(StringPool.BLANK)) {
1699 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1700 }
1701 else {
1702 bindUuid = true;
1703
1704 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1705 }
1706
1707 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1708
1709 if (!getDB().isSupportsInlineDistinct()) {
1710 query.append(_FILTER_SQL_SELECT_LAYOUTPROTOTYPE_NO_INLINE_DISTINCT_WHERE_2);
1711 }
1712
1713 if (orderByComparator != null) {
1714 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1715
1716 if (orderByConditionFields.length > 0) {
1717 query.append(WHERE_AND);
1718 }
1719
1720 for (int i = 0; i < orderByConditionFields.length; i++) {
1721 if (getDB().isSupportsInlineDistinct()) {
1722 query.append(_ORDER_BY_ENTITY_ALIAS);
1723 }
1724 else {
1725 query.append(_ORDER_BY_ENTITY_TABLE);
1726 }
1727
1728 query.append(orderByConditionFields[i]);
1729
1730 if ((i + 1) < orderByConditionFields.length) {
1731 if (orderByComparator.isAscending() ^ previous) {
1732 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1733 }
1734 else {
1735 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1736 }
1737 }
1738 else {
1739 if (orderByComparator.isAscending() ^ previous) {
1740 query.append(WHERE_GREATER_THAN);
1741 }
1742 else {
1743 query.append(WHERE_LESSER_THAN);
1744 }
1745 }
1746 }
1747
1748 query.append(ORDER_BY_CLAUSE);
1749
1750 String[] orderByFields = orderByComparator.getOrderByFields();
1751
1752 for (int i = 0; i < orderByFields.length; i++) {
1753 if (getDB().isSupportsInlineDistinct()) {
1754 query.append(_ORDER_BY_ENTITY_ALIAS);
1755 }
1756 else {
1757 query.append(_ORDER_BY_ENTITY_TABLE);
1758 }
1759
1760 query.append(orderByFields[i]);
1761
1762 if ((i + 1) < orderByFields.length) {
1763 if (orderByComparator.isAscending() ^ previous) {
1764 query.append(ORDER_BY_ASC_HAS_NEXT);
1765 }
1766 else {
1767 query.append(ORDER_BY_DESC_HAS_NEXT);
1768 }
1769 }
1770 else {
1771 if (orderByComparator.isAscending() ^ previous) {
1772 query.append(ORDER_BY_ASC);
1773 }
1774 else {
1775 query.append(ORDER_BY_DESC);
1776 }
1777 }
1778 }
1779 }
1780 else {
1781 if (getDB().isSupportsInlineDistinct()) {
1782 query.append(LayoutPrototypeModelImpl.ORDER_BY_JPQL);
1783 }
1784 else {
1785 query.append(LayoutPrototypeModelImpl.ORDER_BY_SQL);
1786 }
1787 }
1788
1789 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1790 LayoutPrototype.class.getName(),
1791 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1792
1793 SQLQuery q = session.createSQLQuery(sql);
1794
1795 q.setFirstResult(0);
1796 q.setMaxResults(2);
1797
1798 if (getDB().isSupportsInlineDistinct()) {
1799 q.addEntity(_FILTER_ENTITY_ALIAS, LayoutPrototypeImpl.class);
1800 }
1801 else {
1802 q.addEntity(_FILTER_ENTITY_TABLE, LayoutPrototypeImpl.class);
1803 }
1804
1805 QueryPos qPos = QueryPos.getInstance(q);
1806
1807 if (bindUuid) {
1808 qPos.add(uuid);
1809 }
1810
1811 qPos.add(companyId);
1812
1813 if (orderByComparator != null) {
1814 Object[] values = orderByComparator.getOrderByConditionValues(layoutPrototype);
1815
1816 for (Object value : values) {
1817 qPos.add(value);
1818 }
1819 }
1820
1821 List<LayoutPrototype> list = q.list();
1822
1823 if (list.size() == 2) {
1824 return list.get(1);
1825 }
1826 else {
1827 return null;
1828 }
1829 }
1830
1831
1838 public void removeByUuid_C(String uuid, long companyId)
1839 throws SystemException {
1840 for (LayoutPrototype layoutPrototype : findByUuid_C(uuid, companyId,
1841 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1842 remove(layoutPrototype);
1843 }
1844 }
1845
1846
1854 public int countByUuid_C(String uuid, long companyId)
1855 throws SystemException {
1856 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1857
1858 Object[] finderArgs = new Object[] { uuid, companyId };
1859
1860 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1861 this);
1862
1863 if (count == null) {
1864 StringBundler query = new StringBundler(3);
1865
1866 query.append(_SQL_COUNT_LAYOUTPROTOTYPE_WHERE);
1867
1868 boolean bindUuid = false;
1869
1870 if (uuid == null) {
1871 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1872 }
1873 else if (uuid.equals(StringPool.BLANK)) {
1874 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1875 }
1876 else {
1877 bindUuid = true;
1878
1879 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1880 }
1881
1882 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1883
1884 String sql = query.toString();
1885
1886 Session session = null;
1887
1888 try {
1889 session = openSession();
1890
1891 Query q = session.createQuery(sql);
1892
1893 QueryPos qPos = QueryPos.getInstance(q);
1894
1895 if (bindUuid) {
1896 qPos.add(uuid);
1897 }
1898
1899 qPos.add(companyId);
1900
1901 count = (Long)q.uniqueResult();
1902
1903 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1904 }
1905 catch (Exception e) {
1906 FinderCacheUtil.removeResult(finderPath, finderArgs);
1907
1908 throw processException(e);
1909 }
1910 finally {
1911 closeSession(session);
1912 }
1913 }
1914
1915 return count.intValue();
1916 }
1917
1918
1926 public int filterCountByUuid_C(String uuid, long companyId)
1927 throws SystemException {
1928 if (!InlineSQLHelperUtil.isEnabled()) {
1929 return countByUuid_C(uuid, companyId);
1930 }
1931
1932 StringBundler query = new StringBundler(3);
1933
1934 query.append(_FILTER_SQL_COUNT_LAYOUTPROTOTYPE_WHERE);
1935
1936 boolean bindUuid = false;
1937
1938 if (uuid == null) {
1939 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1940 }
1941 else if (uuid.equals(StringPool.BLANK)) {
1942 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1943 }
1944 else {
1945 bindUuid = true;
1946
1947 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1948 }
1949
1950 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1951
1952 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1953 LayoutPrototype.class.getName(),
1954 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1955
1956 Session session = null;
1957
1958 try {
1959 session = openSession();
1960
1961 SQLQuery q = session.createSQLQuery(sql);
1962
1963 q.addScalar(COUNT_COLUMN_NAME,
1964 com.liferay.portal.kernel.dao.orm.Type.LONG);
1965
1966 QueryPos qPos = QueryPos.getInstance(q);
1967
1968 if (bindUuid) {
1969 qPos.add(uuid);
1970 }
1971
1972 qPos.add(companyId);
1973
1974 Long count = (Long)q.uniqueResult();
1975
1976 return count.intValue();
1977 }
1978 catch (Exception e) {
1979 throw processException(e);
1980 }
1981 finally {
1982 closeSession(session);
1983 }
1984 }
1985
1986 private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "layoutPrototype.uuid IS NULL AND ";
1987 private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "layoutPrototype.uuid = ? AND ";
1988 private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(layoutPrototype.uuid IS NULL OR layoutPrototype.uuid = '') AND ";
1989 private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "layoutPrototype.companyId = ?";
1990 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
1991 new FinderPath(LayoutPrototypeModelImpl.ENTITY_CACHE_ENABLED,
1992 LayoutPrototypeModelImpl.FINDER_CACHE_ENABLED,
1993 LayoutPrototypeImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
1994 "findByCompanyId",
1995 new String[] {
1996 Long.class.getName(),
1997
1998 Integer.class.getName(), Integer.class.getName(),
1999 OrderByComparator.class.getName()
2000 });
2001 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
2002 new FinderPath(LayoutPrototypeModelImpl.ENTITY_CACHE_ENABLED,
2003 LayoutPrototypeModelImpl.FINDER_CACHE_ENABLED,
2004 LayoutPrototypeImpl.class,
2005 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
2006 new String[] { Long.class.getName() },
2007 LayoutPrototypeModelImpl.COMPANYID_COLUMN_BITMASK);
2008 public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(LayoutPrototypeModelImpl.ENTITY_CACHE_ENABLED,
2009 LayoutPrototypeModelImpl.FINDER_CACHE_ENABLED, Long.class,
2010 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
2011 new String[] { Long.class.getName() });
2012
2013
2020 public List<LayoutPrototype> findByCompanyId(long companyId)
2021 throws SystemException {
2022 return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2023 null);
2024 }
2025
2026
2039 public List<LayoutPrototype> findByCompanyId(long companyId, int start,
2040 int end) throws SystemException {
2041 return findByCompanyId(companyId, start, end, null);
2042 }
2043
2044
2058 public List<LayoutPrototype> findByCompanyId(long companyId, int start,
2059 int end, OrderByComparator orderByComparator) throws SystemException {
2060 boolean pagination = true;
2061 FinderPath finderPath = null;
2062 Object[] finderArgs = null;
2063
2064 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2065 (orderByComparator == null)) {
2066 pagination = false;
2067 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
2068 finderArgs = new Object[] { companyId };
2069 }
2070 else {
2071 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
2072 finderArgs = new Object[] { companyId, start, end, orderByComparator };
2073 }
2074
2075 List<LayoutPrototype> list = (List<LayoutPrototype>)FinderCacheUtil.getResult(finderPath,
2076 finderArgs, this);
2077
2078 if ((list != null) && !list.isEmpty()) {
2079 for (LayoutPrototype layoutPrototype : list) {
2080 if ((companyId != layoutPrototype.getCompanyId())) {
2081 list = null;
2082
2083 break;
2084 }
2085 }
2086 }
2087
2088 if (list == null) {
2089 StringBundler query = null;
2090
2091 if (orderByComparator != null) {
2092 query = new StringBundler(3 +
2093 (orderByComparator.getOrderByFields().length * 3));
2094 }
2095 else {
2096 query = new StringBundler(3);
2097 }
2098
2099 query.append(_SQL_SELECT_LAYOUTPROTOTYPE_WHERE);
2100
2101 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2102
2103 if (orderByComparator != null) {
2104 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2105 orderByComparator);
2106 }
2107 else
2108 if (pagination) {
2109 query.append(LayoutPrototypeModelImpl.ORDER_BY_JPQL);
2110 }
2111
2112 String sql = query.toString();
2113
2114 Session session = null;
2115
2116 try {
2117 session = openSession();
2118
2119 Query q = session.createQuery(sql);
2120
2121 QueryPos qPos = QueryPos.getInstance(q);
2122
2123 qPos.add(companyId);
2124
2125 if (!pagination) {
2126 list = (List<LayoutPrototype>)QueryUtil.list(q,
2127 getDialect(), start, end, false);
2128
2129 Collections.sort(list);
2130
2131 list = new UnmodifiableList<LayoutPrototype>(list);
2132 }
2133 else {
2134 list = (List<LayoutPrototype>)QueryUtil.list(q,
2135 getDialect(), start, end);
2136 }
2137
2138 cacheResult(list);
2139
2140 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2141 }
2142 catch (Exception e) {
2143 FinderCacheUtil.removeResult(finderPath, finderArgs);
2144
2145 throw processException(e);
2146 }
2147 finally {
2148 closeSession(session);
2149 }
2150 }
2151
2152 return list;
2153 }
2154
2155
2164 public LayoutPrototype findByCompanyId_First(long companyId,
2165 OrderByComparator orderByComparator)
2166 throws NoSuchLayoutPrototypeException, SystemException {
2167 LayoutPrototype layoutPrototype = fetchByCompanyId_First(companyId,
2168 orderByComparator);
2169
2170 if (layoutPrototype != null) {
2171 return layoutPrototype;
2172 }
2173
2174 StringBundler msg = new StringBundler(4);
2175
2176 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2177
2178 msg.append("companyId=");
2179 msg.append(companyId);
2180
2181 msg.append(StringPool.CLOSE_CURLY_BRACE);
2182
2183 throw new NoSuchLayoutPrototypeException(msg.toString());
2184 }
2185
2186
2194 public LayoutPrototype fetchByCompanyId_First(long companyId,
2195 OrderByComparator orderByComparator) throws SystemException {
2196 List<LayoutPrototype> list = findByCompanyId(companyId, 0, 1,
2197 orderByComparator);
2198
2199 if (!list.isEmpty()) {
2200 return list.get(0);
2201 }
2202
2203 return null;
2204 }
2205
2206
2215 public LayoutPrototype findByCompanyId_Last(long companyId,
2216 OrderByComparator orderByComparator)
2217 throws NoSuchLayoutPrototypeException, SystemException {
2218 LayoutPrototype layoutPrototype = fetchByCompanyId_Last(companyId,
2219 orderByComparator);
2220
2221 if (layoutPrototype != null) {
2222 return layoutPrototype;
2223 }
2224
2225 StringBundler msg = new StringBundler(4);
2226
2227 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2228
2229 msg.append("companyId=");
2230 msg.append(companyId);
2231
2232 msg.append(StringPool.CLOSE_CURLY_BRACE);
2233
2234 throw new NoSuchLayoutPrototypeException(msg.toString());
2235 }
2236
2237
2245 public LayoutPrototype fetchByCompanyId_Last(long companyId,
2246 OrderByComparator orderByComparator) throws SystemException {
2247 int count = countByCompanyId(companyId);
2248
2249 List<LayoutPrototype> list = findByCompanyId(companyId, count - 1,
2250 count, orderByComparator);
2251
2252 if (!list.isEmpty()) {
2253 return list.get(0);
2254 }
2255
2256 return null;
2257 }
2258
2259
2269 public LayoutPrototype[] findByCompanyId_PrevAndNext(
2270 long layoutPrototypeId, long companyId,
2271 OrderByComparator orderByComparator)
2272 throws NoSuchLayoutPrototypeException, SystemException {
2273 LayoutPrototype layoutPrototype = findByPrimaryKey(layoutPrototypeId);
2274
2275 Session session = null;
2276
2277 try {
2278 session = openSession();
2279
2280 LayoutPrototype[] array = new LayoutPrototypeImpl[3];
2281
2282 array[0] = getByCompanyId_PrevAndNext(session, layoutPrototype,
2283 companyId, orderByComparator, true);
2284
2285 array[1] = layoutPrototype;
2286
2287 array[2] = getByCompanyId_PrevAndNext(session, layoutPrototype,
2288 companyId, orderByComparator, false);
2289
2290 return array;
2291 }
2292 catch (Exception e) {
2293 throw processException(e);
2294 }
2295 finally {
2296 closeSession(session);
2297 }
2298 }
2299
2300 protected LayoutPrototype getByCompanyId_PrevAndNext(Session session,
2301 LayoutPrototype layoutPrototype, long companyId,
2302 OrderByComparator orderByComparator, boolean previous) {
2303 StringBundler query = null;
2304
2305 if (orderByComparator != null) {
2306 query = new StringBundler(6 +
2307 (orderByComparator.getOrderByFields().length * 6));
2308 }
2309 else {
2310 query = new StringBundler(3);
2311 }
2312
2313 query.append(_SQL_SELECT_LAYOUTPROTOTYPE_WHERE);
2314
2315 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2316
2317 if (orderByComparator != null) {
2318 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2319
2320 if (orderByConditionFields.length > 0) {
2321 query.append(WHERE_AND);
2322 }
2323
2324 for (int i = 0; i < orderByConditionFields.length; i++) {
2325 query.append(_ORDER_BY_ENTITY_ALIAS);
2326 query.append(orderByConditionFields[i]);
2327
2328 if ((i + 1) < orderByConditionFields.length) {
2329 if (orderByComparator.isAscending() ^ previous) {
2330 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2331 }
2332 else {
2333 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2334 }
2335 }
2336 else {
2337 if (orderByComparator.isAscending() ^ previous) {
2338 query.append(WHERE_GREATER_THAN);
2339 }
2340 else {
2341 query.append(WHERE_LESSER_THAN);
2342 }
2343 }
2344 }
2345
2346 query.append(ORDER_BY_CLAUSE);
2347
2348 String[] orderByFields = orderByComparator.getOrderByFields();
2349
2350 for (int i = 0; i < orderByFields.length; i++) {
2351 query.append(_ORDER_BY_ENTITY_ALIAS);
2352 query.append(orderByFields[i]);
2353
2354 if ((i + 1) < orderByFields.length) {
2355 if (orderByComparator.isAscending() ^ previous) {
2356 query.append(ORDER_BY_ASC_HAS_NEXT);
2357 }
2358 else {
2359 query.append(ORDER_BY_DESC_HAS_NEXT);
2360 }
2361 }
2362 else {
2363 if (orderByComparator.isAscending() ^ previous) {
2364 query.append(ORDER_BY_ASC);
2365 }
2366 else {
2367 query.append(ORDER_BY_DESC);
2368 }
2369 }
2370 }
2371 }
2372 else {
2373 query.append(LayoutPrototypeModelImpl.ORDER_BY_JPQL);
2374 }
2375
2376 String sql = query.toString();
2377
2378 Query q = session.createQuery(sql);
2379
2380 q.setFirstResult(0);
2381 q.setMaxResults(2);
2382
2383 QueryPos qPos = QueryPos.getInstance(q);
2384
2385 qPos.add(companyId);
2386
2387 if (orderByComparator != null) {
2388 Object[] values = orderByComparator.getOrderByConditionValues(layoutPrototype);
2389
2390 for (Object value : values) {
2391 qPos.add(value);
2392 }
2393 }
2394
2395 List<LayoutPrototype> list = q.list();
2396
2397 if (list.size() == 2) {
2398 return list.get(1);
2399 }
2400 else {
2401 return null;
2402 }
2403 }
2404
2405
2412 public List<LayoutPrototype> filterFindByCompanyId(long companyId)
2413 throws SystemException {
2414 return filterFindByCompanyId(companyId, QueryUtil.ALL_POS,
2415 QueryUtil.ALL_POS, null);
2416 }
2417
2418
2431 public List<LayoutPrototype> filterFindByCompanyId(long companyId,
2432 int start, int end) throws SystemException {
2433 return filterFindByCompanyId(companyId, start, end, null);
2434 }
2435
2436
2450 public List<LayoutPrototype> filterFindByCompanyId(long companyId,
2451 int start, int end, OrderByComparator orderByComparator)
2452 throws SystemException {
2453 if (!InlineSQLHelperUtil.isEnabled()) {
2454 return findByCompanyId(companyId, start, end, orderByComparator);
2455 }
2456
2457 StringBundler query = null;
2458
2459 if (orderByComparator != null) {
2460 query = new StringBundler(3 +
2461 (orderByComparator.getOrderByFields().length * 3));
2462 }
2463 else {
2464 query = new StringBundler(3);
2465 }
2466
2467 if (getDB().isSupportsInlineDistinct()) {
2468 query.append(_FILTER_SQL_SELECT_LAYOUTPROTOTYPE_WHERE);
2469 }
2470 else {
2471 query.append(_FILTER_SQL_SELECT_LAYOUTPROTOTYPE_NO_INLINE_DISTINCT_WHERE_1);
2472 }
2473
2474 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2475
2476 if (!getDB().isSupportsInlineDistinct()) {
2477 query.append(_FILTER_SQL_SELECT_LAYOUTPROTOTYPE_NO_INLINE_DISTINCT_WHERE_2);
2478 }
2479
2480 if (orderByComparator != null) {
2481 if (getDB().isSupportsInlineDistinct()) {
2482 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2483 orderByComparator);
2484 }
2485 else {
2486 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2487 orderByComparator);
2488 }
2489 }
2490 else {
2491 if (getDB().isSupportsInlineDistinct()) {
2492 query.append(LayoutPrototypeModelImpl.ORDER_BY_JPQL);
2493 }
2494 else {
2495 query.append(LayoutPrototypeModelImpl.ORDER_BY_SQL);
2496 }
2497 }
2498
2499 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2500 LayoutPrototype.class.getName(),
2501 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2502
2503 Session session = null;
2504
2505 try {
2506 session = openSession();
2507
2508 SQLQuery q = session.createSQLQuery(sql);
2509
2510 if (getDB().isSupportsInlineDistinct()) {
2511 q.addEntity(_FILTER_ENTITY_ALIAS, LayoutPrototypeImpl.class);
2512 }
2513 else {
2514 q.addEntity(_FILTER_ENTITY_TABLE, LayoutPrototypeImpl.class);
2515 }
2516
2517 QueryPos qPos = QueryPos.getInstance(q);
2518
2519 qPos.add(companyId);
2520
2521 return (List<LayoutPrototype>)QueryUtil.list(q, getDialect(),
2522 start, end);
2523 }
2524 catch (Exception e) {
2525 throw processException(e);
2526 }
2527 finally {
2528 closeSession(session);
2529 }
2530 }
2531
2532
2542 public LayoutPrototype[] filterFindByCompanyId_PrevAndNext(
2543 long layoutPrototypeId, long companyId,
2544 OrderByComparator orderByComparator)
2545 throws NoSuchLayoutPrototypeException, SystemException {
2546 if (!InlineSQLHelperUtil.isEnabled()) {
2547 return findByCompanyId_PrevAndNext(layoutPrototypeId, companyId,
2548 orderByComparator);
2549 }
2550
2551 LayoutPrototype layoutPrototype = findByPrimaryKey(layoutPrototypeId);
2552
2553 Session session = null;
2554
2555 try {
2556 session = openSession();
2557
2558 LayoutPrototype[] array = new LayoutPrototypeImpl[3];
2559
2560 array[0] = filterGetByCompanyId_PrevAndNext(session,
2561 layoutPrototype, companyId, orderByComparator, true);
2562
2563 array[1] = layoutPrototype;
2564
2565 array[2] = filterGetByCompanyId_PrevAndNext(session,
2566 layoutPrototype, companyId, orderByComparator, false);
2567
2568 return array;
2569 }
2570 catch (Exception e) {
2571 throw processException(e);
2572 }
2573 finally {
2574 closeSession(session);
2575 }
2576 }
2577
2578 protected LayoutPrototype filterGetByCompanyId_PrevAndNext(
2579 Session session, LayoutPrototype layoutPrototype, long companyId,
2580 OrderByComparator orderByComparator, boolean previous) {
2581 StringBundler query = null;
2582
2583 if (orderByComparator != null) {
2584 query = new StringBundler(6 +
2585 (orderByComparator.getOrderByFields().length * 6));
2586 }
2587 else {
2588 query = new StringBundler(3);
2589 }
2590
2591 if (getDB().isSupportsInlineDistinct()) {
2592 query.append(_FILTER_SQL_SELECT_LAYOUTPROTOTYPE_WHERE);
2593 }
2594 else {
2595 query.append(_FILTER_SQL_SELECT_LAYOUTPROTOTYPE_NO_INLINE_DISTINCT_WHERE_1);
2596 }
2597
2598 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2599
2600 if (!getDB().isSupportsInlineDistinct()) {
2601 query.append(_FILTER_SQL_SELECT_LAYOUTPROTOTYPE_NO_INLINE_DISTINCT_WHERE_2);
2602 }
2603
2604 if (orderByComparator != null) {
2605 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2606
2607 if (orderByConditionFields.length > 0) {
2608 query.append(WHERE_AND);
2609 }
2610
2611 for (int i = 0; i < orderByConditionFields.length; i++) {
2612 if (getDB().isSupportsInlineDistinct()) {
2613 query.append(_ORDER_BY_ENTITY_ALIAS);
2614 }
2615 else {
2616 query.append(_ORDER_BY_ENTITY_TABLE);
2617 }
2618
2619 query.append(orderByConditionFields[i]);
2620
2621 if ((i + 1) < orderByConditionFields.length) {
2622 if (orderByComparator.isAscending() ^ previous) {
2623 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2624 }
2625 else {
2626 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2627 }
2628 }
2629 else {
2630 if (orderByComparator.isAscending() ^ previous) {
2631 query.append(WHERE_GREATER_THAN);
2632 }
2633 else {
2634 query.append(WHERE_LESSER_THAN);
2635 }
2636 }
2637 }
2638
2639 query.append(ORDER_BY_CLAUSE);
2640
2641 String[] orderByFields = orderByComparator.getOrderByFields();
2642
2643 for (int i = 0; i < orderByFields.length; i++) {
2644 if (getDB().isSupportsInlineDistinct()) {
2645 query.append(_ORDER_BY_ENTITY_ALIAS);
2646 }
2647 else {
2648 query.append(_ORDER_BY_ENTITY_TABLE);
2649 }
2650
2651 query.append(orderByFields[i]);
2652
2653 if ((i + 1) < orderByFields.length) {
2654 if (orderByComparator.isAscending() ^ previous) {
2655 query.append(ORDER_BY_ASC_HAS_NEXT);
2656 }
2657 else {
2658 query.append(ORDER_BY_DESC_HAS_NEXT);
2659 }
2660 }
2661 else {
2662 if (orderByComparator.isAscending() ^ previous) {
2663 query.append(ORDER_BY_ASC);
2664 }
2665 else {
2666 query.append(ORDER_BY_DESC);
2667 }
2668 }
2669 }
2670 }
2671 else {
2672 if (getDB().isSupportsInlineDistinct()) {
2673 query.append(LayoutPrototypeModelImpl.ORDER_BY_JPQL);
2674 }
2675 else {
2676 query.append(LayoutPrototypeModelImpl.ORDER_BY_SQL);
2677 }
2678 }
2679
2680 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2681 LayoutPrototype.class.getName(),
2682 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2683
2684 SQLQuery q = session.createSQLQuery(sql);
2685
2686 q.setFirstResult(0);
2687 q.setMaxResults(2);
2688
2689 if (getDB().isSupportsInlineDistinct()) {
2690 q.addEntity(_FILTER_ENTITY_ALIAS, LayoutPrototypeImpl.class);
2691 }
2692 else {
2693 q.addEntity(_FILTER_ENTITY_TABLE, LayoutPrototypeImpl.class);
2694 }
2695
2696 QueryPos qPos = QueryPos.getInstance(q);
2697
2698 qPos.add(companyId);
2699
2700 if (orderByComparator != null) {
2701 Object[] values = orderByComparator.getOrderByConditionValues(layoutPrototype);
2702
2703 for (Object value : values) {
2704 qPos.add(value);
2705 }
2706 }
2707
2708 List<LayoutPrototype> list = q.list();
2709
2710 if (list.size() == 2) {
2711 return list.get(1);
2712 }
2713 else {
2714 return null;
2715 }
2716 }
2717
2718
2724 public void removeByCompanyId(long companyId) throws SystemException {
2725 for (LayoutPrototype layoutPrototype : findByCompanyId(companyId,
2726 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2727 remove(layoutPrototype);
2728 }
2729 }
2730
2731
2738 public int countByCompanyId(long companyId) throws SystemException {
2739 FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
2740
2741 Object[] finderArgs = new Object[] { companyId };
2742
2743 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2744 this);
2745
2746 if (count == null) {
2747 StringBundler query = new StringBundler(2);
2748
2749 query.append(_SQL_COUNT_LAYOUTPROTOTYPE_WHERE);
2750
2751 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2752
2753 String sql = query.toString();
2754
2755 Session session = null;
2756
2757 try {
2758 session = openSession();
2759
2760 Query q = session.createQuery(sql);
2761
2762 QueryPos qPos = QueryPos.getInstance(q);
2763
2764 qPos.add(companyId);
2765
2766 count = (Long)q.uniqueResult();
2767
2768 FinderCacheUtil.putResult(finderPath, finderArgs, count);
2769 }
2770 catch (Exception e) {
2771 FinderCacheUtil.removeResult(finderPath, finderArgs);
2772
2773 throw processException(e);
2774 }
2775 finally {
2776 closeSession(session);
2777 }
2778 }
2779
2780 return count.intValue();
2781 }
2782
2783
2790 public int filterCountByCompanyId(long companyId) throws SystemException {
2791 if (!InlineSQLHelperUtil.isEnabled()) {
2792 return countByCompanyId(companyId);
2793 }
2794
2795 StringBundler query = new StringBundler(2);
2796
2797 query.append(_FILTER_SQL_COUNT_LAYOUTPROTOTYPE_WHERE);
2798
2799 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2800
2801 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2802 LayoutPrototype.class.getName(),
2803 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2804
2805 Session session = null;
2806
2807 try {
2808 session = openSession();
2809
2810 SQLQuery q = session.createSQLQuery(sql);
2811
2812 q.addScalar(COUNT_COLUMN_NAME,
2813 com.liferay.portal.kernel.dao.orm.Type.LONG);
2814
2815 QueryPos qPos = QueryPos.getInstance(q);
2816
2817 qPos.add(companyId);
2818
2819 Long count = (Long)q.uniqueResult();
2820
2821 return count.intValue();
2822 }
2823 catch (Exception e) {
2824 throw processException(e);
2825 }
2826 finally {
2827 closeSession(session);
2828 }
2829 }
2830
2831 private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "layoutPrototype.companyId = ?";
2832 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_A = new FinderPath(LayoutPrototypeModelImpl.ENTITY_CACHE_ENABLED,
2833 LayoutPrototypeModelImpl.FINDER_CACHE_ENABLED,
2834 LayoutPrototypeImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
2835 "findByC_A",
2836 new String[] {
2837 Long.class.getName(), Boolean.class.getName(),
2838
2839 Integer.class.getName(), Integer.class.getName(),
2840 OrderByComparator.class.getName()
2841 });
2842 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_A = new FinderPath(LayoutPrototypeModelImpl.ENTITY_CACHE_ENABLED,
2843 LayoutPrototypeModelImpl.FINDER_CACHE_ENABLED,
2844 LayoutPrototypeImpl.class,
2845 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_A",
2846 new String[] { Long.class.getName(), Boolean.class.getName() },
2847 LayoutPrototypeModelImpl.COMPANYID_COLUMN_BITMASK |
2848 LayoutPrototypeModelImpl.ACTIVE_COLUMN_BITMASK);
2849 public static final FinderPath FINDER_PATH_COUNT_BY_C_A = new FinderPath(LayoutPrototypeModelImpl.ENTITY_CACHE_ENABLED,
2850 LayoutPrototypeModelImpl.FINDER_CACHE_ENABLED, Long.class,
2851 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_A",
2852 new String[] { Long.class.getName(), Boolean.class.getName() });
2853
2854
2862 public List<LayoutPrototype> findByC_A(long companyId, boolean active)
2863 throws SystemException {
2864 return findByC_A(companyId, active, QueryUtil.ALL_POS,
2865 QueryUtil.ALL_POS, null);
2866 }
2867
2868
2882 public List<LayoutPrototype> findByC_A(long companyId, boolean active,
2883 int start, int end) throws SystemException {
2884 return findByC_A(companyId, active, start, end, null);
2885 }
2886
2887
2902 public List<LayoutPrototype> findByC_A(long companyId, boolean active,
2903 int start, int end, OrderByComparator orderByComparator)
2904 throws SystemException {
2905 boolean pagination = true;
2906 FinderPath finderPath = null;
2907 Object[] finderArgs = null;
2908
2909 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2910 (orderByComparator == null)) {
2911 pagination = false;
2912 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_A;
2913 finderArgs = new Object[] { companyId, active };
2914 }
2915 else {
2916 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_A;
2917 finderArgs = new Object[] {
2918 companyId, active,
2919
2920 start, end, orderByComparator
2921 };
2922 }
2923
2924 List<LayoutPrototype> list = (List<LayoutPrototype>)FinderCacheUtil.getResult(finderPath,
2925 finderArgs, this);
2926
2927 if ((list != null) && !list.isEmpty()) {
2928 for (LayoutPrototype layoutPrototype : list) {
2929 if ((companyId != layoutPrototype.getCompanyId()) ||
2930 (active != layoutPrototype.getActive())) {
2931 list = null;
2932
2933 break;
2934 }
2935 }
2936 }
2937
2938 if (list == null) {
2939 StringBundler query = null;
2940
2941 if (orderByComparator != null) {
2942 query = new StringBundler(4 +
2943 (orderByComparator.getOrderByFields().length * 3));
2944 }
2945 else {
2946 query = new StringBundler(4);
2947 }
2948
2949 query.append(_SQL_SELECT_LAYOUTPROTOTYPE_WHERE);
2950
2951 query.append(_FINDER_COLUMN_C_A_COMPANYID_2);
2952
2953 query.append(_FINDER_COLUMN_C_A_ACTIVE_2);
2954
2955 if (orderByComparator != null) {
2956 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2957 orderByComparator);
2958 }
2959 else
2960 if (pagination) {
2961 query.append(LayoutPrototypeModelImpl.ORDER_BY_JPQL);
2962 }
2963
2964 String sql = query.toString();
2965
2966 Session session = null;
2967
2968 try {
2969 session = openSession();
2970
2971 Query q = session.createQuery(sql);
2972
2973 QueryPos qPos = QueryPos.getInstance(q);
2974
2975 qPos.add(companyId);
2976
2977 qPos.add(active);
2978
2979 if (!pagination) {
2980 list = (List<LayoutPrototype>)QueryUtil.list(q,
2981 getDialect(), start, end, false);
2982
2983 Collections.sort(list);
2984
2985 list = new UnmodifiableList<LayoutPrototype>(list);
2986 }
2987 else {
2988 list = (List<LayoutPrototype>)QueryUtil.list(q,
2989 getDialect(), start, end);
2990 }
2991
2992 cacheResult(list);
2993
2994 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2995 }
2996 catch (Exception e) {
2997 FinderCacheUtil.removeResult(finderPath, finderArgs);
2998
2999 throw processException(e);
3000 }
3001 finally {
3002 closeSession(session);
3003 }
3004 }
3005
3006 return list;
3007 }
3008
3009
3019 public LayoutPrototype findByC_A_First(long companyId, boolean active,
3020 OrderByComparator orderByComparator)
3021 throws NoSuchLayoutPrototypeException, SystemException {
3022 LayoutPrototype layoutPrototype = fetchByC_A_First(companyId, active,
3023 orderByComparator);
3024
3025 if (layoutPrototype != null) {
3026 return layoutPrototype;
3027 }
3028
3029 StringBundler msg = new StringBundler(6);
3030
3031 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3032
3033 msg.append("companyId=");
3034 msg.append(companyId);
3035
3036 msg.append(", active=");
3037 msg.append(active);
3038
3039 msg.append(StringPool.CLOSE_CURLY_BRACE);
3040
3041 throw new NoSuchLayoutPrototypeException(msg.toString());
3042 }
3043
3044
3053 public LayoutPrototype fetchByC_A_First(long companyId, boolean active,
3054 OrderByComparator orderByComparator) throws SystemException {
3055 List<LayoutPrototype> list = findByC_A(companyId, active, 0, 1,
3056 orderByComparator);
3057
3058 if (!list.isEmpty()) {
3059 return list.get(0);
3060 }
3061
3062 return null;
3063 }
3064
3065
3075 public LayoutPrototype findByC_A_Last(long companyId, boolean active,
3076 OrderByComparator orderByComparator)
3077 throws NoSuchLayoutPrototypeException, SystemException {
3078 LayoutPrototype layoutPrototype = fetchByC_A_Last(companyId, active,
3079 orderByComparator);
3080
3081 if (layoutPrototype != null) {
3082 return layoutPrototype;
3083 }
3084
3085 StringBundler msg = new StringBundler(6);
3086
3087 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3088
3089 msg.append("companyId=");
3090 msg.append(companyId);
3091
3092 msg.append(", active=");
3093 msg.append(active);
3094
3095 msg.append(StringPool.CLOSE_CURLY_BRACE);
3096
3097 throw new NoSuchLayoutPrototypeException(msg.toString());
3098 }
3099
3100
3109 public LayoutPrototype fetchByC_A_Last(long companyId, boolean active,
3110 OrderByComparator orderByComparator) throws SystemException {
3111 int count = countByC_A(companyId, active);
3112
3113 List<LayoutPrototype> list = findByC_A(companyId, active, count - 1,
3114 count, orderByComparator);
3115
3116 if (!list.isEmpty()) {
3117 return list.get(0);
3118 }
3119
3120 return null;
3121 }
3122
3123
3134 public LayoutPrototype[] findByC_A_PrevAndNext(long layoutPrototypeId,
3135 long companyId, boolean active, OrderByComparator orderByComparator)
3136 throws NoSuchLayoutPrototypeException, SystemException {
3137 LayoutPrototype layoutPrototype = findByPrimaryKey(layoutPrototypeId);
3138
3139 Session session = null;
3140
3141 try {
3142 session = openSession();
3143
3144 LayoutPrototype[] array = new LayoutPrototypeImpl[3];
3145
3146 array[0] = getByC_A_PrevAndNext(session, layoutPrototype,
3147 companyId, active, orderByComparator, true);
3148
3149 array[1] = layoutPrototype;
3150
3151 array[2] = getByC_A_PrevAndNext(session, layoutPrototype,
3152 companyId, active, orderByComparator, false);
3153
3154 return array;
3155 }
3156 catch (Exception e) {
3157 throw processException(e);
3158 }
3159 finally {
3160 closeSession(session);
3161 }
3162 }
3163
3164 protected LayoutPrototype getByC_A_PrevAndNext(Session session,
3165 LayoutPrototype layoutPrototype, long companyId, boolean active,
3166 OrderByComparator orderByComparator, boolean previous) {
3167 StringBundler query = null;
3168
3169 if (orderByComparator != null) {
3170 query = new StringBundler(6 +
3171 (orderByComparator.getOrderByFields().length * 6));
3172 }
3173 else {
3174 query = new StringBundler(3);
3175 }
3176
3177 query.append(_SQL_SELECT_LAYOUTPROTOTYPE_WHERE);
3178
3179 query.append(_FINDER_COLUMN_C_A_COMPANYID_2);
3180
3181 query.append(_FINDER_COLUMN_C_A_ACTIVE_2);
3182
3183 if (orderByComparator != null) {
3184 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3185
3186 if (orderByConditionFields.length > 0) {
3187 query.append(WHERE_AND);
3188 }
3189
3190 for (int i = 0; i < orderByConditionFields.length; i++) {
3191 query.append(_ORDER_BY_ENTITY_ALIAS);
3192 query.append(orderByConditionFields[i]);
3193
3194 if ((i + 1) < orderByConditionFields.length) {
3195 if (orderByComparator.isAscending() ^ previous) {
3196 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3197 }
3198 else {
3199 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3200 }
3201 }
3202 else {
3203 if (orderByComparator.isAscending() ^ previous) {
3204 query.append(WHERE_GREATER_THAN);
3205 }
3206 else {
3207 query.append(WHERE_LESSER_THAN);
3208 }
3209 }
3210 }
3211
3212 query.append(ORDER_BY_CLAUSE);
3213
3214 String[] orderByFields = orderByComparator.getOrderByFields();
3215
3216 for (int i = 0; i < orderByFields.length; i++) {
3217 query.append(_ORDER_BY_ENTITY_ALIAS);
3218 query.append(orderByFields[i]);
3219
3220 if ((i + 1) < orderByFields.length) {
3221 if (orderByComparator.isAscending() ^ previous) {
3222 query.append(ORDER_BY_ASC_HAS_NEXT);
3223 }
3224 else {
3225 query.append(ORDER_BY_DESC_HAS_NEXT);
3226 }
3227 }
3228 else {
3229 if (orderByComparator.isAscending() ^ previous) {
3230 query.append(ORDER_BY_ASC);
3231 }
3232 else {
3233 query.append(ORDER_BY_DESC);
3234 }
3235 }
3236 }
3237 }
3238 else {
3239 query.append(LayoutPrototypeModelImpl.ORDER_BY_JPQL);
3240 }
3241
3242 String sql = query.toString();
3243
3244 Query q = session.createQuery(sql);
3245
3246 q.setFirstResult(0);
3247 q.setMaxResults(2);
3248
3249 QueryPos qPos = QueryPos.getInstance(q);
3250
3251 qPos.add(companyId);
3252
3253 qPos.add(active);
3254
3255 if (orderByComparator != null) {
3256 Object[] values = orderByComparator.getOrderByConditionValues(layoutPrototype);
3257
3258 for (Object value : values) {
3259 qPos.add(value);
3260 }
3261 }
3262
3263 List<LayoutPrototype> list = q.list();
3264
3265 if (list.size() == 2) {
3266 return list.get(1);
3267 }
3268 else {
3269 return null;
3270 }
3271 }
3272
3273
3281 public List<LayoutPrototype> filterFindByC_A(long companyId, boolean active)
3282 throws SystemException {
3283 return filterFindByC_A(companyId, active, QueryUtil.ALL_POS,
3284 QueryUtil.ALL_POS, null);
3285 }
3286
3287
3301 public List<LayoutPrototype> filterFindByC_A(long companyId,
3302 boolean active, int start, int end) throws SystemException {
3303 return filterFindByC_A(companyId, active, start, end, null);
3304 }
3305
3306
3321 public List<LayoutPrototype> filterFindByC_A(long companyId,
3322 boolean active, int start, int end, OrderByComparator orderByComparator)
3323 throws SystemException {
3324 if (!InlineSQLHelperUtil.isEnabled()) {
3325 return findByC_A(companyId, active, start, end, orderByComparator);
3326 }
3327
3328 StringBundler query = null;
3329
3330 if (orderByComparator != null) {
3331 query = new StringBundler(4 +
3332 (orderByComparator.getOrderByFields().length * 3));
3333 }
3334 else {
3335 query = new StringBundler(4);
3336 }
3337
3338 if (getDB().isSupportsInlineDistinct()) {
3339 query.append(_FILTER_SQL_SELECT_LAYOUTPROTOTYPE_WHERE);
3340 }
3341 else {
3342 query.append(_FILTER_SQL_SELECT_LAYOUTPROTOTYPE_NO_INLINE_DISTINCT_WHERE_1);
3343 }
3344
3345 query.append(_FINDER_COLUMN_C_A_COMPANYID_2);
3346
3347 query.append(_FINDER_COLUMN_C_A_ACTIVE_2);
3348
3349 if (!getDB().isSupportsInlineDistinct()) {
3350 query.append(_FILTER_SQL_SELECT_LAYOUTPROTOTYPE_NO_INLINE_DISTINCT_WHERE_2);
3351 }
3352
3353 if (orderByComparator != null) {
3354 if (getDB().isSupportsInlineDistinct()) {
3355 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3356 orderByComparator);
3357 }
3358 else {
3359 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3360 orderByComparator);
3361 }
3362 }
3363 else {
3364 if (getDB().isSupportsInlineDistinct()) {
3365 query.append(LayoutPrototypeModelImpl.ORDER_BY_JPQL);
3366 }
3367 else {
3368 query.append(LayoutPrototypeModelImpl.ORDER_BY_SQL);
3369 }
3370 }
3371
3372 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3373 LayoutPrototype.class.getName(),
3374 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
3375
3376 Session session = null;
3377
3378 try {
3379 session = openSession();
3380
3381 SQLQuery q = session.createSQLQuery(sql);
3382
3383 if (getDB().isSupportsInlineDistinct()) {
3384 q.addEntity(_FILTER_ENTITY_ALIAS, LayoutPrototypeImpl.class);
3385 }
3386 else {
3387 q.addEntity(_FILTER_ENTITY_TABLE, LayoutPrototypeImpl.class);
3388 }
3389
3390 QueryPos qPos = QueryPos.getInstance(q);
3391
3392 qPos.add(companyId);
3393
3394 qPos.add(active);
3395
3396 return (List<LayoutPrototype>)QueryUtil.list(q, getDialect(),
3397 start, end);
3398 }
3399 catch (Exception e) {
3400 throw processException(e);
3401 }
3402 finally {
3403 closeSession(session);
3404 }
3405 }
3406
3407
3418 public LayoutPrototype[] filterFindByC_A_PrevAndNext(
3419 long layoutPrototypeId, long companyId, boolean active,
3420 OrderByComparator orderByComparator)
3421 throws NoSuchLayoutPrototypeException, SystemException {
3422 if (!InlineSQLHelperUtil.isEnabled()) {
3423 return findByC_A_PrevAndNext(layoutPrototypeId, companyId, active,
3424 orderByComparator);
3425 }
3426
3427 LayoutPrototype layoutPrototype = findByPrimaryKey(layoutPrototypeId);
3428
3429 Session session = null;
3430
3431 try {
3432 session = openSession();
3433
3434 LayoutPrototype[] array = new LayoutPrototypeImpl[3];
3435
3436 array[0] = filterGetByC_A_PrevAndNext(session, layoutPrototype,
3437 companyId, active, orderByComparator, true);
3438
3439 array[1] = layoutPrototype;
3440
3441 array[2] = filterGetByC_A_PrevAndNext(session, layoutPrototype,
3442 companyId, active, orderByComparator, false);
3443
3444 return array;
3445 }
3446 catch (Exception e) {
3447 throw processException(e);
3448 }
3449 finally {
3450 closeSession(session);
3451 }
3452 }
3453
3454 protected LayoutPrototype filterGetByC_A_PrevAndNext(Session session,
3455 LayoutPrototype layoutPrototype, long companyId, boolean active,
3456 OrderByComparator orderByComparator, boolean previous) {
3457 StringBundler query = null;
3458
3459 if (orderByComparator != null) {
3460 query = new StringBundler(6 +
3461 (orderByComparator.getOrderByFields().length * 6));
3462 }
3463 else {
3464 query = new StringBundler(3);
3465 }
3466
3467 if (getDB().isSupportsInlineDistinct()) {
3468 query.append(_FILTER_SQL_SELECT_LAYOUTPROTOTYPE_WHERE);
3469 }
3470 else {
3471 query.append(_FILTER_SQL_SELECT_LAYOUTPROTOTYPE_NO_INLINE_DISTINCT_WHERE_1);
3472 }
3473
3474 query.append(_FINDER_COLUMN_C_A_COMPANYID_2);
3475
3476 query.append(_FINDER_COLUMN_C_A_ACTIVE_2);
3477
3478 if (!getDB().isSupportsInlineDistinct()) {
3479 query.append(_FILTER_SQL_SELECT_LAYOUTPROTOTYPE_NO_INLINE_DISTINCT_WHERE_2);
3480 }
3481
3482 if (orderByComparator != null) {
3483 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3484
3485 if (orderByConditionFields.length > 0) {
3486 query.append(WHERE_AND);
3487 }
3488
3489 for (int i = 0; i < orderByConditionFields.length; i++) {
3490 if (getDB().isSupportsInlineDistinct()) {
3491 query.append(_ORDER_BY_ENTITY_ALIAS);
3492 }
3493 else {
3494 query.append(_ORDER_BY_ENTITY_TABLE);
3495 }
3496
3497 query.append(orderByConditionFields[i]);
3498
3499 if ((i + 1) < orderByConditionFields.length) {
3500 if (orderByComparator.isAscending() ^ previous) {
3501 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3502 }
3503 else {
3504 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3505 }
3506 }
3507 else {
3508 if (orderByComparator.isAscending() ^ previous) {
3509 query.append(WHERE_GREATER_THAN);
3510 }
3511 else {
3512 query.append(WHERE_LESSER_THAN);
3513 }
3514 }
3515 }
3516
3517 query.append(ORDER_BY_CLAUSE);
3518
3519 String[] orderByFields = orderByComparator.getOrderByFields();
3520
3521 for (int i = 0; i < orderByFields.length; i++) {
3522 if (getDB().isSupportsInlineDistinct()) {
3523 query.append(_ORDER_BY_ENTITY_ALIAS);
3524 }
3525 else {
3526 query.append(_ORDER_BY_ENTITY_TABLE);
3527 }
3528
3529 query.append(orderByFields[i]);
3530
3531 if ((i + 1) < orderByFields.length) {
3532 if (orderByComparator.isAscending() ^ previous) {
3533 query.append(ORDER_BY_ASC_HAS_NEXT);
3534 }
3535 else {
3536 query.append(ORDER_BY_DESC_HAS_NEXT);
3537 }
3538 }
3539 else {
3540 if (orderByComparator.isAscending() ^ previous) {
3541 query.append(ORDER_BY_ASC);
3542 }
3543 else {
3544 query.append(ORDER_BY_DESC);
3545 }
3546 }
3547 }
3548 }
3549 else {
3550 if (getDB().isSupportsInlineDistinct()) {
3551 query.append(LayoutPrototypeModelImpl.ORDER_BY_JPQL);
3552 }
3553 else {
3554 query.append(LayoutPrototypeModelImpl.ORDER_BY_SQL);
3555 }
3556 }
3557
3558 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3559 LayoutPrototype.class.getName(),
3560 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
3561
3562 SQLQuery q = session.createSQLQuery(sql);
3563
3564 q.setFirstResult(0);
3565 q.setMaxResults(2);
3566
3567 if (getDB().isSupportsInlineDistinct()) {
3568 q.addEntity(_FILTER_ENTITY_ALIAS, LayoutPrototypeImpl.class);
3569 }
3570 else {
3571 q.addEntity(_FILTER_ENTITY_TABLE, LayoutPrototypeImpl.class);
3572 }
3573
3574 QueryPos qPos = QueryPos.getInstance(q);
3575
3576 qPos.add(companyId);
3577
3578 qPos.add(active);
3579
3580 if (orderByComparator != null) {
3581 Object[] values = orderByComparator.getOrderByConditionValues(layoutPrototype);
3582
3583 for (Object value : values) {
3584 qPos.add(value);
3585 }
3586 }
3587
3588 List<LayoutPrototype> list = q.list();
3589
3590 if (list.size() == 2) {
3591 return list.get(1);
3592 }
3593 else {
3594 return null;
3595 }
3596 }
3597
3598
3605 public void removeByC_A(long companyId, boolean active)
3606 throws SystemException {
3607 for (LayoutPrototype layoutPrototype : findByC_A(companyId, active,
3608 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3609 remove(layoutPrototype);
3610 }
3611 }
3612
3613
3621 public int countByC_A(long companyId, boolean active)
3622 throws SystemException {
3623 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_A;
3624
3625 Object[] finderArgs = new Object[] { companyId, active };
3626
3627 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3628 this);
3629
3630 if (count == null) {
3631 StringBundler query = new StringBundler(3);
3632
3633 query.append(_SQL_COUNT_LAYOUTPROTOTYPE_WHERE);
3634
3635 query.append(_FINDER_COLUMN_C_A_COMPANYID_2);
3636
3637 query.append(_FINDER_COLUMN_C_A_ACTIVE_2);
3638
3639 String sql = query.toString();
3640
3641 Session session = null;
3642
3643 try {
3644 session = openSession();
3645
3646 Query q = session.createQuery(sql);
3647
3648 QueryPos qPos = QueryPos.getInstance(q);
3649
3650 qPos.add(companyId);
3651
3652 qPos.add(active);
3653
3654 count = (Long)q.uniqueResult();
3655
3656 FinderCacheUtil.putResult(finderPath, finderArgs, count);
3657 }
3658 catch (Exception e) {
3659 FinderCacheUtil.removeResult(finderPath, finderArgs);
3660
3661 throw processException(e);
3662 }
3663 finally {
3664 closeSession(session);
3665 }
3666 }
3667
3668 return count.intValue();
3669 }
3670
3671
3679 public int filterCountByC_A(long companyId, boolean active)
3680 throws SystemException {
3681 if (!InlineSQLHelperUtil.isEnabled()) {
3682 return countByC_A(companyId, active);
3683 }
3684
3685 StringBundler query = new StringBundler(3);
3686
3687 query.append(_FILTER_SQL_COUNT_LAYOUTPROTOTYPE_WHERE);
3688
3689 query.append(_FINDER_COLUMN_C_A_COMPANYID_2);
3690
3691 query.append(_FINDER_COLUMN_C_A_ACTIVE_2);
3692
3693 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3694 LayoutPrototype.class.getName(),
3695 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
3696
3697 Session session = null;
3698
3699 try {
3700 session = openSession();
3701
3702 SQLQuery q = session.createSQLQuery(sql);
3703
3704 q.addScalar(COUNT_COLUMN_NAME,
3705 com.liferay.portal.kernel.dao.orm.Type.LONG);
3706
3707 QueryPos qPos = QueryPos.getInstance(q);
3708
3709 qPos.add(companyId);
3710
3711 qPos.add(active);
3712
3713 Long count = (Long)q.uniqueResult();
3714
3715 return count.intValue();
3716 }
3717 catch (Exception e) {
3718 throw processException(e);
3719 }
3720 finally {
3721 closeSession(session);
3722 }
3723 }
3724
3725 private static final String _FINDER_COLUMN_C_A_COMPANYID_2 = "layoutPrototype.companyId = ? AND ";
3726 private static final String _FINDER_COLUMN_C_A_ACTIVE_2 = "layoutPrototype.active = ?";
3727
3728
3733 public void cacheResult(LayoutPrototype layoutPrototype) {
3734 EntityCacheUtil.putResult(LayoutPrototypeModelImpl.ENTITY_CACHE_ENABLED,
3735 LayoutPrototypeImpl.class, layoutPrototype.getPrimaryKey(),
3736 layoutPrototype);
3737
3738 layoutPrototype.resetOriginalValues();
3739 }
3740
3741
3746 public void cacheResult(List<LayoutPrototype> layoutPrototypes) {
3747 for (LayoutPrototype layoutPrototype : layoutPrototypes) {
3748 if (EntityCacheUtil.getResult(
3749 LayoutPrototypeModelImpl.ENTITY_CACHE_ENABLED,
3750 LayoutPrototypeImpl.class,
3751 layoutPrototype.getPrimaryKey()) == null) {
3752 cacheResult(layoutPrototype);
3753 }
3754 else {
3755 layoutPrototype.resetOriginalValues();
3756 }
3757 }
3758 }
3759
3760
3767 @Override
3768 public void clearCache() {
3769 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
3770 CacheRegistryUtil.clear(LayoutPrototypeImpl.class.getName());
3771 }
3772
3773 EntityCacheUtil.clearCache(LayoutPrototypeImpl.class.getName());
3774
3775 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
3776 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3777 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3778 }
3779
3780
3787 @Override
3788 public void clearCache(LayoutPrototype layoutPrototype) {
3789 EntityCacheUtil.removeResult(LayoutPrototypeModelImpl.ENTITY_CACHE_ENABLED,
3790 LayoutPrototypeImpl.class, layoutPrototype.getPrimaryKey());
3791
3792 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3793 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3794 }
3795
3796 @Override
3797 public void clearCache(List<LayoutPrototype> layoutPrototypes) {
3798 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3799 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3800
3801 for (LayoutPrototype layoutPrototype : layoutPrototypes) {
3802 EntityCacheUtil.removeResult(LayoutPrototypeModelImpl.ENTITY_CACHE_ENABLED,
3803 LayoutPrototypeImpl.class, layoutPrototype.getPrimaryKey());
3804 }
3805 }
3806
3807
3813 public LayoutPrototype create(long layoutPrototypeId) {
3814 LayoutPrototype layoutPrototype = new LayoutPrototypeImpl();
3815
3816 layoutPrototype.setNew(true);
3817 layoutPrototype.setPrimaryKey(layoutPrototypeId);
3818
3819 String uuid = PortalUUIDUtil.generate();
3820
3821 layoutPrototype.setUuid(uuid);
3822
3823 return layoutPrototype;
3824 }
3825
3826
3834 public LayoutPrototype remove(long layoutPrototypeId)
3835 throws NoSuchLayoutPrototypeException, SystemException {
3836 return remove((Serializable)layoutPrototypeId);
3837 }
3838
3839
3847 @Override
3848 public LayoutPrototype remove(Serializable primaryKey)
3849 throws NoSuchLayoutPrototypeException, SystemException {
3850 Session session = null;
3851
3852 try {
3853 session = openSession();
3854
3855 LayoutPrototype layoutPrototype = (LayoutPrototype)session.get(LayoutPrototypeImpl.class,
3856 primaryKey);
3857
3858 if (layoutPrototype == null) {
3859 if (_log.isWarnEnabled()) {
3860 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
3861 }
3862
3863 throw new NoSuchLayoutPrototypeException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
3864 primaryKey);
3865 }
3866
3867 return remove(layoutPrototype);
3868 }
3869 catch (NoSuchLayoutPrototypeException nsee) {
3870 throw nsee;
3871 }
3872 catch (Exception e) {
3873 throw processException(e);
3874 }
3875 finally {
3876 closeSession(session);
3877 }
3878 }
3879
3880 @Override
3881 protected LayoutPrototype removeImpl(LayoutPrototype layoutPrototype)
3882 throws SystemException {
3883 layoutPrototype = toUnwrappedModel(layoutPrototype);
3884
3885 Session session = null;
3886
3887 try {
3888 session = openSession();
3889
3890 if (!session.contains(layoutPrototype)) {
3891 layoutPrototype = (LayoutPrototype)session.get(LayoutPrototypeImpl.class,
3892 layoutPrototype.getPrimaryKeyObj());
3893 }
3894
3895 if (layoutPrototype != null) {
3896 session.delete(layoutPrototype);
3897 }
3898 }
3899 catch (Exception e) {
3900 throw processException(e);
3901 }
3902 finally {
3903 closeSession(session);
3904 }
3905
3906 if (layoutPrototype != null) {
3907 clearCache(layoutPrototype);
3908 }
3909
3910 return layoutPrototype;
3911 }
3912
3913 @Override
3914 public LayoutPrototype updateImpl(
3915 com.liferay.portal.model.LayoutPrototype layoutPrototype)
3916 throws SystemException {
3917 layoutPrototype = toUnwrappedModel(layoutPrototype);
3918
3919 boolean isNew = layoutPrototype.isNew();
3920
3921 LayoutPrototypeModelImpl layoutPrototypeModelImpl = (LayoutPrototypeModelImpl)layoutPrototype;
3922
3923 if (Validator.isNull(layoutPrototype.getUuid())) {
3924 String uuid = PortalUUIDUtil.generate();
3925
3926 layoutPrototype.setUuid(uuid);
3927 }
3928
3929 Session session = null;
3930
3931 try {
3932 session = openSession();
3933
3934 if (layoutPrototype.isNew()) {
3935 session.save(layoutPrototype);
3936
3937 layoutPrototype.setNew(false);
3938 }
3939 else {
3940 session.merge(layoutPrototype);
3941 }
3942 }
3943 catch (Exception e) {
3944 throw processException(e);
3945 }
3946 finally {
3947 closeSession(session);
3948 }
3949
3950 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3951
3952 if (isNew || !LayoutPrototypeModelImpl.COLUMN_BITMASK_ENABLED) {
3953 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3954 }
3955
3956 else {
3957 if ((layoutPrototypeModelImpl.getColumnBitmask() &
3958 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
3959 Object[] args = new Object[] {
3960 layoutPrototypeModelImpl.getOriginalUuid()
3961 };
3962
3963 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
3964 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
3965 args);
3966
3967 args = new Object[] { layoutPrototypeModelImpl.getUuid() };
3968
3969 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
3970 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
3971 args);
3972 }
3973
3974 if ((layoutPrototypeModelImpl.getColumnBitmask() &
3975 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
3976 Object[] args = new Object[] {
3977 layoutPrototypeModelImpl.getOriginalUuid(),
3978 layoutPrototypeModelImpl.getOriginalCompanyId()
3979 };
3980
3981 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
3982 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
3983 args);
3984
3985 args = new Object[] {
3986 layoutPrototypeModelImpl.getUuid(),
3987 layoutPrototypeModelImpl.getCompanyId()
3988 };
3989
3990 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
3991 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
3992 args);
3993 }
3994
3995 if ((layoutPrototypeModelImpl.getColumnBitmask() &
3996 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
3997 Object[] args = new Object[] {
3998 layoutPrototypeModelImpl.getOriginalCompanyId()
3999 };
4000
4001 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
4002 args);
4003 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
4004 args);
4005
4006 args = new Object[] { layoutPrototypeModelImpl.getCompanyId() };
4007
4008 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
4009 args);
4010 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
4011 args);
4012 }
4013
4014 if ((layoutPrototypeModelImpl.getColumnBitmask() &
4015 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_A.getColumnBitmask()) != 0) {
4016 Object[] args = new Object[] {
4017 layoutPrototypeModelImpl.getOriginalCompanyId(),
4018 layoutPrototypeModelImpl.getOriginalActive()
4019 };
4020
4021 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_A, args);
4022 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_A,
4023 args);
4024
4025 args = new Object[] {
4026 layoutPrototypeModelImpl.getCompanyId(),
4027 layoutPrototypeModelImpl.getActive()
4028 };
4029
4030 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_A, args);
4031 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_A,
4032 args);
4033 }
4034 }
4035
4036 EntityCacheUtil.putResult(LayoutPrototypeModelImpl.ENTITY_CACHE_ENABLED,
4037 LayoutPrototypeImpl.class, layoutPrototype.getPrimaryKey(),
4038 layoutPrototype);
4039
4040 return layoutPrototype;
4041 }
4042
4043 protected LayoutPrototype toUnwrappedModel(LayoutPrototype layoutPrototype) {
4044 if (layoutPrototype instanceof LayoutPrototypeImpl) {
4045 return layoutPrototype;
4046 }
4047
4048 LayoutPrototypeImpl layoutPrototypeImpl = new LayoutPrototypeImpl();
4049
4050 layoutPrototypeImpl.setNew(layoutPrototype.isNew());
4051 layoutPrototypeImpl.setPrimaryKey(layoutPrototype.getPrimaryKey());
4052
4053 layoutPrototypeImpl.setUuid(layoutPrototype.getUuid());
4054 layoutPrototypeImpl.setLayoutPrototypeId(layoutPrototype.getLayoutPrototypeId());
4055 layoutPrototypeImpl.setCompanyId(layoutPrototype.getCompanyId());
4056 layoutPrototypeImpl.setName(layoutPrototype.getName());
4057 layoutPrototypeImpl.setDescription(layoutPrototype.getDescription());
4058 layoutPrototypeImpl.setSettings(layoutPrototype.getSettings());
4059 layoutPrototypeImpl.setActive(layoutPrototype.isActive());
4060
4061 return layoutPrototypeImpl;
4062 }
4063
4064
4072 @Override
4073 public LayoutPrototype findByPrimaryKey(Serializable primaryKey)
4074 throws NoSuchLayoutPrototypeException, SystemException {
4075 LayoutPrototype layoutPrototype = fetchByPrimaryKey(primaryKey);
4076
4077 if (layoutPrototype == null) {
4078 if (_log.isWarnEnabled()) {
4079 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
4080 }
4081
4082 throw new NoSuchLayoutPrototypeException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
4083 primaryKey);
4084 }
4085
4086 return layoutPrototype;
4087 }
4088
4089
4097 public LayoutPrototype findByPrimaryKey(long layoutPrototypeId)
4098 throws NoSuchLayoutPrototypeException, SystemException {
4099 return findByPrimaryKey((Serializable)layoutPrototypeId);
4100 }
4101
4102
4109 @Override
4110 public LayoutPrototype fetchByPrimaryKey(Serializable primaryKey)
4111 throws SystemException {
4112 LayoutPrototype layoutPrototype = (LayoutPrototype)EntityCacheUtil.getResult(LayoutPrototypeModelImpl.ENTITY_CACHE_ENABLED,
4113 LayoutPrototypeImpl.class, primaryKey);
4114
4115 if (layoutPrototype == _nullLayoutPrototype) {
4116 return null;
4117 }
4118
4119 if (layoutPrototype == null) {
4120 Session session = null;
4121
4122 try {
4123 session = openSession();
4124
4125 layoutPrototype = (LayoutPrototype)session.get(LayoutPrototypeImpl.class,
4126 primaryKey);
4127
4128 if (layoutPrototype != null) {
4129 cacheResult(layoutPrototype);
4130 }
4131 else {
4132 EntityCacheUtil.putResult(LayoutPrototypeModelImpl.ENTITY_CACHE_ENABLED,
4133 LayoutPrototypeImpl.class, primaryKey,
4134 _nullLayoutPrototype);
4135 }
4136 }
4137 catch (Exception e) {
4138 EntityCacheUtil.removeResult(LayoutPrototypeModelImpl.ENTITY_CACHE_ENABLED,
4139 LayoutPrototypeImpl.class, primaryKey);
4140
4141 throw processException(e);
4142 }
4143 finally {
4144 closeSession(session);
4145 }
4146 }
4147
4148 return layoutPrototype;
4149 }
4150
4151
4158 public LayoutPrototype fetchByPrimaryKey(long layoutPrototypeId)
4159 throws SystemException {
4160 return fetchByPrimaryKey((Serializable)layoutPrototypeId);
4161 }
4162
4163
4169 public List<LayoutPrototype> findAll() throws SystemException {
4170 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
4171 }
4172
4173
4185 public List<LayoutPrototype> findAll(int start, int end)
4186 throws SystemException {
4187 return findAll(start, end, null);
4188 }
4189
4190
4203 public List<LayoutPrototype> findAll(int start, int end,
4204 OrderByComparator orderByComparator) throws SystemException {
4205 boolean pagination = true;
4206 FinderPath finderPath = null;
4207 Object[] finderArgs = null;
4208
4209 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4210 (orderByComparator == null)) {
4211 pagination = false;
4212 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
4213 finderArgs = FINDER_ARGS_EMPTY;
4214 }
4215 else {
4216 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
4217 finderArgs = new Object[] { start, end, orderByComparator };
4218 }
4219
4220 List<LayoutPrototype> list = (List<LayoutPrototype>)FinderCacheUtil.getResult(finderPath,
4221 finderArgs, this);
4222
4223 if (list == null) {
4224 StringBundler query = null;
4225 String sql = null;
4226
4227 if (orderByComparator != null) {
4228 query = new StringBundler(2 +
4229 (orderByComparator.getOrderByFields().length * 3));
4230
4231 query.append(_SQL_SELECT_LAYOUTPROTOTYPE);
4232
4233 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4234 orderByComparator);
4235
4236 sql = query.toString();
4237 }
4238 else {
4239 sql = _SQL_SELECT_LAYOUTPROTOTYPE;
4240
4241 if (pagination) {
4242 sql = sql.concat(LayoutPrototypeModelImpl.ORDER_BY_JPQL);
4243 }
4244 }
4245
4246 Session session = null;
4247
4248 try {
4249 session = openSession();
4250
4251 Query q = session.createQuery(sql);
4252
4253 if (!pagination) {
4254 list = (List<LayoutPrototype>)QueryUtil.list(q,
4255 getDialect(), start, end, false);
4256
4257 Collections.sort(list);
4258
4259 list = new UnmodifiableList<LayoutPrototype>(list);
4260 }
4261 else {
4262 list = (List<LayoutPrototype>)QueryUtil.list(q,
4263 getDialect(), start, end);
4264 }
4265
4266 cacheResult(list);
4267
4268 FinderCacheUtil.putResult(finderPath, finderArgs, list);
4269 }
4270 catch (Exception e) {
4271 FinderCacheUtil.removeResult(finderPath, finderArgs);
4272
4273 throw processException(e);
4274 }
4275 finally {
4276 closeSession(session);
4277 }
4278 }
4279
4280 return list;
4281 }
4282
4283
4288 public void removeAll() throws SystemException {
4289 for (LayoutPrototype layoutPrototype : findAll()) {
4290 remove(layoutPrototype);
4291 }
4292 }
4293
4294
4300 public int countAll() throws SystemException {
4301 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
4302 FINDER_ARGS_EMPTY, this);
4303
4304 if (count == null) {
4305 Session session = null;
4306
4307 try {
4308 session = openSession();
4309
4310 Query q = session.createQuery(_SQL_COUNT_LAYOUTPROTOTYPE);
4311
4312 count = (Long)q.uniqueResult();
4313
4314 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
4315 FINDER_ARGS_EMPTY, count);
4316 }
4317 catch (Exception e) {
4318 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
4319 FINDER_ARGS_EMPTY);
4320
4321 throw processException(e);
4322 }
4323 finally {
4324 closeSession(session);
4325 }
4326 }
4327
4328 return count.intValue();
4329 }
4330
4331
4334 public void afterPropertiesSet() {
4335 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
4336 com.liferay.portal.util.PropsUtil.get(
4337 "value.object.listener.com.liferay.portal.model.LayoutPrototype")));
4338
4339 if (listenerClassNames.length > 0) {
4340 try {
4341 List<ModelListener<LayoutPrototype>> listenersList = new ArrayList<ModelListener<LayoutPrototype>>();
4342
4343 for (String listenerClassName : listenerClassNames) {
4344 listenersList.add((ModelListener<LayoutPrototype>)InstanceFactory.newInstance(
4345 listenerClassName));
4346 }
4347
4348 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
4349 }
4350 catch (Exception e) {
4351 _log.error(e);
4352 }
4353 }
4354 }
4355
4356 public void destroy() {
4357 EntityCacheUtil.removeCache(LayoutPrototypeImpl.class.getName());
4358 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
4359 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4360 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4361 }
4362
4363 private static final String _SQL_SELECT_LAYOUTPROTOTYPE = "SELECT layoutPrototype FROM LayoutPrototype layoutPrototype";
4364 private static final String _SQL_SELECT_LAYOUTPROTOTYPE_WHERE = "SELECT layoutPrototype FROM LayoutPrototype layoutPrototype WHERE ";
4365 private static final String _SQL_COUNT_LAYOUTPROTOTYPE = "SELECT COUNT(layoutPrototype) FROM LayoutPrototype layoutPrototype";
4366 private static final String _SQL_COUNT_LAYOUTPROTOTYPE_WHERE = "SELECT COUNT(layoutPrototype) FROM LayoutPrototype layoutPrototype WHERE ";
4367 private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "layoutPrototype.layoutPrototypeId";
4368 private static final String _FILTER_SQL_SELECT_LAYOUTPROTOTYPE_WHERE = "SELECT DISTINCT {layoutPrototype.*} FROM LayoutPrototype layoutPrototype WHERE ";
4369 private static final String _FILTER_SQL_SELECT_LAYOUTPROTOTYPE_NO_INLINE_DISTINCT_WHERE_1 =
4370 "SELECT {LayoutPrototype.*} FROM (SELECT DISTINCT layoutPrototype.layoutPrototypeId FROM LayoutPrototype layoutPrototype WHERE ";
4371 private static final String _FILTER_SQL_SELECT_LAYOUTPROTOTYPE_NO_INLINE_DISTINCT_WHERE_2 =
4372 ") TEMP_TABLE INNER JOIN LayoutPrototype ON TEMP_TABLE.layoutPrototypeId = LayoutPrototype.layoutPrototypeId";
4373 private static final String _FILTER_SQL_COUNT_LAYOUTPROTOTYPE_WHERE = "SELECT COUNT(DISTINCT layoutPrototype.layoutPrototypeId) AS COUNT_VALUE FROM LayoutPrototype layoutPrototype WHERE ";
4374 private static final String _FILTER_ENTITY_ALIAS = "layoutPrototype";
4375 private static final String _FILTER_ENTITY_TABLE = "LayoutPrototype";
4376 private static final String _ORDER_BY_ENTITY_ALIAS = "layoutPrototype.";
4377 private static final String _ORDER_BY_ENTITY_TABLE = "LayoutPrototype.";
4378 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No LayoutPrototype exists with the primary key ";
4379 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No LayoutPrototype exists with the key {";
4380 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
4381 private static Log _log = LogFactoryUtil.getLog(LayoutPrototypePersistenceImpl.class);
4382 private static LayoutPrototype _nullLayoutPrototype = new LayoutPrototypeImpl() {
4383 @Override
4384 public Object clone() {
4385 return this;
4386 }
4387
4388 @Override
4389 public CacheModel<LayoutPrototype> toCacheModel() {
4390 return _nullLayoutPrototypeCacheModel;
4391 }
4392 };
4393
4394 private static CacheModel<LayoutPrototype> _nullLayoutPrototypeCacheModel = new CacheModel<LayoutPrototype>() {
4395 public LayoutPrototype toEntityModel() {
4396 return _nullLayoutPrototype;
4397 }
4398 };
4399 }