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