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("FROM com.liferay.portal.model.LayoutSet WHERE ");
413
414 query.append("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("FROM com.liferay.portal.model.LayoutSet WHERE ");
471
472 query.append("groupId = ?");
473
474 query.append(" ");
475
476 if (obc != null) {
477 query.append("ORDER BY ");
478 query.append(obc.getOrderBy());
479 }
480
481 Query q = session.createQuery(query.toString());
482
483 QueryPos qPos = QueryPos.getInstance(q);
484
485 qPos.add(groupId);
486
487 list = (List<LayoutSet>)QueryUtil.list(q, getDialect(), start,
488 end);
489 }
490 catch (Exception e) {
491 throw processException(e);
492 }
493 finally {
494 if (list == null) {
495 list = new ArrayList<LayoutSet>();
496 }
497
498 cacheResult(list);
499
500 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_GROUPID,
501 finderArgs, list);
502
503 closeSession(session);
504 }
505 }
506
507 return list;
508 }
509
510 public LayoutSet findByGroupId_First(long groupId, OrderByComparator obc)
511 throws NoSuchLayoutSetException, SystemException {
512 List<LayoutSet> list = findByGroupId(groupId, 0, 1, obc);
513
514 if (list.isEmpty()) {
515 StringBuilder msg = new StringBuilder();
516
517 msg.append("No LayoutSet exists with the key {");
518
519 msg.append("groupId=" + groupId);
520
521 msg.append(StringPool.CLOSE_CURLY_BRACE);
522
523 throw new NoSuchLayoutSetException(msg.toString());
524 }
525 else {
526 return list.get(0);
527 }
528 }
529
530 public LayoutSet findByGroupId_Last(long groupId, OrderByComparator obc)
531 throws NoSuchLayoutSetException, SystemException {
532 int count = countByGroupId(groupId);
533
534 List<LayoutSet> list = findByGroupId(groupId, count - 1, count, obc);
535
536 if (list.isEmpty()) {
537 StringBuilder msg = new StringBuilder();
538
539 msg.append("No LayoutSet exists with the key {");
540
541 msg.append("groupId=" + groupId);
542
543 msg.append(StringPool.CLOSE_CURLY_BRACE);
544
545 throw new NoSuchLayoutSetException(msg.toString());
546 }
547 else {
548 return list.get(0);
549 }
550 }
551
552 public LayoutSet[] findByGroupId_PrevAndNext(long layoutSetId,
553 long groupId, OrderByComparator obc)
554 throws NoSuchLayoutSetException, SystemException {
555 LayoutSet layoutSet = findByPrimaryKey(layoutSetId);
556
557 int count = countByGroupId(groupId);
558
559 Session session = null;
560
561 try {
562 session = openSession();
563
564 StringBuilder query = new StringBuilder();
565
566 query.append("FROM com.liferay.portal.model.LayoutSet WHERE ");
567
568 query.append("groupId = ?");
569
570 query.append(" ");
571
572 if (obc != null) {
573 query.append("ORDER BY ");
574 query.append(obc.getOrderBy());
575 }
576
577 Query q = session.createQuery(query.toString());
578
579 QueryPos qPos = QueryPos.getInstance(q);
580
581 qPos.add(groupId);
582
583 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
584 layoutSet);
585
586 LayoutSet[] array = new LayoutSetImpl[3];
587
588 array[0] = (LayoutSet)objArray[0];
589 array[1] = (LayoutSet)objArray[1];
590 array[2] = (LayoutSet)objArray[2];
591
592 return array;
593 }
594 catch (Exception e) {
595 throw processException(e);
596 }
597 finally {
598 closeSession(session);
599 }
600 }
601
602 public LayoutSet findByVirtualHost(String virtualHost)
603 throws NoSuchLayoutSetException, SystemException {
604 LayoutSet layoutSet = fetchByVirtualHost(virtualHost);
605
606 if (layoutSet == null) {
607 StringBuilder msg = new StringBuilder();
608
609 msg.append("No LayoutSet exists with the key {");
610
611 msg.append("virtualHost=" + virtualHost);
612
613 msg.append(StringPool.CLOSE_CURLY_BRACE);
614
615 if (_log.isWarnEnabled()) {
616 _log.warn(msg.toString());
617 }
618
619 throw new NoSuchLayoutSetException(msg.toString());
620 }
621
622 return layoutSet;
623 }
624
625 public LayoutSet fetchByVirtualHost(String virtualHost)
626 throws SystemException {
627 return fetchByVirtualHost(virtualHost, true);
628 }
629
630 public LayoutSet fetchByVirtualHost(String virtualHost,
631 boolean retrieveFromCache) throws SystemException {
632 Object[] finderArgs = new Object[] { virtualHost };
633
634 Object result = null;
635
636 if (retrieveFromCache) {
637 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_VIRTUALHOST,
638 finderArgs, this);
639 }
640
641 if (result == null) {
642 Session session = null;
643
644 try {
645 session = openSession();
646
647 StringBuilder query = new StringBuilder();
648
649 query.append("FROM com.liferay.portal.model.LayoutSet WHERE ");
650
651 if (virtualHost == null) {
652 query.append("virtualHost IS NULL");
653 }
654 else {
655 query.append("virtualHost = ?");
656 }
657
658 query.append(" ");
659
660 Query q = session.createQuery(query.toString());
661
662 QueryPos qPos = QueryPos.getInstance(q);
663
664 if (virtualHost != null) {
665 qPos.add(virtualHost);
666 }
667
668 List<LayoutSet> list = q.list();
669
670 result = list;
671
672 LayoutSet layoutSet = null;
673
674 if (list.isEmpty()) {
675 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_VIRTUALHOST,
676 finderArgs, list);
677 }
678 else {
679 layoutSet = list.get(0);
680
681 cacheResult(layoutSet);
682
683 if ((layoutSet.getVirtualHost() == null) ||
684 !layoutSet.getVirtualHost().equals(virtualHost)) {
685 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_VIRTUALHOST,
686 finderArgs, layoutSet);
687 }
688 }
689
690 return layoutSet;
691 }
692 catch (Exception e) {
693 throw processException(e);
694 }
695 finally {
696 if (result == null) {
697 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_VIRTUALHOST,
698 finderArgs, new ArrayList<LayoutSet>());
699 }
700
701 closeSession(session);
702 }
703 }
704 else {
705 if (result instanceof List) {
706 return null;
707 }
708 else {
709 return (LayoutSet)result;
710 }
711 }
712 }
713
714 public LayoutSet findByG_P(long groupId, boolean privateLayout)
715 throws NoSuchLayoutSetException, SystemException {
716 LayoutSet layoutSet = fetchByG_P(groupId, privateLayout);
717
718 if (layoutSet == null) {
719 StringBuilder msg = new StringBuilder();
720
721 msg.append("No LayoutSet exists with the key {");
722
723 msg.append("groupId=" + groupId);
724
725 msg.append(", ");
726 msg.append("privateLayout=" + privateLayout);
727
728 msg.append(StringPool.CLOSE_CURLY_BRACE);
729
730 if (_log.isWarnEnabled()) {
731 _log.warn(msg.toString());
732 }
733
734 throw new NoSuchLayoutSetException(msg.toString());
735 }
736
737 return layoutSet;
738 }
739
740 public LayoutSet fetchByG_P(long groupId, boolean privateLayout)
741 throws SystemException {
742 return fetchByG_P(groupId, privateLayout, true);
743 }
744
745 public LayoutSet fetchByG_P(long groupId, boolean privateLayout,
746 boolean retrieveFromCache) throws SystemException {
747 Object[] finderArgs = new Object[] {
748 new Long(groupId), Boolean.valueOf(privateLayout)
749 };
750
751 Object result = null;
752
753 if (retrieveFromCache) {
754 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_P,
755 finderArgs, this);
756 }
757
758 if (result == null) {
759 Session session = null;
760
761 try {
762 session = openSession();
763
764 StringBuilder query = new StringBuilder();
765
766 query.append("FROM com.liferay.portal.model.LayoutSet WHERE ");
767
768 query.append("groupId = ?");
769
770 query.append(" AND ");
771
772 query.append("privateLayout = ?");
773
774 query.append(" ");
775
776 Query q = session.createQuery(query.toString());
777
778 QueryPos qPos = QueryPos.getInstance(q);
779
780 qPos.add(groupId);
781
782 qPos.add(privateLayout);
783
784 List<LayoutSet> list = q.list();
785
786 result = list;
787
788 LayoutSet layoutSet = null;
789
790 if (list.isEmpty()) {
791 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P,
792 finderArgs, list);
793 }
794 else {
795 layoutSet = list.get(0);
796
797 cacheResult(layoutSet);
798
799 if ((layoutSet.getGroupId() != groupId) ||
800 (layoutSet.getPrivateLayout() != privateLayout)) {
801 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P,
802 finderArgs, layoutSet);
803 }
804 }
805
806 return layoutSet;
807 }
808 catch (Exception e) {
809 throw processException(e);
810 }
811 finally {
812 if (result == null) {
813 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P,
814 finderArgs, new ArrayList<LayoutSet>());
815 }
816
817 closeSession(session);
818 }
819 }
820 else {
821 if (result instanceof List) {
822 return null;
823 }
824 else {
825 return (LayoutSet)result;
826 }
827 }
828 }
829
830 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
831 throws SystemException {
832 Session session = null;
833
834 try {
835 session = openSession();
836
837 dynamicQuery.compile(session);
838
839 return dynamicQuery.list();
840 }
841 catch (Exception e) {
842 throw processException(e);
843 }
844 finally {
845 closeSession(session);
846 }
847 }
848
849 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
850 int start, int end) throws SystemException {
851 Session session = null;
852
853 try {
854 session = openSession();
855
856 dynamicQuery.setLimit(start, end);
857
858 dynamicQuery.compile(session);
859
860 return dynamicQuery.list();
861 }
862 catch (Exception e) {
863 throw processException(e);
864 }
865 finally {
866 closeSession(session);
867 }
868 }
869
870 public List<LayoutSet> findAll() throws SystemException {
871 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
872 }
873
874 public List<LayoutSet> findAll(int start, int end)
875 throws SystemException {
876 return findAll(start, end, null);
877 }
878
879 public List<LayoutSet> findAll(int start, int end, OrderByComparator obc)
880 throws SystemException {
881 Object[] finderArgs = new Object[] {
882 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
883 };
884
885 List<LayoutSet> list = (List<LayoutSet>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
886 finderArgs, this);
887
888 if (list == null) {
889 Session session = null;
890
891 try {
892 session = openSession();
893
894 StringBuilder query = new StringBuilder();
895
896 query.append("FROM com.liferay.portal.model.LayoutSet ");
897
898 if (obc != null) {
899 query.append("ORDER BY ");
900 query.append(obc.getOrderBy());
901 }
902
903 Query q = session.createQuery(query.toString());
904
905 if (obc == null) {
906 list = (List<LayoutSet>)QueryUtil.list(q, getDialect(),
907 start, end, false);
908
909 Collections.sort(list);
910 }
911 else {
912 list = (List<LayoutSet>)QueryUtil.list(q, getDialect(),
913 start, end);
914 }
915 }
916 catch (Exception e) {
917 throw processException(e);
918 }
919 finally {
920 if (list == null) {
921 list = new ArrayList<LayoutSet>();
922 }
923
924 cacheResult(list);
925
926 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
927
928 closeSession(session);
929 }
930 }
931
932 return list;
933 }
934
935 public void removeByGroupId(long groupId) throws SystemException {
936 for (LayoutSet layoutSet : findByGroupId(groupId)) {
937 remove(layoutSet);
938 }
939 }
940
941 public void removeByVirtualHost(String virtualHost)
942 throws NoSuchLayoutSetException, SystemException {
943 LayoutSet layoutSet = findByVirtualHost(virtualHost);
944
945 remove(layoutSet);
946 }
947
948 public void removeByG_P(long groupId, boolean privateLayout)
949 throws NoSuchLayoutSetException, SystemException {
950 LayoutSet layoutSet = findByG_P(groupId, privateLayout);
951
952 remove(layoutSet);
953 }
954
955 public void removeAll() throws SystemException {
956 for (LayoutSet layoutSet : findAll()) {
957 remove(layoutSet);
958 }
959 }
960
961 public int countByGroupId(long groupId) throws SystemException {
962 Object[] finderArgs = new Object[] { new Long(groupId) };
963
964 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
965 finderArgs, this);
966
967 if (count == null) {
968 Session session = null;
969
970 try {
971 session = openSession();
972
973 StringBuilder query = new StringBuilder();
974
975 query.append("SELECT COUNT(*) ");
976 query.append("FROM com.liferay.portal.model.LayoutSet WHERE ");
977
978 query.append("groupId = ?");
979
980 query.append(" ");
981
982 Query q = session.createQuery(query.toString());
983
984 QueryPos qPos = QueryPos.getInstance(q);
985
986 qPos.add(groupId);
987
988 count = (Long)q.uniqueResult();
989 }
990 catch (Exception e) {
991 throw processException(e);
992 }
993 finally {
994 if (count == null) {
995 count = Long.valueOf(0);
996 }
997
998 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
999 finderArgs, count);
1000
1001 closeSession(session);
1002 }
1003 }
1004
1005 return count.intValue();
1006 }
1007
1008 public int countByVirtualHost(String virtualHost) throws SystemException {
1009 Object[] finderArgs = new Object[] { virtualHost };
1010
1011 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_VIRTUALHOST,
1012 finderArgs, this);
1013
1014 if (count == null) {
1015 Session session = null;
1016
1017 try {
1018 session = openSession();
1019
1020 StringBuilder query = new StringBuilder();
1021
1022 query.append("SELECT COUNT(*) ");
1023 query.append("FROM com.liferay.portal.model.LayoutSet WHERE ");
1024
1025 if (virtualHost == null) {
1026 query.append("virtualHost IS NULL");
1027 }
1028 else {
1029 query.append("virtualHost = ?");
1030 }
1031
1032 query.append(" ");
1033
1034 Query q = session.createQuery(query.toString());
1035
1036 QueryPos qPos = QueryPos.getInstance(q);
1037
1038 if (virtualHost != null) {
1039 qPos.add(virtualHost);
1040 }
1041
1042 count = (Long)q.uniqueResult();
1043 }
1044 catch (Exception e) {
1045 throw processException(e);
1046 }
1047 finally {
1048 if (count == null) {
1049 count = Long.valueOf(0);
1050 }
1051
1052 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_VIRTUALHOST,
1053 finderArgs, count);
1054
1055 closeSession(session);
1056 }
1057 }
1058
1059 return count.intValue();
1060 }
1061
1062 public int countByG_P(long groupId, boolean privateLayout)
1063 throws SystemException {
1064 Object[] finderArgs = new Object[] {
1065 new Long(groupId), Boolean.valueOf(privateLayout)
1066 };
1067
1068 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_P,
1069 finderArgs, this);
1070
1071 if (count == null) {
1072 Session session = null;
1073
1074 try {
1075 session = openSession();
1076
1077 StringBuilder query = new StringBuilder();
1078
1079 query.append("SELECT COUNT(*) ");
1080 query.append("FROM com.liferay.portal.model.LayoutSet WHERE ");
1081
1082 query.append("groupId = ?");
1083
1084 query.append(" AND ");
1085
1086 query.append("privateLayout = ?");
1087
1088 query.append(" ");
1089
1090 Query q = session.createQuery(query.toString());
1091
1092 QueryPos qPos = QueryPos.getInstance(q);
1093
1094 qPos.add(groupId);
1095
1096 qPos.add(privateLayout);
1097
1098 count = (Long)q.uniqueResult();
1099 }
1100 catch (Exception e) {
1101 throw processException(e);
1102 }
1103 finally {
1104 if (count == null) {
1105 count = Long.valueOf(0);
1106 }
1107
1108 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_P, finderArgs,
1109 count);
1110
1111 closeSession(session);
1112 }
1113 }
1114
1115 return count.intValue();
1116 }
1117
1118 public int countAll() throws SystemException {
1119 Object[] finderArgs = new Object[0];
1120
1121 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1122 finderArgs, this);
1123
1124 if (count == null) {
1125 Session session = null;
1126
1127 try {
1128 session = openSession();
1129
1130 Query q = session.createQuery(
1131 "SELECT COUNT(*) FROM com.liferay.portal.model.LayoutSet");
1132
1133 count = (Long)q.uniqueResult();
1134 }
1135 catch (Exception e) {
1136 throw processException(e);
1137 }
1138 finally {
1139 if (count == null) {
1140 count = Long.valueOf(0);
1141 }
1142
1143 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1144 count);
1145
1146 closeSession(session);
1147 }
1148 }
1149
1150 return count.intValue();
1151 }
1152
1153 public void afterPropertiesSet() {
1154 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1155 com.liferay.portal.util.PropsUtil.get(
1156 "value.object.listener.com.liferay.portal.model.LayoutSet")));
1157
1158 if (listenerClassNames.length > 0) {
1159 try {
1160 List<ModelListener<LayoutSet>> listenersList = new ArrayList<ModelListener<LayoutSet>>();
1161
1162 for (String listenerClassName : listenerClassNames) {
1163 listenersList.add((ModelListener<LayoutSet>)Class.forName(
1164 listenerClassName).newInstance());
1165 }
1166
1167 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1168 }
1169 catch (Exception e) {
1170 _log.error(e);
1171 }
1172 }
1173 }
1174
1175 @BeanReference(name = "com.liferay.portal.service.persistence.AccountPersistence.impl")
1176 protected com.liferay.portal.service.persistence.AccountPersistence accountPersistence;
1177 @BeanReference(name = "com.liferay.portal.service.persistence.AddressPersistence.impl")
1178 protected com.liferay.portal.service.persistence.AddressPersistence addressPersistence;
1179 @BeanReference(name = "com.liferay.portal.service.persistence.BrowserTrackerPersistence.impl")
1180 protected com.liferay.portal.service.persistence.BrowserTrackerPersistence browserTrackerPersistence;
1181 @BeanReference(name = "com.liferay.portal.service.persistence.ClassNamePersistence.impl")
1182 protected com.liferay.portal.service.persistence.ClassNamePersistence classNamePersistence;
1183 @BeanReference(name = "com.liferay.portal.service.persistence.CompanyPersistence.impl")
1184 protected com.liferay.portal.service.persistence.CompanyPersistence companyPersistence;
1185 @BeanReference(name = "com.liferay.portal.service.persistence.ContactPersistence.impl")
1186 protected com.liferay.portal.service.persistence.ContactPersistence contactPersistence;
1187 @BeanReference(name = "com.liferay.portal.service.persistence.CountryPersistence.impl")
1188 protected com.liferay.portal.service.persistence.CountryPersistence countryPersistence;
1189 @BeanReference(name = "com.liferay.portal.service.persistence.EmailAddressPersistence.impl")
1190 protected com.liferay.portal.service.persistence.EmailAddressPersistence emailAddressPersistence;
1191 @BeanReference(name = "com.liferay.portal.service.persistence.GroupPersistence.impl")
1192 protected com.liferay.portal.service.persistence.GroupPersistence groupPersistence;
1193 @BeanReference(name = "com.liferay.portal.service.persistence.ImagePersistence.impl")
1194 protected com.liferay.portal.service.persistence.ImagePersistence imagePersistence;
1195 @BeanReference(name = "com.liferay.portal.service.persistence.LayoutPersistence.impl")
1196 protected com.liferay.portal.service.persistence.LayoutPersistence layoutPersistence;
1197 @BeanReference(name = "com.liferay.portal.service.persistence.LayoutSetPersistence.impl")
1198 protected com.liferay.portal.service.persistence.LayoutSetPersistence layoutSetPersistence;
1199 @BeanReference(name = "com.liferay.portal.service.persistence.ListTypePersistence.impl")
1200 protected com.liferay.portal.service.persistence.ListTypePersistence listTypePersistence;
1201 @BeanReference(name = "com.liferay.portal.service.persistence.MembershipRequestPersistence.impl")
1202 protected com.liferay.portal.service.persistence.MembershipRequestPersistence membershipRequestPersistence;
1203 @BeanReference(name = "com.liferay.portal.service.persistence.OrganizationPersistence.impl")
1204 protected com.liferay.portal.service.persistence.OrganizationPersistence organizationPersistence;
1205 @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupPermissionPersistence.impl")
1206 protected com.liferay.portal.service.persistence.OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1207 @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupRolePersistence.impl")
1208 protected com.liferay.portal.service.persistence.OrgGroupRolePersistence orgGroupRolePersistence;
1209 @BeanReference(name = "com.liferay.portal.service.persistence.OrgLaborPersistence.impl")
1210 protected com.liferay.portal.service.persistence.OrgLaborPersistence orgLaborPersistence;
1211 @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyPersistence.impl")
1212 protected com.liferay.portal.service.persistence.PasswordPolicyPersistence passwordPolicyPersistence;
1213 @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyRelPersistence.impl")
1214 protected com.liferay.portal.service.persistence.PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1215 @BeanReference(name = "com.liferay.portal.service.persistence.PasswordTrackerPersistence.impl")
1216 protected com.liferay.portal.service.persistence.PasswordTrackerPersistence passwordTrackerPersistence;
1217 @BeanReference(name = "com.liferay.portal.service.persistence.PermissionPersistence.impl")
1218 protected com.liferay.portal.service.persistence.PermissionPersistence permissionPersistence;
1219 @BeanReference(name = "com.liferay.portal.service.persistence.PhonePersistence.impl")
1220 protected com.liferay.portal.service.persistence.PhonePersistence phonePersistence;
1221 @BeanReference(name = "com.liferay.portal.service.persistence.PluginSettingPersistence.impl")
1222 protected com.liferay.portal.service.persistence.PluginSettingPersistence pluginSettingPersistence;
1223 @BeanReference(name = "com.liferay.portal.service.persistence.PortletPersistence.impl")
1224 protected com.liferay.portal.service.persistence.PortletPersistence portletPersistence;
1225 @BeanReference(name = "com.liferay.portal.service.persistence.PortletItemPersistence.impl")
1226 protected com.liferay.portal.service.persistence.PortletItemPersistence portletItemPersistence;
1227 @BeanReference(name = "com.liferay.portal.service.persistence.PortletPreferencesPersistence.impl")
1228 protected com.liferay.portal.service.persistence.PortletPreferencesPersistence portletPreferencesPersistence;
1229 @BeanReference(name = "com.liferay.portal.service.persistence.RegionPersistence.impl")
1230 protected com.liferay.portal.service.persistence.RegionPersistence regionPersistence;
1231 @BeanReference(name = "com.liferay.portal.service.persistence.ReleasePersistence.impl")
1232 protected com.liferay.portal.service.persistence.ReleasePersistence releasePersistence;
1233 @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence.impl")
1234 protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
1235 @BeanReference(name = "com.liferay.portal.service.persistence.ResourceActionPersistence.impl")
1236 protected com.liferay.portal.service.persistence.ResourceActionPersistence resourceActionPersistence;
1237 @BeanReference(name = "com.liferay.portal.service.persistence.ResourceCodePersistence.impl")
1238 protected com.liferay.portal.service.persistence.ResourceCodePersistence resourceCodePersistence;
1239 @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePermissionPersistence.impl")
1240 protected com.liferay.portal.service.persistence.ResourcePermissionPersistence resourcePermissionPersistence;
1241 @BeanReference(name = "com.liferay.portal.service.persistence.RolePersistence.impl")
1242 protected com.liferay.portal.service.persistence.RolePersistence rolePersistence;
1243 @BeanReference(name = "com.liferay.portal.service.persistence.ServiceComponentPersistence.impl")
1244 protected com.liferay.portal.service.persistence.ServiceComponentPersistence serviceComponentPersistence;
1245 @BeanReference(name = "com.liferay.portal.service.persistence.ShardPersistence.impl")
1246 protected com.liferay.portal.service.persistence.ShardPersistence shardPersistence;
1247 @BeanReference(name = "com.liferay.portal.service.persistence.SubscriptionPersistence.impl")
1248 protected com.liferay.portal.service.persistence.SubscriptionPersistence subscriptionPersistence;
1249 @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence.impl")
1250 protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
1251 @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupPersistence.impl")
1252 protected com.liferay.portal.service.persistence.UserGroupPersistence userGroupPersistence;
1253 @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupRolePersistence.impl")
1254 protected com.liferay.portal.service.persistence.UserGroupRolePersistence userGroupRolePersistence;
1255 @BeanReference(name = "com.liferay.portal.service.persistence.UserIdMapperPersistence.impl")
1256 protected com.liferay.portal.service.persistence.UserIdMapperPersistence userIdMapperPersistence;
1257 @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPersistence.impl")
1258 protected com.liferay.portal.service.persistence.UserTrackerPersistence userTrackerPersistence;
1259 @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPathPersistence.impl")
1260 protected com.liferay.portal.service.persistence.UserTrackerPathPersistence userTrackerPathPersistence;
1261 @BeanReference(name = "com.liferay.portal.service.persistence.WebDAVPropsPersistence.impl")
1262 protected com.liferay.portal.service.persistence.WebDAVPropsPersistence webDAVPropsPersistence;
1263 @BeanReference(name = "com.liferay.portal.service.persistence.WebsitePersistence.impl")
1264 protected com.liferay.portal.service.persistence.WebsitePersistence websitePersistence;
1265 private static Log _log = LogFactoryUtil.getLog(LayoutSetPersistenceImpl.class);
1266}