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 @Override
169 public void clearCache(List<ListType> listTypes) {
170 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
171 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
172
173 for (ListType listType : listTypes) {
174 EntityCacheUtil.removeResult(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
175 ListTypeImpl.class, listType.getPrimaryKey());
176 }
177 }
178
179
185 public ListType create(int listTypeId) {
186 ListType listType = new ListTypeImpl();
187
188 listType.setNew(true);
189 listType.setPrimaryKey(listTypeId);
190
191 return listType;
192 }
193
194
202 public ListType remove(int listTypeId)
203 throws NoSuchListTypeException, SystemException {
204 return remove(Integer.valueOf(listTypeId));
205 }
206
207
215 @Override
216 public ListType remove(Serializable primaryKey)
217 throws NoSuchListTypeException, SystemException {
218 Session session = null;
219
220 try {
221 session = openSession();
222
223 ListType listType = (ListType)session.get(ListTypeImpl.class,
224 primaryKey);
225
226 if (listType == null) {
227 if (_log.isWarnEnabled()) {
228 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
229 }
230
231 throw new NoSuchListTypeException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
232 primaryKey);
233 }
234
235 return remove(listType);
236 }
237 catch (NoSuchListTypeException nsee) {
238 throw nsee;
239 }
240 catch (Exception e) {
241 throw processException(e);
242 }
243 finally {
244 closeSession(session);
245 }
246 }
247
248 @Override
249 protected ListType removeImpl(ListType listType) throws SystemException {
250 listType = toUnwrappedModel(listType);
251
252 Session session = null;
253
254 try {
255 session = openSession();
256
257 BatchSessionUtil.delete(session, listType);
258 }
259 catch (Exception e) {
260 throw processException(e);
261 }
262 finally {
263 closeSession(session);
264 }
265
266 clearCache(listType);
267
268 return listType;
269 }
270
271 @Override
272 public ListType updateImpl(com.liferay.portal.model.ListType listType,
273 boolean merge) throws SystemException {
274 listType = toUnwrappedModel(listType);
275
276 boolean isNew = listType.isNew();
277
278 ListTypeModelImpl listTypeModelImpl = (ListTypeModelImpl)listType;
279
280 Session session = null;
281
282 try {
283 session = openSession();
284
285 BatchSessionUtil.update(session, listType, merge);
286
287 listType.setNew(false);
288 }
289 catch (Exception e) {
290 throw processException(e);
291 }
292 finally {
293 closeSession(session);
294 }
295
296 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
297
298 if (isNew || !ListTypeModelImpl.COLUMN_BITMASK_ENABLED) {
299 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
300 }
301
302 else {
303 if ((listTypeModelImpl.getColumnBitmask() &
304 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE.getColumnBitmask()) != 0) {
305 Object[] args = new Object[] { listTypeModelImpl.getOriginalType() };
306
307 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TYPE, args);
308 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE,
309 args);
310
311 args = new Object[] { listTypeModelImpl.getType() };
312
313 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TYPE, args);
314 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE,
315 args);
316 }
317 }
318
319 EntityCacheUtil.putResult(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
320 ListTypeImpl.class, listType.getPrimaryKey(), listType);
321
322 return listType;
323 }
324
325 protected ListType toUnwrappedModel(ListType listType) {
326 if (listType instanceof ListTypeImpl) {
327 return listType;
328 }
329
330 ListTypeImpl listTypeImpl = new ListTypeImpl();
331
332 listTypeImpl.setNew(listType.isNew());
333 listTypeImpl.setPrimaryKey(listType.getPrimaryKey());
334
335 listTypeImpl.setListTypeId(listType.getListTypeId());
336 listTypeImpl.setName(listType.getName());
337 listTypeImpl.setType(listType.getType());
338
339 return listTypeImpl;
340 }
341
342
350 @Override
351 public ListType findByPrimaryKey(Serializable primaryKey)
352 throws NoSuchModelException, SystemException {
353 return findByPrimaryKey(((Integer)primaryKey).intValue());
354 }
355
356
364 public ListType findByPrimaryKey(int listTypeId)
365 throws NoSuchListTypeException, SystemException {
366 ListType listType = fetchByPrimaryKey(listTypeId);
367
368 if (listType == null) {
369 if (_log.isWarnEnabled()) {
370 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + listTypeId);
371 }
372
373 throw new NoSuchListTypeException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
374 listTypeId);
375 }
376
377 return listType;
378 }
379
380
387 @Override
388 public ListType fetchByPrimaryKey(Serializable primaryKey)
389 throws SystemException {
390 return fetchByPrimaryKey(((Integer)primaryKey).intValue());
391 }
392
393
400 public ListType fetchByPrimaryKey(int listTypeId) throws SystemException {
401 ListType listType = (ListType)EntityCacheUtil.getResult(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
402 ListTypeImpl.class, listTypeId);
403
404 if (listType == _nullListType) {
405 return null;
406 }
407
408 if (listType == null) {
409 Session session = null;
410
411 boolean hasException = false;
412
413 try {
414 session = openSession();
415
416 listType = (ListType)session.get(ListTypeImpl.class,
417 Integer.valueOf(listTypeId));
418 }
419 catch (Exception e) {
420 hasException = true;
421
422 throw processException(e);
423 }
424 finally {
425 if (listType != null) {
426 cacheResult(listType);
427 }
428 else if (!hasException) {
429 EntityCacheUtil.putResult(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
430 ListTypeImpl.class, listTypeId, _nullListType);
431 }
432
433 closeSession(session);
434 }
435 }
436
437 return listType;
438 }
439
440
447 public List<ListType> findByType(String type) throws SystemException {
448 return findByType(type, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
449 }
450
451
464 public List<ListType> findByType(String type, int start, int end)
465 throws SystemException {
466 return findByType(type, start, end, null);
467 }
468
469
483 public List<ListType> findByType(String type, int start, int end,
484 OrderByComparator orderByComparator) throws SystemException {
485 FinderPath finderPath = null;
486 Object[] finderArgs = null;
487
488 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
489 (orderByComparator == null)) {
490 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE;
491 finderArgs = new Object[] { type };
492 }
493 else {
494 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_TYPE;
495 finderArgs = new Object[] { type, start, end, orderByComparator };
496 }
497
498 List<ListType> list = (List<ListType>)FinderCacheUtil.getResult(finderPath,
499 finderArgs, this);
500
501 if (list == null) {
502 StringBundler query = null;
503
504 if (orderByComparator != null) {
505 query = new StringBundler(3 +
506 (orderByComparator.getOrderByFields().length * 3));
507 }
508 else {
509 query = new StringBundler(3);
510 }
511
512 query.append(_SQL_SELECT_LISTTYPE_WHERE);
513
514 if (type == null) {
515 query.append(_FINDER_COLUMN_TYPE_TYPE_1);
516 }
517 else {
518 if (type.equals(StringPool.BLANK)) {
519 query.append(_FINDER_COLUMN_TYPE_TYPE_3);
520 }
521 else {
522 query.append(_FINDER_COLUMN_TYPE_TYPE_2);
523 }
524 }
525
526 if (orderByComparator != null) {
527 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
528 orderByComparator);
529 }
530
531 else {
532 query.append(ListTypeModelImpl.ORDER_BY_JPQL);
533 }
534
535 String sql = query.toString();
536
537 Session session = null;
538
539 try {
540 session = openSession();
541
542 Query q = session.createQuery(sql);
543
544 QueryPos qPos = QueryPos.getInstance(q);
545
546 if (type != null) {
547 qPos.add(type);
548 }
549
550 list = (List<ListType>)QueryUtil.list(q, getDialect(), start,
551 end);
552 }
553 catch (Exception e) {
554 throw processException(e);
555 }
556 finally {
557 if (list == null) {
558 FinderCacheUtil.removeResult(finderPath, finderArgs);
559 }
560 else {
561 cacheResult(list);
562
563 FinderCacheUtil.putResult(finderPath, finderArgs, list);
564 }
565
566 closeSession(session);
567 }
568 }
569
570 return list;
571 }
572
573
586 public ListType findByType_First(String type,
587 OrderByComparator orderByComparator)
588 throws NoSuchListTypeException, SystemException {
589 List<ListType> list = findByType(type, 0, 1, orderByComparator);
590
591 if (list.isEmpty()) {
592 StringBundler msg = new StringBundler(4);
593
594 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
595
596 msg.append("type=");
597 msg.append(type);
598
599 msg.append(StringPool.CLOSE_CURLY_BRACE);
600
601 throw new NoSuchListTypeException(msg.toString());
602 }
603 else {
604 return list.get(0);
605 }
606 }
607
608
621 public ListType findByType_Last(String type,
622 OrderByComparator orderByComparator)
623 throws NoSuchListTypeException, SystemException {
624 int count = countByType(type);
625
626 List<ListType> list = findByType(type, count - 1, count,
627 orderByComparator);
628
629 if (list.isEmpty()) {
630 StringBundler msg = new StringBundler(4);
631
632 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
633
634 msg.append("type=");
635 msg.append(type);
636
637 msg.append(StringPool.CLOSE_CURLY_BRACE);
638
639 throw new NoSuchListTypeException(msg.toString());
640 }
641 else {
642 return list.get(0);
643 }
644 }
645
646
660 public ListType[] findByType_PrevAndNext(int listTypeId, String type,
661 OrderByComparator orderByComparator)
662 throws NoSuchListTypeException, SystemException {
663 ListType listType = findByPrimaryKey(listTypeId);
664
665 Session session = null;
666
667 try {
668 session = openSession();
669
670 ListType[] array = new ListTypeImpl[3];
671
672 array[0] = getByType_PrevAndNext(session, listType, type,
673 orderByComparator, true);
674
675 array[1] = listType;
676
677 array[2] = getByType_PrevAndNext(session, listType, type,
678 orderByComparator, false);
679
680 return array;
681 }
682 catch (Exception e) {
683 throw processException(e);
684 }
685 finally {
686 closeSession(session);
687 }
688 }
689
690 protected ListType getByType_PrevAndNext(Session session,
691 ListType listType, String type, OrderByComparator orderByComparator,
692 boolean previous) {
693 StringBundler query = null;
694
695 if (orderByComparator != null) {
696 query = new StringBundler(6 +
697 (orderByComparator.getOrderByFields().length * 6));
698 }
699 else {
700 query = new StringBundler(3);
701 }
702
703 query.append(_SQL_SELECT_LISTTYPE_WHERE);
704
705 if (type == null) {
706 query.append(_FINDER_COLUMN_TYPE_TYPE_1);
707 }
708 else {
709 if (type.equals(StringPool.BLANK)) {
710 query.append(_FINDER_COLUMN_TYPE_TYPE_3);
711 }
712 else {
713 query.append(_FINDER_COLUMN_TYPE_TYPE_2);
714 }
715 }
716
717 if (orderByComparator != null) {
718 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
719
720 if (orderByConditionFields.length > 0) {
721 query.append(WHERE_AND);
722 }
723
724 for (int i = 0; i < orderByConditionFields.length; i++) {
725 query.append(_ORDER_BY_ENTITY_ALIAS);
726 query.append(orderByConditionFields[i]);
727
728 if ((i + 1) < orderByConditionFields.length) {
729 if (orderByComparator.isAscending() ^ previous) {
730 query.append(WHERE_GREATER_THAN_HAS_NEXT);
731 }
732 else {
733 query.append(WHERE_LESSER_THAN_HAS_NEXT);
734 }
735 }
736 else {
737 if (orderByComparator.isAscending() ^ previous) {
738 query.append(WHERE_GREATER_THAN);
739 }
740 else {
741 query.append(WHERE_LESSER_THAN);
742 }
743 }
744 }
745
746 query.append(ORDER_BY_CLAUSE);
747
748 String[] orderByFields = orderByComparator.getOrderByFields();
749
750 for (int i = 0; i < orderByFields.length; i++) {
751 query.append(_ORDER_BY_ENTITY_ALIAS);
752 query.append(orderByFields[i]);
753
754 if ((i + 1) < orderByFields.length) {
755 if (orderByComparator.isAscending() ^ previous) {
756 query.append(ORDER_BY_ASC_HAS_NEXT);
757 }
758 else {
759 query.append(ORDER_BY_DESC_HAS_NEXT);
760 }
761 }
762 else {
763 if (orderByComparator.isAscending() ^ previous) {
764 query.append(ORDER_BY_ASC);
765 }
766 else {
767 query.append(ORDER_BY_DESC);
768 }
769 }
770 }
771 }
772
773 else {
774 query.append(ListTypeModelImpl.ORDER_BY_JPQL);
775 }
776
777 String sql = query.toString();
778
779 Query q = session.createQuery(sql);
780
781 q.setFirstResult(0);
782 q.setMaxResults(2);
783
784 QueryPos qPos = QueryPos.getInstance(q);
785
786 if (type != null) {
787 qPos.add(type);
788 }
789
790 if (orderByComparator != null) {
791 Object[] values = orderByComparator.getOrderByConditionValues(listType);
792
793 for (Object value : values) {
794 qPos.add(value);
795 }
796 }
797
798 List<ListType> list = q.list();
799
800 if (list.size() == 2) {
801 return list.get(1);
802 }
803 else {
804 return null;
805 }
806 }
807
808
814 public List<ListType> findAll() throws SystemException {
815 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
816 }
817
818
830 public List<ListType> findAll(int start, int end) throws SystemException {
831 return findAll(start, end, null);
832 }
833
834
847 public List<ListType> findAll(int start, int end,
848 OrderByComparator orderByComparator) throws SystemException {
849 FinderPath finderPath = null;
850 Object[] finderArgs = new Object[] { start, end, orderByComparator };
851
852 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
853 (orderByComparator == null)) {
854 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
855 finderArgs = FINDER_ARGS_EMPTY;
856 }
857 else {
858 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
859 finderArgs = new Object[] { start, end, orderByComparator };
860 }
861
862 List<ListType> list = (List<ListType>)FinderCacheUtil.getResult(finderPath,
863 finderArgs, this);
864
865 if (list == null) {
866 StringBundler query = null;
867 String sql = null;
868
869 if (orderByComparator != null) {
870 query = new StringBundler(2 +
871 (orderByComparator.getOrderByFields().length * 3));
872
873 query.append(_SQL_SELECT_LISTTYPE);
874
875 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
876 orderByComparator);
877
878 sql = query.toString();
879 }
880 else {
881 sql = _SQL_SELECT_LISTTYPE.concat(ListTypeModelImpl.ORDER_BY_JPQL);
882 }
883
884 Session session = null;
885
886 try {
887 session = openSession();
888
889 Query q = session.createQuery(sql);
890
891 if (orderByComparator == null) {
892 list = (List<ListType>)QueryUtil.list(q, getDialect(),
893 start, end, false);
894
895 Collections.sort(list);
896 }
897 else {
898 list = (List<ListType>)QueryUtil.list(q, getDialect(),
899 start, end);
900 }
901 }
902 catch (Exception e) {
903 throw processException(e);
904 }
905 finally {
906 if (list == null) {
907 FinderCacheUtil.removeResult(finderPath, finderArgs);
908 }
909 else {
910 cacheResult(list);
911
912 FinderCacheUtil.putResult(finderPath, finderArgs, list);
913 }
914
915 closeSession(session);
916 }
917 }
918
919 return list;
920 }
921
922
928 public void removeByType(String type) throws SystemException {
929 for (ListType listType : findByType(type)) {
930 remove(listType);
931 }
932 }
933
934
939 public void removeAll() throws SystemException {
940 for (ListType listType : findAll()) {
941 remove(listType);
942 }
943 }
944
945
952 public int countByType(String type) throws SystemException {
953 Object[] finderArgs = new Object[] { type };
954
955 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_TYPE,
956 finderArgs, this);
957
958 if (count == null) {
959 StringBundler query = new StringBundler(2);
960
961 query.append(_SQL_COUNT_LISTTYPE_WHERE);
962
963 if (type == null) {
964 query.append(_FINDER_COLUMN_TYPE_TYPE_1);
965 }
966 else {
967 if (type.equals(StringPool.BLANK)) {
968 query.append(_FINDER_COLUMN_TYPE_TYPE_3);
969 }
970 else {
971 query.append(_FINDER_COLUMN_TYPE_TYPE_2);
972 }
973 }
974
975 String sql = query.toString();
976
977 Session session = null;
978
979 try {
980 session = openSession();
981
982 Query q = session.createQuery(sql);
983
984 QueryPos qPos = QueryPos.getInstance(q);
985
986 if (type != null) {
987 qPos.add(type);
988 }
989
990 count = (Long)q.uniqueResult();
991 }
992 catch (Exception e) {
993 throw processException(e);
994 }
995 finally {
996 if (count == null) {
997 count = Long.valueOf(0);
998 }
999
1000 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_TYPE,
1001 finderArgs, count);
1002
1003 closeSession(session);
1004 }
1005 }
1006
1007 return count.intValue();
1008 }
1009
1010
1016 public int countAll() throws SystemException {
1017 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1018 FINDER_ARGS_EMPTY, this);
1019
1020 if (count == null) {
1021 Session session = null;
1022
1023 try {
1024 session = openSession();
1025
1026 Query q = session.createQuery(_SQL_COUNT_LISTTYPE);
1027
1028 count = (Long)q.uniqueResult();
1029 }
1030 catch (Exception e) {
1031 throw processException(e);
1032 }
1033 finally {
1034 if (count == null) {
1035 count = Long.valueOf(0);
1036 }
1037
1038 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1039 FINDER_ARGS_EMPTY, count);
1040
1041 closeSession(session);
1042 }
1043 }
1044
1045 return count.intValue();
1046 }
1047
1048
1051 public void afterPropertiesSet() {
1052 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1053 com.liferay.portal.util.PropsUtil.get(
1054 "value.object.listener.com.liferay.portal.model.ListType")));
1055
1056 if (listenerClassNames.length > 0) {
1057 try {
1058 List<ModelListener<ListType>> listenersList = new ArrayList<ModelListener<ListType>>();
1059
1060 for (String listenerClassName : listenerClassNames) {
1061 listenersList.add((ModelListener<ListType>)InstanceFactory.newInstance(
1062 listenerClassName));
1063 }
1064
1065 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1066 }
1067 catch (Exception e) {
1068 _log.error(e);
1069 }
1070 }
1071 }
1072
1073 public void destroy() {
1074 EntityCacheUtil.removeCache(ListTypeImpl.class.getName());
1075 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1076 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1077 }
1078
1079 @BeanReference(type = AccountPersistence.class)
1080 protected AccountPersistence accountPersistence;
1081 @BeanReference(type = AddressPersistence.class)
1082 protected AddressPersistence addressPersistence;
1083 @BeanReference(type = BrowserTrackerPersistence.class)
1084 protected BrowserTrackerPersistence browserTrackerPersistence;
1085 @BeanReference(type = ClassNamePersistence.class)
1086 protected ClassNamePersistence classNamePersistence;
1087 @BeanReference(type = ClusterGroupPersistence.class)
1088 protected ClusterGroupPersistence clusterGroupPersistence;
1089 @BeanReference(type = CompanyPersistence.class)
1090 protected CompanyPersistence companyPersistence;
1091 @BeanReference(type = ContactPersistence.class)
1092 protected ContactPersistence contactPersistence;
1093 @BeanReference(type = CountryPersistence.class)
1094 protected CountryPersistence countryPersistence;
1095 @BeanReference(type = EmailAddressPersistence.class)
1096 protected EmailAddressPersistence emailAddressPersistence;
1097 @BeanReference(type = GroupPersistence.class)
1098 protected GroupPersistence groupPersistence;
1099 @BeanReference(type = ImagePersistence.class)
1100 protected ImagePersistence imagePersistence;
1101 @BeanReference(type = LayoutPersistence.class)
1102 protected LayoutPersistence layoutPersistence;
1103 @BeanReference(type = LayoutBranchPersistence.class)
1104 protected LayoutBranchPersistence layoutBranchPersistence;
1105 @BeanReference(type = LayoutPrototypePersistence.class)
1106 protected LayoutPrototypePersistence layoutPrototypePersistence;
1107 @BeanReference(type = LayoutRevisionPersistence.class)
1108 protected LayoutRevisionPersistence layoutRevisionPersistence;
1109 @BeanReference(type = LayoutSetPersistence.class)
1110 protected LayoutSetPersistence layoutSetPersistence;
1111 @BeanReference(type = LayoutSetBranchPersistence.class)
1112 protected LayoutSetBranchPersistence layoutSetBranchPersistence;
1113 @BeanReference(type = LayoutSetPrototypePersistence.class)
1114 protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
1115 @BeanReference(type = ListTypePersistence.class)
1116 protected ListTypePersistence listTypePersistence;
1117 @BeanReference(type = LockPersistence.class)
1118 protected LockPersistence lockPersistence;
1119 @BeanReference(type = MembershipRequestPersistence.class)
1120 protected MembershipRequestPersistence membershipRequestPersistence;
1121 @BeanReference(type = OrganizationPersistence.class)
1122 protected OrganizationPersistence organizationPersistence;
1123 @BeanReference(type = OrgGroupPermissionPersistence.class)
1124 protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1125 @BeanReference(type = OrgGroupRolePersistence.class)
1126 protected OrgGroupRolePersistence orgGroupRolePersistence;
1127 @BeanReference(type = OrgLaborPersistence.class)
1128 protected OrgLaborPersistence orgLaborPersistence;
1129 @BeanReference(type = PasswordPolicyPersistence.class)
1130 protected PasswordPolicyPersistence passwordPolicyPersistence;
1131 @BeanReference(type = PasswordPolicyRelPersistence.class)
1132 protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1133 @BeanReference(type = PasswordTrackerPersistence.class)
1134 protected PasswordTrackerPersistence passwordTrackerPersistence;
1135 @BeanReference(type = PermissionPersistence.class)
1136 protected PermissionPersistence permissionPersistence;
1137 @BeanReference(type = PhonePersistence.class)
1138 protected PhonePersistence phonePersistence;
1139 @BeanReference(type = PluginSettingPersistence.class)
1140 protected PluginSettingPersistence pluginSettingPersistence;
1141 @BeanReference(type = PortalPreferencesPersistence.class)
1142 protected PortalPreferencesPersistence portalPreferencesPersistence;
1143 @BeanReference(type = PortletPersistence.class)
1144 protected PortletPersistence portletPersistence;
1145 @BeanReference(type = PortletItemPersistence.class)
1146 protected PortletItemPersistence portletItemPersistence;
1147 @BeanReference(type = PortletPreferencesPersistence.class)
1148 protected PortletPreferencesPersistence portletPreferencesPersistence;
1149 @BeanReference(type = RegionPersistence.class)
1150 protected RegionPersistence regionPersistence;
1151 @BeanReference(type = ReleasePersistence.class)
1152 protected ReleasePersistence releasePersistence;
1153 @BeanReference(type = RepositoryPersistence.class)
1154 protected RepositoryPersistence repositoryPersistence;
1155 @BeanReference(type = RepositoryEntryPersistence.class)
1156 protected RepositoryEntryPersistence repositoryEntryPersistence;
1157 @BeanReference(type = ResourcePersistence.class)
1158 protected ResourcePersistence resourcePersistence;
1159 @BeanReference(type = ResourceActionPersistence.class)
1160 protected ResourceActionPersistence resourceActionPersistence;
1161 @BeanReference(type = ResourceBlockPersistence.class)
1162 protected ResourceBlockPersistence resourceBlockPersistence;
1163 @BeanReference(type = ResourceBlockPermissionPersistence.class)
1164 protected ResourceBlockPermissionPersistence resourceBlockPermissionPersistence;
1165 @BeanReference(type = ResourceCodePersistence.class)
1166 protected ResourceCodePersistence resourceCodePersistence;
1167 @BeanReference(type = ResourcePermissionPersistence.class)
1168 protected ResourcePermissionPersistence resourcePermissionPersistence;
1169 @BeanReference(type = ResourceTypePermissionPersistence.class)
1170 protected ResourceTypePermissionPersistence resourceTypePermissionPersistence;
1171 @BeanReference(type = RolePersistence.class)
1172 protected RolePersistence rolePersistence;
1173 @BeanReference(type = ServiceComponentPersistence.class)
1174 protected ServiceComponentPersistence serviceComponentPersistence;
1175 @BeanReference(type = ShardPersistence.class)
1176 protected ShardPersistence shardPersistence;
1177 @BeanReference(type = SubscriptionPersistence.class)
1178 protected SubscriptionPersistence subscriptionPersistence;
1179 @BeanReference(type = TeamPersistence.class)
1180 protected TeamPersistence teamPersistence;
1181 @BeanReference(type = TicketPersistence.class)
1182 protected TicketPersistence ticketPersistence;
1183 @BeanReference(type = UserPersistence.class)
1184 protected UserPersistence userPersistence;
1185 @BeanReference(type = UserGroupPersistence.class)
1186 protected UserGroupPersistence userGroupPersistence;
1187 @BeanReference(type = UserGroupGroupRolePersistence.class)
1188 protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1189 @BeanReference(type = UserGroupRolePersistence.class)
1190 protected UserGroupRolePersistence userGroupRolePersistence;
1191 @BeanReference(type = UserIdMapperPersistence.class)
1192 protected UserIdMapperPersistence userIdMapperPersistence;
1193 @BeanReference(type = UserNotificationEventPersistence.class)
1194 protected UserNotificationEventPersistence userNotificationEventPersistence;
1195 @BeanReference(type = UserTrackerPersistence.class)
1196 protected UserTrackerPersistence userTrackerPersistence;
1197 @BeanReference(type = UserTrackerPathPersistence.class)
1198 protected UserTrackerPathPersistence userTrackerPathPersistence;
1199 @BeanReference(type = VirtualHostPersistence.class)
1200 protected VirtualHostPersistence virtualHostPersistence;
1201 @BeanReference(type = WebDAVPropsPersistence.class)
1202 protected WebDAVPropsPersistence webDAVPropsPersistence;
1203 @BeanReference(type = WebsitePersistence.class)
1204 protected WebsitePersistence websitePersistence;
1205 @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
1206 protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
1207 @BeanReference(type = WorkflowInstanceLinkPersistence.class)
1208 protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
1209 private static final String _SQL_SELECT_LISTTYPE = "SELECT listType FROM ListType listType";
1210 private static final String _SQL_SELECT_LISTTYPE_WHERE = "SELECT listType FROM ListType listType WHERE ";
1211 private static final String _SQL_COUNT_LISTTYPE = "SELECT COUNT(listType) FROM ListType listType";
1212 private static final String _SQL_COUNT_LISTTYPE_WHERE = "SELECT COUNT(listType) FROM ListType listType WHERE ";
1213 private static final String _FINDER_COLUMN_TYPE_TYPE_1 = "listType.type IS NULL";
1214 private static final String _FINDER_COLUMN_TYPE_TYPE_2 = "listType.type = ?";
1215 private static final String _FINDER_COLUMN_TYPE_TYPE_3 = "(listType.type IS NULL OR listType.type = ?)";
1216 private static final String _ORDER_BY_ENTITY_ALIAS = "listType.";
1217 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ListType exists with the primary key ";
1218 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ListType exists with the key {";
1219 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1220 private static Log _log = LogFactoryUtil.getLog(ListTypePersistenceImpl.class);
1221 private static ListType _nullListType = new ListTypeImpl() {
1222 @Override
1223 public Object clone() {
1224 return this;
1225 }
1226
1227 @Override
1228 public CacheModel<ListType> toCacheModel() {
1229 return _nullListTypeCacheModel;
1230 }
1231 };
1232
1233 private static CacheModel<ListType> _nullListTypeCacheModel = new CacheModel<ListType>() {
1234 public ListType toEntityModel() {
1235 return _nullListType;
1236 }
1237 };
1238 }