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