001
014
015 package com.liferay.portal.service.persistence;
016
017 import com.liferay.portal.NoSuchLayoutPrototypeException;
018 import com.liferay.portal.NoSuchModelException;
019 import com.liferay.portal.kernel.annotation.BeanReference;
020 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
021 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
023 import com.liferay.portal.kernel.dao.orm.FinderPath;
024 import com.liferay.portal.kernel.dao.orm.Query;
025 import com.liferay.portal.kernel.dao.orm.QueryPos;
026 import com.liferay.portal.kernel.dao.orm.QueryUtil;
027 import com.liferay.portal.kernel.dao.orm.Session;
028 import com.liferay.portal.kernel.exception.SystemException;
029 import com.liferay.portal.kernel.log.Log;
030 import com.liferay.portal.kernel.log.LogFactoryUtil;
031 import com.liferay.portal.kernel.util.GetterUtil;
032 import com.liferay.portal.kernel.util.InstanceFactory;
033 import com.liferay.portal.kernel.util.OrderByComparator;
034 import com.liferay.portal.kernel.util.StringBundler;
035 import com.liferay.portal.kernel.util.StringPool;
036 import com.liferay.portal.kernel.util.StringUtil;
037 import com.liferay.portal.model.LayoutPrototype;
038 import com.liferay.portal.model.ModelListener;
039 import com.liferay.portal.model.impl.LayoutPrototypeImpl;
040 import com.liferay.portal.model.impl.LayoutPrototypeModelImpl;
041 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
042
043 import java.io.Serializable;
044
045 import java.util.ArrayList;
046 import java.util.Collections;
047 import java.util.List;
048
049
065 public class LayoutPrototypePersistenceImpl extends BasePersistenceImpl<LayoutPrototype>
066 implements LayoutPrototypePersistence {
067 public static final String FINDER_CLASS_NAME_ENTITY = LayoutPrototypeImpl.class.getName();
068 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
069 ".List";
070 public static final FinderPath FINDER_PATH_FIND_BY_COMPANYID = new FinderPath(LayoutPrototypeModelImpl.ENTITY_CACHE_ENABLED,
071 LayoutPrototypeModelImpl.FINDER_CACHE_ENABLED,
072 FINDER_CLASS_NAME_LIST, "findByCompanyId",
073 new String[] {
074 Long.class.getName(),
075
076 "java.lang.Integer", "java.lang.Integer",
077 "com.liferay.portal.kernel.util.OrderByComparator"
078 });
079 public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(LayoutPrototypeModelImpl.ENTITY_CACHE_ENABLED,
080 LayoutPrototypeModelImpl.FINDER_CACHE_ENABLED,
081 FINDER_CLASS_NAME_LIST, "countByCompanyId",
082 new String[] { Long.class.getName() });
083 public static final FinderPath FINDER_PATH_FIND_BY_C_A = new FinderPath(LayoutPrototypeModelImpl.ENTITY_CACHE_ENABLED,
084 LayoutPrototypeModelImpl.FINDER_CACHE_ENABLED,
085 FINDER_CLASS_NAME_LIST, "findByC_A",
086 new String[] {
087 Long.class.getName(), Boolean.class.getName(),
088
089 "java.lang.Integer", "java.lang.Integer",
090 "com.liferay.portal.kernel.util.OrderByComparator"
091 });
092 public static final FinderPath FINDER_PATH_COUNT_BY_C_A = new FinderPath(LayoutPrototypeModelImpl.ENTITY_CACHE_ENABLED,
093 LayoutPrototypeModelImpl.FINDER_CACHE_ENABLED,
094 FINDER_CLASS_NAME_LIST, "countByC_A",
095 new String[] { Long.class.getName(), Boolean.class.getName() });
096 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(LayoutPrototypeModelImpl.ENTITY_CACHE_ENABLED,
097 LayoutPrototypeModelImpl.FINDER_CACHE_ENABLED,
098 FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
099 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(LayoutPrototypeModelImpl.ENTITY_CACHE_ENABLED,
100 LayoutPrototypeModelImpl.FINDER_CACHE_ENABLED,
101 FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
102
103
108 public void cacheResult(LayoutPrototype layoutPrototype) {
109 EntityCacheUtil.putResult(LayoutPrototypeModelImpl.ENTITY_CACHE_ENABLED,
110 LayoutPrototypeImpl.class, layoutPrototype.getPrimaryKey(),
111 layoutPrototype);
112 }
113
114
119 public void cacheResult(List<LayoutPrototype> layoutPrototypes) {
120 for (LayoutPrototype layoutPrototype : layoutPrototypes) {
121 if (EntityCacheUtil.getResult(
122 LayoutPrototypeModelImpl.ENTITY_CACHE_ENABLED,
123 LayoutPrototypeImpl.class,
124 layoutPrototype.getPrimaryKey(), this) == null) {
125 cacheResult(layoutPrototype);
126 }
127 }
128 }
129
130
137 public void clearCache() {
138 CacheRegistryUtil.clear(LayoutPrototypeImpl.class.getName());
139 EntityCacheUtil.clearCache(LayoutPrototypeImpl.class.getName());
140 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
141 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
142 }
143
144
151 public void clearCache(LayoutPrototype layoutPrototype) {
152 EntityCacheUtil.removeResult(LayoutPrototypeModelImpl.ENTITY_CACHE_ENABLED,
153 LayoutPrototypeImpl.class, layoutPrototype.getPrimaryKey());
154 }
155
156
162 public LayoutPrototype create(long layoutPrototypeId) {
163 LayoutPrototype layoutPrototype = new LayoutPrototypeImpl();
164
165 layoutPrototype.setNew(true);
166 layoutPrototype.setPrimaryKey(layoutPrototypeId);
167
168 return layoutPrototype;
169 }
170
171
179 public LayoutPrototype remove(Serializable primaryKey)
180 throws NoSuchModelException, SystemException {
181 return remove(((Long)primaryKey).longValue());
182 }
183
184
192 public LayoutPrototype remove(long layoutPrototypeId)
193 throws NoSuchLayoutPrototypeException, SystemException {
194 Session session = null;
195
196 try {
197 session = openSession();
198
199 LayoutPrototype layoutPrototype = (LayoutPrototype)session.get(LayoutPrototypeImpl.class,
200 new Long(layoutPrototypeId));
201
202 if (layoutPrototype == null) {
203 if (_log.isWarnEnabled()) {
204 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
205 layoutPrototypeId);
206 }
207
208 throw new NoSuchLayoutPrototypeException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
209 layoutPrototypeId);
210 }
211
212 return remove(layoutPrototype);
213 }
214 catch (NoSuchLayoutPrototypeException nsee) {
215 throw nsee;
216 }
217 catch (Exception e) {
218 throw processException(e);
219 }
220 finally {
221 closeSession(session);
222 }
223 }
224
225 protected LayoutPrototype removeImpl(LayoutPrototype layoutPrototype)
226 throws SystemException {
227 layoutPrototype = toUnwrappedModel(layoutPrototype);
228
229 Session session = null;
230
231 try {
232 session = openSession();
233
234 if (layoutPrototype.isCachedModel() ||
235 BatchSessionUtil.isEnabled()) {
236 Object staleObject = session.get(LayoutPrototypeImpl.class,
237 layoutPrototype.getPrimaryKeyObj());
238
239 if (staleObject != null) {
240 session.evict(staleObject);
241 }
242 }
243
244 session.delete(layoutPrototype);
245
246 session.flush();
247 }
248 catch (Exception e) {
249 throw processException(e);
250 }
251 finally {
252 closeSession(session);
253 }
254
255 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
256
257 EntityCacheUtil.removeResult(LayoutPrototypeModelImpl.ENTITY_CACHE_ENABLED,
258 LayoutPrototypeImpl.class, layoutPrototype.getPrimaryKey());
259
260 return layoutPrototype;
261 }
262
263 public LayoutPrototype updateImpl(
264 com.liferay.portal.model.LayoutPrototype layoutPrototype, boolean merge)
265 throws SystemException {
266 layoutPrototype = toUnwrappedModel(layoutPrototype);
267
268 Session session = null;
269
270 try {
271 session = openSession();
272
273 BatchSessionUtil.update(session, layoutPrototype, merge);
274
275 layoutPrototype.setNew(false);
276 }
277 catch (Exception e) {
278 throw processException(e);
279 }
280 finally {
281 closeSession(session);
282 }
283
284 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
285
286 EntityCacheUtil.putResult(LayoutPrototypeModelImpl.ENTITY_CACHE_ENABLED,
287 LayoutPrototypeImpl.class, layoutPrototype.getPrimaryKey(),
288 layoutPrototype);
289
290 return layoutPrototype;
291 }
292
293 protected LayoutPrototype toUnwrappedModel(LayoutPrototype layoutPrototype) {
294 if (layoutPrototype instanceof LayoutPrototypeImpl) {
295 return layoutPrototype;
296 }
297
298 LayoutPrototypeImpl layoutPrototypeImpl = new LayoutPrototypeImpl();
299
300 layoutPrototypeImpl.setNew(layoutPrototype.isNew());
301 layoutPrototypeImpl.setPrimaryKey(layoutPrototype.getPrimaryKey());
302
303 layoutPrototypeImpl.setLayoutPrototypeId(layoutPrototype.getLayoutPrototypeId());
304 layoutPrototypeImpl.setCompanyId(layoutPrototype.getCompanyId());
305 layoutPrototypeImpl.setName(layoutPrototype.getName());
306 layoutPrototypeImpl.setDescription(layoutPrototype.getDescription());
307 layoutPrototypeImpl.setSettings(layoutPrototype.getSettings());
308 layoutPrototypeImpl.setActive(layoutPrototype.isActive());
309
310 return layoutPrototypeImpl;
311 }
312
313
321 public LayoutPrototype findByPrimaryKey(Serializable primaryKey)
322 throws NoSuchModelException, SystemException {
323 return findByPrimaryKey(((Long)primaryKey).longValue());
324 }
325
326
334 public LayoutPrototype findByPrimaryKey(long layoutPrototypeId)
335 throws NoSuchLayoutPrototypeException, SystemException {
336 LayoutPrototype layoutPrototype = fetchByPrimaryKey(layoutPrototypeId);
337
338 if (layoutPrototype == null) {
339 if (_log.isWarnEnabled()) {
340 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + layoutPrototypeId);
341 }
342
343 throw new NoSuchLayoutPrototypeException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
344 layoutPrototypeId);
345 }
346
347 return layoutPrototype;
348 }
349
350
357 public LayoutPrototype fetchByPrimaryKey(Serializable primaryKey)
358 throws SystemException {
359 return fetchByPrimaryKey(((Long)primaryKey).longValue());
360 }
361
362
369 public LayoutPrototype fetchByPrimaryKey(long layoutPrototypeId)
370 throws SystemException {
371 LayoutPrototype layoutPrototype = (LayoutPrototype)EntityCacheUtil.getResult(LayoutPrototypeModelImpl.ENTITY_CACHE_ENABLED,
372 LayoutPrototypeImpl.class, layoutPrototypeId, this);
373
374 if (layoutPrototype == null) {
375 Session session = null;
376
377 try {
378 session = openSession();
379
380 layoutPrototype = (LayoutPrototype)session.get(LayoutPrototypeImpl.class,
381 new Long(layoutPrototypeId));
382 }
383 catch (Exception e) {
384 throw processException(e);
385 }
386 finally {
387 if (layoutPrototype != null) {
388 cacheResult(layoutPrototype);
389 }
390
391 closeSession(session);
392 }
393 }
394
395 return layoutPrototype;
396 }
397
398
405 public List<LayoutPrototype> findByCompanyId(long companyId)
406 throws SystemException {
407 return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
408 null);
409 }
410
411
424 public List<LayoutPrototype> findByCompanyId(long companyId, int start,
425 int end) throws SystemException {
426 return findByCompanyId(companyId, start, end, null);
427 }
428
429
443 public List<LayoutPrototype> findByCompanyId(long companyId, int start,
444 int end, OrderByComparator orderByComparator) throws SystemException {
445 Object[] finderArgs = new Object[] {
446 companyId,
447
448 String.valueOf(start), String.valueOf(end),
449 String.valueOf(orderByComparator)
450 };
451
452 List<LayoutPrototype> list = (List<LayoutPrototype>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_COMPANYID,
453 finderArgs, this);
454
455 if (list == null) {
456 Session session = null;
457
458 try {
459 session = openSession();
460
461 StringBundler query = null;
462
463 if (orderByComparator != null) {
464 query = new StringBundler(3 +
465 (orderByComparator.getOrderByFields().length * 3));
466 }
467 else {
468 query = new StringBundler(2);
469 }
470
471 query.append(_SQL_SELECT_LAYOUTPROTOTYPE_WHERE);
472
473 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
474
475 if (orderByComparator != null) {
476 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
477 orderByComparator);
478 }
479
480 String sql = query.toString();
481
482 Query q = session.createQuery(sql);
483
484 QueryPos qPos = QueryPos.getInstance(q);
485
486 qPos.add(companyId);
487
488 list = (List<LayoutPrototype>)QueryUtil.list(q, getDialect(),
489 start, end);
490 }
491 catch (Exception e) {
492 throw processException(e);
493 }
494 finally {
495 if (list == null) {
496 list = new ArrayList<LayoutPrototype>();
497 }
498
499 cacheResult(list);
500
501 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_COMPANYID,
502 finderArgs, list);
503
504 closeSession(session);
505 }
506 }
507
508 return list;
509 }
510
511
524 public LayoutPrototype findByCompanyId_First(long companyId,
525 OrderByComparator orderByComparator)
526 throws NoSuchLayoutPrototypeException, SystemException {
527 List<LayoutPrototype> list = findByCompanyId(companyId, 0, 1,
528 orderByComparator);
529
530 if (list.isEmpty()) {
531 StringBundler msg = new StringBundler(4);
532
533 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
534
535 msg.append("companyId=");
536 msg.append(companyId);
537
538 msg.append(StringPool.CLOSE_CURLY_BRACE);
539
540 throw new NoSuchLayoutPrototypeException(msg.toString());
541 }
542 else {
543 return list.get(0);
544 }
545 }
546
547
560 public LayoutPrototype findByCompanyId_Last(long companyId,
561 OrderByComparator orderByComparator)
562 throws NoSuchLayoutPrototypeException, SystemException {
563 int count = countByCompanyId(companyId);
564
565 List<LayoutPrototype> list = findByCompanyId(companyId, count - 1,
566 count, orderByComparator);
567
568 if (list.isEmpty()) {
569 StringBundler msg = new StringBundler(4);
570
571 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
572
573 msg.append("companyId=");
574 msg.append(companyId);
575
576 msg.append(StringPool.CLOSE_CURLY_BRACE);
577
578 throw new NoSuchLayoutPrototypeException(msg.toString());
579 }
580 else {
581 return list.get(0);
582 }
583 }
584
585
599 public LayoutPrototype[] findByCompanyId_PrevAndNext(
600 long layoutPrototypeId, long companyId,
601 OrderByComparator orderByComparator)
602 throws NoSuchLayoutPrototypeException, SystemException {
603 LayoutPrototype layoutPrototype = findByPrimaryKey(layoutPrototypeId);
604
605 Session session = null;
606
607 try {
608 session = openSession();
609
610 LayoutPrototype[] array = new LayoutPrototypeImpl[3];
611
612 array[0] = getByCompanyId_PrevAndNext(session, layoutPrototype,
613 companyId, orderByComparator, true);
614
615 array[1] = layoutPrototype;
616
617 array[2] = getByCompanyId_PrevAndNext(session, layoutPrototype,
618 companyId, orderByComparator, false);
619
620 return array;
621 }
622 catch (Exception e) {
623 throw processException(e);
624 }
625 finally {
626 closeSession(session);
627 }
628 }
629
630 protected LayoutPrototype getByCompanyId_PrevAndNext(Session session,
631 LayoutPrototype layoutPrototype, long companyId,
632 OrderByComparator orderByComparator, boolean previous) {
633 StringBundler query = null;
634
635 if (orderByComparator != null) {
636 query = new StringBundler(6 +
637 (orderByComparator.getOrderByFields().length * 6));
638 }
639 else {
640 query = new StringBundler(3);
641 }
642
643 query.append(_SQL_SELECT_LAYOUTPROTOTYPE_WHERE);
644
645 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
646
647 if (orderByComparator != null) {
648 String[] orderByFields = orderByComparator.getOrderByFields();
649
650 if (orderByFields.length > 0) {
651 query.append(WHERE_AND);
652 }
653
654 for (int i = 0; i < orderByFields.length; i++) {
655 query.append(_ORDER_BY_ENTITY_ALIAS);
656 query.append(orderByFields[i]);
657
658 if ((i + 1) < orderByFields.length) {
659 if (orderByComparator.isAscending() ^ previous) {
660 query.append(WHERE_GREATER_THAN_HAS_NEXT);
661 }
662 else {
663 query.append(WHERE_LESSER_THAN_HAS_NEXT);
664 }
665 }
666 else {
667 if (orderByComparator.isAscending() ^ previous) {
668 query.append(WHERE_GREATER_THAN);
669 }
670 else {
671 query.append(WHERE_LESSER_THAN);
672 }
673 }
674 }
675
676 query.append(ORDER_BY_CLAUSE);
677
678 for (int i = 0; i < orderByFields.length; i++) {
679 query.append(_ORDER_BY_ENTITY_ALIAS);
680 query.append(orderByFields[i]);
681
682 if ((i + 1) < orderByFields.length) {
683 if (orderByComparator.isAscending() ^ previous) {
684 query.append(ORDER_BY_ASC_HAS_NEXT);
685 }
686 else {
687 query.append(ORDER_BY_DESC_HAS_NEXT);
688 }
689 }
690 else {
691 if (orderByComparator.isAscending() ^ previous) {
692 query.append(ORDER_BY_ASC);
693 }
694 else {
695 query.append(ORDER_BY_DESC);
696 }
697 }
698 }
699 }
700
701 String sql = query.toString();
702
703 Query q = session.createQuery(sql);
704
705 q.setFirstResult(0);
706 q.setMaxResults(2);
707
708 QueryPos qPos = QueryPos.getInstance(q);
709
710 qPos.add(companyId);
711
712 if (orderByComparator != null) {
713 Object[] values = orderByComparator.getOrderByValues(layoutPrototype);
714
715 for (Object value : values) {
716 qPos.add(value);
717 }
718 }
719
720 List<LayoutPrototype> list = q.list();
721
722 if (list.size() == 2) {
723 return list.get(1);
724 }
725 else {
726 return null;
727 }
728 }
729
730
738 public List<LayoutPrototype> findByC_A(long companyId, boolean active)
739 throws SystemException {
740 return findByC_A(companyId, active, QueryUtil.ALL_POS,
741 QueryUtil.ALL_POS, null);
742 }
743
744
758 public List<LayoutPrototype> findByC_A(long companyId, boolean active,
759 int start, int end) throws SystemException {
760 return findByC_A(companyId, active, start, end, null);
761 }
762
763
778 public List<LayoutPrototype> findByC_A(long companyId, boolean active,
779 int start, int end, OrderByComparator orderByComparator)
780 throws SystemException {
781 Object[] finderArgs = new Object[] {
782 companyId, active,
783
784 String.valueOf(start), String.valueOf(end),
785 String.valueOf(orderByComparator)
786 };
787
788 List<LayoutPrototype> list = (List<LayoutPrototype>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_A,
789 finderArgs, this);
790
791 if (list == null) {
792 Session session = null;
793
794 try {
795 session = openSession();
796
797 StringBundler query = null;
798
799 if (orderByComparator != null) {
800 query = new StringBundler(4 +
801 (orderByComparator.getOrderByFields().length * 3));
802 }
803 else {
804 query = new StringBundler(3);
805 }
806
807 query.append(_SQL_SELECT_LAYOUTPROTOTYPE_WHERE);
808
809 query.append(_FINDER_COLUMN_C_A_COMPANYID_2);
810
811 query.append(_FINDER_COLUMN_C_A_ACTIVE_2);
812
813 if (orderByComparator != null) {
814 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
815 orderByComparator);
816 }
817
818 String sql = query.toString();
819
820 Query q = session.createQuery(sql);
821
822 QueryPos qPos = QueryPos.getInstance(q);
823
824 qPos.add(companyId);
825
826 qPos.add(active);
827
828 list = (List<LayoutPrototype>)QueryUtil.list(q, getDialect(),
829 start, end);
830 }
831 catch (Exception e) {
832 throw processException(e);
833 }
834 finally {
835 if (list == null) {
836 list = new ArrayList<LayoutPrototype>();
837 }
838
839 cacheResult(list);
840
841 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_A, finderArgs,
842 list);
843
844 closeSession(session);
845 }
846 }
847
848 return list;
849 }
850
851
865 public LayoutPrototype findByC_A_First(long companyId, boolean active,
866 OrderByComparator orderByComparator)
867 throws NoSuchLayoutPrototypeException, SystemException {
868 List<LayoutPrototype> list = findByC_A(companyId, active, 0, 1,
869 orderByComparator);
870
871 if (list.isEmpty()) {
872 StringBundler msg = new StringBundler(6);
873
874 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
875
876 msg.append("companyId=");
877 msg.append(companyId);
878
879 msg.append(", active=");
880 msg.append(active);
881
882 msg.append(StringPool.CLOSE_CURLY_BRACE);
883
884 throw new NoSuchLayoutPrototypeException(msg.toString());
885 }
886 else {
887 return list.get(0);
888 }
889 }
890
891
905 public LayoutPrototype findByC_A_Last(long companyId, boolean active,
906 OrderByComparator orderByComparator)
907 throws NoSuchLayoutPrototypeException, SystemException {
908 int count = countByC_A(companyId, active);
909
910 List<LayoutPrototype> list = findByC_A(companyId, active, count - 1,
911 count, orderByComparator);
912
913 if (list.isEmpty()) {
914 StringBundler msg = new StringBundler(6);
915
916 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
917
918 msg.append("companyId=");
919 msg.append(companyId);
920
921 msg.append(", active=");
922 msg.append(active);
923
924 msg.append(StringPool.CLOSE_CURLY_BRACE);
925
926 throw new NoSuchLayoutPrototypeException(msg.toString());
927 }
928 else {
929 return list.get(0);
930 }
931 }
932
933
948 public LayoutPrototype[] findByC_A_PrevAndNext(long layoutPrototypeId,
949 long companyId, boolean active, OrderByComparator orderByComparator)
950 throws NoSuchLayoutPrototypeException, SystemException {
951 LayoutPrototype layoutPrototype = findByPrimaryKey(layoutPrototypeId);
952
953 Session session = null;
954
955 try {
956 session = openSession();
957
958 LayoutPrototype[] array = new LayoutPrototypeImpl[3];
959
960 array[0] = getByC_A_PrevAndNext(session, layoutPrototype,
961 companyId, active, orderByComparator, true);
962
963 array[1] = layoutPrototype;
964
965 array[2] = getByC_A_PrevAndNext(session, layoutPrototype,
966 companyId, active, orderByComparator, false);
967
968 return array;
969 }
970 catch (Exception e) {
971 throw processException(e);
972 }
973 finally {
974 closeSession(session);
975 }
976 }
977
978 protected LayoutPrototype getByC_A_PrevAndNext(Session session,
979 LayoutPrototype layoutPrototype, long companyId, boolean active,
980 OrderByComparator orderByComparator, boolean previous) {
981 StringBundler query = null;
982
983 if (orderByComparator != null) {
984 query = new StringBundler(6 +
985 (orderByComparator.getOrderByFields().length * 6));
986 }
987 else {
988 query = new StringBundler(3);
989 }
990
991 query.append(_SQL_SELECT_LAYOUTPROTOTYPE_WHERE);
992
993 query.append(_FINDER_COLUMN_C_A_COMPANYID_2);
994
995 query.append(_FINDER_COLUMN_C_A_ACTIVE_2);
996
997 if (orderByComparator != null) {
998 String[] orderByFields = orderByComparator.getOrderByFields();
999
1000 if (orderByFields.length > 0) {
1001 query.append(WHERE_AND);
1002 }
1003
1004 for (int i = 0; i < orderByFields.length; i++) {
1005 query.append(_ORDER_BY_ENTITY_ALIAS);
1006 query.append(orderByFields[i]);
1007
1008 if ((i + 1) < orderByFields.length) {
1009 if (orderByComparator.isAscending() ^ previous) {
1010 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1011 }
1012 else {
1013 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1014 }
1015 }
1016 else {
1017 if (orderByComparator.isAscending() ^ previous) {
1018 query.append(WHERE_GREATER_THAN);
1019 }
1020 else {
1021 query.append(WHERE_LESSER_THAN);
1022 }
1023 }
1024 }
1025
1026 query.append(ORDER_BY_CLAUSE);
1027
1028 for (int i = 0; i < orderByFields.length; i++) {
1029 query.append(_ORDER_BY_ENTITY_ALIAS);
1030 query.append(orderByFields[i]);
1031
1032 if ((i + 1) < orderByFields.length) {
1033 if (orderByComparator.isAscending() ^ previous) {
1034 query.append(ORDER_BY_ASC_HAS_NEXT);
1035 }
1036 else {
1037 query.append(ORDER_BY_DESC_HAS_NEXT);
1038 }
1039 }
1040 else {
1041 if (orderByComparator.isAscending() ^ previous) {
1042 query.append(ORDER_BY_ASC);
1043 }
1044 else {
1045 query.append(ORDER_BY_DESC);
1046 }
1047 }
1048 }
1049 }
1050
1051 String sql = query.toString();
1052
1053 Query q = session.createQuery(sql);
1054
1055 q.setFirstResult(0);
1056 q.setMaxResults(2);
1057
1058 QueryPos qPos = QueryPos.getInstance(q);
1059
1060 qPos.add(companyId);
1061
1062 qPos.add(active);
1063
1064 if (orderByComparator != null) {
1065 Object[] values = orderByComparator.getOrderByValues(layoutPrototype);
1066
1067 for (Object value : values) {
1068 qPos.add(value);
1069 }
1070 }
1071
1072 List<LayoutPrototype> list = q.list();
1073
1074 if (list.size() == 2) {
1075 return list.get(1);
1076 }
1077 else {
1078 return null;
1079 }
1080 }
1081
1082
1088 public List<LayoutPrototype> findAll() throws SystemException {
1089 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1090 }
1091
1092
1104 public List<LayoutPrototype> findAll(int start, int end)
1105 throws SystemException {
1106 return findAll(start, end, null);
1107 }
1108
1109
1122 public List<LayoutPrototype> findAll(int start, int end,
1123 OrderByComparator orderByComparator) throws SystemException {
1124 Object[] finderArgs = new Object[] {
1125 String.valueOf(start), String.valueOf(end),
1126 String.valueOf(orderByComparator)
1127 };
1128
1129 List<LayoutPrototype> list = (List<LayoutPrototype>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1130 finderArgs, this);
1131
1132 if (list == null) {
1133 Session session = null;
1134
1135 try {
1136 session = openSession();
1137
1138 StringBundler query = null;
1139 String sql = null;
1140
1141 if (orderByComparator != null) {
1142 query = new StringBundler(2 +
1143 (orderByComparator.getOrderByFields().length * 3));
1144
1145 query.append(_SQL_SELECT_LAYOUTPROTOTYPE);
1146
1147 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1148 orderByComparator);
1149
1150 sql = query.toString();
1151 }
1152 else {
1153 sql = _SQL_SELECT_LAYOUTPROTOTYPE;
1154 }
1155
1156 Query q = session.createQuery(sql);
1157
1158 if (orderByComparator == null) {
1159 list = (List<LayoutPrototype>)QueryUtil.list(q,
1160 getDialect(), start, end, false);
1161
1162 Collections.sort(list);
1163 }
1164 else {
1165 list = (List<LayoutPrototype>)QueryUtil.list(q,
1166 getDialect(), start, end);
1167 }
1168 }
1169 catch (Exception e) {
1170 throw processException(e);
1171 }
1172 finally {
1173 if (list == null) {
1174 list = new ArrayList<LayoutPrototype>();
1175 }
1176
1177 cacheResult(list);
1178
1179 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1180
1181 closeSession(session);
1182 }
1183 }
1184
1185 return list;
1186 }
1187
1188
1194 public void removeByCompanyId(long companyId) throws SystemException {
1195 for (LayoutPrototype layoutPrototype : findByCompanyId(companyId)) {
1196 remove(layoutPrototype);
1197 }
1198 }
1199
1200
1207 public void removeByC_A(long companyId, boolean active)
1208 throws SystemException {
1209 for (LayoutPrototype layoutPrototype : findByC_A(companyId, active)) {
1210 remove(layoutPrototype);
1211 }
1212 }
1213
1214
1219 public void removeAll() throws SystemException {
1220 for (LayoutPrototype layoutPrototype : findAll()) {
1221 remove(layoutPrototype);
1222 }
1223 }
1224
1225
1232 public int countByCompanyId(long companyId) throws SystemException {
1233 Object[] finderArgs = new Object[] { companyId };
1234
1235 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
1236 finderArgs, this);
1237
1238 if (count == null) {
1239 Session session = null;
1240
1241 try {
1242 session = openSession();
1243
1244 StringBundler query = new StringBundler(2);
1245
1246 query.append(_SQL_COUNT_LAYOUTPROTOTYPE_WHERE);
1247
1248 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1249
1250 String sql = query.toString();
1251
1252 Query q = session.createQuery(sql);
1253
1254 QueryPos qPos = QueryPos.getInstance(q);
1255
1256 qPos.add(companyId);
1257
1258 count = (Long)q.uniqueResult();
1259 }
1260 catch (Exception e) {
1261 throw processException(e);
1262 }
1263 finally {
1264 if (count == null) {
1265 count = Long.valueOf(0);
1266 }
1267
1268 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
1269 finderArgs, count);
1270
1271 closeSession(session);
1272 }
1273 }
1274
1275 return count.intValue();
1276 }
1277
1278
1286 public int countByC_A(long companyId, boolean active)
1287 throws SystemException {
1288 Object[] finderArgs = new Object[] { companyId, active };
1289
1290 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_A,
1291 finderArgs, this);
1292
1293 if (count == null) {
1294 Session session = null;
1295
1296 try {
1297 session = openSession();
1298
1299 StringBundler query = new StringBundler(3);
1300
1301 query.append(_SQL_COUNT_LAYOUTPROTOTYPE_WHERE);
1302
1303 query.append(_FINDER_COLUMN_C_A_COMPANYID_2);
1304
1305 query.append(_FINDER_COLUMN_C_A_ACTIVE_2);
1306
1307 String sql = query.toString();
1308
1309 Query q = session.createQuery(sql);
1310
1311 QueryPos qPos = QueryPos.getInstance(q);
1312
1313 qPos.add(companyId);
1314
1315 qPos.add(active);
1316
1317 count = (Long)q.uniqueResult();
1318 }
1319 catch (Exception e) {
1320 throw processException(e);
1321 }
1322 finally {
1323 if (count == null) {
1324 count = Long.valueOf(0);
1325 }
1326
1327 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_A, finderArgs,
1328 count);
1329
1330 closeSession(session);
1331 }
1332 }
1333
1334 return count.intValue();
1335 }
1336
1337
1343 public int countAll() throws SystemException {
1344 Object[] finderArgs = new Object[0];
1345
1346 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1347 finderArgs, this);
1348
1349 if (count == null) {
1350 Session session = null;
1351
1352 try {
1353 session = openSession();
1354
1355 Query q = session.createQuery(_SQL_COUNT_LAYOUTPROTOTYPE);
1356
1357 count = (Long)q.uniqueResult();
1358 }
1359 catch (Exception e) {
1360 throw processException(e);
1361 }
1362 finally {
1363 if (count == null) {
1364 count = Long.valueOf(0);
1365 }
1366
1367 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1368 count);
1369
1370 closeSession(session);
1371 }
1372 }
1373
1374 return count.intValue();
1375 }
1376
1377
1380 public void afterPropertiesSet() {
1381 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1382 com.liferay.portal.util.PropsUtil.get(
1383 "value.object.listener.com.liferay.portal.model.LayoutPrototype")));
1384
1385 if (listenerClassNames.length > 0) {
1386 try {
1387 List<ModelListener<LayoutPrototype>> listenersList = new ArrayList<ModelListener<LayoutPrototype>>();
1388
1389 for (String listenerClassName : listenerClassNames) {
1390 listenersList.add((ModelListener<LayoutPrototype>)InstanceFactory.newInstance(
1391 listenerClassName));
1392 }
1393
1394 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1395 }
1396 catch (Exception e) {
1397 _log.error(e);
1398 }
1399 }
1400 }
1401
1402 @BeanReference(type = AccountPersistence.class)
1403 protected AccountPersistence accountPersistence;
1404 @BeanReference(type = AddressPersistence.class)
1405 protected AddressPersistence addressPersistence;
1406 @BeanReference(type = BrowserTrackerPersistence.class)
1407 protected BrowserTrackerPersistence browserTrackerPersistence;
1408 @BeanReference(type = ClassNamePersistence.class)
1409 protected ClassNamePersistence classNamePersistence;
1410 @BeanReference(type = ClusterGroupPersistence.class)
1411 protected ClusterGroupPersistence clusterGroupPersistence;
1412 @BeanReference(type = CompanyPersistence.class)
1413 protected CompanyPersistence companyPersistence;
1414 @BeanReference(type = ContactPersistence.class)
1415 protected ContactPersistence contactPersistence;
1416 @BeanReference(type = CountryPersistence.class)
1417 protected CountryPersistence countryPersistence;
1418 @BeanReference(type = EmailAddressPersistence.class)
1419 protected EmailAddressPersistence emailAddressPersistence;
1420 @BeanReference(type = GroupPersistence.class)
1421 protected GroupPersistence groupPersistence;
1422 @BeanReference(type = ImagePersistence.class)
1423 protected ImagePersistence imagePersistence;
1424 @BeanReference(type = LayoutPersistence.class)
1425 protected LayoutPersistence layoutPersistence;
1426 @BeanReference(type = LayoutPrototypePersistence.class)
1427 protected LayoutPrototypePersistence layoutPrototypePersistence;
1428 @BeanReference(type = LayoutSetPersistence.class)
1429 protected LayoutSetPersistence layoutSetPersistence;
1430 @BeanReference(type = LayoutSetPrototypePersistence.class)
1431 protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
1432 @BeanReference(type = ListTypePersistence.class)
1433 protected ListTypePersistence listTypePersistence;
1434 @BeanReference(type = LockPersistence.class)
1435 protected LockPersistence lockPersistence;
1436 @BeanReference(type = MembershipRequestPersistence.class)
1437 protected MembershipRequestPersistence membershipRequestPersistence;
1438 @BeanReference(type = OrganizationPersistence.class)
1439 protected OrganizationPersistence organizationPersistence;
1440 @BeanReference(type = OrgGroupPermissionPersistence.class)
1441 protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1442 @BeanReference(type = OrgGroupRolePersistence.class)
1443 protected OrgGroupRolePersistence orgGroupRolePersistence;
1444 @BeanReference(type = OrgLaborPersistence.class)
1445 protected OrgLaborPersistence orgLaborPersistence;
1446 @BeanReference(type = PasswordPolicyPersistence.class)
1447 protected PasswordPolicyPersistence passwordPolicyPersistence;
1448 @BeanReference(type = PasswordPolicyRelPersistence.class)
1449 protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1450 @BeanReference(type = PasswordTrackerPersistence.class)
1451 protected PasswordTrackerPersistence passwordTrackerPersistence;
1452 @BeanReference(type = PermissionPersistence.class)
1453 protected PermissionPersistence permissionPersistence;
1454 @BeanReference(type = PhonePersistence.class)
1455 protected PhonePersistence phonePersistence;
1456 @BeanReference(type = PluginSettingPersistence.class)
1457 protected PluginSettingPersistence pluginSettingPersistence;
1458 @BeanReference(type = PortletPersistence.class)
1459 protected PortletPersistence portletPersistence;
1460 @BeanReference(type = PortletItemPersistence.class)
1461 protected PortletItemPersistence portletItemPersistence;
1462 @BeanReference(type = PortletPreferencesPersistence.class)
1463 protected PortletPreferencesPersistence portletPreferencesPersistence;
1464 @BeanReference(type = RegionPersistence.class)
1465 protected RegionPersistence regionPersistence;
1466 @BeanReference(type = ReleasePersistence.class)
1467 protected ReleasePersistence releasePersistence;
1468 @BeanReference(type = ResourcePersistence.class)
1469 protected ResourcePersistence resourcePersistence;
1470 @BeanReference(type = ResourceActionPersistence.class)
1471 protected ResourceActionPersistence resourceActionPersistence;
1472 @BeanReference(type = ResourceCodePersistence.class)
1473 protected ResourceCodePersistence resourceCodePersistence;
1474 @BeanReference(type = ResourcePermissionPersistence.class)
1475 protected ResourcePermissionPersistence resourcePermissionPersistence;
1476 @BeanReference(type = RolePersistence.class)
1477 protected RolePersistence rolePersistence;
1478 @BeanReference(type = ServiceComponentPersistence.class)
1479 protected ServiceComponentPersistence serviceComponentPersistence;
1480 @BeanReference(type = ShardPersistence.class)
1481 protected ShardPersistence shardPersistence;
1482 @BeanReference(type = SubscriptionPersistence.class)
1483 protected SubscriptionPersistence subscriptionPersistence;
1484 @BeanReference(type = TicketPersistence.class)
1485 protected TicketPersistence ticketPersistence;
1486 @BeanReference(type = TeamPersistence.class)
1487 protected TeamPersistence teamPersistence;
1488 @BeanReference(type = UserPersistence.class)
1489 protected UserPersistence userPersistence;
1490 @BeanReference(type = UserGroupPersistence.class)
1491 protected UserGroupPersistence userGroupPersistence;
1492 @BeanReference(type = UserGroupGroupRolePersistence.class)
1493 protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1494 @BeanReference(type = UserGroupRolePersistence.class)
1495 protected UserGroupRolePersistence userGroupRolePersistence;
1496 @BeanReference(type = UserIdMapperPersistence.class)
1497 protected UserIdMapperPersistence userIdMapperPersistence;
1498 @BeanReference(type = UserTrackerPersistence.class)
1499 protected UserTrackerPersistence userTrackerPersistence;
1500 @BeanReference(type = UserTrackerPathPersistence.class)
1501 protected UserTrackerPathPersistence userTrackerPathPersistence;
1502 @BeanReference(type = WebDAVPropsPersistence.class)
1503 protected WebDAVPropsPersistence webDAVPropsPersistence;
1504 @BeanReference(type = WebsitePersistence.class)
1505 protected WebsitePersistence websitePersistence;
1506 @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
1507 protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
1508 @BeanReference(type = WorkflowInstanceLinkPersistence.class)
1509 protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
1510 private static final String _SQL_SELECT_LAYOUTPROTOTYPE = "SELECT layoutPrototype FROM LayoutPrototype layoutPrototype";
1511 private static final String _SQL_SELECT_LAYOUTPROTOTYPE_WHERE = "SELECT layoutPrototype FROM LayoutPrototype layoutPrototype WHERE ";
1512 private static final String _SQL_COUNT_LAYOUTPROTOTYPE = "SELECT COUNT(layoutPrototype) FROM LayoutPrototype layoutPrototype";
1513 private static final String _SQL_COUNT_LAYOUTPROTOTYPE_WHERE = "SELECT COUNT(layoutPrototype) FROM LayoutPrototype layoutPrototype WHERE ";
1514 private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "layoutPrototype.companyId = ?";
1515 private static final String _FINDER_COLUMN_C_A_COMPANYID_2 = "layoutPrototype.companyId = ? AND ";
1516 private static final String _FINDER_COLUMN_C_A_ACTIVE_2 = "layoutPrototype.active = ?";
1517 private static final String _ORDER_BY_ENTITY_ALIAS = "layoutPrototype.";
1518 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No LayoutPrototype exists with the primary key ";
1519 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No LayoutPrototype exists with the key {";
1520 private static Log _log = LogFactoryUtil.getLog(LayoutPrototypePersistenceImpl.class);
1521 }