001
014
015 package com.liferay.portal.service.persistence;
016
017 import com.liferay.portal.NoSuchListTypeException;
018 import com.liferay.portal.NoSuchModelException;
019 import com.liferay.portal.kernel.bean.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.CacheModel;
039 import com.liferay.portal.model.ListType;
040 import com.liferay.portal.model.ModelListener;
041 import com.liferay.portal.model.impl.ListTypeImpl;
042 import com.liferay.portal.model.impl.ListTypeModelImpl;
043 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
044
045 import java.io.Serializable;
046
047 import java.util.ArrayList;
048 import java.util.Collections;
049 import java.util.List;
050
051
063 public class ListTypePersistenceImpl extends BasePersistenceImpl<ListType>
064 implements ListTypePersistence {
065
070 public static final String FINDER_CLASS_NAME_ENTITY = ListTypeImpl.class.getName();
071 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
072 ".List1";
073 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
074 ".List2";
075 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_TYPE = new FinderPath(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
076 ListTypeModelImpl.FINDER_CACHE_ENABLED, ListTypeImpl.class,
077 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByType",
078 new String[] {
079 String.class.getName(),
080
081 "java.lang.Integer", "java.lang.Integer",
082 "com.liferay.portal.kernel.util.OrderByComparator"
083 });
084 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE = new FinderPath(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
085 ListTypeModelImpl.FINDER_CACHE_ENABLED, ListTypeImpl.class,
086 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByType",
087 new String[] { String.class.getName() },
088 ListTypeModelImpl.TYPE_COLUMN_BITMASK);
089 public static final FinderPath FINDER_PATH_COUNT_BY_TYPE = new FinderPath(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
090 ListTypeModelImpl.FINDER_CACHE_ENABLED, Long.class,
091 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByType",
092 new String[] { String.class.getName() });
093 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
094 ListTypeModelImpl.FINDER_CACHE_ENABLED, ListTypeImpl.class,
095 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
096 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
097 ListTypeModelImpl.FINDER_CACHE_ENABLED, ListTypeImpl.class,
098 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
099 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
100 ListTypeModelImpl.FINDER_CACHE_ENABLED, Long.class,
101 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
102
103
108 public void cacheResult(ListType listType) {
109 EntityCacheUtil.putResult(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
110 ListTypeImpl.class, listType.getPrimaryKey(), listType);
111
112 listType.resetOriginalValues();
113 }
114
115
120 public void cacheResult(List<ListType> listTypes) {
121 for (ListType listType : listTypes) {
122 if (EntityCacheUtil.getResult(
123 ListTypeModelImpl.ENTITY_CACHE_ENABLED,
124 ListTypeImpl.class, listType.getPrimaryKey()) == null) {
125 cacheResult(listType);
126 }
127 else {
128 listType.resetOriginalValues();
129 }
130 }
131 }
132
133
140 @Override
141 public void clearCache() {
142 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
143 CacheRegistryUtil.clear(ListTypeImpl.class.getName());
144 }
145
146 EntityCacheUtil.clearCache(ListTypeImpl.class.getName());
147
148 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
149 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
150 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
151 }
152
153
160 @Override
161 public void clearCache(ListType listType) {
162 EntityCacheUtil.removeResult(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
163 ListTypeImpl.class, listType.getPrimaryKey());
164
165 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
166 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
167 }
168
169 @Override
170 public void clearCache(List<ListType> listTypes) {
171 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
172 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
173
174 for (ListType listType : listTypes) {
175 EntityCacheUtil.removeResult(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
176 ListTypeImpl.class, listType.getPrimaryKey());
177 }
178 }
179
180
186 public ListType create(int listTypeId) {
187 ListType listType = new ListTypeImpl();
188
189 listType.setNew(true);
190 listType.setPrimaryKey(listTypeId);
191
192 return listType;
193 }
194
195
203 public ListType remove(int listTypeId)
204 throws NoSuchListTypeException, SystemException {
205 return remove(Integer.valueOf(listTypeId));
206 }
207
208
216 @Override
217 public ListType remove(Serializable primaryKey)
218 throws NoSuchListTypeException, SystemException {
219 Session session = null;
220
221 try {
222 session = openSession();
223
224 ListType listType = (ListType)session.get(ListTypeImpl.class,
225 primaryKey);
226
227 if (listType == null) {
228 if (_log.isWarnEnabled()) {
229 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
230 }
231
232 throw new NoSuchListTypeException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
233 primaryKey);
234 }
235
236 return remove(listType);
237 }
238 catch (NoSuchListTypeException nsee) {
239 throw nsee;
240 }
241 catch (Exception e) {
242 throw processException(e);
243 }
244 finally {
245 closeSession(session);
246 }
247 }
248
249 @Override
250 protected ListType removeImpl(ListType listType) throws SystemException {
251 listType = toUnwrappedModel(listType);
252
253 Session session = null;
254
255 try {
256 session = openSession();
257
258 BatchSessionUtil.delete(session, listType);
259 }
260 catch (Exception e) {
261 throw processException(e);
262 }
263 finally {
264 closeSession(session);
265 }
266
267 clearCache(listType);
268
269 return listType;
270 }
271
272 @Override
273 public ListType updateImpl(com.liferay.portal.model.ListType listType,
274 boolean merge) throws SystemException {
275 listType = toUnwrappedModel(listType);
276
277 boolean isNew = listType.isNew();
278
279 ListTypeModelImpl listTypeModelImpl = (ListTypeModelImpl)listType;
280
281 Session session = null;
282
283 try {
284 session = openSession();
285
286 BatchSessionUtil.update(session, listType, merge);
287
288 listType.setNew(false);
289 }
290 catch (Exception e) {
291 throw processException(e);
292 }
293 finally {
294 closeSession(session);
295 }
296
297 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
298
299 if (isNew || !ListTypeModelImpl.COLUMN_BITMASK_ENABLED) {
300 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
301 }
302
303 else {
304 if ((listTypeModelImpl.getColumnBitmask() &
305 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE.getColumnBitmask()) != 0) {
306 Object[] args = new Object[] { listTypeModelImpl.getOriginalType() };
307
308 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TYPE, args);
309 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE,
310 args);
311
312 args = new Object[] { listTypeModelImpl.getType() };
313
314 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TYPE, args);
315 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE,
316 args);
317 }
318 }
319
320 EntityCacheUtil.putResult(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
321 ListTypeImpl.class, listType.getPrimaryKey(), listType);
322
323 return listType;
324 }
325
326 protected ListType toUnwrappedModel(ListType listType) {
327 if (listType instanceof ListTypeImpl) {
328 return listType;
329 }
330
331 ListTypeImpl listTypeImpl = new ListTypeImpl();
332
333 listTypeImpl.setNew(listType.isNew());
334 listTypeImpl.setPrimaryKey(listType.getPrimaryKey());
335
336 listTypeImpl.setListTypeId(listType.getListTypeId());
337 listTypeImpl.setName(listType.getName());
338 listTypeImpl.setType(listType.getType());
339
340 return listTypeImpl;
341 }
342
343
351 @Override
352 public ListType findByPrimaryKey(Serializable primaryKey)
353 throws NoSuchModelException, SystemException {
354 return findByPrimaryKey(((Integer)primaryKey).intValue());
355 }
356
357
365 public ListType findByPrimaryKey(int listTypeId)
366 throws NoSuchListTypeException, SystemException {
367 ListType listType = fetchByPrimaryKey(listTypeId);
368
369 if (listType == null) {
370 if (_log.isWarnEnabled()) {
371 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + listTypeId);
372 }
373
374 throw new NoSuchListTypeException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
375 listTypeId);
376 }
377
378 return listType;
379 }
380
381
388 @Override
389 public ListType fetchByPrimaryKey(Serializable primaryKey)
390 throws SystemException {
391 return fetchByPrimaryKey(((Integer)primaryKey).intValue());
392 }
393
394
401 public ListType fetchByPrimaryKey(int listTypeId) throws SystemException {
402 ListType listType = (ListType)EntityCacheUtil.getResult(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
403 ListTypeImpl.class, listTypeId);
404
405 if (listType == _nullListType) {
406 return null;
407 }
408
409 if (listType == null) {
410 Session session = null;
411
412 boolean hasException = false;
413
414 try {
415 session = openSession();
416
417 listType = (ListType)session.get(ListTypeImpl.class,
418 Integer.valueOf(listTypeId));
419 }
420 catch (Exception e) {
421 hasException = true;
422
423 throw processException(e);
424 }
425 finally {
426 if (listType != null) {
427 cacheResult(listType);
428 }
429 else if (!hasException) {
430 EntityCacheUtil.putResult(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
431 ListTypeImpl.class, listTypeId, _nullListType);
432 }
433
434 closeSession(session);
435 }
436 }
437
438 return listType;
439 }
440
441
448 public List<ListType> findByType(String type) throws SystemException {
449 return findByType(type, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
450 }
451
452
465 public List<ListType> findByType(String type, int start, int end)
466 throws SystemException {
467 return findByType(type, start, end, null);
468 }
469
470
484 public List<ListType> findByType(String type, int start, int end,
485 OrderByComparator orderByComparator) throws SystemException {
486 FinderPath finderPath = null;
487 Object[] finderArgs = null;
488
489 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
490 (orderByComparator == null)) {
491 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE;
492 finderArgs = new Object[] { type };
493 }
494 else {
495 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_TYPE;
496 finderArgs = new Object[] { type, start, end, orderByComparator };
497 }
498
499 List<ListType> list = (List<ListType>)FinderCacheUtil.getResult(finderPath,
500 finderArgs, this);
501
502 if ((list != null) && !list.isEmpty()) {
503 for (ListType listType : list) {
504 if (!Validator.equals(type, listType.getType())) {
505 list = null;
506
507 break;
508 }
509 }
510 }
511
512 if (list == null) {
513 StringBundler query = null;
514
515 if (orderByComparator != null) {
516 query = new StringBundler(3 +
517 (orderByComparator.getOrderByFields().length * 3));
518 }
519 else {
520 query = new StringBundler(3);
521 }
522
523 query.append(_SQL_SELECT_LISTTYPE_WHERE);
524
525 if (type == null) {
526 query.append(_FINDER_COLUMN_TYPE_TYPE_1);
527 }
528 else {
529 if (type.equals(StringPool.BLANK)) {
530 query.append(_FINDER_COLUMN_TYPE_TYPE_3);
531 }
532 else {
533 query.append(_FINDER_COLUMN_TYPE_TYPE_2);
534 }
535 }
536
537 if (orderByComparator != null) {
538 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
539 orderByComparator);
540 }
541
542 else {
543 query.append(ListTypeModelImpl.ORDER_BY_JPQL);
544 }
545
546 String sql = query.toString();
547
548 Session session = null;
549
550 try {
551 session = openSession();
552
553 Query q = session.createQuery(sql);
554
555 QueryPos qPos = QueryPos.getInstance(q);
556
557 if (type != null) {
558 qPos.add(type);
559 }
560
561 list = (List<ListType>)QueryUtil.list(q, getDialect(), start,
562 end);
563 }
564 catch (Exception e) {
565 throw processException(e);
566 }
567 finally {
568 if (list == null) {
569 FinderCacheUtil.removeResult(finderPath, finderArgs);
570 }
571 else {
572 cacheResult(list);
573
574 FinderCacheUtil.putResult(finderPath, finderArgs, list);
575 }
576
577 closeSession(session);
578 }
579 }
580
581 return list;
582 }
583
584
593 public ListType findByType_First(String type,
594 OrderByComparator orderByComparator)
595 throws NoSuchListTypeException, SystemException {
596 ListType listType = fetchByType_First(type, orderByComparator);
597
598 if (listType != null) {
599 return listType;
600 }
601
602 StringBundler msg = new StringBundler(4);
603
604 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
605
606 msg.append("type=");
607 msg.append(type);
608
609 msg.append(StringPool.CLOSE_CURLY_BRACE);
610
611 throw new NoSuchListTypeException(msg.toString());
612 }
613
614
622 public ListType fetchByType_First(String type,
623 OrderByComparator orderByComparator) throws SystemException {
624 List<ListType> list = findByType(type, 0, 1, orderByComparator);
625
626 if (!list.isEmpty()) {
627 return list.get(0);
628 }
629
630 return null;
631 }
632
633
642 public ListType findByType_Last(String type,
643 OrderByComparator orderByComparator)
644 throws NoSuchListTypeException, SystemException {
645 ListType listType = fetchByType_Last(type, orderByComparator);
646
647 if (listType != null) {
648 return listType;
649 }
650
651 StringBundler msg = new StringBundler(4);
652
653 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
654
655 msg.append("type=");
656 msg.append(type);
657
658 msg.append(StringPool.CLOSE_CURLY_BRACE);
659
660 throw new NoSuchListTypeException(msg.toString());
661 }
662
663
671 public ListType fetchByType_Last(String type,
672 OrderByComparator orderByComparator) throws SystemException {
673 int count = countByType(type);
674
675 List<ListType> list = findByType(type, count - 1, count,
676 orderByComparator);
677
678 if (!list.isEmpty()) {
679 return list.get(0);
680 }
681
682 return null;
683 }
684
685
695 public ListType[] findByType_PrevAndNext(int listTypeId, String type,
696 OrderByComparator orderByComparator)
697 throws NoSuchListTypeException, SystemException {
698 ListType listType = findByPrimaryKey(listTypeId);
699
700 Session session = null;
701
702 try {
703 session = openSession();
704
705 ListType[] array = new ListTypeImpl[3];
706
707 array[0] = getByType_PrevAndNext(session, listType, type,
708 orderByComparator, true);
709
710 array[1] = listType;
711
712 array[2] = getByType_PrevAndNext(session, listType, type,
713 orderByComparator, false);
714
715 return array;
716 }
717 catch (Exception e) {
718 throw processException(e);
719 }
720 finally {
721 closeSession(session);
722 }
723 }
724
725 protected ListType getByType_PrevAndNext(Session session,
726 ListType listType, String type, OrderByComparator orderByComparator,
727 boolean previous) {
728 StringBundler query = null;
729
730 if (orderByComparator != null) {
731 query = new StringBundler(6 +
732 (orderByComparator.getOrderByFields().length * 6));
733 }
734 else {
735 query = new StringBundler(3);
736 }
737
738 query.append(_SQL_SELECT_LISTTYPE_WHERE);
739
740 if (type == null) {
741 query.append(_FINDER_COLUMN_TYPE_TYPE_1);
742 }
743 else {
744 if (type.equals(StringPool.BLANK)) {
745 query.append(_FINDER_COLUMN_TYPE_TYPE_3);
746 }
747 else {
748 query.append(_FINDER_COLUMN_TYPE_TYPE_2);
749 }
750 }
751
752 if (orderByComparator != null) {
753 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
754
755 if (orderByConditionFields.length > 0) {
756 query.append(WHERE_AND);
757 }
758
759 for (int i = 0; i < orderByConditionFields.length; i++) {
760 query.append(_ORDER_BY_ENTITY_ALIAS);
761 query.append(orderByConditionFields[i]);
762
763 if ((i + 1) < orderByConditionFields.length) {
764 if (orderByComparator.isAscending() ^ previous) {
765 query.append(WHERE_GREATER_THAN_HAS_NEXT);
766 }
767 else {
768 query.append(WHERE_LESSER_THAN_HAS_NEXT);
769 }
770 }
771 else {
772 if (orderByComparator.isAscending() ^ previous) {
773 query.append(WHERE_GREATER_THAN);
774 }
775 else {
776 query.append(WHERE_LESSER_THAN);
777 }
778 }
779 }
780
781 query.append(ORDER_BY_CLAUSE);
782
783 String[] orderByFields = orderByComparator.getOrderByFields();
784
785 for (int i = 0; i < orderByFields.length; i++) {
786 query.append(_ORDER_BY_ENTITY_ALIAS);
787 query.append(orderByFields[i]);
788
789 if ((i + 1) < orderByFields.length) {
790 if (orderByComparator.isAscending() ^ previous) {
791 query.append(ORDER_BY_ASC_HAS_NEXT);
792 }
793 else {
794 query.append(ORDER_BY_DESC_HAS_NEXT);
795 }
796 }
797 else {
798 if (orderByComparator.isAscending() ^ previous) {
799 query.append(ORDER_BY_ASC);
800 }
801 else {
802 query.append(ORDER_BY_DESC);
803 }
804 }
805 }
806 }
807
808 else {
809 query.append(ListTypeModelImpl.ORDER_BY_JPQL);
810 }
811
812 String sql = query.toString();
813
814 Query q = session.createQuery(sql);
815
816 q.setFirstResult(0);
817 q.setMaxResults(2);
818
819 QueryPos qPos = QueryPos.getInstance(q);
820
821 if (type != null) {
822 qPos.add(type);
823 }
824
825 if (orderByComparator != null) {
826 Object[] values = orderByComparator.getOrderByConditionValues(listType);
827
828 for (Object value : values) {
829 qPos.add(value);
830 }
831 }
832
833 List<ListType> list = q.list();
834
835 if (list.size() == 2) {
836 return list.get(1);
837 }
838 else {
839 return null;
840 }
841 }
842
843
849 public List<ListType> findAll() throws SystemException {
850 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
851 }
852
853
865 public List<ListType> findAll(int start, int end) throws SystemException {
866 return findAll(start, end, null);
867 }
868
869
882 public List<ListType> findAll(int start, int end,
883 OrderByComparator orderByComparator) throws SystemException {
884 FinderPath finderPath = null;
885 Object[] finderArgs = new Object[] { start, end, orderByComparator };
886
887 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
888 (orderByComparator == null)) {
889 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
890 finderArgs = FINDER_ARGS_EMPTY;
891 }
892 else {
893 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
894 finderArgs = new Object[] { start, end, orderByComparator };
895 }
896
897 List<ListType> list = (List<ListType>)FinderCacheUtil.getResult(finderPath,
898 finderArgs, this);
899
900 if (list == null) {
901 StringBundler query = null;
902 String sql = null;
903
904 if (orderByComparator != null) {
905 query = new StringBundler(2 +
906 (orderByComparator.getOrderByFields().length * 3));
907
908 query.append(_SQL_SELECT_LISTTYPE);
909
910 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
911 orderByComparator);
912
913 sql = query.toString();
914 }
915 else {
916 sql = _SQL_SELECT_LISTTYPE.concat(ListTypeModelImpl.ORDER_BY_JPQL);
917 }
918
919 Session session = null;
920
921 try {
922 session = openSession();
923
924 Query q = session.createQuery(sql);
925
926 if (orderByComparator == null) {
927 list = (List<ListType>)QueryUtil.list(q, getDialect(),
928 start, end, false);
929
930 Collections.sort(list);
931 }
932 else {
933 list = (List<ListType>)QueryUtil.list(q, getDialect(),
934 start, end);
935 }
936 }
937 catch (Exception e) {
938 throw processException(e);
939 }
940 finally {
941 if (list == null) {
942 FinderCacheUtil.removeResult(finderPath, finderArgs);
943 }
944 else {
945 cacheResult(list);
946
947 FinderCacheUtil.putResult(finderPath, finderArgs, list);
948 }
949
950 closeSession(session);
951 }
952 }
953
954 return list;
955 }
956
957
963 public void removeByType(String type) throws SystemException {
964 for (ListType listType : findByType(type)) {
965 remove(listType);
966 }
967 }
968
969
974 public void removeAll() throws SystemException {
975 for (ListType listType : findAll()) {
976 remove(listType);
977 }
978 }
979
980
987 public int countByType(String type) throws SystemException {
988 Object[] finderArgs = new Object[] { type };
989
990 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_TYPE,
991 finderArgs, this);
992
993 if (count == null) {
994 StringBundler query = new StringBundler(2);
995
996 query.append(_SQL_COUNT_LISTTYPE_WHERE);
997
998 if (type == null) {
999 query.append(_FINDER_COLUMN_TYPE_TYPE_1);
1000 }
1001 else {
1002 if (type.equals(StringPool.BLANK)) {
1003 query.append(_FINDER_COLUMN_TYPE_TYPE_3);
1004 }
1005 else {
1006 query.append(_FINDER_COLUMN_TYPE_TYPE_2);
1007 }
1008 }
1009
1010 String sql = query.toString();
1011
1012 Session session = null;
1013
1014 try {
1015 session = openSession();
1016
1017 Query q = session.createQuery(sql);
1018
1019 QueryPos qPos = QueryPos.getInstance(q);
1020
1021 if (type != null) {
1022 qPos.add(type);
1023 }
1024
1025 count = (Long)q.uniqueResult();
1026 }
1027 catch (Exception e) {
1028 throw processException(e);
1029 }
1030 finally {
1031 if (count == null) {
1032 count = Long.valueOf(0);
1033 }
1034
1035 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_TYPE,
1036 finderArgs, count);
1037
1038 closeSession(session);
1039 }
1040 }
1041
1042 return count.intValue();
1043 }
1044
1045
1051 public int countAll() throws SystemException {
1052 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1053 FINDER_ARGS_EMPTY, this);
1054
1055 if (count == null) {
1056 Session session = null;
1057
1058 try {
1059 session = openSession();
1060
1061 Query q = session.createQuery(_SQL_COUNT_LISTTYPE);
1062
1063 count = (Long)q.uniqueResult();
1064 }
1065 catch (Exception e) {
1066 throw processException(e);
1067 }
1068 finally {
1069 if (count == null) {
1070 count = Long.valueOf(0);
1071 }
1072
1073 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1074 FINDER_ARGS_EMPTY, count);
1075
1076 closeSession(session);
1077 }
1078 }
1079
1080 return count.intValue();
1081 }
1082
1083
1086 public void afterPropertiesSet() {
1087 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1088 com.liferay.portal.util.PropsUtil.get(
1089 "value.object.listener.com.liferay.portal.model.ListType")));
1090
1091 if (listenerClassNames.length > 0) {
1092 try {
1093 List<ModelListener<ListType>> listenersList = new ArrayList<ModelListener<ListType>>();
1094
1095 for (String listenerClassName : listenerClassNames) {
1096 Class<?> clazz = getClass();
1097
1098 listenersList.add((ModelListener<ListType>)InstanceFactory.newInstance(
1099 clazz.getClassLoader(), listenerClassName));
1100 }
1101
1102 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1103 }
1104 catch (Exception e) {
1105 _log.error(e);
1106 }
1107 }
1108 }
1109
1110 public void destroy() {
1111 EntityCacheUtil.removeCache(ListTypeImpl.class.getName());
1112 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1113 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1114 }
1115
1116 @BeanReference(type = AccountPersistence.class)
1117 protected AccountPersistence accountPersistence;
1118 @BeanReference(type = AddressPersistence.class)
1119 protected AddressPersistence addressPersistence;
1120 @BeanReference(type = BrowserTrackerPersistence.class)
1121 protected BrowserTrackerPersistence browserTrackerPersistence;
1122 @BeanReference(type = ClassNamePersistence.class)
1123 protected ClassNamePersistence classNamePersistence;
1124 @BeanReference(type = ClusterGroupPersistence.class)
1125 protected ClusterGroupPersistence clusterGroupPersistence;
1126 @BeanReference(type = CompanyPersistence.class)
1127 protected CompanyPersistence companyPersistence;
1128 @BeanReference(type = ContactPersistence.class)
1129 protected ContactPersistence contactPersistence;
1130 @BeanReference(type = CountryPersistence.class)
1131 protected CountryPersistence countryPersistence;
1132 @BeanReference(type = EmailAddressPersistence.class)
1133 protected EmailAddressPersistence emailAddressPersistence;
1134 @BeanReference(type = GroupPersistence.class)
1135 protected GroupPersistence groupPersistence;
1136 @BeanReference(type = ImagePersistence.class)
1137 protected ImagePersistence imagePersistence;
1138 @BeanReference(type = LayoutPersistence.class)
1139 protected LayoutPersistence layoutPersistence;
1140 @BeanReference(type = LayoutBranchPersistence.class)
1141 protected LayoutBranchPersistence layoutBranchPersistence;
1142 @BeanReference(type = LayoutPrototypePersistence.class)
1143 protected LayoutPrototypePersistence layoutPrototypePersistence;
1144 @BeanReference(type = LayoutRevisionPersistence.class)
1145 protected LayoutRevisionPersistence layoutRevisionPersistence;
1146 @BeanReference(type = LayoutSetPersistence.class)
1147 protected LayoutSetPersistence layoutSetPersistence;
1148 @BeanReference(type = LayoutSetBranchPersistence.class)
1149 protected LayoutSetBranchPersistence layoutSetBranchPersistence;
1150 @BeanReference(type = LayoutSetPrototypePersistence.class)
1151 protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
1152 @BeanReference(type = ListTypePersistence.class)
1153 protected ListTypePersistence listTypePersistence;
1154 @BeanReference(type = LockPersistence.class)
1155 protected LockPersistence lockPersistence;
1156 @BeanReference(type = MembershipRequestPersistence.class)
1157 protected MembershipRequestPersistence membershipRequestPersistence;
1158 @BeanReference(type = OrganizationPersistence.class)
1159 protected OrganizationPersistence organizationPersistence;
1160 @BeanReference(type = OrgGroupPermissionPersistence.class)
1161 protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1162 @BeanReference(type = OrgGroupRolePersistence.class)
1163 protected OrgGroupRolePersistence orgGroupRolePersistence;
1164 @BeanReference(type = OrgLaborPersistence.class)
1165 protected OrgLaborPersistence orgLaborPersistence;
1166 @BeanReference(type = PasswordPolicyPersistence.class)
1167 protected PasswordPolicyPersistence passwordPolicyPersistence;
1168 @BeanReference(type = PasswordPolicyRelPersistence.class)
1169 protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1170 @BeanReference(type = PasswordTrackerPersistence.class)
1171 protected PasswordTrackerPersistence passwordTrackerPersistence;
1172 @BeanReference(type = PermissionPersistence.class)
1173 protected PermissionPersistence permissionPersistence;
1174 @BeanReference(type = PhonePersistence.class)
1175 protected PhonePersistence phonePersistence;
1176 @BeanReference(type = PluginSettingPersistence.class)
1177 protected PluginSettingPersistence pluginSettingPersistence;
1178 @BeanReference(type = PortalPreferencesPersistence.class)
1179 protected PortalPreferencesPersistence portalPreferencesPersistence;
1180 @BeanReference(type = PortletPersistence.class)
1181 protected PortletPersistence portletPersistence;
1182 @BeanReference(type = PortletItemPersistence.class)
1183 protected PortletItemPersistence portletItemPersistence;
1184 @BeanReference(type = PortletPreferencesPersistence.class)
1185 protected PortletPreferencesPersistence portletPreferencesPersistence;
1186 @BeanReference(type = RegionPersistence.class)
1187 protected RegionPersistence regionPersistence;
1188 @BeanReference(type = ReleasePersistence.class)
1189 protected ReleasePersistence releasePersistence;
1190 @BeanReference(type = RepositoryPersistence.class)
1191 protected RepositoryPersistence repositoryPersistence;
1192 @BeanReference(type = RepositoryEntryPersistence.class)
1193 protected RepositoryEntryPersistence repositoryEntryPersistence;
1194 @BeanReference(type = ResourcePersistence.class)
1195 protected ResourcePersistence resourcePersistence;
1196 @BeanReference(type = ResourceActionPersistence.class)
1197 protected ResourceActionPersistence resourceActionPersistence;
1198 @BeanReference(type = ResourceBlockPersistence.class)
1199 protected ResourceBlockPersistence resourceBlockPersistence;
1200 @BeanReference(type = ResourceBlockPermissionPersistence.class)
1201 protected ResourceBlockPermissionPersistence resourceBlockPermissionPersistence;
1202 @BeanReference(type = ResourceCodePersistence.class)
1203 protected ResourceCodePersistence resourceCodePersistence;
1204 @BeanReference(type = ResourcePermissionPersistence.class)
1205 protected ResourcePermissionPersistence resourcePermissionPersistence;
1206 @BeanReference(type = ResourceTypePermissionPersistence.class)
1207 protected ResourceTypePermissionPersistence resourceTypePermissionPersistence;
1208 @BeanReference(type = RolePersistence.class)
1209 protected RolePersistence rolePersistence;
1210 @BeanReference(type = ServiceComponentPersistence.class)
1211 protected ServiceComponentPersistence serviceComponentPersistence;
1212 @BeanReference(type = ShardPersistence.class)
1213 protected ShardPersistence shardPersistence;
1214 @BeanReference(type = SubscriptionPersistence.class)
1215 protected SubscriptionPersistence subscriptionPersistence;
1216 @BeanReference(type = TeamPersistence.class)
1217 protected TeamPersistence teamPersistence;
1218 @BeanReference(type = TicketPersistence.class)
1219 protected TicketPersistence ticketPersistence;
1220 @BeanReference(type = UserPersistence.class)
1221 protected UserPersistence userPersistence;
1222 @BeanReference(type = UserGroupPersistence.class)
1223 protected UserGroupPersistence userGroupPersistence;
1224 @BeanReference(type = UserGroupGroupRolePersistence.class)
1225 protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1226 @BeanReference(type = UserGroupRolePersistence.class)
1227 protected UserGroupRolePersistence userGroupRolePersistence;
1228 @BeanReference(type = UserIdMapperPersistence.class)
1229 protected UserIdMapperPersistence userIdMapperPersistence;
1230 @BeanReference(type = UserNotificationEventPersistence.class)
1231 protected UserNotificationEventPersistence userNotificationEventPersistence;
1232 @BeanReference(type = UserTrackerPersistence.class)
1233 protected UserTrackerPersistence userTrackerPersistence;
1234 @BeanReference(type = UserTrackerPathPersistence.class)
1235 protected UserTrackerPathPersistence userTrackerPathPersistence;
1236 @BeanReference(type = VirtualHostPersistence.class)
1237 protected VirtualHostPersistence virtualHostPersistence;
1238 @BeanReference(type = WebDAVPropsPersistence.class)
1239 protected WebDAVPropsPersistence webDAVPropsPersistence;
1240 @BeanReference(type = WebsitePersistence.class)
1241 protected WebsitePersistence websitePersistence;
1242 @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
1243 protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
1244 @BeanReference(type = WorkflowInstanceLinkPersistence.class)
1245 protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
1246 private static final String _SQL_SELECT_LISTTYPE = "SELECT listType FROM ListType listType";
1247 private static final String _SQL_SELECT_LISTTYPE_WHERE = "SELECT listType FROM ListType listType WHERE ";
1248 private static final String _SQL_COUNT_LISTTYPE = "SELECT COUNT(listType) FROM ListType listType";
1249 private static final String _SQL_COUNT_LISTTYPE_WHERE = "SELECT COUNT(listType) FROM ListType listType WHERE ";
1250 private static final String _FINDER_COLUMN_TYPE_TYPE_1 = "listType.type IS NULL";
1251 private static final String _FINDER_COLUMN_TYPE_TYPE_2 = "listType.type = ?";
1252 private static final String _FINDER_COLUMN_TYPE_TYPE_3 = "(listType.type IS NULL OR listType.type = ?)";
1253 private static final String _ORDER_BY_ENTITY_ALIAS = "listType.";
1254 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ListType exists with the primary key ";
1255 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ListType exists with the key {";
1256 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1257 private static Log _log = LogFactoryUtil.getLog(ListTypePersistenceImpl.class);
1258 private static ListType _nullListType = new ListTypeImpl() {
1259 @Override
1260 public Object clone() {
1261 return this;
1262 }
1263
1264 @Override
1265 public CacheModel<ListType> toCacheModel() {
1266 return _nullListTypeCacheModel;
1267 }
1268 };
1269
1270 private static CacheModel<ListType> _nullListTypeCacheModel = new CacheModel<ListType>() {
1271 public ListType toEntityModel() {
1272 return _nullListType;
1273 }
1274 };
1275 }