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