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
066 public class LayoutSetPersistenceImpl extends BasePersistenceImpl<LayoutSet>
067 implements LayoutSetPersistence {
068 public static final String FINDER_CLASS_NAME_ENTITY = LayoutSetImpl.class.getName();
069 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
070 ".List";
071 public static final FinderPath FINDER_PATH_FIND_BY_GROUPID = new FinderPath(LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
072 LayoutSetModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
073 "findByGroupId",
074 new String[] {
075 Long.class.getName(),
076
077 "java.lang.Integer", "java.lang.Integer",
078 "com.liferay.portal.kernel.util.OrderByComparator"
079 });
080 public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
081 LayoutSetModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
082 "countByGroupId", new String[] { Long.class.getName() });
083 public static final FinderPath FINDER_PATH_FETCH_BY_VIRTUALHOST = new FinderPath(LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
084 LayoutSetModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
085 "fetchByVirtualHost", new String[] { String.class.getName() });
086 public static final FinderPath FINDER_PATH_COUNT_BY_VIRTUALHOST = new FinderPath(LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
087 LayoutSetModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
088 "countByVirtualHost", new String[] { String.class.getName() });
089 public static final FinderPath FINDER_PATH_FETCH_BY_G_P = new FinderPath(LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
090 LayoutSetModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
091 "fetchByG_P",
092 new String[] { Long.class.getName(), Boolean.class.getName() });
093 public static final FinderPath FINDER_PATH_COUNT_BY_G_P = new FinderPath(LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
094 LayoutSetModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
095 "countByG_P",
096 new String[] { Long.class.getName(), Boolean.class.getName() });
097 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
098 LayoutSetModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
099 "findAll", new String[0]);
100 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
101 LayoutSetModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
102 "countAll", new String[0]);
103
104
109 public void cacheResult(LayoutSet layoutSet) {
110 EntityCacheUtil.putResult(LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
111 LayoutSetImpl.class, layoutSet.getPrimaryKey(), layoutSet);
112
113 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_VIRTUALHOST,
114 new Object[] { layoutSet.getVirtualHost() }, layoutSet);
115
116 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P,
117 new Object[] {
118 new Long(layoutSet.getGroupId()),
119 Boolean.valueOf(layoutSet.getPrivateLayout())
120 }, layoutSet);
121 }
122
123
128 public void cacheResult(List<LayoutSet> layoutSets) {
129 for (LayoutSet layoutSet : layoutSets) {
130 if (EntityCacheUtil.getResult(
131 LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
132 LayoutSetImpl.class, layoutSet.getPrimaryKey(), this) == null) {
133 cacheResult(layoutSet);
134 }
135 }
136 }
137
138
145 public void clearCache() {
146 CacheRegistryUtil.clear(LayoutSetImpl.class.getName());
147 EntityCacheUtil.clearCache(LayoutSetImpl.class.getName());
148 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
149 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
150 }
151
152
159 public void clearCache(LayoutSet layoutSet) {
160 EntityCacheUtil.removeResult(LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
161 LayoutSetImpl.class, layoutSet.getPrimaryKey());
162
163 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_VIRTUALHOST,
164 new Object[] { layoutSet.getVirtualHost() });
165
166 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P,
167 new Object[] {
168 new Long(layoutSet.getGroupId()),
169 Boolean.valueOf(layoutSet.getPrivateLayout())
170 });
171 }
172
173
179 public LayoutSet create(long layoutSetId) {
180 LayoutSet layoutSet = new LayoutSetImpl();
181
182 layoutSet.setNew(true);
183 layoutSet.setPrimaryKey(layoutSetId);
184
185 return layoutSet;
186 }
187
188
196 public LayoutSet remove(Serializable primaryKey)
197 throws NoSuchModelException, SystemException {
198 return remove(((Long)primaryKey).longValue());
199 }
200
201
209 public LayoutSet remove(long layoutSetId)
210 throws NoSuchLayoutSetException, SystemException {
211 Session session = null;
212
213 try {
214 session = openSession();
215
216 LayoutSet layoutSet = (LayoutSet)session.get(LayoutSetImpl.class,
217 new Long(layoutSetId));
218
219 if (layoutSet == null) {
220 if (_log.isWarnEnabled()) {
221 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + layoutSetId);
222 }
223
224 throw new NoSuchLayoutSetException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
225 layoutSetId);
226 }
227
228 return remove(layoutSet);
229 }
230 catch (NoSuchLayoutSetException nsee) {
231 throw nsee;
232 }
233 catch (Exception e) {
234 throw processException(e);
235 }
236 finally {
237 closeSession(session);
238 }
239 }
240
241 protected LayoutSet removeImpl(LayoutSet layoutSet)
242 throws SystemException {
243 layoutSet = toUnwrappedModel(layoutSet);
244
245 Session session = null;
246
247 try {
248 session = openSession();
249
250 if (layoutSet.isCachedModel() || BatchSessionUtil.isEnabled()) {
251 Object staleObject = session.get(LayoutSetImpl.class,
252 layoutSet.getPrimaryKeyObj());
253
254 if (staleObject != null) {
255 session.evict(staleObject);
256 }
257 }
258
259 session.delete(layoutSet);
260
261 session.flush();
262 }
263 catch (Exception e) {
264 throw processException(e);
265 }
266 finally {
267 closeSession(session);
268 }
269
270 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
271
272 LayoutSetModelImpl layoutSetModelImpl = (LayoutSetModelImpl)layoutSet;
273
274 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_VIRTUALHOST,
275 new Object[] { layoutSetModelImpl.getOriginalVirtualHost() });
276
277 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P,
278 new Object[] {
279 new Long(layoutSetModelImpl.getOriginalGroupId()),
280 Boolean.valueOf(layoutSetModelImpl.getOriginalPrivateLayout())
281 });
282
283 EntityCacheUtil.removeResult(LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
284 LayoutSetImpl.class, layoutSet.getPrimaryKey());
285
286 return layoutSet;
287 }
288
289 public LayoutSet updateImpl(com.liferay.portal.model.LayoutSet layoutSet,
290 boolean merge) throws SystemException {
291 layoutSet = toUnwrappedModel(layoutSet);
292
293 boolean isNew = layoutSet.isNew();
294
295 LayoutSetModelImpl layoutSetModelImpl = (LayoutSetModelImpl)layoutSet;
296
297 Session session = null;
298
299 try {
300 session = openSession();
301
302 BatchSessionUtil.update(session, layoutSet, merge);
303
304 layoutSet.setNew(false);
305 }
306 catch (Exception e) {
307 throw processException(e);
308 }
309 finally {
310 closeSession(session);
311 }
312
313 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
314
315 EntityCacheUtil.putResult(LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
316 LayoutSetImpl.class, layoutSet.getPrimaryKey(), layoutSet);
317
318 if (!isNew &&
319 (!Validator.equals(layoutSet.getVirtualHost(),
320 layoutSetModelImpl.getOriginalVirtualHost()))) {
321 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_VIRTUALHOST,
322 new Object[] { layoutSetModelImpl.getOriginalVirtualHost() });
323 }
324
325 if (isNew ||
326 (!Validator.equals(layoutSet.getVirtualHost(),
327 layoutSetModelImpl.getOriginalVirtualHost()))) {
328 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_VIRTUALHOST,
329 new Object[] { layoutSet.getVirtualHost() }, layoutSet);
330 }
331
332 if (!isNew &&
333 ((layoutSet.getGroupId() != layoutSetModelImpl.getOriginalGroupId()) ||
334 (layoutSet.getPrivateLayout() != layoutSetModelImpl.getOriginalPrivateLayout()))) {
335 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P,
336 new Object[] {
337 new Long(layoutSetModelImpl.getOriginalGroupId()),
338 Boolean.valueOf(
339 layoutSetModelImpl.getOriginalPrivateLayout())
340 });
341 }
342
343 if (isNew ||
344 ((layoutSet.getGroupId() != layoutSetModelImpl.getOriginalGroupId()) ||
345 (layoutSet.getPrivateLayout() != layoutSetModelImpl.getOriginalPrivateLayout()))) {
346 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P,
347 new Object[] {
348 new Long(layoutSet.getGroupId()),
349 Boolean.valueOf(layoutSet.getPrivateLayout())
350 }, layoutSet);
351 }
352
353 return layoutSet;
354 }
355
356 protected LayoutSet toUnwrappedModel(LayoutSet layoutSet) {
357 if (layoutSet instanceof LayoutSetImpl) {
358 return layoutSet;
359 }
360
361 LayoutSetImpl layoutSetImpl = new LayoutSetImpl();
362
363 layoutSetImpl.setNew(layoutSet.isNew());
364 layoutSetImpl.setPrimaryKey(layoutSet.getPrimaryKey());
365
366 layoutSetImpl.setLayoutSetId(layoutSet.getLayoutSetId());
367 layoutSetImpl.setGroupId(layoutSet.getGroupId());
368 layoutSetImpl.setCompanyId(layoutSet.getCompanyId());
369 layoutSetImpl.setPrivateLayout(layoutSet.isPrivateLayout());
370 layoutSetImpl.setLogo(layoutSet.isLogo());
371 layoutSetImpl.setLogoId(layoutSet.getLogoId());
372 layoutSetImpl.setThemeId(layoutSet.getThemeId());
373 layoutSetImpl.setColorSchemeId(layoutSet.getColorSchemeId());
374 layoutSetImpl.setWapThemeId(layoutSet.getWapThemeId());
375 layoutSetImpl.setWapColorSchemeId(layoutSet.getWapColorSchemeId());
376 layoutSetImpl.setCss(layoutSet.getCss());
377 layoutSetImpl.setPageCount(layoutSet.getPageCount());
378 layoutSetImpl.setVirtualHost(layoutSet.getVirtualHost());
379 layoutSetImpl.setSettings(layoutSet.getSettings());
380 layoutSetImpl.setLayoutSetPrototypeId(layoutSet.getLayoutSetPrototypeId());
381
382 return layoutSetImpl;
383 }
384
385
393 public LayoutSet findByPrimaryKey(Serializable primaryKey)
394 throws NoSuchModelException, SystemException {
395 return findByPrimaryKey(((Long)primaryKey).longValue());
396 }
397
398
406 public LayoutSet findByPrimaryKey(long layoutSetId)
407 throws NoSuchLayoutSetException, SystemException {
408 LayoutSet layoutSet = fetchByPrimaryKey(layoutSetId);
409
410 if (layoutSet == null) {
411 if (_log.isWarnEnabled()) {
412 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + layoutSetId);
413 }
414
415 throw new NoSuchLayoutSetException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
416 layoutSetId);
417 }
418
419 return layoutSet;
420 }
421
422
429 public LayoutSet fetchByPrimaryKey(Serializable primaryKey)
430 throws SystemException {
431 return fetchByPrimaryKey(((Long)primaryKey).longValue());
432 }
433
434
441 public LayoutSet fetchByPrimaryKey(long layoutSetId)
442 throws SystemException {
443 LayoutSet layoutSet = (LayoutSet)EntityCacheUtil.getResult(LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
444 LayoutSetImpl.class, layoutSetId, this);
445
446 if (layoutSet == null) {
447 Session session = null;
448
449 try {
450 session = openSession();
451
452 layoutSet = (LayoutSet)session.get(LayoutSetImpl.class,
453 new Long(layoutSetId));
454 }
455 catch (Exception e) {
456 throw processException(e);
457 }
458 finally {
459 if (layoutSet != null) {
460 cacheResult(layoutSet);
461 }
462
463 closeSession(session);
464 }
465 }
466
467 return layoutSet;
468 }
469
470
477 public List<LayoutSet> findByGroupId(long groupId)
478 throws SystemException {
479 return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
480 }
481
482
495 public List<LayoutSet> findByGroupId(long groupId, int start, int end)
496 throws SystemException {
497 return findByGroupId(groupId, start, end, null);
498 }
499
500
514 public List<LayoutSet> findByGroupId(long groupId, int start, int end,
515 OrderByComparator orderByComparator) throws SystemException {
516 Object[] finderArgs = new Object[] {
517 groupId,
518
519 String.valueOf(start), String.valueOf(end),
520 String.valueOf(orderByComparator)
521 };
522
523 List<LayoutSet> list = (List<LayoutSet>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
524 finderArgs, this);
525
526 if (list == null) {
527 Session session = null;
528
529 try {
530 session = openSession();
531
532 StringBundler query = null;
533
534 if (orderByComparator != null) {
535 query = new StringBundler(3 +
536 (orderByComparator.getOrderByFields().length * 3));
537 }
538 else {
539 query = new StringBundler(2);
540 }
541
542 query.append(_SQL_SELECT_LAYOUTSET_WHERE);
543
544 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
545
546 if (orderByComparator != null) {
547 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
548 orderByComparator);
549 }
550
551 String sql = query.toString();
552
553 Query q = session.createQuery(sql);
554
555 QueryPos qPos = QueryPos.getInstance(q);
556
557 qPos.add(groupId);
558
559 list = (List<LayoutSet>)QueryUtil.list(q, getDialect(), start,
560 end);
561 }
562 catch (Exception e) {
563 throw processException(e);
564 }
565 finally {
566 if (list == null) {
567 list = new ArrayList<LayoutSet>();
568 }
569
570 cacheResult(list);
571
572 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
573 finderArgs, list);
574
575 closeSession(session);
576 }
577 }
578
579 return list;
580 }
581
582
595 public LayoutSet findByGroupId_First(long groupId,
596 OrderByComparator orderByComparator)
597 throws NoSuchLayoutSetException, SystemException {
598 List<LayoutSet> list = findByGroupId(groupId, 0, 1, orderByComparator);
599
600 if (list.isEmpty()) {
601 StringBundler msg = new StringBundler(4);
602
603 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
604
605 msg.append("groupId=");
606 msg.append(groupId);
607
608 msg.append(StringPool.CLOSE_CURLY_BRACE);
609
610 throw new NoSuchLayoutSetException(msg.toString());
611 }
612 else {
613 return list.get(0);
614 }
615 }
616
617
630 public LayoutSet findByGroupId_Last(long groupId,
631 OrderByComparator orderByComparator)
632 throws NoSuchLayoutSetException, SystemException {
633 int count = countByGroupId(groupId);
634
635 List<LayoutSet> list = findByGroupId(groupId, count - 1, count,
636 orderByComparator);
637
638 if (list.isEmpty()) {
639 StringBundler msg = new StringBundler(4);
640
641 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
642
643 msg.append("groupId=");
644 msg.append(groupId);
645
646 msg.append(StringPool.CLOSE_CURLY_BRACE);
647
648 throw new NoSuchLayoutSetException(msg.toString());
649 }
650 else {
651 return list.get(0);
652 }
653 }
654
655
669 public LayoutSet[] findByGroupId_PrevAndNext(long layoutSetId,
670 long groupId, OrderByComparator orderByComparator)
671 throws NoSuchLayoutSetException, SystemException {
672 LayoutSet layoutSet = findByPrimaryKey(layoutSetId);
673
674 Session session = null;
675
676 try {
677 session = openSession();
678
679 LayoutSet[] array = new LayoutSetImpl[3];
680
681 array[0] = getByGroupId_PrevAndNext(session, layoutSet, groupId,
682 orderByComparator, true);
683
684 array[1] = layoutSet;
685
686 array[2] = getByGroupId_PrevAndNext(session, layoutSet, groupId,
687 orderByComparator, false);
688
689 return array;
690 }
691 catch (Exception e) {
692 throw processException(e);
693 }
694 finally {
695 closeSession(session);
696 }
697 }
698
699 protected LayoutSet getByGroupId_PrevAndNext(Session session,
700 LayoutSet layoutSet, long groupId, OrderByComparator orderByComparator,
701 boolean previous) {
702 StringBundler query = null;
703
704 if (orderByComparator != null) {
705 query = new StringBundler(6 +
706 (orderByComparator.getOrderByFields().length * 6));
707 }
708 else {
709 query = new StringBundler(3);
710 }
711
712 query.append(_SQL_SELECT_LAYOUTSET_WHERE);
713
714 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
715
716 if (orderByComparator != null) {
717 String[] orderByFields = orderByComparator.getOrderByFields();
718
719 if (orderByFields.length > 0) {
720 query.append(WHERE_AND);
721 }
722
723 for (int i = 0; i < orderByFields.length; i++) {
724 query.append(_ORDER_BY_ENTITY_ALIAS);
725 query.append(orderByFields[i]);
726
727 if ((i + 1) < orderByFields.length) {
728 if (orderByComparator.isAscending() ^ previous) {
729 query.append(WHERE_GREATER_THAN_HAS_NEXT);
730 }
731 else {
732 query.append(WHERE_LESSER_THAN_HAS_NEXT);
733 }
734 }
735 else {
736 if (orderByComparator.isAscending() ^ previous) {
737 query.append(WHERE_GREATER_THAN);
738 }
739 else {
740 query.append(WHERE_LESSER_THAN);
741 }
742 }
743 }
744
745 query.append(ORDER_BY_CLAUSE);
746
747 for (int i = 0; i < orderByFields.length; i++) {
748 query.append(_ORDER_BY_ENTITY_ALIAS);
749 query.append(orderByFields[i]);
750
751 if ((i + 1) < orderByFields.length) {
752 if (orderByComparator.isAscending() ^ previous) {
753 query.append(ORDER_BY_ASC_HAS_NEXT);
754 }
755 else {
756 query.append(ORDER_BY_DESC_HAS_NEXT);
757 }
758 }
759 else {
760 if (orderByComparator.isAscending() ^ previous) {
761 query.append(ORDER_BY_ASC);
762 }
763 else {
764 query.append(ORDER_BY_DESC);
765 }
766 }
767 }
768 }
769
770 String sql = query.toString();
771
772 Query q = session.createQuery(sql);
773
774 q.setFirstResult(0);
775 q.setMaxResults(2);
776
777 QueryPos qPos = QueryPos.getInstance(q);
778
779 qPos.add(groupId);
780
781 if (orderByComparator != null) {
782 Object[] values = orderByComparator.getOrderByValues(layoutSet);
783
784 for (Object value : values) {
785 qPos.add(value);
786 }
787 }
788
789 List<LayoutSet> list = q.list();
790
791 if (list.size() == 2) {
792 return list.get(1);
793 }
794 else {
795 return null;
796 }
797 }
798
799
807 public LayoutSet findByVirtualHost(String virtualHost)
808 throws NoSuchLayoutSetException, SystemException {
809 LayoutSet layoutSet = fetchByVirtualHost(virtualHost);
810
811 if (layoutSet == null) {
812 StringBundler msg = new StringBundler(4);
813
814 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
815
816 msg.append("virtualHost=");
817 msg.append(virtualHost);
818
819 msg.append(StringPool.CLOSE_CURLY_BRACE);
820
821 if (_log.isWarnEnabled()) {
822 _log.warn(msg.toString());
823 }
824
825 throw new NoSuchLayoutSetException(msg.toString());
826 }
827
828 return layoutSet;
829 }
830
831
838 public LayoutSet fetchByVirtualHost(String virtualHost)
839 throws SystemException {
840 return fetchByVirtualHost(virtualHost, true);
841 }
842
843
850 public LayoutSet fetchByVirtualHost(String virtualHost,
851 boolean retrieveFromCache) throws SystemException {
852 Object[] finderArgs = new Object[] { virtualHost };
853
854 Object result = null;
855
856 if (retrieveFromCache) {
857 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_VIRTUALHOST,
858 finderArgs, this);
859 }
860
861 if (result == null) {
862 Session session = null;
863
864 try {
865 session = openSession();
866
867 StringBundler query = new StringBundler(2);
868
869 query.append(_SQL_SELECT_LAYOUTSET_WHERE);
870
871 if (virtualHost == null) {
872 query.append(_FINDER_COLUMN_VIRTUALHOST_VIRTUALHOST_1);
873 }
874 else {
875 if (virtualHost.equals(StringPool.BLANK)) {
876 query.append(_FINDER_COLUMN_VIRTUALHOST_VIRTUALHOST_3);
877 }
878 else {
879 query.append(_FINDER_COLUMN_VIRTUALHOST_VIRTUALHOST_2);
880 }
881 }
882
883 String sql = query.toString();
884
885 Query q = session.createQuery(sql);
886
887 QueryPos qPos = QueryPos.getInstance(q);
888
889 if (virtualHost != null) {
890 qPos.add(virtualHost);
891 }
892
893 List<LayoutSet> list = q.list();
894
895 result = list;
896
897 LayoutSet layoutSet = null;
898
899 if (list.isEmpty()) {
900 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_VIRTUALHOST,
901 finderArgs, list);
902 }
903 else {
904 layoutSet = list.get(0);
905
906 cacheResult(layoutSet);
907
908 if ((layoutSet.getVirtualHost() == null) ||
909 !layoutSet.getVirtualHost().equals(virtualHost)) {
910 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_VIRTUALHOST,
911 finderArgs, layoutSet);
912 }
913 }
914
915 return layoutSet;
916 }
917 catch (Exception e) {
918 throw processException(e);
919 }
920 finally {
921 if (result == null) {
922 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_VIRTUALHOST,
923 finderArgs, new ArrayList<LayoutSet>());
924 }
925
926 closeSession(session);
927 }
928 }
929 else {
930 if (result instanceof List<?>) {
931 return null;
932 }
933 else {
934 return (LayoutSet)result;
935 }
936 }
937 }
938
939
948 public LayoutSet findByG_P(long groupId, boolean privateLayout)
949 throws NoSuchLayoutSetException, SystemException {
950 LayoutSet layoutSet = fetchByG_P(groupId, privateLayout);
951
952 if (layoutSet == null) {
953 StringBundler msg = new StringBundler(6);
954
955 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
956
957 msg.append("groupId=");
958 msg.append(groupId);
959
960 msg.append(", privateLayout=");
961 msg.append(privateLayout);
962
963 msg.append(StringPool.CLOSE_CURLY_BRACE);
964
965 if (_log.isWarnEnabled()) {
966 _log.warn(msg.toString());
967 }
968
969 throw new NoSuchLayoutSetException(msg.toString());
970 }
971
972 return layoutSet;
973 }
974
975
983 public LayoutSet fetchByG_P(long groupId, boolean privateLayout)
984 throws SystemException {
985 return fetchByG_P(groupId, privateLayout, true);
986 }
987
988
996 public LayoutSet fetchByG_P(long groupId, boolean privateLayout,
997 boolean retrieveFromCache) throws SystemException {
998 Object[] finderArgs = new Object[] { groupId, privateLayout };
999
1000 Object result = null;
1001
1002 if (retrieveFromCache) {
1003 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_P,
1004 finderArgs, this);
1005 }
1006
1007 if (result == null) {
1008 Session session = null;
1009
1010 try {
1011 session = openSession();
1012
1013 StringBundler query = new StringBundler(3);
1014
1015 query.append(_SQL_SELECT_LAYOUTSET_WHERE);
1016
1017 query.append(_FINDER_COLUMN_G_P_GROUPID_2);
1018
1019 query.append(_FINDER_COLUMN_G_P_PRIVATELAYOUT_2);
1020
1021 String sql = query.toString();
1022
1023 Query q = session.createQuery(sql);
1024
1025 QueryPos qPos = QueryPos.getInstance(q);
1026
1027 qPos.add(groupId);
1028
1029 qPos.add(privateLayout);
1030
1031 List<LayoutSet> list = q.list();
1032
1033 result = list;
1034
1035 LayoutSet layoutSet = null;
1036
1037 if (list.isEmpty()) {
1038 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P,
1039 finderArgs, list);
1040 }
1041 else {
1042 layoutSet = list.get(0);
1043
1044 cacheResult(layoutSet);
1045
1046 if ((layoutSet.getGroupId() != groupId) ||
1047 (layoutSet.getPrivateLayout() != privateLayout)) {
1048 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P,
1049 finderArgs, layoutSet);
1050 }
1051 }
1052
1053 return layoutSet;
1054 }
1055 catch (Exception e) {
1056 throw processException(e);
1057 }
1058 finally {
1059 if (result == null) {
1060 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P,
1061 finderArgs, new ArrayList<LayoutSet>());
1062 }
1063
1064 closeSession(session);
1065 }
1066 }
1067 else {
1068 if (result instanceof List<?>) {
1069 return null;
1070 }
1071 else {
1072 return (LayoutSet)result;
1073 }
1074 }
1075 }
1076
1077
1083 public List<LayoutSet> findAll() throws SystemException {
1084 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1085 }
1086
1087
1099 public List<LayoutSet> findAll(int start, int end)
1100 throws SystemException {
1101 return findAll(start, end, null);
1102 }
1103
1104
1117 public List<LayoutSet> findAll(int start, int end,
1118 OrderByComparator orderByComparator) throws SystemException {
1119 Object[] finderArgs = new Object[] {
1120 String.valueOf(start), String.valueOf(end),
1121 String.valueOf(orderByComparator)
1122 };
1123
1124 List<LayoutSet> list = (List<LayoutSet>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1125 finderArgs, this);
1126
1127 if (list == null) {
1128 Session session = null;
1129
1130 try {
1131 session = openSession();
1132
1133 StringBundler query = null;
1134 String sql = null;
1135
1136 if (orderByComparator != null) {
1137 query = new StringBundler(2 +
1138 (orderByComparator.getOrderByFields().length * 3));
1139
1140 query.append(_SQL_SELECT_LAYOUTSET);
1141
1142 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1143 orderByComparator);
1144
1145 sql = query.toString();
1146 }
1147 else {
1148 sql = _SQL_SELECT_LAYOUTSET;
1149 }
1150
1151 Query q = session.createQuery(sql);
1152
1153 if (orderByComparator == null) {
1154 list = (List<LayoutSet>)QueryUtil.list(q, getDialect(),
1155 start, end, false);
1156
1157 Collections.sort(list);
1158 }
1159 else {
1160 list = (List<LayoutSet>)QueryUtil.list(q, getDialect(),
1161 start, end);
1162 }
1163 }
1164 catch (Exception e) {
1165 throw processException(e);
1166 }
1167 finally {
1168 if (list == null) {
1169 list = new ArrayList<LayoutSet>();
1170 }
1171
1172 cacheResult(list);
1173
1174 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1175
1176 closeSession(session);
1177 }
1178 }
1179
1180 return list;
1181 }
1182
1183
1189 public void removeByGroupId(long groupId) throws SystemException {
1190 for (LayoutSet layoutSet : findByGroupId(groupId)) {
1191 remove(layoutSet);
1192 }
1193 }
1194
1195
1201 public void removeByVirtualHost(String virtualHost)
1202 throws NoSuchLayoutSetException, SystemException {
1203 LayoutSet layoutSet = findByVirtualHost(virtualHost);
1204
1205 remove(layoutSet);
1206 }
1207
1208
1215 public void removeByG_P(long groupId, boolean privateLayout)
1216 throws NoSuchLayoutSetException, SystemException {
1217 LayoutSet layoutSet = findByG_P(groupId, privateLayout);
1218
1219 remove(layoutSet);
1220 }
1221
1222
1227 public void removeAll() throws SystemException {
1228 for (LayoutSet layoutSet : findAll()) {
1229 remove(layoutSet);
1230 }
1231 }
1232
1233
1240 public int countByGroupId(long groupId) throws SystemException {
1241 Object[] finderArgs = new Object[] { groupId };
1242
1243 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
1244 finderArgs, this);
1245
1246 if (count == null) {
1247 Session session = null;
1248
1249 try {
1250 session = openSession();
1251
1252 StringBundler query = new StringBundler(2);
1253
1254 query.append(_SQL_COUNT_LAYOUTSET_WHERE);
1255
1256 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1257
1258 String sql = query.toString();
1259
1260 Query q = session.createQuery(sql);
1261
1262 QueryPos qPos = QueryPos.getInstance(q);
1263
1264 qPos.add(groupId);
1265
1266 count = (Long)q.uniqueResult();
1267 }
1268 catch (Exception e) {
1269 throw processException(e);
1270 }
1271 finally {
1272 if (count == null) {
1273 count = Long.valueOf(0);
1274 }
1275
1276 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
1277 finderArgs, count);
1278
1279 closeSession(session);
1280 }
1281 }
1282
1283 return count.intValue();
1284 }
1285
1286
1293 public int countByVirtualHost(String virtualHost) throws SystemException {
1294 Object[] finderArgs = new Object[] { virtualHost };
1295
1296 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_VIRTUALHOST,
1297 finderArgs, this);
1298
1299 if (count == null) {
1300 Session session = null;
1301
1302 try {
1303 session = openSession();
1304
1305 StringBundler query = new StringBundler(2);
1306
1307 query.append(_SQL_COUNT_LAYOUTSET_WHERE);
1308
1309 if (virtualHost == null) {
1310 query.append(_FINDER_COLUMN_VIRTUALHOST_VIRTUALHOST_1);
1311 }
1312 else {
1313 if (virtualHost.equals(StringPool.BLANK)) {
1314 query.append(_FINDER_COLUMN_VIRTUALHOST_VIRTUALHOST_3);
1315 }
1316 else {
1317 query.append(_FINDER_COLUMN_VIRTUALHOST_VIRTUALHOST_2);
1318 }
1319 }
1320
1321 String sql = query.toString();
1322
1323 Query q = session.createQuery(sql);
1324
1325 QueryPos qPos = QueryPos.getInstance(q);
1326
1327 if (virtualHost != null) {
1328 qPos.add(virtualHost);
1329 }
1330
1331 count = (Long)q.uniqueResult();
1332 }
1333 catch (Exception e) {
1334 throw processException(e);
1335 }
1336 finally {
1337 if (count == null) {
1338 count = Long.valueOf(0);
1339 }
1340
1341 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_VIRTUALHOST,
1342 finderArgs, count);
1343
1344 closeSession(session);
1345 }
1346 }
1347
1348 return count.intValue();
1349 }
1350
1351
1359 public int countByG_P(long groupId, boolean privateLayout)
1360 throws SystemException {
1361 Object[] finderArgs = new Object[] { groupId, privateLayout };
1362
1363 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_P,
1364 finderArgs, this);
1365
1366 if (count == null) {
1367 Session session = null;
1368
1369 try {
1370 session = openSession();
1371
1372 StringBundler query = new StringBundler(3);
1373
1374 query.append(_SQL_COUNT_LAYOUTSET_WHERE);
1375
1376 query.append(_FINDER_COLUMN_G_P_GROUPID_2);
1377
1378 query.append(_FINDER_COLUMN_G_P_PRIVATELAYOUT_2);
1379
1380 String sql = query.toString();
1381
1382 Query q = session.createQuery(sql);
1383
1384 QueryPos qPos = QueryPos.getInstance(q);
1385
1386 qPos.add(groupId);
1387
1388 qPos.add(privateLayout);
1389
1390 count = (Long)q.uniqueResult();
1391 }
1392 catch (Exception e) {
1393 throw processException(e);
1394 }
1395 finally {
1396 if (count == null) {
1397 count = Long.valueOf(0);
1398 }
1399
1400 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_P, finderArgs,
1401 count);
1402
1403 closeSession(session);
1404 }
1405 }
1406
1407 return count.intValue();
1408 }
1409
1410
1416 public int countAll() throws SystemException {
1417 Object[] finderArgs = new Object[0];
1418
1419 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1420 finderArgs, this);
1421
1422 if (count == null) {
1423 Session session = null;
1424
1425 try {
1426 session = openSession();
1427
1428 Query q = session.createQuery(_SQL_COUNT_LAYOUTSET);
1429
1430 count = (Long)q.uniqueResult();
1431 }
1432 catch (Exception e) {
1433 throw processException(e);
1434 }
1435 finally {
1436 if (count == null) {
1437 count = Long.valueOf(0);
1438 }
1439
1440 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1441 count);
1442
1443 closeSession(session);
1444 }
1445 }
1446
1447 return count.intValue();
1448 }
1449
1450
1453 public void afterPropertiesSet() {
1454 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1455 com.liferay.portal.util.PropsUtil.get(
1456 "value.object.listener.com.liferay.portal.model.LayoutSet")));
1457
1458 if (listenerClassNames.length > 0) {
1459 try {
1460 List<ModelListener<LayoutSet>> listenersList = new ArrayList<ModelListener<LayoutSet>>();
1461
1462 for (String listenerClassName : listenerClassNames) {
1463 listenersList.add((ModelListener<LayoutSet>)InstanceFactory.newInstance(
1464 listenerClassName));
1465 }
1466
1467 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1468 }
1469 catch (Exception e) {
1470 _log.error(e);
1471 }
1472 }
1473 }
1474
1475 @BeanReference(type = AccountPersistence.class)
1476 protected AccountPersistence accountPersistence;
1477 @BeanReference(type = AddressPersistence.class)
1478 protected AddressPersistence addressPersistence;
1479 @BeanReference(type = BrowserTrackerPersistence.class)
1480 protected BrowserTrackerPersistence browserTrackerPersistence;
1481 @BeanReference(type = ClassNamePersistence.class)
1482 protected ClassNamePersistence classNamePersistence;
1483 @BeanReference(type = CompanyPersistence.class)
1484 protected CompanyPersistence companyPersistence;
1485 @BeanReference(type = ContactPersistence.class)
1486 protected ContactPersistence contactPersistence;
1487 @BeanReference(type = CountryPersistence.class)
1488 protected CountryPersistence countryPersistence;
1489 @BeanReference(type = EmailAddressPersistence.class)
1490 protected EmailAddressPersistence emailAddressPersistence;
1491 @BeanReference(type = GroupPersistence.class)
1492 protected GroupPersistence groupPersistence;
1493 @BeanReference(type = ImagePersistence.class)
1494 protected ImagePersistence imagePersistence;
1495 @BeanReference(type = LayoutPersistence.class)
1496 protected LayoutPersistence layoutPersistence;
1497 @BeanReference(type = LayoutPrototypePersistence.class)
1498 protected LayoutPrototypePersistence layoutPrototypePersistence;
1499 @BeanReference(type = LayoutSetPersistence.class)
1500 protected LayoutSetPersistence layoutSetPersistence;
1501 @BeanReference(type = LayoutSetPrototypePersistence.class)
1502 protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
1503 @BeanReference(type = ListTypePersistence.class)
1504 protected ListTypePersistence listTypePersistence;
1505 @BeanReference(type = LockPersistence.class)
1506 protected LockPersistence lockPersistence;
1507 @BeanReference(type = MembershipRequestPersistence.class)
1508 protected MembershipRequestPersistence membershipRequestPersistence;
1509 @BeanReference(type = OrganizationPersistence.class)
1510 protected OrganizationPersistence organizationPersistence;
1511 @BeanReference(type = OrgGroupPermissionPersistence.class)
1512 protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1513 @BeanReference(type = OrgGroupRolePersistence.class)
1514 protected OrgGroupRolePersistence orgGroupRolePersistence;
1515 @BeanReference(type = OrgLaborPersistence.class)
1516 protected OrgLaborPersistence orgLaborPersistence;
1517 @BeanReference(type = PasswordPolicyPersistence.class)
1518 protected PasswordPolicyPersistence passwordPolicyPersistence;
1519 @BeanReference(type = PasswordPolicyRelPersistence.class)
1520 protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1521 @BeanReference(type = PasswordTrackerPersistence.class)
1522 protected PasswordTrackerPersistence passwordTrackerPersistence;
1523 @BeanReference(type = PermissionPersistence.class)
1524 protected PermissionPersistence permissionPersistence;
1525 @BeanReference(type = PhonePersistence.class)
1526 protected PhonePersistence phonePersistence;
1527 @BeanReference(type = PluginSettingPersistence.class)
1528 protected PluginSettingPersistence pluginSettingPersistence;
1529 @BeanReference(type = PortletPersistence.class)
1530 protected PortletPersistence portletPersistence;
1531 @BeanReference(type = PortletItemPersistence.class)
1532 protected PortletItemPersistence portletItemPersistence;
1533 @BeanReference(type = PortletPreferencesPersistence.class)
1534 protected PortletPreferencesPersistence portletPreferencesPersistence;
1535 @BeanReference(type = RegionPersistence.class)
1536 protected RegionPersistence regionPersistence;
1537 @BeanReference(type = ReleasePersistence.class)
1538 protected ReleasePersistence releasePersistence;
1539 @BeanReference(type = ResourcePersistence.class)
1540 protected ResourcePersistence resourcePersistence;
1541 @BeanReference(type = ResourceActionPersistence.class)
1542 protected ResourceActionPersistence resourceActionPersistence;
1543 @BeanReference(type = ResourceCodePersistence.class)
1544 protected ResourceCodePersistence resourceCodePersistence;
1545 @BeanReference(type = ResourcePermissionPersistence.class)
1546 protected ResourcePermissionPersistence resourcePermissionPersistence;
1547 @BeanReference(type = RolePersistence.class)
1548 protected RolePersistence rolePersistence;
1549 @BeanReference(type = ServiceComponentPersistence.class)
1550 protected ServiceComponentPersistence serviceComponentPersistence;
1551 @BeanReference(type = ShardPersistence.class)
1552 protected ShardPersistence shardPersistence;
1553 @BeanReference(type = SubscriptionPersistence.class)
1554 protected SubscriptionPersistence subscriptionPersistence;
1555 @BeanReference(type = TicketPersistence.class)
1556 protected TicketPersistence ticketPersistence;
1557 @BeanReference(type = TeamPersistence.class)
1558 protected TeamPersistence teamPersistence;
1559 @BeanReference(type = UserPersistence.class)
1560 protected UserPersistence userPersistence;
1561 @BeanReference(type = UserGroupPersistence.class)
1562 protected UserGroupPersistence userGroupPersistence;
1563 @BeanReference(type = UserGroupGroupRolePersistence.class)
1564 protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1565 @BeanReference(type = UserGroupRolePersistence.class)
1566 protected UserGroupRolePersistence userGroupRolePersistence;
1567 @BeanReference(type = UserIdMapperPersistence.class)
1568 protected UserIdMapperPersistence userIdMapperPersistence;
1569 @BeanReference(type = UserTrackerPersistence.class)
1570 protected UserTrackerPersistence userTrackerPersistence;
1571 @BeanReference(type = UserTrackerPathPersistence.class)
1572 protected UserTrackerPathPersistence userTrackerPathPersistence;
1573 @BeanReference(type = WebDAVPropsPersistence.class)
1574 protected WebDAVPropsPersistence webDAVPropsPersistence;
1575 @BeanReference(type = WebsitePersistence.class)
1576 protected WebsitePersistence websitePersistence;
1577 @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
1578 protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
1579 @BeanReference(type = WorkflowInstanceLinkPersistence.class)
1580 protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
1581 private static final String _SQL_SELECT_LAYOUTSET = "SELECT layoutSet FROM LayoutSet layoutSet";
1582 private static final String _SQL_SELECT_LAYOUTSET_WHERE = "SELECT layoutSet FROM LayoutSet layoutSet WHERE ";
1583 private static final String _SQL_COUNT_LAYOUTSET = "SELECT COUNT(layoutSet) FROM LayoutSet layoutSet";
1584 private static final String _SQL_COUNT_LAYOUTSET_WHERE = "SELECT COUNT(layoutSet) FROM LayoutSet layoutSet WHERE ";
1585 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "layoutSet.groupId = ?";
1586 private static final String _FINDER_COLUMN_VIRTUALHOST_VIRTUALHOST_1 = "layoutSet.virtualHost IS NULL";
1587 private static final String _FINDER_COLUMN_VIRTUALHOST_VIRTUALHOST_2 = "layoutSet.virtualHost = ?";
1588 private static final String _FINDER_COLUMN_VIRTUALHOST_VIRTUALHOST_3 = "(layoutSet.virtualHost IS NULL OR layoutSet.virtualHost = ?)";
1589 private static final String _FINDER_COLUMN_G_P_GROUPID_2 = "layoutSet.groupId = ? AND ";
1590 private static final String _FINDER_COLUMN_G_P_PRIVATELAYOUT_2 = "layoutSet.privateLayout = ?";
1591 private static final String _ORDER_BY_ENTITY_ALIAS = "layoutSet.";
1592 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No LayoutSet exists with the primary key ";
1593 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No LayoutSet exists with the key {";
1594 private static Log _log = LogFactoryUtil.getLog(LayoutSetPersistenceImpl.class);
1595 }