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.model.CacheModel;
038 import com.liferay.portal.model.ListType;
039 import com.liferay.portal.model.ModelListener;
040 import com.liferay.portal.model.impl.ListTypeImpl;
041 import com.liferay.portal.model.impl.ListTypeModelImpl;
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
062 public class ListTypePersistenceImpl extends BasePersistenceImpl<ListType>
063 implements ListTypePersistence {
064
069 public static final String FINDER_CLASS_NAME_ENTITY = ListTypeImpl.class.getName();
070 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
071 ".List1";
072 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
073 ".List2";
074 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_TYPE = new FinderPath(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
075 ListTypeModelImpl.FINDER_CACHE_ENABLED, ListTypeImpl.class,
076 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByType",
077 new String[] {
078 String.class.getName(),
079
080 "java.lang.Integer", "java.lang.Integer",
081 "com.liferay.portal.kernel.util.OrderByComparator"
082 });
083 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE = new FinderPath(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
084 ListTypeModelImpl.FINDER_CACHE_ENABLED, ListTypeImpl.class,
085 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByType",
086 new String[] { String.class.getName() },
087 ListTypeModelImpl.TYPE_COLUMN_BITMASK);
088 public static final FinderPath FINDER_PATH_COUNT_BY_TYPE = new FinderPath(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
089 ListTypeModelImpl.FINDER_CACHE_ENABLED, Long.class,
090 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByType",
091 new String[] { String.class.getName() });
092 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
093 ListTypeModelImpl.FINDER_CACHE_ENABLED, ListTypeImpl.class,
094 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
095 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
096 ListTypeModelImpl.FINDER_CACHE_ENABLED, ListTypeImpl.class,
097 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
098 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
099 ListTypeModelImpl.FINDER_CACHE_ENABLED, Long.class,
100 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
101
102
107 public void cacheResult(ListType listType) {
108 EntityCacheUtil.putResult(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
109 ListTypeImpl.class, listType.getPrimaryKey(), listType);
110
111 listType.resetOriginalValues();
112 }
113
114
119 public void cacheResult(List<ListType> listTypes) {
120 for (ListType listType : listTypes) {
121 if (EntityCacheUtil.getResult(
122 ListTypeModelImpl.ENTITY_CACHE_ENABLED,
123 ListTypeImpl.class, listType.getPrimaryKey()) == null) {
124 cacheResult(listType);
125 }
126 else {
127 listType.resetOriginalValues();
128 }
129 }
130 }
131
132
139 @Override
140 public void clearCache() {
141 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
142 CacheRegistryUtil.clear(ListTypeImpl.class.getName());
143 }
144
145 EntityCacheUtil.clearCache(ListTypeImpl.class.getName());
146
147 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
148 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
149 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
150 }
151
152
159 @Override
160 public void clearCache(ListType listType) {
161 EntityCacheUtil.removeResult(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
162 ListTypeImpl.class, listType.getPrimaryKey());
163
164 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
165 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
166 }
167
168
174 public ListType create(int listTypeId) {
175 ListType listType = new ListTypeImpl();
176
177 listType.setNew(true);
178 listType.setPrimaryKey(listTypeId);
179
180 return listType;
181 }
182
183
191 @Override
192 public ListType remove(Serializable primaryKey)
193 throws NoSuchModelException, SystemException {
194 return remove(((Integer)primaryKey).intValue());
195 }
196
197
205 public ListType remove(int listTypeId)
206 throws NoSuchListTypeException, SystemException {
207 Session session = null;
208
209 try {
210 session = openSession();
211
212 ListType listType = (ListType)session.get(ListTypeImpl.class,
213 Integer.valueOf(listTypeId));
214
215 if (listType == null) {
216 if (_log.isWarnEnabled()) {
217 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + listTypeId);
218 }
219
220 throw new NoSuchListTypeException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
221 listTypeId);
222 }
223
224 return listTypePersistence.remove(listType);
225 }
226 catch (NoSuchListTypeException nsee) {
227 throw nsee;
228 }
229 catch (Exception e) {
230 throw processException(e);
231 }
232 finally {
233 closeSession(session);
234 }
235 }
236
237
244 @Override
245 public ListType remove(ListType listType) throws SystemException {
246 return super.remove(listType);
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 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
268 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
269
270 EntityCacheUtil.removeResult(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
271 ListTypeImpl.class, listType.getPrimaryKey());
272
273 return listType;
274 }
275
276 @Override
277 public ListType updateImpl(com.liferay.portal.model.ListType listType,
278 boolean merge) throws SystemException {
279 listType = toUnwrappedModel(listType);
280
281 boolean isNew = listType.isNew();
282
283 ListTypeModelImpl listTypeModelImpl = (ListTypeModelImpl)listType;
284
285 Session session = null;
286
287 try {
288 session = openSession();
289
290 BatchSessionUtil.update(session, listType, merge);
291
292 listType.setNew(false);
293 }
294 catch (Exception e) {
295 throw processException(e);
296 }
297 finally {
298 closeSession(session);
299 }
300
301 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
302
303 if (isNew || !ListTypeModelImpl.COLUMN_BITMASK_ENABLED) {
304 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
305 }
306
307 else {
308 if ((listTypeModelImpl.getColumnBitmask() &
309 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE.getColumnBitmask()) != 0) {
310 Object[] args = new Object[] { listTypeModelImpl.getOriginalType() };
311
312 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TYPE, args);
313 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE,
314 args);
315
316 args = new Object[] { listTypeModelImpl.getType() };
317
318 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TYPE, args);
319 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE,
320 args);
321 }
322 }
323
324 EntityCacheUtil.putResult(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
325 ListTypeImpl.class, listType.getPrimaryKey(), listType);
326
327 return listType;
328 }
329
330 protected ListType toUnwrappedModel(ListType listType) {
331 if (listType instanceof ListTypeImpl) {
332 return listType;
333 }
334
335 ListTypeImpl listTypeImpl = new ListTypeImpl();
336
337 listTypeImpl.setNew(listType.isNew());
338 listTypeImpl.setPrimaryKey(listType.getPrimaryKey());
339
340 listTypeImpl.setListTypeId(listType.getListTypeId());
341 listTypeImpl.setName(listType.getName());
342 listTypeImpl.setType(listType.getType());
343
344 return listTypeImpl;
345 }
346
347
355 @Override
356 public ListType findByPrimaryKey(Serializable primaryKey)
357 throws NoSuchModelException, SystemException {
358 return findByPrimaryKey(((Integer)primaryKey).intValue());
359 }
360
361
369 public ListType findByPrimaryKey(int listTypeId)
370 throws NoSuchListTypeException, SystemException {
371 ListType listType = fetchByPrimaryKey(listTypeId);
372
373 if (listType == null) {
374 if (_log.isWarnEnabled()) {
375 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + listTypeId);
376 }
377
378 throw new NoSuchListTypeException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
379 listTypeId);
380 }
381
382 return listType;
383 }
384
385
392 @Override
393 public ListType fetchByPrimaryKey(Serializable primaryKey)
394 throws SystemException {
395 return fetchByPrimaryKey(((Integer)primaryKey).intValue());
396 }
397
398
405 public ListType fetchByPrimaryKey(int listTypeId) throws SystemException {
406 ListType listType = (ListType)EntityCacheUtil.getResult(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
407 ListTypeImpl.class, listTypeId);
408
409 if (listType == _nullListType) {
410 return null;
411 }
412
413 if (listType == null) {
414 Session session = null;
415
416 boolean hasException = false;
417
418 try {
419 session = openSession();
420
421 listType = (ListType)session.get(ListTypeImpl.class,
422 Integer.valueOf(listTypeId));
423 }
424 catch (Exception e) {
425 hasException = true;
426
427 throw processException(e);
428 }
429 finally {
430 if (listType != null) {
431 cacheResult(listType);
432 }
433 else if (!hasException) {
434 EntityCacheUtil.putResult(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
435 ListTypeImpl.class, listTypeId, _nullListType);
436 }
437
438 closeSession(session);
439 }
440 }
441
442 return listType;
443 }
444
445
452 public List<ListType> findByType(String type) throws SystemException {
453 return findByType(type, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
454 }
455
456
469 public List<ListType> findByType(String type, int start, int end)
470 throws SystemException {
471 return findByType(type, start, end, null);
472 }
473
474
488 public List<ListType> findByType(String type, int start, int end,
489 OrderByComparator orderByComparator) throws SystemException {
490 FinderPath finderPath = null;
491 Object[] finderArgs = null;
492
493 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
494 (orderByComparator == null)) {
495 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE;
496 finderArgs = new Object[] { type };
497 }
498 else {
499 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_TYPE;
500 finderArgs = new Object[] { type, start, end, orderByComparator };
501 }
502
503 List<ListType> list = (List<ListType>)FinderCacheUtil.getResult(finderPath,
504 finderArgs, this);
505
506 if (list == null) {
507 StringBundler query = null;
508
509 if (orderByComparator != null) {
510 query = new StringBundler(3 +
511 (orderByComparator.getOrderByFields().length * 3));
512 }
513 else {
514 query = new StringBundler(3);
515 }
516
517 query.append(_SQL_SELECT_LISTTYPE_WHERE);
518
519 if (type == null) {
520 query.append(_FINDER_COLUMN_TYPE_TYPE_1);
521 }
522 else {
523 if (type.equals(StringPool.BLANK)) {
524 query.append(_FINDER_COLUMN_TYPE_TYPE_3);
525 }
526 else {
527 query.append(_FINDER_COLUMN_TYPE_TYPE_2);
528 }
529 }
530
531 if (orderByComparator != null) {
532 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
533 orderByComparator);
534 }
535
536 else {
537 query.append(ListTypeModelImpl.ORDER_BY_JPQL);
538 }
539
540 String sql = query.toString();
541
542 Session session = null;
543
544 try {
545 session = openSession();
546
547 Query q = session.createQuery(sql);
548
549 QueryPos qPos = QueryPos.getInstance(q);
550
551 if (type != null) {
552 qPos.add(type);
553 }
554
555 list = (List<ListType>)QueryUtil.list(q, getDialect(), start,
556 end);
557 }
558 catch (Exception e) {
559 throw processException(e);
560 }
561 finally {
562 if (list == null) {
563 FinderCacheUtil.removeResult(finderPath, finderArgs);
564 }
565 else {
566 cacheResult(list);
567
568 FinderCacheUtil.putResult(finderPath, finderArgs, list);
569 }
570
571 closeSession(session);
572 }
573 }
574
575 return list;
576 }
577
578
591 public ListType findByType_First(String type,
592 OrderByComparator orderByComparator)
593 throws NoSuchListTypeException, SystemException {
594 List<ListType> list = findByType(type, 0, 1, orderByComparator);
595
596 if (list.isEmpty()) {
597 StringBundler msg = new StringBundler(4);
598
599 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
600
601 msg.append("type=");
602 msg.append(type);
603
604 msg.append(StringPool.CLOSE_CURLY_BRACE);
605
606 throw new NoSuchListTypeException(msg.toString());
607 }
608 else {
609 return list.get(0);
610 }
611 }
612
613
626 public ListType findByType_Last(String type,
627 OrderByComparator orderByComparator)
628 throws NoSuchListTypeException, SystemException {
629 int count = countByType(type);
630
631 List<ListType> list = findByType(type, count - 1, count,
632 orderByComparator);
633
634 if (list.isEmpty()) {
635 StringBundler msg = new StringBundler(4);
636
637 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
638
639 msg.append("type=");
640 msg.append(type);
641
642 msg.append(StringPool.CLOSE_CURLY_BRACE);
643
644 throw new NoSuchListTypeException(msg.toString());
645 }
646 else {
647 return list.get(0);
648 }
649 }
650
651
665 public ListType[] findByType_PrevAndNext(int listTypeId, String type,
666 OrderByComparator orderByComparator)
667 throws NoSuchListTypeException, SystemException {
668 ListType listType = findByPrimaryKey(listTypeId);
669
670 Session session = null;
671
672 try {
673 session = openSession();
674
675 ListType[] array = new ListTypeImpl[3];
676
677 array[0] = getByType_PrevAndNext(session, listType, type,
678 orderByComparator, true);
679
680 array[1] = listType;
681
682 array[2] = getByType_PrevAndNext(session, listType, type,
683 orderByComparator, false);
684
685 return array;
686 }
687 catch (Exception e) {
688 throw processException(e);
689 }
690 finally {
691 closeSession(session);
692 }
693 }
694
695 protected ListType getByType_PrevAndNext(Session session,
696 ListType listType, String type, OrderByComparator orderByComparator,
697 boolean previous) {
698 StringBundler query = null;
699
700 if (orderByComparator != null) {
701 query = new StringBundler(6 +
702 (orderByComparator.getOrderByFields().length * 6));
703 }
704 else {
705 query = new StringBundler(3);
706 }
707
708 query.append(_SQL_SELECT_LISTTYPE_WHERE);
709
710 if (type == null) {
711 query.append(_FINDER_COLUMN_TYPE_TYPE_1);
712 }
713 else {
714 if (type.equals(StringPool.BLANK)) {
715 query.append(_FINDER_COLUMN_TYPE_TYPE_3);
716 }
717 else {
718 query.append(_FINDER_COLUMN_TYPE_TYPE_2);
719 }
720 }
721
722 if (orderByComparator != null) {
723 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
724
725 if (orderByConditionFields.length > 0) {
726 query.append(WHERE_AND);
727 }
728
729 for (int i = 0; i < orderByConditionFields.length; i++) {
730 query.append(_ORDER_BY_ENTITY_ALIAS);
731 query.append(orderByConditionFields[i]);
732
733 if ((i + 1) < orderByConditionFields.length) {
734 if (orderByComparator.isAscending() ^ previous) {
735 query.append(WHERE_GREATER_THAN_HAS_NEXT);
736 }
737 else {
738 query.append(WHERE_LESSER_THAN_HAS_NEXT);
739 }
740 }
741 else {
742 if (orderByComparator.isAscending() ^ previous) {
743 query.append(WHERE_GREATER_THAN);
744 }
745 else {
746 query.append(WHERE_LESSER_THAN);
747 }
748 }
749 }
750
751 query.append(ORDER_BY_CLAUSE);
752
753 String[] orderByFields = orderByComparator.getOrderByFields();
754
755 for (int i = 0; i < orderByFields.length; i++) {
756 query.append(_ORDER_BY_ENTITY_ALIAS);
757 query.append(orderByFields[i]);
758
759 if ((i + 1) < orderByFields.length) {
760 if (orderByComparator.isAscending() ^ previous) {
761 query.append(ORDER_BY_ASC_HAS_NEXT);
762 }
763 else {
764 query.append(ORDER_BY_DESC_HAS_NEXT);
765 }
766 }
767 else {
768 if (orderByComparator.isAscending() ^ previous) {
769 query.append(ORDER_BY_ASC);
770 }
771 else {
772 query.append(ORDER_BY_DESC);
773 }
774 }
775 }
776 }
777
778 else {
779 query.append(ListTypeModelImpl.ORDER_BY_JPQL);
780 }
781
782 String sql = query.toString();
783
784 Query q = session.createQuery(sql);
785
786 q.setFirstResult(0);
787 q.setMaxResults(2);
788
789 QueryPos qPos = QueryPos.getInstance(q);
790
791 if (type != null) {
792 qPos.add(type);
793 }
794
795 if (orderByComparator != null) {
796 Object[] values = orderByComparator.getOrderByConditionValues(listType);
797
798 for (Object value : values) {
799 qPos.add(value);
800 }
801 }
802
803 List<ListType> list = q.list();
804
805 if (list.size() == 2) {
806 return list.get(1);
807 }
808 else {
809 return null;
810 }
811 }
812
813
819 public List<ListType> findAll() throws SystemException {
820 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
821 }
822
823
835 public List<ListType> findAll(int start, int end) throws SystemException {
836 return findAll(start, end, null);
837 }
838
839
852 public List<ListType> findAll(int start, int end,
853 OrderByComparator orderByComparator) throws SystemException {
854 FinderPath finderPath = null;
855 Object[] finderArgs = new Object[] { start, end, orderByComparator };
856
857 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
858 (orderByComparator == null)) {
859 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
860 finderArgs = FINDER_ARGS_EMPTY;
861 }
862 else {
863 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
864 finderArgs = new Object[] { start, end, orderByComparator };
865 }
866
867 List<ListType> list = (List<ListType>)FinderCacheUtil.getResult(finderPath,
868 finderArgs, this);
869
870 if (list == null) {
871 StringBundler query = null;
872 String sql = null;
873
874 if (orderByComparator != null) {
875 query = new StringBundler(2 +
876 (orderByComparator.getOrderByFields().length * 3));
877
878 query.append(_SQL_SELECT_LISTTYPE);
879
880 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
881 orderByComparator);
882
883 sql = query.toString();
884 }
885 else {
886 sql = _SQL_SELECT_LISTTYPE.concat(ListTypeModelImpl.ORDER_BY_JPQL);
887 }
888
889 Session session = null;
890
891 try {
892 session = openSession();
893
894 Query q = session.createQuery(sql);
895
896 if (orderByComparator == null) {
897 list = (List<ListType>)QueryUtil.list(q, getDialect(),
898 start, end, false);
899
900 Collections.sort(list);
901 }
902 else {
903 list = (List<ListType>)QueryUtil.list(q, getDialect(),
904 start, end);
905 }
906 }
907 catch (Exception e) {
908 throw processException(e);
909 }
910 finally {
911 if (list == null) {
912 FinderCacheUtil.removeResult(finderPath, finderArgs);
913 }
914 else {
915 cacheResult(list);
916
917 FinderCacheUtil.putResult(finderPath, finderArgs, list);
918 }
919
920 closeSession(session);
921 }
922 }
923
924 return list;
925 }
926
927
933 public void removeByType(String type) throws SystemException {
934 for (ListType listType : findByType(type)) {
935 listTypePersistence.remove(listType);
936 }
937 }
938
939
944 public void removeAll() throws SystemException {
945 for (ListType listType : findAll()) {
946 listTypePersistence.remove(listType);
947 }
948 }
949
950
957 public int countByType(String type) throws SystemException {
958 Object[] finderArgs = new Object[] { type };
959
960 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_TYPE,
961 finderArgs, this);
962
963 if (count == null) {
964 StringBundler query = new StringBundler(2);
965
966 query.append(_SQL_COUNT_LISTTYPE_WHERE);
967
968 if (type == null) {
969 query.append(_FINDER_COLUMN_TYPE_TYPE_1);
970 }
971 else {
972 if (type.equals(StringPool.BLANK)) {
973 query.append(_FINDER_COLUMN_TYPE_TYPE_3);
974 }
975 else {
976 query.append(_FINDER_COLUMN_TYPE_TYPE_2);
977 }
978 }
979
980 String sql = query.toString();
981
982 Session session = null;
983
984 try {
985 session = openSession();
986
987 Query q = session.createQuery(sql);
988
989 QueryPos qPos = QueryPos.getInstance(q);
990
991 if (type != null) {
992 qPos.add(type);
993 }
994
995 count = (Long)q.uniqueResult();
996 }
997 catch (Exception e) {
998 throw processException(e);
999 }
1000 finally {
1001 if (count == null) {
1002 count = Long.valueOf(0);
1003 }
1004
1005 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_TYPE,
1006 finderArgs, count);
1007
1008 closeSession(session);
1009 }
1010 }
1011
1012 return count.intValue();
1013 }
1014
1015
1021 public int countAll() throws SystemException {
1022 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1023 FINDER_ARGS_EMPTY, this);
1024
1025 if (count == null) {
1026 Session session = null;
1027
1028 try {
1029 session = openSession();
1030
1031 Query q = session.createQuery(_SQL_COUNT_LISTTYPE);
1032
1033 count = (Long)q.uniqueResult();
1034 }
1035 catch (Exception e) {
1036 throw processException(e);
1037 }
1038 finally {
1039 if (count == null) {
1040 count = Long.valueOf(0);
1041 }
1042
1043 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1044 FINDER_ARGS_EMPTY, count);
1045
1046 closeSession(session);
1047 }
1048 }
1049
1050 return count.intValue();
1051 }
1052
1053
1056 public void afterPropertiesSet() {
1057 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1058 com.liferay.portal.util.PropsUtil.get(
1059 "value.object.listener.com.liferay.portal.model.ListType")));
1060
1061 if (listenerClassNames.length > 0) {
1062 try {
1063 List<ModelListener<ListType>> listenersList = new ArrayList<ModelListener<ListType>>();
1064
1065 for (String listenerClassName : listenerClassNames) {
1066 listenersList.add((ModelListener<ListType>)InstanceFactory.newInstance(
1067 listenerClassName));
1068 }
1069
1070 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1071 }
1072 catch (Exception e) {
1073 _log.error(e);
1074 }
1075 }
1076 }
1077
1078 public void destroy() {
1079 EntityCacheUtil.removeCache(ListTypeImpl.class.getName());
1080 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1081 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1082 }
1083
1084 @BeanReference(type = AccountPersistence.class)
1085 protected AccountPersistence accountPersistence;
1086 @BeanReference(type = AddressPersistence.class)
1087 protected AddressPersistence addressPersistence;
1088 @BeanReference(type = BrowserTrackerPersistence.class)
1089 protected BrowserTrackerPersistence browserTrackerPersistence;
1090 @BeanReference(type = ClassNamePersistence.class)
1091 protected ClassNamePersistence classNamePersistence;
1092 @BeanReference(type = ClusterGroupPersistence.class)
1093 protected ClusterGroupPersistence clusterGroupPersistence;
1094 @BeanReference(type = CompanyPersistence.class)
1095 protected CompanyPersistence companyPersistence;
1096 @BeanReference(type = ContactPersistence.class)
1097 protected ContactPersistence contactPersistence;
1098 @BeanReference(type = CountryPersistence.class)
1099 protected CountryPersistence countryPersistence;
1100 @BeanReference(type = EmailAddressPersistence.class)
1101 protected EmailAddressPersistence emailAddressPersistence;
1102 @BeanReference(type = GroupPersistence.class)
1103 protected GroupPersistence groupPersistence;
1104 @BeanReference(type = ImagePersistence.class)
1105 protected ImagePersistence imagePersistence;
1106 @BeanReference(type = LayoutPersistence.class)
1107 protected LayoutPersistence layoutPersistence;
1108 @BeanReference(type = LayoutBranchPersistence.class)
1109 protected LayoutBranchPersistence layoutBranchPersistence;
1110 @BeanReference(type = LayoutPrototypePersistence.class)
1111 protected LayoutPrototypePersistence layoutPrototypePersistence;
1112 @BeanReference(type = LayoutRevisionPersistence.class)
1113 protected LayoutRevisionPersistence layoutRevisionPersistence;
1114 @BeanReference(type = LayoutSetPersistence.class)
1115 protected LayoutSetPersistence layoutSetPersistence;
1116 @BeanReference(type = LayoutSetBranchPersistence.class)
1117 protected LayoutSetBranchPersistence layoutSetBranchPersistence;
1118 @BeanReference(type = LayoutSetPrototypePersistence.class)
1119 protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
1120 @BeanReference(type = ListTypePersistence.class)
1121 protected ListTypePersistence listTypePersistence;
1122 @BeanReference(type = LockPersistence.class)
1123 protected LockPersistence lockPersistence;
1124 @BeanReference(type = MembershipRequestPersistence.class)
1125 protected MembershipRequestPersistence membershipRequestPersistence;
1126 @BeanReference(type = OrganizationPersistence.class)
1127 protected OrganizationPersistence organizationPersistence;
1128 @BeanReference(type = OrgGroupPermissionPersistence.class)
1129 protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1130 @BeanReference(type = OrgGroupRolePersistence.class)
1131 protected OrgGroupRolePersistence orgGroupRolePersistence;
1132 @BeanReference(type = OrgLaborPersistence.class)
1133 protected OrgLaborPersistence orgLaborPersistence;
1134 @BeanReference(type = PasswordPolicyPersistence.class)
1135 protected PasswordPolicyPersistence passwordPolicyPersistence;
1136 @BeanReference(type = PasswordPolicyRelPersistence.class)
1137 protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1138 @BeanReference(type = PasswordTrackerPersistence.class)
1139 protected PasswordTrackerPersistence passwordTrackerPersistence;
1140 @BeanReference(type = PermissionPersistence.class)
1141 protected PermissionPersistence permissionPersistence;
1142 @BeanReference(type = PhonePersistence.class)
1143 protected PhonePersistence phonePersistence;
1144 @BeanReference(type = PluginSettingPersistence.class)
1145 protected PluginSettingPersistence pluginSettingPersistence;
1146 @BeanReference(type = PortalPreferencesPersistence.class)
1147 protected PortalPreferencesPersistence portalPreferencesPersistence;
1148 @BeanReference(type = PortletPersistence.class)
1149 protected PortletPersistence portletPersistence;
1150 @BeanReference(type = PortletItemPersistence.class)
1151 protected PortletItemPersistence portletItemPersistence;
1152 @BeanReference(type = PortletPreferencesPersistence.class)
1153 protected PortletPreferencesPersistence portletPreferencesPersistence;
1154 @BeanReference(type = RegionPersistence.class)
1155 protected RegionPersistence regionPersistence;
1156 @BeanReference(type = ReleasePersistence.class)
1157 protected ReleasePersistence releasePersistence;
1158 @BeanReference(type = RepositoryPersistence.class)
1159 protected RepositoryPersistence repositoryPersistence;
1160 @BeanReference(type = RepositoryEntryPersistence.class)
1161 protected RepositoryEntryPersistence repositoryEntryPersistence;
1162 @BeanReference(type = ResourcePersistence.class)
1163 protected ResourcePersistence resourcePersistence;
1164 @BeanReference(type = ResourceActionPersistence.class)
1165 protected ResourceActionPersistence resourceActionPersistence;
1166 @BeanReference(type = ResourceBlockPersistence.class)
1167 protected ResourceBlockPersistence resourceBlockPersistence;
1168 @BeanReference(type = ResourceBlockPermissionPersistence.class)
1169 protected ResourceBlockPermissionPersistence resourceBlockPermissionPersistence;
1170 @BeanReference(type = ResourceCodePersistence.class)
1171 protected ResourceCodePersistence resourceCodePersistence;
1172 @BeanReference(type = ResourcePermissionPersistence.class)
1173 protected ResourcePermissionPersistence resourcePermissionPersistence;
1174 @BeanReference(type = ResourceTypePermissionPersistence.class)
1175 protected ResourceTypePermissionPersistence resourceTypePermissionPersistence;
1176 @BeanReference(type = RolePersistence.class)
1177 protected RolePersistence rolePersistence;
1178 @BeanReference(type = ServiceComponentPersistence.class)
1179 protected ServiceComponentPersistence serviceComponentPersistence;
1180 @BeanReference(type = ShardPersistence.class)
1181 protected ShardPersistence shardPersistence;
1182 @BeanReference(type = SubscriptionPersistence.class)
1183 protected SubscriptionPersistence subscriptionPersistence;
1184 @BeanReference(type = TeamPersistence.class)
1185 protected TeamPersistence teamPersistence;
1186 @BeanReference(type = TicketPersistence.class)
1187 protected TicketPersistence ticketPersistence;
1188 @BeanReference(type = UserPersistence.class)
1189 protected UserPersistence userPersistence;
1190 @BeanReference(type = UserGroupPersistence.class)
1191 protected UserGroupPersistence userGroupPersistence;
1192 @BeanReference(type = UserGroupGroupRolePersistence.class)
1193 protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1194 @BeanReference(type = UserGroupRolePersistence.class)
1195 protected UserGroupRolePersistence userGroupRolePersistence;
1196 @BeanReference(type = UserIdMapperPersistence.class)
1197 protected UserIdMapperPersistence userIdMapperPersistence;
1198 @BeanReference(type = UserNotificationEventPersistence.class)
1199 protected UserNotificationEventPersistence userNotificationEventPersistence;
1200 @BeanReference(type = UserTrackerPersistence.class)
1201 protected UserTrackerPersistence userTrackerPersistence;
1202 @BeanReference(type = UserTrackerPathPersistence.class)
1203 protected UserTrackerPathPersistence userTrackerPathPersistence;
1204 @BeanReference(type = VirtualHostPersistence.class)
1205 protected VirtualHostPersistence virtualHostPersistence;
1206 @BeanReference(type = WebDAVPropsPersistence.class)
1207 protected WebDAVPropsPersistence webDAVPropsPersistence;
1208 @BeanReference(type = WebsitePersistence.class)
1209 protected WebsitePersistence websitePersistence;
1210 @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
1211 protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
1212 @BeanReference(type = WorkflowInstanceLinkPersistence.class)
1213 protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
1214 private static final String _SQL_SELECT_LISTTYPE = "SELECT listType FROM ListType listType";
1215 private static final String _SQL_SELECT_LISTTYPE_WHERE = "SELECT listType FROM ListType listType WHERE ";
1216 private static final String _SQL_COUNT_LISTTYPE = "SELECT COUNT(listType) FROM ListType listType";
1217 private static final String _SQL_COUNT_LISTTYPE_WHERE = "SELECT COUNT(listType) FROM ListType listType WHERE ";
1218 private static final String _FINDER_COLUMN_TYPE_TYPE_1 = "listType.type IS NULL";
1219 private static final String _FINDER_COLUMN_TYPE_TYPE_2 = "listType.type = ?";
1220 private static final String _FINDER_COLUMN_TYPE_TYPE_3 = "(listType.type IS NULL OR listType.type = ?)";
1221 private static final String _ORDER_BY_ENTITY_ALIAS = "listType.";
1222 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ListType exists with the primary key ";
1223 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ListType exists with the key {";
1224 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1225 private static Log _log = LogFactoryUtil.getLog(ListTypePersistenceImpl.class);
1226 private static ListType _nullListType = new ListTypeImpl() {
1227 @Override
1228 public Object clone() {
1229 return this;
1230 }
1231
1232 @Override
1233 public CacheModel<ListType> toCacheModel() {
1234 return _nullListTypeCacheModel;
1235 }
1236 };
1237
1238 private static CacheModel<ListType> _nullListTypeCacheModel = new CacheModel<ListType>() {
1239 public ListType toEntityModel() {
1240 return _nullListType;
1241 }
1242 };
1243 }