001
014
015 package com.liferay.portal.service.persistence;
016
017 import com.liferay.portal.NoSuchListTypeException;
018 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
019 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
020 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderPath;
022 import com.liferay.portal.kernel.dao.orm.Query;
023 import com.liferay.portal.kernel.dao.orm.QueryPos;
024 import com.liferay.portal.kernel.dao.orm.QueryUtil;
025 import com.liferay.portal.kernel.dao.orm.Session;
026 import com.liferay.portal.kernel.exception.SystemException;
027 import com.liferay.portal.kernel.log.Log;
028 import com.liferay.portal.kernel.log.LogFactoryUtil;
029 import com.liferay.portal.kernel.util.GetterUtil;
030 import com.liferay.portal.kernel.util.InstanceFactory;
031 import com.liferay.portal.kernel.util.OrderByComparator;
032 import com.liferay.portal.kernel.util.SetUtil;
033 import com.liferay.portal.kernel.util.StringBundler;
034 import com.liferay.portal.kernel.util.StringPool;
035 import com.liferay.portal.kernel.util.StringUtil;
036 import com.liferay.portal.kernel.util.UnmodifiableList;
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 import java.util.Set;
051
052
064 public class ListTypePersistenceImpl extends BasePersistenceImpl<ListType>
065 implements ListTypePersistence {
066
071 public static final String FINDER_CLASS_NAME_ENTITY = ListTypeImpl.class.getName();
072 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
073 ".List1";
074 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
075 ".List2";
076 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
077 ListTypeModelImpl.FINDER_CACHE_ENABLED, ListTypeImpl.class,
078 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
079 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
080 ListTypeModelImpl.FINDER_CACHE_ENABLED, ListTypeImpl.class,
081 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
082 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
083 ListTypeModelImpl.FINDER_CACHE_ENABLED, Long.class,
084 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
085 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_TYPE = new FinderPath(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
086 ListTypeModelImpl.FINDER_CACHE_ENABLED, ListTypeImpl.class,
087 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByType",
088 new String[] {
089 String.class.getName(),
090
091 Integer.class.getName(), Integer.class.getName(),
092 OrderByComparator.class.getName()
093 });
094 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE = new FinderPath(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
095 ListTypeModelImpl.FINDER_CACHE_ENABLED, ListTypeImpl.class,
096 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByType",
097 new String[] { String.class.getName() },
098 ListTypeModelImpl.TYPE_COLUMN_BITMASK |
099 ListTypeModelImpl.NAME_COLUMN_BITMASK);
100 public static final FinderPath FINDER_PATH_COUNT_BY_TYPE = new FinderPath(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
101 ListTypeModelImpl.FINDER_CACHE_ENABLED, Long.class,
102 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByType",
103 new String[] { String.class.getName() });
104
105
112 @Override
113 public List<ListType> findByType(String type) throws SystemException {
114 return findByType(type, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
115 }
116
117
130 @Override
131 public List<ListType> findByType(String type, int start, int end)
132 throws SystemException {
133 return findByType(type, start, end, null);
134 }
135
136
150 @Override
151 public List<ListType> findByType(String type, int start, int end,
152 OrderByComparator orderByComparator) throws SystemException {
153 boolean pagination = true;
154 FinderPath finderPath = null;
155 Object[] finderArgs = null;
156
157 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
158 (orderByComparator == null)) {
159 pagination = false;
160 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE;
161 finderArgs = new Object[] { type };
162 }
163 else {
164 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_TYPE;
165 finderArgs = new Object[] { type, start, end, orderByComparator };
166 }
167
168 List<ListType> list = (List<ListType>)FinderCacheUtil.getResult(finderPath,
169 finderArgs, this);
170
171 if ((list != null) && !list.isEmpty()) {
172 for (ListType listType : list) {
173 if (!Validator.equals(type, listType.getType())) {
174 list = null;
175
176 break;
177 }
178 }
179 }
180
181 if (list == null) {
182 StringBundler query = null;
183
184 if (orderByComparator != null) {
185 query = new StringBundler(3 +
186 (orderByComparator.getOrderByFields().length * 3));
187 }
188 else {
189 query = new StringBundler(3);
190 }
191
192 query.append(_SQL_SELECT_LISTTYPE_WHERE);
193
194 boolean bindType = false;
195
196 if (type == null) {
197 query.append(_FINDER_COLUMN_TYPE_TYPE_1);
198 }
199 else if (type.equals(StringPool.BLANK)) {
200 query.append(_FINDER_COLUMN_TYPE_TYPE_3);
201 }
202 else {
203 bindType = true;
204
205 query.append(_FINDER_COLUMN_TYPE_TYPE_2);
206 }
207
208 if (orderByComparator != null) {
209 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
210 orderByComparator);
211 }
212 else
213 if (pagination) {
214 query.append(ListTypeModelImpl.ORDER_BY_JPQL);
215 }
216
217 String sql = query.toString();
218
219 Session session = null;
220
221 try {
222 session = openSession();
223
224 Query q = session.createQuery(sql);
225
226 QueryPos qPos = QueryPos.getInstance(q);
227
228 if (bindType) {
229 qPos.add(type);
230 }
231
232 if (!pagination) {
233 list = (List<ListType>)QueryUtil.list(q, getDialect(),
234 start, end, false);
235
236 Collections.sort(list);
237
238 list = new UnmodifiableList<ListType>(list);
239 }
240 else {
241 list = (List<ListType>)QueryUtil.list(q, getDialect(),
242 start, end);
243 }
244
245 cacheResult(list);
246
247 FinderCacheUtil.putResult(finderPath, finderArgs, list);
248 }
249 catch (Exception e) {
250 FinderCacheUtil.removeResult(finderPath, finderArgs);
251
252 throw processException(e);
253 }
254 finally {
255 closeSession(session);
256 }
257 }
258
259 return list;
260 }
261
262
271 @Override
272 public ListType findByType_First(String type,
273 OrderByComparator orderByComparator)
274 throws NoSuchListTypeException, SystemException {
275 ListType listType = fetchByType_First(type, orderByComparator);
276
277 if (listType != null) {
278 return listType;
279 }
280
281 StringBundler msg = new StringBundler(4);
282
283 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
284
285 msg.append("type=");
286 msg.append(type);
287
288 msg.append(StringPool.CLOSE_CURLY_BRACE);
289
290 throw new NoSuchListTypeException(msg.toString());
291 }
292
293
301 @Override
302 public ListType fetchByType_First(String type,
303 OrderByComparator orderByComparator) throws SystemException {
304 List<ListType> list = findByType(type, 0, 1, orderByComparator);
305
306 if (!list.isEmpty()) {
307 return list.get(0);
308 }
309
310 return null;
311 }
312
313
322 @Override
323 public ListType findByType_Last(String type,
324 OrderByComparator orderByComparator)
325 throws NoSuchListTypeException, SystemException {
326 ListType listType = fetchByType_Last(type, orderByComparator);
327
328 if (listType != null) {
329 return listType;
330 }
331
332 StringBundler msg = new StringBundler(4);
333
334 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
335
336 msg.append("type=");
337 msg.append(type);
338
339 msg.append(StringPool.CLOSE_CURLY_BRACE);
340
341 throw new NoSuchListTypeException(msg.toString());
342 }
343
344
352 @Override
353 public ListType fetchByType_Last(String type,
354 OrderByComparator orderByComparator) throws SystemException {
355 int count = countByType(type);
356
357 if (count == 0) {
358 return null;
359 }
360
361 List<ListType> list = findByType(type, count - 1, count,
362 orderByComparator);
363
364 if (!list.isEmpty()) {
365 return list.get(0);
366 }
367
368 return null;
369 }
370
371
381 @Override
382 public ListType[] findByType_PrevAndNext(int listTypeId, String type,
383 OrderByComparator orderByComparator)
384 throws NoSuchListTypeException, SystemException {
385 ListType listType = findByPrimaryKey(listTypeId);
386
387 Session session = null;
388
389 try {
390 session = openSession();
391
392 ListType[] array = new ListTypeImpl[3];
393
394 array[0] = getByType_PrevAndNext(session, listType, type,
395 orderByComparator, true);
396
397 array[1] = listType;
398
399 array[2] = getByType_PrevAndNext(session, listType, type,
400 orderByComparator, false);
401
402 return array;
403 }
404 catch (Exception e) {
405 throw processException(e);
406 }
407 finally {
408 closeSession(session);
409 }
410 }
411
412 protected ListType getByType_PrevAndNext(Session session,
413 ListType listType, String type, OrderByComparator orderByComparator,
414 boolean previous) {
415 StringBundler query = null;
416
417 if (orderByComparator != null) {
418 query = new StringBundler(6 +
419 (orderByComparator.getOrderByFields().length * 6));
420 }
421 else {
422 query = new StringBundler(3);
423 }
424
425 query.append(_SQL_SELECT_LISTTYPE_WHERE);
426
427 boolean bindType = false;
428
429 if (type == null) {
430 query.append(_FINDER_COLUMN_TYPE_TYPE_1);
431 }
432 else if (type.equals(StringPool.BLANK)) {
433 query.append(_FINDER_COLUMN_TYPE_TYPE_3);
434 }
435 else {
436 bindType = true;
437
438 query.append(_FINDER_COLUMN_TYPE_TYPE_2);
439 }
440
441 if (orderByComparator != null) {
442 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
443
444 if (orderByConditionFields.length > 0) {
445 query.append(WHERE_AND);
446 }
447
448 for (int i = 0; i < orderByConditionFields.length; i++) {
449 query.append(_ORDER_BY_ENTITY_ALIAS);
450 query.append(orderByConditionFields[i]);
451
452 if ((i + 1) < orderByConditionFields.length) {
453 if (orderByComparator.isAscending() ^ previous) {
454 query.append(WHERE_GREATER_THAN_HAS_NEXT);
455 }
456 else {
457 query.append(WHERE_LESSER_THAN_HAS_NEXT);
458 }
459 }
460 else {
461 if (orderByComparator.isAscending() ^ previous) {
462 query.append(WHERE_GREATER_THAN);
463 }
464 else {
465 query.append(WHERE_LESSER_THAN);
466 }
467 }
468 }
469
470 query.append(ORDER_BY_CLAUSE);
471
472 String[] orderByFields = orderByComparator.getOrderByFields();
473
474 for (int i = 0; i < orderByFields.length; i++) {
475 query.append(_ORDER_BY_ENTITY_ALIAS);
476 query.append(orderByFields[i]);
477
478 if ((i + 1) < orderByFields.length) {
479 if (orderByComparator.isAscending() ^ previous) {
480 query.append(ORDER_BY_ASC_HAS_NEXT);
481 }
482 else {
483 query.append(ORDER_BY_DESC_HAS_NEXT);
484 }
485 }
486 else {
487 if (orderByComparator.isAscending() ^ previous) {
488 query.append(ORDER_BY_ASC);
489 }
490 else {
491 query.append(ORDER_BY_DESC);
492 }
493 }
494 }
495 }
496 else {
497 query.append(ListTypeModelImpl.ORDER_BY_JPQL);
498 }
499
500 String sql = query.toString();
501
502 Query q = session.createQuery(sql);
503
504 q.setFirstResult(0);
505 q.setMaxResults(2);
506
507 QueryPos qPos = QueryPos.getInstance(q);
508
509 if (bindType) {
510 qPos.add(type);
511 }
512
513 if (orderByComparator != null) {
514 Object[] values = orderByComparator.getOrderByConditionValues(listType);
515
516 for (Object value : values) {
517 qPos.add(value);
518 }
519 }
520
521 List<ListType> list = q.list();
522
523 if (list.size() == 2) {
524 return list.get(1);
525 }
526 else {
527 return null;
528 }
529 }
530
531
537 @Override
538 public void removeByType(String type) throws SystemException {
539 for (ListType listType : findByType(type, QueryUtil.ALL_POS,
540 QueryUtil.ALL_POS, null)) {
541 remove(listType);
542 }
543 }
544
545
552 @Override
553 public int countByType(String type) throws SystemException {
554 FinderPath finderPath = FINDER_PATH_COUNT_BY_TYPE;
555
556 Object[] finderArgs = new Object[] { type };
557
558 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
559 this);
560
561 if (count == null) {
562 StringBundler query = new StringBundler(2);
563
564 query.append(_SQL_COUNT_LISTTYPE_WHERE);
565
566 boolean bindType = false;
567
568 if (type == null) {
569 query.append(_FINDER_COLUMN_TYPE_TYPE_1);
570 }
571 else if (type.equals(StringPool.BLANK)) {
572 query.append(_FINDER_COLUMN_TYPE_TYPE_3);
573 }
574 else {
575 bindType = true;
576
577 query.append(_FINDER_COLUMN_TYPE_TYPE_2);
578 }
579
580 String sql = query.toString();
581
582 Session session = null;
583
584 try {
585 session = openSession();
586
587 Query q = session.createQuery(sql);
588
589 QueryPos qPos = QueryPos.getInstance(q);
590
591 if (bindType) {
592 qPos.add(type);
593 }
594
595 count = (Long)q.uniqueResult();
596
597 FinderCacheUtil.putResult(finderPath, finderArgs, count);
598 }
599 catch (Exception e) {
600 FinderCacheUtil.removeResult(finderPath, finderArgs);
601
602 throw processException(e);
603 }
604 finally {
605 closeSession(session);
606 }
607 }
608
609 return count.intValue();
610 }
611
612 private static final String _FINDER_COLUMN_TYPE_TYPE_1 = "listType.type IS NULL";
613 private static final String _FINDER_COLUMN_TYPE_TYPE_2 = "listType.type = ?";
614 private static final String _FINDER_COLUMN_TYPE_TYPE_3 = "(listType.type IS NULL OR listType.type = '')";
615
616
621 @Override
622 public void cacheResult(ListType listType) {
623 EntityCacheUtil.putResult(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
624 ListTypeImpl.class, listType.getPrimaryKey(), listType);
625
626 listType.resetOriginalValues();
627 }
628
629
634 @Override
635 public void cacheResult(List<ListType> listTypes) {
636 for (ListType listType : listTypes) {
637 if (EntityCacheUtil.getResult(
638 ListTypeModelImpl.ENTITY_CACHE_ENABLED,
639 ListTypeImpl.class, listType.getPrimaryKey()) == null) {
640 cacheResult(listType);
641 }
642 else {
643 listType.resetOriginalValues();
644 }
645 }
646 }
647
648
655 @Override
656 public void clearCache() {
657 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
658 CacheRegistryUtil.clear(ListTypeImpl.class.getName());
659 }
660
661 EntityCacheUtil.clearCache(ListTypeImpl.class.getName());
662
663 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
664 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
665 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
666 }
667
668
675 @Override
676 public void clearCache(ListType listType) {
677 EntityCacheUtil.removeResult(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
678 ListTypeImpl.class, listType.getPrimaryKey());
679
680 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
681 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
682 }
683
684 @Override
685 public void clearCache(List<ListType> listTypes) {
686 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
687 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
688
689 for (ListType listType : listTypes) {
690 EntityCacheUtil.removeResult(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
691 ListTypeImpl.class, listType.getPrimaryKey());
692 }
693 }
694
695
701 @Override
702 public ListType create(int listTypeId) {
703 ListType listType = new ListTypeImpl();
704
705 listType.setNew(true);
706 listType.setPrimaryKey(listTypeId);
707
708 return listType;
709 }
710
711
719 @Override
720 public ListType remove(int listTypeId)
721 throws NoSuchListTypeException, SystemException {
722 return remove((Serializable)listTypeId);
723 }
724
725
733 @Override
734 public ListType remove(Serializable primaryKey)
735 throws NoSuchListTypeException, SystemException {
736 Session session = null;
737
738 try {
739 session = openSession();
740
741 ListType listType = (ListType)session.get(ListTypeImpl.class,
742 primaryKey);
743
744 if (listType == null) {
745 if (_log.isWarnEnabled()) {
746 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
747 }
748
749 throw new NoSuchListTypeException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
750 primaryKey);
751 }
752
753 return remove(listType);
754 }
755 catch (NoSuchListTypeException nsee) {
756 throw nsee;
757 }
758 catch (Exception e) {
759 throw processException(e);
760 }
761 finally {
762 closeSession(session);
763 }
764 }
765
766 @Override
767 protected ListType removeImpl(ListType listType) throws SystemException {
768 listType = toUnwrappedModel(listType);
769
770 Session session = null;
771
772 try {
773 session = openSession();
774
775 if (!session.contains(listType)) {
776 listType = (ListType)session.get(ListTypeImpl.class,
777 listType.getPrimaryKeyObj());
778 }
779
780 if (listType != null) {
781 session.delete(listType);
782 }
783 }
784 catch (Exception e) {
785 throw processException(e);
786 }
787 finally {
788 closeSession(session);
789 }
790
791 if (listType != null) {
792 clearCache(listType);
793 }
794
795 return listType;
796 }
797
798 @Override
799 public ListType updateImpl(com.liferay.portal.model.ListType listType)
800 throws SystemException {
801 listType = toUnwrappedModel(listType);
802
803 boolean isNew = listType.isNew();
804
805 ListTypeModelImpl listTypeModelImpl = (ListTypeModelImpl)listType;
806
807 Session session = null;
808
809 try {
810 session = openSession();
811
812 if (listType.isNew()) {
813 session.save(listType);
814
815 listType.setNew(false);
816 }
817 else {
818 session.merge(listType);
819 }
820 }
821 catch (Exception e) {
822 throw processException(e);
823 }
824 finally {
825 closeSession(session);
826 }
827
828 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
829
830 if (isNew || !ListTypeModelImpl.COLUMN_BITMASK_ENABLED) {
831 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
832 }
833
834 else {
835 if ((listTypeModelImpl.getColumnBitmask() &
836 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE.getColumnBitmask()) != 0) {
837 Object[] args = new Object[] { listTypeModelImpl.getOriginalType() };
838
839 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TYPE, args);
840 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE,
841 args);
842
843 args = new Object[] { listTypeModelImpl.getType() };
844
845 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TYPE, args);
846 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE,
847 args);
848 }
849 }
850
851 EntityCacheUtil.putResult(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
852 ListTypeImpl.class, listType.getPrimaryKey(), listType);
853
854 return listType;
855 }
856
857 protected ListType toUnwrappedModel(ListType listType) {
858 if (listType instanceof ListTypeImpl) {
859 return listType;
860 }
861
862 ListTypeImpl listTypeImpl = new ListTypeImpl();
863
864 listTypeImpl.setNew(listType.isNew());
865 listTypeImpl.setPrimaryKey(listType.getPrimaryKey());
866
867 listTypeImpl.setListTypeId(listType.getListTypeId());
868 listTypeImpl.setName(listType.getName());
869 listTypeImpl.setType(listType.getType());
870
871 return listTypeImpl;
872 }
873
874
882 @Override
883 public ListType findByPrimaryKey(Serializable primaryKey)
884 throws NoSuchListTypeException, SystemException {
885 ListType listType = fetchByPrimaryKey(primaryKey);
886
887 if (listType == null) {
888 if (_log.isWarnEnabled()) {
889 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
890 }
891
892 throw new NoSuchListTypeException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
893 primaryKey);
894 }
895
896 return listType;
897 }
898
899
907 @Override
908 public ListType findByPrimaryKey(int listTypeId)
909 throws NoSuchListTypeException, SystemException {
910 return findByPrimaryKey((Serializable)listTypeId);
911 }
912
913
920 @Override
921 public ListType fetchByPrimaryKey(Serializable primaryKey)
922 throws SystemException {
923 ListType listType = (ListType)EntityCacheUtil.getResult(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
924 ListTypeImpl.class, primaryKey);
925
926 if (listType == _nullListType) {
927 return null;
928 }
929
930 if (listType == null) {
931 Session session = null;
932
933 try {
934 session = openSession();
935
936 listType = (ListType)session.get(ListTypeImpl.class, primaryKey);
937
938 if (listType != null) {
939 cacheResult(listType);
940 }
941 else {
942 EntityCacheUtil.putResult(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
943 ListTypeImpl.class, primaryKey, _nullListType);
944 }
945 }
946 catch (Exception e) {
947 EntityCacheUtil.removeResult(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
948 ListTypeImpl.class, primaryKey);
949
950 throw processException(e);
951 }
952 finally {
953 closeSession(session);
954 }
955 }
956
957 return listType;
958 }
959
960
967 @Override
968 public ListType fetchByPrimaryKey(int listTypeId) throws SystemException {
969 return fetchByPrimaryKey((Serializable)listTypeId);
970 }
971
972
978 @Override
979 public List<ListType> findAll() throws SystemException {
980 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
981 }
982
983
995 @Override
996 public List<ListType> findAll(int start, int end) throws SystemException {
997 return findAll(start, end, null);
998 }
999
1000
1013 @Override
1014 public List<ListType> findAll(int start, int end,
1015 OrderByComparator orderByComparator) throws SystemException {
1016 boolean pagination = true;
1017 FinderPath finderPath = null;
1018 Object[] finderArgs = null;
1019
1020 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1021 (orderByComparator == null)) {
1022 pagination = false;
1023 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1024 finderArgs = FINDER_ARGS_EMPTY;
1025 }
1026 else {
1027 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1028 finderArgs = new Object[] { start, end, orderByComparator };
1029 }
1030
1031 List<ListType> list = (List<ListType>)FinderCacheUtil.getResult(finderPath,
1032 finderArgs, this);
1033
1034 if (list == null) {
1035 StringBundler query = null;
1036 String sql = null;
1037
1038 if (orderByComparator != null) {
1039 query = new StringBundler(2 +
1040 (orderByComparator.getOrderByFields().length * 3));
1041
1042 query.append(_SQL_SELECT_LISTTYPE);
1043
1044 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1045 orderByComparator);
1046
1047 sql = query.toString();
1048 }
1049 else {
1050 sql = _SQL_SELECT_LISTTYPE;
1051
1052 if (pagination) {
1053 sql = sql.concat(ListTypeModelImpl.ORDER_BY_JPQL);
1054 }
1055 }
1056
1057 Session session = null;
1058
1059 try {
1060 session = openSession();
1061
1062 Query q = session.createQuery(sql);
1063
1064 if (!pagination) {
1065 list = (List<ListType>)QueryUtil.list(q, getDialect(),
1066 start, end, false);
1067
1068 Collections.sort(list);
1069
1070 list = new UnmodifiableList<ListType>(list);
1071 }
1072 else {
1073 list = (List<ListType>)QueryUtil.list(q, getDialect(),
1074 start, end);
1075 }
1076
1077 cacheResult(list);
1078
1079 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1080 }
1081 catch (Exception e) {
1082 FinderCacheUtil.removeResult(finderPath, finderArgs);
1083
1084 throw processException(e);
1085 }
1086 finally {
1087 closeSession(session);
1088 }
1089 }
1090
1091 return list;
1092 }
1093
1094
1099 @Override
1100 public void removeAll() throws SystemException {
1101 for (ListType listType : findAll()) {
1102 remove(listType);
1103 }
1104 }
1105
1106
1112 @Override
1113 public int countAll() throws SystemException {
1114 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1115 FINDER_ARGS_EMPTY, this);
1116
1117 if (count == null) {
1118 Session session = null;
1119
1120 try {
1121 session = openSession();
1122
1123 Query q = session.createQuery(_SQL_COUNT_LISTTYPE);
1124
1125 count = (Long)q.uniqueResult();
1126
1127 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1128 FINDER_ARGS_EMPTY, count);
1129 }
1130 catch (Exception e) {
1131 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
1132 FINDER_ARGS_EMPTY);
1133
1134 throw processException(e);
1135 }
1136 finally {
1137 closeSession(session);
1138 }
1139 }
1140
1141 return count.intValue();
1142 }
1143
1144 @Override
1145 protected Set<String> getBadColumnNames() {
1146 return _badColumnNames;
1147 }
1148
1149
1152 public void afterPropertiesSet() {
1153 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1154 com.liferay.portal.util.PropsUtil.get(
1155 "value.object.listener.com.liferay.portal.model.ListType")));
1156
1157 if (listenerClassNames.length > 0) {
1158 try {
1159 List<ModelListener<ListType>> listenersList = new ArrayList<ModelListener<ListType>>();
1160
1161 for (String listenerClassName : listenerClassNames) {
1162 listenersList.add((ModelListener<ListType>)InstanceFactory.newInstance(
1163 getClassLoader(), listenerClassName));
1164 }
1165
1166 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1167 }
1168 catch (Exception e) {
1169 _log.error(e);
1170 }
1171 }
1172 }
1173
1174 public void destroy() {
1175 EntityCacheUtil.removeCache(ListTypeImpl.class.getName());
1176 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1177 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1178 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1179 }
1180
1181 private static final String _SQL_SELECT_LISTTYPE = "SELECT listType FROM ListType listType";
1182 private static final String _SQL_SELECT_LISTTYPE_WHERE = "SELECT listType FROM ListType listType WHERE ";
1183 private static final String _SQL_COUNT_LISTTYPE = "SELECT COUNT(listType) FROM ListType listType";
1184 private static final String _SQL_COUNT_LISTTYPE_WHERE = "SELECT COUNT(listType) FROM ListType listType WHERE ";
1185 private static final String _ORDER_BY_ENTITY_ALIAS = "listType.";
1186 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ListType exists with the primary key ";
1187 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ListType exists with the key {";
1188 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1189 private static Log _log = LogFactoryUtil.getLog(ListTypePersistenceImpl.class);
1190 private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
1191 "type"
1192 });
1193 private static ListType _nullListType = new ListTypeImpl() {
1194 @Override
1195 public Object clone() {
1196 return this;
1197 }
1198
1199 @Override
1200 public CacheModel<ListType> toCacheModel() {
1201 return _nullListTypeCacheModel;
1202 }
1203 };
1204
1205 private static CacheModel<ListType> _nullListTypeCacheModel = new CacheModel<ListType>() {
1206 @Override
1207 public ListType toEntityModel() {
1208 return _nullListType;
1209 }
1210 };
1211 }