1
14
15 package com.liferay.portal.service.persistence;
16
17 import com.liferay.portal.NoSuchLayoutPrototypeException;
18 import com.liferay.portal.NoSuchModelException;
19 import com.liferay.portal.kernel.annotation.BeanReference;
20 import com.liferay.portal.kernel.cache.CacheRegistry;
21 import com.liferay.portal.kernel.dao.orm.DynamicQuery;
22 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
23 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
24 import com.liferay.portal.kernel.dao.orm.FinderPath;
25 import com.liferay.portal.kernel.dao.orm.Query;
26 import com.liferay.portal.kernel.dao.orm.QueryPos;
27 import com.liferay.portal.kernel.dao.orm.QueryUtil;
28 import com.liferay.portal.kernel.dao.orm.Session;
29 import com.liferay.portal.kernel.exception.SystemException;
30 import com.liferay.portal.kernel.log.Log;
31 import com.liferay.portal.kernel.log.LogFactoryUtil;
32 import com.liferay.portal.kernel.util.GetterUtil;
33 import com.liferay.portal.kernel.util.OrderByComparator;
34 import com.liferay.portal.kernel.util.StringBundler;
35 import com.liferay.portal.kernel.util.StringPool;
36 import com.liferay.portal.kernel.util.StringUtil;
37 import com.liferay.portal.model.LayoutPrototype;
38 import com.liferay.portal.model.ModelListener;
39 import com.liferay.portal.model.impl.LayoutPrototypeImpl;
40 import com.liferay.portal.model.impl.LayoutPrototypeModelImpl;
41 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
42
43 import java.io.Serializable;
44
45 import java.util.ArrayList;
46 import java.util.Collections;
47 import java.util.List;
48
49
62 public class LayoutPrototypePersistenceImpl extends BasePersistenceImpl<LayoutPrototype>
63 implements LayoutPrototypePersistence {
64 public static final String FINDER_CLASS_NAME_ENTITY = LayoutPrototypeImpl.class.getName();
65 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
66 ".List";
67 public static final FinderPath FINDER_PATH_FIND_BY_COMPANYID = new FinderPath(LayoutPrototypeModelImpl.ENTITY_CACHE_ENABLED,
68 LayoutPrototypeModelImpl.FINDER_CACHE_ENABLED,
69 FINDER_CLASS_NAME_LIST, "findByCompanyId",
70 new String[] { Long.class.getName() });
71 public static final FinderPath FINDER_PATH_FIND_BY_OBC_COMPANYID = new FinderPath(LayoutPrototypeModelImpl.ENTITY_CACHE_ENABLED,
72 LayoutPrototypeModelImpl.FINDER_CACHE_ENABLED,
73 FINDER_CLASS_NAME_LIST, "findByCompanyId",
74 new String[] {
75 Long.class.getName(),
76
77 "java.lang.Integer", "java.lang.Integer",
78 "com.liferay.portal.kernel.util.OrderByComparator"
79 });
80 public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(LayoutPrototypeModelImpl.ENTITY_CACHE_ENABLED,
81 LayoutPrototypeModelImpl.FINDER_CACHE_ENABLED,
82 FINDER_CLASS_NAME_LIST, "countByCompanyId",
83 new String[] { Long.class.getName() });
84 public static final FinderPath FINDER_PATH_FIND_BY_C_A = new FinderPath(LayoutPrototypeModelImpl.ENTITY_CACHE_ENABLED,
85 LayoutPrototypeModelImpl.FINDER_CACHE_ENABLED,
86 FINDER_CLASS_NAME_LIST, "findByC_A",
87 new String[] { Long.class.getName(), Boolean.class.getName() });
88 public static final FinderPath FINDER_PATH_FIND_BY_OBC_C_A = new FinderPath(LayoutPrototypeModelImpl.ENTITY_CACHE_ENABLED,
89 LayoutPrototypeModelImpl.FINDER_CACHE_ENABLED,
90 FINDER_CLASS_NAME_LIST, "findByC_A",
91 new String[] {
92 Long.class.getName(), Boolean.class.getName(),
93
94 "java.lang.Integer", "java.lang.Integer",
95 "com.liferay.portal.kernel.util.OrderByComparator"
96 });
97 public static final FinderPath FINDER_PATH_COUNT_BY_C_A = new FinderPath(LayoutPrototypeModelImpl.ENTITY_CACHE_ENABLED,
98 LayoutPrototypeModelImpl.FINDER_CACHE_ENABLED,
99 FINDER_CLASS_NAME_LIST, "countByC_A",
100 new String[] { Long.class.getName(), Boolean.class.getName() });
101 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(LayoutPrototypeModelImpl.ENTITY_CACHE_ENABLED,
102 LayoutPrototypeModelImpl.FINDER_CACHE_ENABLED,
103 FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
104 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(LayoutPrototypeModelImpl.ENTITY_CACHE_ENABLED,
105 LayoutPrototypeModelImpl.FINDER_CACHE_ENABLED,
106 FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
107
108 public void cacheResult(LayoutPrototype layoutPrototype) {
109 EntityCacheUtil.putResult(LayoutPrototypeModelImpl.ENTITY_CACHE_ENABLED,
110 LayoutPrototypeImpl.class, layoutPrototype.getPrimaryKey(),
111 layoutPrototype);
112 }
113
114 public void cacheResult(List<LayoutPrototype> layoutPrototypes) {
115 for (LayoutPrototype layoutPrototype : layoutPrototypes) {
116 if (EntityCacheUtil.getResult(
117 LayoutPrototypeModelImpl.ENTITY_CACHE_ENABLED,
118 LayoutPrototypeImpl.class,
119 layoutPrototype.getPrimaryKey(), this) == null) {
120 cacheResult(layoutPrototype);
121 }
122 }
123 }
124
125 public void clearCache() {
126 CacheRegistry.clear(LayoutPrototypeImpl.class.getName());
127 EntityCacheUtil.clearCache(LayoutPrototypeImpl.class.getName());
128 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
129 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
130 }
131
132 public LayoutPrototype create(long layoutPrototypeId) {
133 LayoutPrototype layoutPrototype = new LayoutPrototypeImpl();
134
135 layoutPrototype.setNew(true);
136 layoutPrototype.setPrimaryKey(layoutPrototypeId);
137
138 return layoutPrototype;
139 }
140
141 public LayoutPrototype remove(Serializable primaryKey)
142 throws NoSuchModelException, SystemException {
143 return remove(((Long)primaryKey).longValue());
144 }
145
146 public LayoutPrototype remove(long layoutPrototypeId)
147 throws NoSuchLayoutPrototypeException, SystemException {
148 Session session = null;
149
150 try {
151 session = openSession();
152
153 LayoutPrototype layoutPrototype = (LayoutPrototype)session.get(LayoutPrototypeImpl.class,
154 new Long(layoutPrototypeId));
155
156 if (layoutPrototype == null) {
157 if (_log.isWarnEnabled()) {
158 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
159 layoutPrototypeId);
160 }
161
162 throw new NoSuchLayoutPrototypeException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
163 layoutPrototypeId);
164 }
165
166 return remove(layoutPrototype);
167 }
168 catch (NoSuchLayoutPrototypeException nsee) {
169 throw nsee;
170 }
171 catch (Exception e) {
172 throw processException(e);
173 }
174 finally {
175 closeSession(session);
176 }
177 }
178
179 public LayoutPrototype remove(LayoutPrototype layoutPrototype)
180 throws SystemException {
181 for (ModelListener<LayoutPrototype> listener : listeners) {
182 listener.onBeforeRemove(layoutPrototype);
183 }
184
185 layoutPrototype = removeImpl(layoutPrototype);
186
187 for (ModelListener<LayoutPrototype> listener : listeners) {
188 listener.onAfterRemove(layoutPrototype);
189 }
190
191 return layoutPrototype;
192 }
193
194 protected LayoutPrototype removeImpl(LayoutPrototype layoutPrototype)
195 throws SystemException {
196 layoutPrototype = toUnwrappedModel(layoutPrototype);
197
198 Session session = null;
199
200 try {
201 session = openSession();
202
203 if (layoutPrototype.isCachedModel() ||
204 BatchSessionUtil.isEnabled()) {
205 Object staleObject = session.get(LayoutPrototypeImpl.class,
206 layoutPrototype.getPrimaryKeyObj());
207
208 if (staleObject != null) {
209 session.evict(staleObject);
210 }
211 }
212
213 session.delete(layoutPrototype);
214
215 session.flush();
216 }
217 catch (Exception e) {
218 throw processException(e);
219 }
220 finally {
221 closeSession(session);
222 }
223
224 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
225
226 EntityCacheUtil.removeResult(LayoutPrototypeModelImpl.ENTITY_CACHE_ENABLED,
227 LayoutPrototypeImpl.class, layoutPrototype.getPrimaryKey());
228
229 return layoutPrototype;
230 }
231
232 public LayoutPrototype updateImpl(
233 com.liferay.portal.model.LayoutPrototype layoutPrototype, boolean merge)
234 throws SystemException {
235 layoutPrototype = toUnwrappedModel(layoutPrototype);
236
237 Session session = null;
238
239 try {
240 session = openSession();
241
242 BatchSessionUtil.update(session, layoutPrototype, merge);
243
244 layoutPrototype.setNew(false);
245 }
246 catch (Exception e) {
247 throw processException(e);
248 }
249 finally {
250 closeSession(session);
251 }
252
253 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
254
255 EntityCacheUtil.putResult(LayoutPrototypeModelImpl.ENTITY_CACHE_ENABLED,
256 LayoutPrototypeImpl.class, layoutPrototype.getPrimaryKey(),
257 layoutPrototype);
258
259 return layoutPrototype;
260 }
261
262 protected LayoutPrototype toUnwrappedModel(LayoutPrototype layoutPrototype) {
263 if (layoutPrototype instanceof LayoutPrototypeImpl) {
264 return layoutPrototype;
265 }
266
267 LayoutPrototypeImpl layoutPrototypeImpl = new LayoutPrototypeImpl();
268
269 layoutPrototypeImpl.setNew(layoutPrototype.isNew());
270 layoutPrototypeImpl.setPrimaryKey(layoutPrototype.getPrimaryKey());
271
272 layoutPrototypeImpl.setLayoutPrototypeId(layoutPrototype.getLayoutPrototypeId());
273 layoutPrototypeImpl.setCompanyId(layoutPrototype.getCompanyId());
274 layoutPrototypeImpl.setName(layoutPrototype.getName());
275 layoutPrototypeImpl.setDescription(layoutPrototype.getDescription());
276 layoutPrototypeImpl.setSettings(layoutPrototype.getSettings());
277 layoutPrototypeImpl.setActive(layoutPrototype.isActive());
278
279 return layoutPrototypeImpl;
280 }
281
282 public LayoutPrototype findByPrimaryKey(Serializable primaryKey)
283 throws NoSuchModelException, SystemException {
284 return findByPrimaryKey(((Long)primaryKey).longValue());
285 }
286
287 public LayoutPrototype findByPrimaryKey(long layoutPrototypeId)
288 throws NoSuchLayoutPrototypeException, SystemException {
289 LayoutPrototype layoutPrototype = fetchByPrimaryKey(layoutPrototypeId);
290
291 if (layoutPrototype == null) {
292 if (_log.isWarnEnabled()) {
293 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + layoutPrototypeId);
294 }
295
296 throw new NoSuchLayoutPrototypeException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
297 layoutPrototypeId);
298 }
299
300 return layoutPrototype;
301 }
302
303 public LayoutPrototype fetchByPrimaryKey(Serializable primaryKey)
304 throws SystemException {
305 return fetchByPrimaryKey(((Long)primaryKey).longValue());
306 }
307
308 public LayoutPrototype fetchByPrimaryKey(long layoutPrototypeId)
309 throws SystemException {
310 LayoutPrototype layoutPrototype = (LayoutPrototype)EntityCacheUtil.getResult(LayoutPrototypeModelImpl.ENTITY_CACHE_ENABLED,
311 LayoutPrototypeImpl.class, layoutPrototypeId, this);
312
313 if (layoutPrototype == null) {
314 Session session = null;
315
316 try {
317 session = openSession();
318
319 layoutPrototype = (LayoutPrototype)session.get(LayoutPrototypeImpl.class,
320 new Long(layoutPrototypeId));
321 }
322 catch (Exception e) {
323 throw processException(e);
324 }
325 finally {
326 if (layoutPrototype != null) {
327 cacheResult(layoutPrototype);
328 }
329
330 closeSession(session);
331 }
332 }
333
334 return layoutPrototype;
335 }
336
337 public List<LayoutPrototype> findByCompanyId(long companyId)
338 throws SystemException {
339 Object[] finderArgs = new Object[] { new Long(companyId) };
340
341 List<LayoutPrototype> list = (List<LayoutPrototype>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_COMPANYID,
342 finderArgs, this);
343
344 if (list == null) {
345 Session session = null;
346
347 try {
348 session = openSession();
349
350 StringBundler query = new StringBundler(2);
351
352 query.append(_SQL_SELECT_LAYOUTPROTOTYPE_WHERE);
353
354 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
355
356 String sql = query.toString();
357
358 Query q = session.createQuery(sql);
359
360 QueryPos qPos = QueryPos.getInstance(q);
361
362 qPos.add(companyId);
363
364 list = q.list();
365 }
366 catch (Exception e) {
367 throw processException(e);
368 }
369 finally {
370 if (list == null) {
371 list = new ArrayList<LayoutPrototype>();
372 }
373
374 cacheResult(list);
375
376 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_COMPANYID,
377 finderArgs, list);
378
379 closeSession(session);
380 }
381 }
382
383 return list;
384 }
385
386 public List<LayoutPrototype> findByCompanyId(long companyId, int start,
387 int end) throws SystemException {
388 return findByCompanyId(companyId, start, end, null);
389 }
390
391 public List<LayoutPrototype> findByCompanyId(long companyId, int start,
392 int end, OrderByComparator obc) throws SystemException {
393 Object[] finderArgs = new Object[] {
394 new Long(companyId),
395
396 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
397 };
398
399 List<LayoutPrototype> list = (List<LayoutPrototype>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_COMPANYID,
400 finderArgs, this);
401
402 if (list == null) {
403 Session session = null;
404
405 try {
406 session = openSession();
407
408 StringBundler query = null;
409
410 if (obc != null) {
411 query = new StringBundler(3 +
412 (obc.getOrderByFields().length * 3));
413 }
414 else {
415 query = new StringBundler(2);
416 }
417
418 query.append(_SQL_SELECT_LAYOUTPROTOTYPE_WHERE);
419
420 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
421
422 if (obc != null) {
423 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
424 }
425
426 String sql = query.toString();
427
428 Query q = session.createQuery(sql);
429
430 QueryPos qPos = QueryPos.getInstance(q);
431
432 qPos.add(companyId);
433
434 list = (List<LayoutPrototype>)QueryUtil.list(q, getDialect(),
435 start, end);
436 }
437 catch (Exception e) {
438 throw processException(e);
439 }
440 finally {
441 if (list == null) {
442 list = new ArrayList<LayoutPrototype>();
443 }
444
445 cacheResult(list);
446
447 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_COMPANYID,
448 finderArgs, list);
449
450 closeSession(session);
451 }
452 }
453
454 return list;
455 }
456
457 public LayoutPrototype findByCompanyId_First(long companyId,
458 OrderByComparator obc)
459 throws NoSuchLayoutPrototypeException, SystemException {
460 List<LayoutPrototype> list = findByCompanyId(companyId, 0, 1, obc);
461
462 if (list.isEmpty()) {
463 StringBundler msg = new StringBundler(4);
464
465 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
466
467 msg.append("companyId=");
468 msg.append(companyId);
469
470 msg.append(StringPool.CLOSE_CURLY_BRACE);
471
472 throw new NoSuchLayoutPrototypeException(msg.toString());
473 }
474 else {
475 return list.get(0);
476 }
477 }
478
479 public LayoutPrototype findByCompanyId_Last(long companyId,
480 OrderByComparator obc)
481 throws NoSuchLayoutPrototypeException, SystemException {
482 int count = countByCompanyId(companyId);
483
484 List<LayoutPrototype> list = findByCompanyId(companyId, count - 1,
485 count, obc);
486
487 if (list.isEmpty()) {
488 StringBundler msg = new StringBundler(4);
489
490 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
491
492 msg.append("companyId=");
493 msg.append(companyId);
494
495 msg.append(StringPool.CLOSE_CURLY_BRACE);
496
497 throw new NoSuchLayoutPrototypeException(msg.toString());
498 }
499 else {
500 return list.get(0);
501 }
502 }
503
504 public LayoutPrototype[] findByCompanyId_PrevAndNext(
505 long layoutPrototypeId, long companyId, OrderByComparator obc)
506 throws NoSuchLayoutPrototypeException, SystemException {
507 LayoutPrototype layoutPrototype = findByPrimaryKey(layoutPrototypeId);
508
509 int count = countByCompanyId(companyId);
510
511 Session session = null;
512
513 try {
514 session = openSession();
515
516 StringBundler query = null;
517
518 if (obc != null) {
519 query = new StringBundler(3 +
520 (obc.getOrderByFields().length * 3));
521 }
522 else {
523 query = new StringBundler(2);
524 }
525
526 query.append(_SQL_SELECT_LAYOUTPROTOTYPE_WHERE);
527
528 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
529
530 if (obc != null) {
531 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
532 }
533
534 String sql = query.toString();
535
536 Query q = session.createQuery(sql);
537
538 QueryPos qPos = QueryPos.getInstance(q);
539
540 qPos.add(companyId);
541
542 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
543 layoutPrototype);
544
545 LayoutPrototype[] array = new LayoutPrototypeImpl[3];
546
547 array[0] = (LayoutPrototype)objArray[0];
548 array[1] = (LayoutPrototype)objArray[1];
549 array[2] = (LayoutPrototype)objArray[2];
550
551 return array;
552 }
553 catch (Exception e) {
554 throw processException(e);
555 }
556 finally {
557 closeSession(session);
558 }
559 }
560
561 public List<LayoutPrototype> findByC_A(long companyId, boolean active)
562 throws SystemException {
563 Object[] finderArgs = new Object[] {
564 new Long(companyId), Boolean.valueOf(active)
565 };
566
567 List<LayoutPrototype> list = (List<LayoutPrototype>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_A,
568 finderArgs, this);
569
570 if (list == null) {
571 Session session = null;
572
573 try {
574 session = openSession();
575
576 StringBundler query = new StringBundler(3);
577
578 query.append(_SQL_SELECT_LAYOUTPROTOTYPE_WHERE);
579
580 query.append(_FINDER_COLUMN_C_A_COMPANYID_2);
581
582 query.append(_FINDER_COLUMN_C_A_ACTIVE_2);
583
584 String sql = query.toString();
585
586 Query q = session.createQuery(sql);
587
588 QueryPos qPos = QueryPos.getInstance(q);
589
590 qPos.add(companyId);
591
592 qPos.add(active);
593
594 list = q.list();
595 }
596 catch (Exception e) {
597 throw processException(e);
598 }
599 finally {
600 if (list == null) {
601 list = new ArrayList<LayoutPrototype>();
602 }
603
604 cacheResult(list);
605
606 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_A, finderArgs,
607 list);
608
609 closeSession(session);
610 }
611 }
612
613 return list;
614 }
615
616 public List<LayoutPrototype> findByC_A(long companyId, boolean active,
617 int start, int end) throws SystemException {
618 return findByC_A(companyId, active, start, end, null);
619 }
620
621 public List<LayoutPrototype> findByC_A(long companyId, boolean active,
622 int start, int end, OrderByComparator obc) throws SystemException {
623 Object[] finderArgs = new Object[] {
624 new Long(companyId), Boolean.valueOf(active),
625
626 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
627 };
628
629 List<LayoutPrototype> list = (List<LayoutPrototype>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_C_A,
630 finderArgs, this);
631
632 if (list == null) {
633 Session session = null;
634
635 try {
636 session = openSession();
637
638 StringBundler query = null;
639
640 if (obc != null) {
641 query = new StringBundler(4 +
642 (obc.getOrderByFields().length * 3));
643 }
644 else {
645 query = new StringBundler(3);
646 }
647
648 query.append(_SQL_SELECT_LAYOUTPROTOTYPE_WHERE);
649
650 query.append(_FINDER_COLUMN_C_A_COMPANYID_2);
651
652 query.append(_FINDER_COLUMN_C_A_ACTIVE_2);
653
654 if (obc != null) {
655 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
656 }
657
658 String sql = query.toString();
659
660 Query q = session.createQuery(sql);
661
662 QueryPos qPos = QueryPos.getInstance(q);
663
664 qPos.add(companyId);
665
666 qPos.add(active);
667
668 list = (List<LayoutPrototype>)QueryUtil.list(q, getDialect(),
669 start, end);
670 }
671 catch (Exception e) {
672 throw processException(e);
673 }
674 finally {
675 if (list == null) {
676 list = new ArrayList<LayoutPrototype>();
677 }
678
679 cacheResult(list);
680
681 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_C_A,
682 finderArgs, list);
683
684 closeSession(session);
685 }
686 }
687
688 return list;
689 }
690
691 public LayoutPrototype findByC_A_First(long companyId, boolean active,
692 OrderByComparator obc)
693 throws NoSuchLayoutPrototypeException, SystemException {
694 List<LayoutPrototype> list = findByC_A(companyId, active, 0, 1, obc);
695
696 if (list.isEmpty()) {
697 StringBundler msg = new StringBundler(6);
698
699 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
700
701 msg.append("companyId=");
702 msg.append(companyId);
703
704 msg.append(", active=");
705 msg.append(active);
706
707 msg.append(StringPool.CLOSE_CURLY_BRACE);
708
709 throw new NoSuchLayoutPrototypeException(msg.toString());
710 }
711 else {
712 return list.get(0);
713 }
714 }
715
716 public LayoutPrototype findByC_A_Last(long companyId, boolean active,
717 OrderByComparator obc)
718 throws NoSuchLayoutPrototypeException, SystemException {
719 int count = countByC_A(companyId, active);
720
721 List<LayoutPrototype> list = findByC_A(companyId, active, count - 1,
722 count, obc);
723
724 if (list.isEmpty()) {
725 StringBundler msg = new StringBundler(6);
726
727 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
728
729 msg.append("companyId=");
730 msg.append(companyId);
731
732 msg.append(", active=");
733 msg.append(active);
734
735 msg.append(StringPool.CLOSE_CURLY_BRACE);
736
737 throw new NoSuchLayoutPrototypeException(msg.toString());
738 }
739 else {
740 return list.get(0);
741 }
742 }
743
744 public LayoutPrototype[] findByC_A_PrevAndNext(long layoutPrototypeId,
745 long companyId, boolean active, OrderByComparator obc)
746 throws NoSuchLayoutPrototypeException, SystemException {
747 LayoutPrototype layoutPrototype = findByPrimaryKey(layoutPrototypeId);
748
749 int count = countByC_A(companyId, active);
750
751 Session session = null;
752
753 try {
754 session = openSession();
755
756 StringBundler query = null;
757
758 if (obc != null) {
759 query = new StringBundler(4 +
760 (obc.getOrderByFields().length * 3));
761 }
762 else {
763 query = new StringBundler(3);
764 }
765
766 query.append(_SQL_SELECT_LAYOUTPROTOTYPE_WHERE);
767
768 query.append(_FINDER_COLUMN_C_A_COMPANYID_2);
769
770 query.append(_FINDER_COLUMN_C_A_ACTIVE_2);
771
772 if (obc != null) {
773 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
774 }
775
776 String sql = query.toString();
777
778 Query q = session.createQuery(sql);
779
780 QueryPos qPos = QueryPos.getInstance(q);
781
782 qPos.add(companyId);
783
784 qPos.add(active);
785
786 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
787 layoutPrototype);
788
789 LayoutPrototype[] array = new LayoutPrototypeImpl[3];
790
791 array[0] = (LayoutPrototype)objArray[0];
792 array[1] = (LayoutPrototype)objArray[1];
793 array[2] = (LayoutPrototype)objArray[2];
794
795 return array;
796 }
797 catch (Exception e) {
798 throw processException(e);
799 }
800 finally {
801 closeSession(session);
802 }
803 }
804
805 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
806 throws SystemException {
807 Session session = null;
808
809 try {
810 session = openSession();
811
812 dynamicQuery.compile(session);
813
814 return dynamicQuery.list();
815 }
816 catch (Exception e) {
817 throw processException(e);
818 }
819 finally {
820 closeSession(session);
821 }
822 }
823
824 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
825 int start, int end) throws SystemException {
826 Session session = null;
827
828 try {
829 session = openSession();
830
831 dynamicQuery.setLimit(start, end);
832
833 dynamicQuery.compile(session);
834
835 return dynamicQuery.list();
836 }
837 catch (Exception e) {
838 throw processException(e);
839 }
840 finally {
841 closeSession(session);
842 }
843 }
844
845 public List<LayoutPrototype> findAll() throws SystemException {
846 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
847 }
848
849 public List<LayoutPrototype> findAll(int start, int end)
850 throws SystemException {
851 return findAll(start, end, null);
852 }
853
854 public List<LayoutPrototype> findAll(int start, int end,
855 OrderByComparator obc) throws SystemException {
856 Object[] finderArgs = new Object[] {
857 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
858 };
859
860 List<LayoutPrototype> list = (List<LayoutPrototype>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
861 finderArgs, this);
862
863 if (list == null) {
864 Session session = null;
865
866 try {
867 session = openSession();
868
869 StringBundler query = null;
870 String sql = null;
871
872 if (obc != null) {
873 query = new StringBundler(2 +
874 (obc.getOrderByFields().length * 3));
875
876 query.append(_SQL_SELECT_LAYOUTPROTOTYPE);
877
878 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
879
880 sql = query.toString();
881 }
882
883 sql = _SQL_SELECT_LAYOUTPROTOTYPE;
884
885 Query q = session.createQuery(sql);
886
887 if (obc == null) {
888 list = (List<LayoutPrototype>)QueryUtil.list(q,
889 getDialect(), start, end, false);
890
891 Collections.sort(list);
892 }
893 else {
894 list = (List<LayoutPrototype>)QueryUtil.list(q,
895 getDialect(), start, end);
896 }
897 }
898 catch (Exception e) {
899 throw processException(e);
900 }
901 finally {
902 if (list == null) {
903 list = new ArrayList<LayoutPrototype>();
904 }
905
906 cacheResult(list);
907
908 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
909
910 closeSession(session);
911 }
912 }
913
914 return list;
915 }
916
917 public void removeByCompanyId(long companyId) throws SystemException {
918 for (LayoutPrototype layoutPrototype : findByCompanyId(companyId)) {
919 remove(layoutPrototype);
920 }
921 }
922
923 public void removeByC_A(long companyId, boolean active)
924 throws SystemException {
925 for (LayoutPrototype layoutPrototype : findByC_A(companyId, active)) {
926 remove(layoutPrototype);
927 }
928 }
929
930 public void removeAll() throws SystemException {
931 for (LayoutPrototype layoutPrototype : findAll()) {
932 remove(layoutPrototype);
933 }
934 }
935
936 public int countByCompanyId(long companyId) throws SystemException {
937 Object[] finderArgs = new Object[] { new Long(companyId) };
938
939 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
940 finderArgs, this);
941
942 if (count == null) {
943 Session session = null;
944
945 try {
946 session = openSession();
947
948 StringBundler query = new StringBundler(2);
949
950 query.append(_SQL_COUNT_LAYOUTPROTOTYPE_WHERE);
951
952 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
953
954 String sql = query.toString();
955
956 Query q = session.createQuery(sql);
957
958 QueryPos qPos = QueryPos.getInstance(q);
959
960 qPos.add(companyId);
961
962 count = (Long)q.uniqueResult();
963 }
964 catch (Exception e) {
965 throw processException(e);
966 }
967 finally {
968 if (count == null) {
969 count = Long.valueOf(0);
970 }
971
972 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
973 finderArgs, count);
974
975 closeSession(session);
976 }
977 }
978
979 return count.intValue();
980 }
981
982 public int countByC_A(long companyId, boolean active)
983 throws SystemException {
984 Object[] finderArgs = new Object[] {
985 new Long(companyId), Boolean.valueOf(active)
986 };
987
988 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_A,
989 finderArgs, this);
990
991 if (count == null) {
992 Session session = null;
993
994 try {
995 session = openSession();
996
997 StringBundler query = new StringBundler(3);
998
999 query.append(_SQL_COUNT_LAYOUTPROTOTYPE_WHERE);
1000
1001 query.append(_FINDER_COLUMN_C_A_COMPANYID_2);
1002
1003 query.append(_FINDER_COLUMN_C_A_ACTIVE_2);
1004
1005 String sql = query.toString();
1006
1007 Query q = session.createQuery(sql);
1008
1009 QueryPos qPos = QueryPos.getInstance(q);
1010
1011 qPos.add(companyId);
1012
1013 qPos.add(active);
1014
1015 count = (Long)q.uniqueResult();
1016 }
1017 catch (Exception e) {
1018 throw processException(e);
1019 }
1020 finally {
1021 if (count == null) {
1022 count = Long.valueOf(0);
1023 }
1024
1025 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_A, finderArgs,
1026 count);
1027
1028 closeSession(session);
1029 }
1030 }
1031
1032 return count.intValue();
1033 }
1034
1035 public int countAll() throws SystemException {
1036 Object[] finderArgs = new Object[0];
1037
1038 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1039 finderArgs, this);
1040
1041 if (count == null) {
1042 Session session = null;
1043
1044 try {
1045 session = openSession();
1046
1047 Query q = session.createQuery(_SQL_COUNT_LAYOUTPROTOTYPE);
1048
1049 count = (Long)q.uniqueResult();
1050 }
1051 catch (Exception e) {
1052 throw processException(e);
1053 }
1054 finally {
1055 if (count == null) {
1056 count = Long.valueOf(0);
1057 }
1058
1059 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1060 count);
1061
1062 closeSession(session);
1063 }
1064 }
1065
1066 return count.intValue();
1067 }
1068
1069 public void afterPropertiesSet() {
1070 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1071 com.liferay.portal.util.PropsUtil.get(
1072 "value.object.listener.com.liferay.portal.model.LayoutPrototype")));
1073
1074 if (listenerClassNames.length > 0) {
1075 try {
1076 List<ModelListener<LayoutPrototype>> listenersList = new ArrayList<ModelListener<LayoutPrototype>>();
1077
1078 for (String listenerClassName : listenerClassNames) {
1079 listenersList.add((ModelListener<LayoutPrototype>)Class.forName(
1080 listenerClassName).newInstance());
1081 }
1082
1083 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1084 }
1085 catch (Exception e) {
1086 _log.error(e);
1087 }
1088 }
1089 }
1090
1091 @BeanReference(name = "com.liferay.portal.service.persistence.AccountPersistence")
1092 protected com.liferay.portal.service.persistence.AccountPersistence accountPersistence;
1093 @BeanReference(name = "com.liferay.portal.service.persistence.AddressPersistence")
1094 protected com.liferay.portal.service.persistence.AddressPersistence addressPersistence;
1095 @BeanReference(name = "com.liferay.portal.service.persistence.BrowserTrackerPersistence")
1096 protected com.liferay.portal.service.persistence.BrowserTrackerPersistence browserTrackerPersistence;
1097 @BeanReference(name = "com.liferay.portal.service.persistence.ClassNamePersistence")
1098 protected com.liferay.portal.service.persistence.ClassNamePersistence classNamePersistence;
1099 @BeanReference(name = "com.liferay.portal.service.persistence.CompanyPersistence")
1100 protected com.liferay.portal.service.persistence.CompanyPersistence companyPersistence;
1101 @BeanReference(name = "com.liferay.portal.service.persistence.ContactPersistence")
1102 protected com.liferay.portal.service.persistence.ContactPersistence contactPersistence;
1103 @BeanReference(name = "com.liferay.portal.service.persistence.CountryPersistence")
1104 protected com.liferay.portal.service.persistence.CountryPersistence countryPersistence;
1105 @BeanReference(name = "com.liferay.portal.service.persistence.EmailAddressPersistence")
1106 protected com.liferay.portal.service.persistence.EmailAddressPersistence emailAddressPersistence;
1107 @BeanReference(name = "com.liferay.portal.service.persistence.GroupPersistence")
1108 protected com.liferay.portal.service.persistence.GroupPersistence groupPersistence;
1109 @BeanReference(name = "com.liferay.portal.service.persistence.ImagePersistence")
1110 protected com.liferay.portal.service.persistence.ImagePersistence imagePersistence;
1111 @BeanReference(name = "com.liferay.portal.service.persistence.LayoutPersistence")
1112 protected com.liferay.portal.service.persistence.LayoutPersistence layoutPersistence;
1113 @BeanReference(name = "com.liferay.portal.service.persistence.LayoutPrototypePersistence")
1114 protected com.liferay.portal.service.persistence.LayoutPrototypePersistence layoutPrototypePersistence;
1115 @BeanReference(name = "com.liferay.portal.service.persistence.LayoutSetPersistence")
1116 protected com.liferay.portal.service.persistence.LayoutSetPersistence layoutSetPersistence;
1117 @BeanReference(name = "com.liferay.portal.service.persistence.LayoutSetPrototypePersistence")
1118 protected com.liferay.portal.service.persistence.LayoutSetPrototypePersistence layoutSetPrototypePersistence;
1119 @BeanReference(name = "com.liferay.portal.service.persistence.ListTypePersistence")
1120 protected com.liferay.portal.service.persistence.ListTypePersistence listTypePersistence;
1121 @BeanReference(name = "com.liferay.portal.service.persistence.LockPersistence")
1122 protected com.liferay.portal.service.persistence.LockPersistence lockPersistence;
1123 @BeanReference(name = "com.liferay.portal.service.persistence.MembershipRequestPersistence")
1124 protected com.liferay.portal.service.persistence.MembershipRequestPersistence membershipRequestPersistence;
1125 @BeanReference(name = "com.liferay.portal.service.persistence.OrganizationPersistence")
1126 protected com.liferay.portal.service.persistence.OrganizationPersistence organizationPersistence;
1127 @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupPermissionPersistence")
1128 protected com.liferay.portal.service.persistence.OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1129 @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupRolePersistence")
1130 protected com.liferay.portal.service.persistence.OrgGroupRolePersistence orgGroupRolePersistence;
1131 @BeanReference(name = "com.liferay.portal.service.persistence.OrgLaborPersistence")
1132 protected com.liferay.portal.service.persistence.OrgLaborPersistence orgLaborPersistence;
1133 @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyPersistence")
1134 protected com.liferay.portal.service.persistence.PasswordPolicyPersistence passwordPolicyPersistence;
1135 @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyRelPersistence")
1136 protected com.liferay.portal.service.persistence.PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1137 @BeanReference(name = "com.liferay.portal.service.persistence.PasswordTrackerPersistence")
1138 protected com.liferay.portal.service.persistence.PasswordTrackerPersistence passwordTrackerPersistence;
1139 @BeanReference(name = "com.liferay.portal.service.persistence.PermissionPersistence")
1140 protected com.liferay.portal.service.persistence.PermissionPersistence permissionPersistence;
1141 @BeanReference(name = "com.liferay.portal.service.persistence.PhonePersistence")
1142 protected com.liferay.portal.service.persistence.PhonePersistence phonePersistence;
1143 @BeanReference(name = "com.liferay.portal.service.persistence.PluginSettingPersistence")
1144 protected com.liferay.portal.service.persistence.PluginSettingPersistence pluginSettingPersistence;
1145 @BeanReference(name = "com.liferay.portal.service.persistence.PortletPersistence")
1146 protected com.liferay.portal.service.persistence.PortletPersistence portletPersistence;
1147 @BeanReference(name = "com.liferay.portal.service.persistence.PortletItemPersistence")
1148 protected com.liferay.portal.service.persistence.PortletItemPersistence portletItemPersistence;
1149 @BeanReference(name = "com.liferay.portal.service.persistence.PortletPreferencesPersistence")
1150 protected com.liferay.portal.service.persistence.PortletPreferencesPersistence portletPreferencesPersistence;
1151 @BeanReference(name = "com.liferay.portal.service.persistence.RegionPersistence")
1152 protected com.liferay.portal.service.persistence.RegionPersistence regionPersistence;
1153 @BeanReference(name = "com.liferay.portal.service.persistence.ReleasePersistence")
1154 protected com.liferay.portal.service.persistence.ReleasePersistence releasePersistence;
1155 @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence")
1156 protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
1157 @BeanReference(name = "com.liferay.portal.service.persistence.ResourceActionPersistence")
1158 protected com.liferay.portal.service.persistence.ResourceActionPersistence resourceActionPersistence;
1159 @BeanReference(name = "com.liferay.portal.service.persistence.ResourceCodePersistence")
1160 protected com.liferay.portal.service.persistence.ResourceCodePersistence resourceCodePersistence;
1161 @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePermissionPersistence")
1162 protected com.liferay.portal.service.persistence.ResourcePermissionPersistence resourcePermissionPersistence;
1163 @BeanReference(name = "com.liferay.portal.service.persistence.RolePersistence")
1164 protected com.liferay.portal.service.persistence.RolePersistence rolePersistence;
1165 @BeanReference(name = "com.liferay.portal.service.persistence.ServiceComponentPersistence")
1166 protected com.liferay.portal.service.persistence.ServiceComponentPersistence serviceComponentPersistence;
1167 @BeanReference(name = "com.liferay.portal.service.persistence.ShardPersistence")
1168 protected com.liferay.portal.service.persistence.ShardPersistence shardPersistence;
1169 @BeanReference(name = "com.liferay.portal.service.persistence.SubscriptionPersistence")
1170 protected com.liferay.portal.service.persistence.SubscriptionPersistence subscriptionPersistence;
1171 @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence")
1172 protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
1173 @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupPersistence")
1174 protected com.liferay.portal.service.persistence.UserGroupPersistence userGroupPersistence;
1175 @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupGroupRolePersistence")
1176 protected com.liferay.portal.service.persistence.UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1177 @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupRolePersistence")
1178 protected com.liferay.portal.service.persistence.UserGroupRolePersistence userGroupRolePersistence;
1179 @BeanReference(name = "com.liferay.portal.service.persistence.UserIdMapperPersistence")
1180 protected com.liferay.portal.service.persistence.UserIdMapperPersistence userIdMapperPersistence;
1181 @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPersistence")
1182 protected com.liferay.portal.service.persistence.UserTrackerPersistence userTrackerPersistence;
1183 @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPathPersistence")
1184 protected com.liferay.portal.service.persistence.UserTrackerPathPersistence userTrackerPathPersistence;
1185 @BeanReference(name = "com.liferay.portal.service.persistence.WebDAVPropsPersistence")
1186 protected com.liferay.portal.service.persistence.WebDAVPropsPersistence webDAVPropsPersistence;
1187 @BeanReference(name = "com.liferay.portal.service.persistence.WebsitePersistence")
1188 protected com.liferay.portal.service.persistence.WebsitePersistence websitePersistence;
1189 @BeanReference(name = "com.liferay.portal.service.persistence.WorkflowDefinitionLinkPersistence")
1190 protected com.liferay.portal.service.persistence.WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
1191 @BeanReference(name = "com.liferay.portal.service.persistence.WorkflowInstanceLinkPersistence")
1192 protected com.liferay.portal.service.persistence.WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
1193 private static final String _SQL_SELECT_LAYOUTPROTOTYPE = "SELECT layoutPrototype FROM LayoutPrototype layoutPrototype";
1194 private static final String _SQL_SELECT_LAYOUTPROTOTYPE_WHERE = "SELECT layoutPrototype FROM LayoutPrototype layoutPrototype WHERE ";
1195 private static final String _SQL_COUNT_LAYOUTPROTOTYPE = "SELECT COUNT(layoutPrototype) FROM LayoutPrototype layoutPrototype";
1196 private static final String _SQL_COUNT_LAYOUTPROTOTYPE_WHERE = "SELECT COUNT(layoutPrototype) FROM LayoutPrototype layoutPrototype WHERE ";
1197 private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "layoutPrototype.companyId = ?";
1198 private static final String _FINDER_COLUMN_C_A_COMPANYID_2 = "layoutPrototype.companyId = ? AND ";
1199 private static final String _FINDER_COLUMN_C_A_ACTIVE_2 = "layoutPrototype.active = ?";
1200 private static final String _ORDER_BY_ENTITY_ALIAS = "layoutPrototype.";
1201 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No LayoutPrototype exists with the primary key ";
1202 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No LayoutPrototype exists with the key {";
1203 private static Log _log = LogFactoryUtil.getLog(LayoutPrototypePersistenceImpl.class);
1204}