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