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