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 public ListTypePersistenceImpl() {
617 setModelClass(ListType.class);
618 }
619
620
625 @Override
626 public void cacheResult(ListType listType) {
627 EntityCacheUtil.putResult(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
628 ListTypeImpl.class, listType.getPrimaryKey(), listType);
629
630 listType.resetOriginalValues();
631 }
632
633
638 @Override
639 public void cacheResult(List<ListType> listTypes) {
640 for (ListType listType : listTypes) {
641 if (EntityCacheUtil.getResult(
642 ListTypeModelImpl.ENTITY_CACHE_ENABLED,
643 ListTypeImpl.class, listType.getPrimaryKey()) == null) {
644 cacheResult(listType);
645 }
646 else {
647 listType.resetOriginalValues();
648 }
649 }
650 }
651
652
659 @Override
660 public void clearCache() {
661 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
662 CacheRegistryUtil.clear(ListTypeImpl.class.getName());
663 }
664
665 EntityCacheUtil.clearCache(ListTypeImpl.class.getName());
666
667 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
668 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
669 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
670 }
671
672
679 @Override
680 public void clearCache(ListType listType) {
681 EntityCacheUtil.removeResult(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
682 ListTypeImpl.class, listType.getPrimaryKey());
683
684 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
685 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
686 }
687
688 @Override
689 public void clearCache(List<ListType> listTypes) {
690 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
691 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
692
693 for (ListType listType : listTypes) {
694 EntityCacheUtil.removeResult(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
695 ListTypeImpl.class, listType.getPrimaryKey());
696 }
697 }
698
699
705 @Override
706 public ListType create(int listTypeId) {
707 ListType listType = new ListTypeImpl();
708
709 listType.setNew(true);
710 listType.setPrimaryKey(listTypeId);
711
712 return listType;
713 }
714
715
723 @Override
724 public ListType remove(int listTypeId)
725 throws NoSuchListTypeException, SystemException {
726 return remove((Serializable)listTypeId);
727 }
728
729
737 @Override
738 public ListType remove(Serializable primaryKey)
739 throws NoSuchListTypeException, SystemException {
740 Session session = null;
741
742 try {
743 session = openSession();
744
745 ListType listType = (ListType)session.get(ListTypeImpl.class,
746 primaryKey);
747
748 if (listType == null) {
749 if (_log.isWarnEnabled()) {
750 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
751 }
752
753 throw new NoSuchListTypeException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
754 primaryKey);
755 }
756
757 return remove(listType);
758 }
759 catch (NoSuchListTypeException nsee) {
760 throw nsee;
761 }
762 catch (Exception e) {
763 throw processException(e);
764 }
765 finally {
766 closeSession(session);
767 }
768 }
769
770 @Override
771 protected ListType removeImpl(ListType listType) throws SystemException {
772 listType = toUnwrappedModel(listType);
773
774 Session session = null;
775
776 try {
777 session = openSession();
778
779 if (!session.contains(listType)) {
780 listType = (ListType)session.get(ListTypeImpl.class,
781 listType.getPrimaryKeyObj());
782 }
783
784 if (listType != null) {
785 session.delete(listType);
786 }
787 }
788 catch (Exception e) {
789 throw processException(e);
790 }
791 finally {
792 closeSession(session);
793 }
794
795 if (listType != null) {
796 clearCache(listType);
797 }
798
799 return listType;
800 }
801
802 @Override
803 public ListType updateImpl(com.liferay.portal.model.ListType listType)
804 throws SystemException {
805 listType = toUnwrappedModel(listType);
806
807 boolean isNew = listType.isNew();
808
809 ListTypeModelImpl listTypeModelImpl = (ListTypeModelImpl)listType;
810
811 Session session = null;
812
813 try {
814 session = openSession();
815
816 if (listType.isNew()) {
817 session.save(listType);
818
819 listType.setNew(false);
820 }
821 else {
822 session.merge(listType);
823 }
824 }
825 catch (Exception e) {
826 throw processException(e);
827 }
828 finally {
829 closeSession(session);
830 }
831
832 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
833
834 if (isNew || !ListTypeModelImpl.COLUMN_BITMASK_ENABLED) {
835 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
836 }
837
838 else {
839 if ((listTypeModelImpl.getColumnBitmask() &
840 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE.getColumnBitmask()) != 0) {
841 Object[] args = new Object[] { listTypeModelImpl.getOriginalType() };
842
843 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TYPE, args);
844 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE,
845 args);
846
847 args = new Object[] { listTypeModelImpl.getType() };
848
849 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TYPE, args);
850 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE,
851 args);
852 }
853 }
854
855 EntityCacheUtil.putResult(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
856 ListTypeImpl.class, listType.getPrimaryKey(), listType);
857
858 return listType;
859 }
860
861 protected ListType toUnwrappedModel(ListType listType) {
862 if (listType instanceof ListTypeImpl) {
863 return listType;
864 }
865
866 ListTypeImpl listTypeImpl = new ListTypeImpl();
867
868 listTypeImpl.setNew(listType.isNew());
869 listTypeImpl.setPrimaryKey(listType.getPrimaryKey());
870
871 listTypeImpl.setListTypeId(listType.getListTypeId());
872 listTypeImpl.setName(listType.getName());
873 listTypeImpl.setType(listType.getType());
874
875 return listTypeImpl;
876 }
877
878
886 @Override
887 public ListType findByPrimaryKey(Serializable primaryKey)
888 throws NoSuchListTypeException, SystemException {
889 ListType listType = fetchByPrimaryKey(primaryKey);
890
891 if (listType == null) {
892 if (_log.isWarnEnabled()) {
893 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
894 }
895
896 throw new NoSuchListTypeException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
897 primaryKey);
898 }
899
900 return listType;
901 }
902
903
911 @Override
912 public ListType findByPrimaryKey(int listTypeId)
913 throws NoSuchListTypeException, SystemException {
914 return findByPrimaryKey((Serializable)listTypeId);
915 }
916
917
924 @Override
925 public ListType fetchByPrimaryKey(Serializable primaryKey)
926 throws SystemException {
927 ListType listType = (ListType)EntityCacheUtil.getResult(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
928 ListTypeImpl.class, primaryKey);
929
930 if (listType == _nullListType) {
931 return null;
932 }
933
934 if (listType == null) {
935 Session session = null;
936
937 try {
938 session = openSession();
939
940 listType = (ListType)session.get(ListTypeImpl.class, primaryKey);
941
942 if (listType != null) {
943 cacheResult(listType);
944 }
945 else {
946 EntityCacheUtil.putResult(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
947 ListTypeImpl.class, primaryKey, _nullListType);
948 }
949 }
950 catch (Exception e) {
951 EntityCacheUtil.removeResult(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
952 ListTypeImpl.class, primaryKey);
953
954 throw processException(e);
955 }
956 finally {
957 closeSession(session);
958 }
959 }
960
961 return listType;
962 }
963
964
971 @Override
972 public ListType fetchByPrimaryKey(int listTypeId) throws SystemException {
973 return fetchByPrimaryKey((Serializable)listTypeId);
974 }
975
976
982 @Override
983 public List<ListType> findAll() throws SystemException {
984 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
985 }
986
987
999 @Override
1000 public List<ListType> findAll(int start, int end) throws SystemException {
1001 return findAll(start, end, null);
1002 }
1003
1004
1017 @Override
1018 public List<ListType> findAll(int start, int end,
1019 OrderByComparator orderByComparator) throws SystemException {
1020 boolean pagination = true;
1021 FinderPath finderPath = null;
1022 Object[] finderArgs = null;
1023
1024 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1025 (orderByComparator == null)) {
1026 pagination = false;
1027 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1028 finderArgs = FINDER_ARGS_EMPTY;
1029 }
1030 else {
1031 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1032 finderArgs = new Object[] { start, end, orderByComparator };
1033 }
1034
1035 List<ListType> list = (List<ListType>)FinderCacheUtil.getResult(finderPath,
1036 finderArgs, this);
1037
1038 if (list == null) {
1039 StringBundler query = null;
1040 String sql = null;
1041
1042 if (orderByComparator != null) {
1043 query = new StringBundler(2 +
1044 (orderByComparator.getOrderByFields().length * 3));
1045
1046 query.append(_SQL_SELECT_LISTTYPE);
1047
1048 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1049 orderByComparator);
1050
1051 sql = query.toString();
1052 }
1053 else {
1054 sql = _SQL_SELECT_LISTTYPE;
1055
1056 if (pagination) {
1057 sql = sql.concat(ListTypeModelImpl.ORDER_BY_JPQL);
1058 }
1059 }
1060
1061 Session session = null;
1062
1063 try {
1064 session = openSession();
1065
1066 Query q = session.createQuery(sql);
1067
1068 if (!pagination) {
1069 list = (List<ListType>)QueryUtil.list(q, getDialect(),
1070 start, end, false);
1071
1072 Collections.sort(list);
1073
1074 list = new UnmodifiableList<ListType>(list);
1075 }
1076 else {
1077 list = (List<ListType>)QueryUtil.list(q, getDialect(),
1078 start, end);
1079 }
1080
1081 cacheResult(list);
1082
1083 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1084 }
1085 catch (Exception e) {
1086 FinderCacheUtil.removeResult(finderPath, finderArgs);
1087
1088 throw processException(e);
1089 }
1090 finally {
1091 closeSession(session);
1092 }
1093 }
1094
1095 return list;
1096 }
1097
1098
1103 @Override
1104 public void removeAll() throws SystemException {
1105 for (ListType listType : findAll()) {
1106 remove(listType);
1107 }
1108 }
1109
1110
1116 @Override
1117 public int countAll() throws SystemException {
1118 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1119 FINDER_ARGS_EMPTY, this);
1120
1121 if (count == null) {
1122 Session session = null;
1123
1124 try {
1125 session = openSession();
1126
1127 Query q = session.createQuery(_SQL_COUNT_LISTTYPE);
1128
1129 count = (Long)q.uniqueResult();
1130
1131 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1132 FINDER_ARGS_EMPTY, count);
1133 }
1134 catch (Exception e) {
1135 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
1136 FINDER_ARGS_EMPTY);
1137
1138 throw processException(e);
1139 }
1140 finally {
1141 closeSession(session);
1142 }
1143 }
1144
1145 return count.intValue();
1146 }
1147
1148 @Override
1149 protected Set<String> getBadColumnNames() {
1150 return _badColumnNames;
1151 }
1152
1153
1156 public void afterPropertiesSet() {
1157 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1158 com.liferay.portal.util.PropsUtil.get(
1159 "value.object.listener.com.liferay.portal.model.ListType")));
1160
1161 if (listenerClassNames.length > 0) {
1162 try {
1163 List<ModelListener<ListType>> listenersList = new ArrayList<ModelListener<ListType>>();
1164
1165 for (String listenerClassName : listenerClassNames) {
1166 listenersList.add((ModelListener<ListType>)InstanceFactory.newInstance(
1167 getClassLoader(), listenerClassName));
1168 }
1169
1170 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1171 }
1172 catch (Exception e) {
1173 _log.error(e);
1174 }
1175 }
1176 }
1177
1178 public void destroy() {
1179 EntityCacheUtil.removeCache(ListTypeImpl.class.getName());
1180 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1181 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1182 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1183 }
1184
1185 private static final String _SQL_SELECT_LISTTYPE = "SELECT listType FROM ListType listType";
1186 private static final String _SQL_SELECT_LISTTYPE_WHERE = "SELECT listType FROM ListType listType WHERE ";
1187 private static final String _SQL_COUNT_LISTTYPE = "SELECT COUNT(listType) FROM ListType listType";
1188 private static final String _SQL_COUNT_LISTTYPE_WHERE = "SELECT COUNT(listType) FROM ListType listType WHERE ";
1189 private static final String _ORDER_BY_ENTITY_ALIAS = "listType.";
1190 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ListType exists with the primary key ";
1191 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ListType exists with the key {";
1192 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1193 private static Log _log = LogFactoryUtil.getLog(ListTypePersistenceImpl.class);
1194 private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
1195 "type"
1196 });
1197 private static ListType _nullListType = new ListTypeImpl() {
1198 @Override
1199 public Object clone() {
1200 return this;
1201 }
1202
1203 @Override
1204 public CacheModel<ListType> toCacheModel() {
1205 return _nullListTypeCacheModel;
1206 }
1207 };
1208
1209 private static CacheModel<ListType> _nullListTypeCacheModel = new CacheModel<ListType>() {
1210 @Override
1211 public ListType toEntityModel() {
1212 return _nullListType;
1213 }
1214 };
1215 }