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