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