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