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