001
014
015 package com.liferay.portal.service.persistence.impl;
016
017 import aQute.bnd.annotation.ProviderType;
018
019 import com.liferay.portal.NoSuchListTypeException;
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.log.Log;
029 import com.liferay.portal.kernel.log.LogFactoryUtil;
030 import com.liferay.portal.kernel.util.OrderByComparator;
031 import com.liferay.portal.kernel.util.SetUtil;
032 import com.liferay.portal.kernel.util.StringBundler;
033 import com.liferay.portal.kernel.util.StringPool;
034 import com.liferay.portal.kernel.util.Validator;
035 import com.liferay.portal.model.CacheModel;
036 import com.liferay.portal.model.ListType;
037 import com.liferay.portal.model.MVCCModel;
038 import com.liferay.portal.model.impl.ListTypeImpl;
039 import com.liferay.portal.model.impl.ListTypeModelImpl;
040 import com.liferay.portal.service.persistence.ListTypePersistence;
041
042 import java.io.Serializable;
043
044 import java.util.Collections;
045 import java.util.HashMap;
046 import java.util.HashSet;
047 import java.util.Iterator;
048 import java.util.List;
049 import java.util.Map;
050 import java.util.Set;
051
052
064 @ProviderType
065 public class ListTypePersistenceImpl extends BasePersistenceImpl<ListType>
066 implements ListTypePersistence {
067
072 public static final String FINDER_CLASS_NAME_ENTITY = ListTypeImpl.class.getName();
073 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
074 ".List1";
075 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
076 ".List2";
077 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
078 ListTypeModelImpl.FINDER_CACHE_ENABLED, ListTypeImpl.class,
079 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
080 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
081 ListTypeModelImpl.FINDER_CACHE_ENABLED, ListTypeImpl.class,
082 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
083 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
084 ListTypeModelImpl.FINDER_CACHE_ENABLED, Long.class,
085 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
086 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_TYPE = new FinderPath(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
087 ListTypeModelImpl.FINDER_CACHE_ENABLED, ListTypeImpl.class,
088 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByType",
089 new String[] {
090 String.class.getName(),
091
092 Integer.class.getName(), Integer.class.getName(),
093 OrderByComparator.class.getName()
094 });
095 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE = new FinderPath(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
096 ListTypeModelImpl.FINDER_CACHE_ENABLED, ListTypeImpl.class,
097 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByType",
098 new String[] { String.class.getName() },
099 ListTypeModelImpl.TYPE_COLUMN_BITMASK |
100 ListTypeModelImpl.NAME_COLUMN_BITMASK);
101 public static final FinderPath FINDER_PATH_COUNT_BY_TYPE = new FinderPath(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
102 ListTypeModelImpl.FINDER_CACHE_ENABLED, Long.class,
103 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByType",
104 new String[] { String.class.getName() });
105
106
112 @Override
113 public List<ListType> findByType(String type) {
114 return findByType(type, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
115 }
116
117
129 @Override
130 public List<ListType> findByType(String type, int start, int end) {
131 return findByType(type, start, end, null);
132 }
133
134
147 @Override
148 public List<ListType> findByType(String type, int start, int end,
149 OrderByComparator<ListType> orderByComparator) {
150 boolean pagination = true;
151 FinderPath finderPath = null;
152 Object[] finderArgs = null;
153
154 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
155 (orderByComparator == null)) {
156 pagination = false;
157 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE;
158 finderArgs = new Object[] { type };
159 }
160 else {
161 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_TYPE;
162 finderArgs = new Object[] { type, start, end, orderByComparator };
163 }
164
165 List<ListType> list = (List<ListType>)FinderCacheUtil.getResult(finderPath,
166 finderArgs, this);
167
168 if ((list != null) && !list.isEmpty()) {
169 for (ListType listType : list) {
170 if (!Validator.equals(type, listType.getType())) {
171 list = null;
172
173 break;
174 }
175 }
176 }
177
178 if (list == null) {
179 StringBundler query = null;
180
181 if (orderByComparator != null) {
182 query = new StringBundler(3 +
183 (orderByComparator.getOrderByFields().length * 3));
184 }
185 else {
186 query = new StringBundler(3);
187 }
188
189 query.append(_SQL_SELECT_LISTTYPE_WHERE);
190
191 boolean bindType = false;
192
193 if (type == null) {
194 query.append(_FINDER_COLUMN_TYPE_TYPE_1);
195 }
196 else if (type.equals(StringPool.BLANK)) {
197 query.append(_FINDER_COLUMN_TYPE_TYPE_3);
198 }
199 else {
200 bindType = true;
201
202 query.append(_FINDER_COLUMN_TYPE_TYPE_2);
203 }
204
205 if (orderByComparator != null) {
206 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
207 orderByComparator);
208 }
209 else
210 if (pagination) {
211 query.append(ListTypeModelImpl.ORDER_BY_JPQL);
212 }
213
214 String sql = query.toString();
215
216 Session session = null;
217
218 try {
219 session = openSession();
220
221 Query q = session.createQuery(sql);
222
223 QueryPos qPos = QueryPos.getInstance(q);
224
225 if (bindType) {
226 qPos.add(type);
227 }
228
229 if (!pagination) {
230 list = (List<ListType>)QueryUtil.list(q, getDialect(),
231 start, end, false);
232
233 Collections.sort(list);
234
235 list = Collections.unmodifiableList(list);
236 }
237 else {
238 list = (List<ListType>)QueryUtil.list(q, getDialect(),
239 start, end);
240 }
241
242 cacheResult(list);
243
244 FinderCacheUtil.putResult(finderPath, finderArgs, list);
245 }
246 catch (Exception e) {
247 FinderCacheUtil.removeResult(finderPath, finderArgs);
248
249 throw processException(e);
250 }
251 finally {
252 closeSession(session);
253 }
254 }
255
256 return list;
257 }
258
259
267 @Override
268 public ListType findByType_First(String type,
269 OrderByComparator<ListType> orderByComparator)
270 throws NoSuchListTypeException {
271 ListType listType = fetchByType_First(type, orderByComparator);
272
273 if (listType != null) {
274 return listType;
275 }
276
277 StringBundler msg = new StringBundler(4);
278
279 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
280
281 msg.append("type=");
282 msg.append(type);
283
284 msg.append(StringPool.CLOSE_CURLY_BRACE);
285
286 throw new NoSuchListTypeException(msg.toString());
287 }
288
289
296 @Override
297 public ListType fetchByType_First(String type,
298 OrderByComparator<ListType> orderByComparator) {
299 List<ListType> list = findByType(type, 0, 1, orderByComparator);
300
301 if (!list.isEmpty()) {
302 return list.get(0);
303 }
304
305 return null;
306 }
307
308
316 @Override
317 public ListType findByType_Last(String type,
318 OrderByComparator<ListType> orderByComparator)
319 throws NoSuchListTypeException {
320 ListType listType = fetchByType_Last(type, orderByComparator);
321
322 if (listType != null) {
323 return listType;
324 }
325
326 StringBundler msg = new StringBundler(4);
327
328 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
329
330 msg.append("type=");
331 msg.append(type);
332
333 msg.append(StringPool.CLOSE_CURLY_BRACE);
334
335 throw new NoSuchListTypeException(msg.toString());
336 }
337
338
345 @Override
346 public ListType fetchByType_Last(String type,
347 OrderByComparator<ListType> orderByComparator) {
348 int count = countByType(type);
349
350 if (count == 0) {
351 return null;
352 }
353
354 List<ListType> list = findByType(type, count - 1, count,
355 orderByComparator);
356
357 if (!list.isEmpty()) {
358 return list.get(0);
359 }
360
361 return null;
362 }
363
364
373 @Override
374 public ListType[] findByType_PrevAndNext(int listTypeId, String type,
375 OrderByComparator<ListType> orderByComparator)
376 throws NoSuchListTypeException {
377 ListType listType = findByPrimaryKey(listTypeId);
378
379 Session session = null;
380
381 try {
382 session = openSession();
383
384 ListType[] array = new ListTypeImpl[3];
385
386 array[0] = getByType_PrevAndNext(session, listType, type,
387 orderByComparator, true);
388
389 array[1] = listType;
390
391 array[2] = getByType_PrevAndNext(session, listType, type,
392 orderByComparator, false);
393
394 return array;
395 }
396 catch (Exception e) {
397 throw processException(e);
398 }
399 finally {
400 closeSession(session);
401 }
402 }
403
404 protected ListType getByType_PrevAndNext(Session session,
405 ListType listType, String type,
406 OrderByComparator<ListType> orderByComparator, boolean previous) {
407 StringBundler query = null;
408
409 if (orderByComparator != null) {
410 query = new StringBundler(6 +
411 (orderByComparator.getOrderByFields().length * 6));
412 }
413 else {
414 query = new StringBundler(3);
415 }
416
417 query.append(_SQL_SELECT_LISTTYPE_WHERE);
418
419 boolean bindType = false;
420
421 if (type == null) {
422 query.append(_FINDER_COLUMN_TYPE_TYPE_1);
423 }
424 else if (type.equals(StringPool.BLANK)) {
425 query.append(_FINDER_COLUMN_TYPE_TYPE_3);
426 }
427 else {
428 bindType = true;
429
430 query.append(_FINDER_COLUMN_TYPE_TYPE_2);
431 }
432
433 if (orderByComparator != null) {
434 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
435
436 if (orderByConditionFields.length > 0) {
437 query.append(WHERE_AND);
438 }
439
440 for (int i = 0; i < orderByConditionFields.length; i++) {
441 query.append(_ORDER_BY_ENTITY_ALIAS);
442 query.append(orderByConditionFields[i]);
443
444 if ((i + 1) < orderByConditionFields.length) {
445 if (orderByComparator.isAscending() ^ previous) {
446 query.append(WHERE_GREATER_THAN_HAS_NEXT);
447 }
448 else {
449 query.append(WHERE_LESSER_THAN_HAS_NEXT);
450 }
451 }
452 else {
453 if (orderByComparator.isAscending() ^ previous) {
454 query.append(WHERE_GREATER_THAN);
455 }
456 else {
457 query.append(WHERE_LESSER_THAN);
458 }
459 }
460 }
461
462 query.append(ORDER_BY_CLAUSE);
463
464 String[] orderByFields = orderByComparator.getOrderByFields();
465
466 for (int i = 0; i < orderByFields.length; i++) {
467 query.append(_ORDER_BY_ENTITY_ALIAS);
468 query.append(orderByFields[i]);
469
470 if ((i + 1) < orderByFields.length) {
471 if (orderByComparator.isAscending() ^ previous) {
472 query.append(ORDER_BY_ASC_HAS_NEXT);
473 }
474 else {
475 query.append(ORDER_BY_DESC_HAS_NEXT);
476 }
477 }
478 else {
479 if (orderByComparator.isAscending() ^ previous) {
480 query.append(ORDER_BY_ASC);
481 }
482 else {
483 query.append(ORDER_BY_DESC);
484 }
485 }
486 }
487 }
488 else {
489 query.append(ListTypeModelImpl.ORDER_BY_JPQL);
490 }
491
492 String sql = query.toString();
493
494 Query q = session.createQuery(sql);
495
496 q.setFirstResult(0);
497 q.setMaxResults(2);
498
499 QueryPos qPos = QueryPos.getInstance(q);
500
501 if (bindType) {
502 qPos.add(type);
503 }
504
505 if (orderByComparator != null) {
506 Object[] values = orderByComparator.getOrderByConditionValues(listType);
507
508 for (Object value : values) {
509 qPos.add(value);
510 }
511 }
512
513 List<ListType> list = q.list();
514
515 if (list.size() == 2) {
516 return list.get(1);
517 }
518 else {
519 return null;
520 }
521 }
522
523
528 @Override
529 public void removeByType(String type) {
530 for (ListType listType : findByType(type, QueryUtil.ALL_POS,
531 QueryUtil.ALL_POS, null)) {
532 remove(listType);
533 }
534 }
535
536
542 @Override
543 public int countByType(String type) {
544 FinderPath finderPath = FINDER_PATH_COUNT_BY_TYPE;
545
546 Object[] finderArgs = new Object[] { type };
547
548 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
549 this);
550
551 if (count == null) {
552 StringBundler query = new StringBundler(2);
553
554 query.append(_SQL_COUNT_LISTTYPE_WHERE);
555
556 boolean bindType = false;
557
558 if (type == null) {
559 query.append(_FINDER_COLUMN_TYPE_TYPE_1);
560 }
561 else if (type.equals(StringPool.BLANK)) {
562 query.append(_FINDER_COLUMN_TYPE_TYPE_3);
563 }
564 else {
565 bindType = true;
566
567 query.append(_FINDER_COLUMN_TYPE_TYPE_2);
568 }
569
570 String sql = query.toString();
571
572 Session session = null;
573
574 try {
575 session = openSession();
576
577 Query q = session.createQuery(sql);
578
579 QueryPos qPos = QueryPos.getInstance(q);
580
581 if (bindType) {
582 qPos.add(type);
583 }
584
585 count = (Long)q.uniqueResult();
586
587 FinderCacheUtil.putResult(finderPath, finderArgs, count);
588 }
589 catch (Exception e) {
590 FinderCacheUtil.removeResult(finderPath, finderArgs);
591
592 throw processException(e);
593 }
594 finally {
595 closeSession(session);
596 }
597 }
598
599 return count.intValue();
600 }
601
602 private static final String _FINDER_COLUMN_TYPE_TYPE_1 = "listType.type IS NULL";
603 private static final String _FINDER_COLUMN_TYPE_TYPE_2 = "listType.type = ?";
604 private static final String _FINDER_COLUMN_TYPE_TYPE_3 = "(listType.type IS NULL OR listType.type = '')";
605
606 public ListTypePersistenceImpl() {
607 setModelClass(ListType.class);
608 }
609
610
615 @Override
616 public void cacheResult(ListType listType) {
617 EntityCacheUtil.putResult(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
618 ListTypeImpl.class, listType.getPrimaryKey(), listType);
619
620 listType.resetOriginalValues();
621 }
622
623
628 @Override
629 public void cacheResult(List<ListType> listTypes) {
630 for (ListType listType : listTypes) {
631 if (EntityCacheUtil.getResult(
632 ListTypeModelImpl.ENTITY_CACHE_ENABLED,
633 ListTypeImpl.class, listType.getPrimaryKey()) == null) {
634 cacheResult(listType);
635 }
636 else {
637 listType.resetOriginalValues();
638 }
639 }
640 }
641
642
649 @Override
650 public void clearCache() {
651 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
652 CacheRegistryUtil.clear(ListTypeImpl.class.getName());
653 }
654
655 EntityCacheUtil.clearCache(ListTypeImpl.class);
656
657 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
658 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
659 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
660 }
661
662
669 @Override
670 public void clearCache(ListType listType) {
671 EntityCacheUtil.removeResult(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
672 ListTypeImpl.class, listType.getPrimaryKey());
673
674 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
675 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
676 }
677
678 @Override
679 public void clearCache(List<ListType> listTypes) {
680 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
681 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
682
683 for (ListType listType : listTypes) {
684 EntityCacheUtil.removeResult(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
685 ListTypeImpl.class, listType.getPrimaryKey());
686 }
687 }
688
689
695 @Override
696 public ListType create(int listTypeId) {
697 ListType listType = new ListTypeImpl();
698
699 listType.setNew(true);
700 listType.setPrimaryKey(listTypeId);
701
702 return listType;
703 }
704
705
712 @Override
713 public ListType remove(int listTypeId) throws NoSuchListTypeException {
714 return remove((Serializable)listTypeId);
715 }
716
717
724 @Override
725 public ListType remove(Serializable primaryKey)
726 throws NoSuchListTypeException {
727 Session session = null;
728
729 try {
730 session = openSession();
731
732 ListType listType = (ListType)session.get(ListTypeImpl.class,
733 primaryKey);
734
735 if (listType == null) {
736 if (_log.isWarnEnabled()) {
737 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
738 }
739
740 throw new NoSuchListTypeException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
741 primaryKey);
742 }
743
744 return remove(listType);
745 }
746 catch (NoSuchListTypeException nsee) {
747 throw nsee;
748 }
749 catch (Exception e) {
750 throw processException(e);
751 }
752 finally {
753 closeSession(session);
754 }
755 }
756
757 @Override
758 protected ListType removeImpl(ListType listType) {
759 listType = toUnwrappedModel(listType);
760
761 Session session = null;
762
763 try {
764 session = openSession();
765
766 if (!session.contains(listType)) {
767 listType = (ListType)session.get(ListTypeImpl.class,
768 listType.getPrimaryKeyObj());
769 }
770
771 if (listType != null) {
772 session.delete(listType);
773 }
774 }
775 catch (Exception e) {
776 throw processException(e);
777 }
778 finally {
779 closeSession(session);
780 }
781
782 if (listType != null) {
783 clearCache(listType);
784 }
785
786 return listType;
787 }
788
789 @Override
790 public ListType updateImpl(com.liferay.portal.model.ListType listType) {
791 listType = toUnwrappedModel(listType);
792
793 boolean isNew = listType.isNew();
794
795 ListTypeModelImpl listTypeModelImpl = (ListTypeModelImpl)listType;
796
797 Session session = null;
798
799 try {
800 session = openSession();
801
802 if (listType.isNew()) {
803 session.save(listType);
804
805 listType.setNew(false);
806 }
807 else {
808 session.merge(listType);
809 }
810 }
811 catch (Exception e) {
812 throw processException(e);
813 }
814 finally {
815 closeSession(session);
816 }
817
818 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
819
820 if (isNew || !ListTypeModelImpl.COLUMN_BITMASK_ENABLED) {
821 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
822 }
823
824 else {
825 if ((listTypeModelImpl.getColumnBitmask() &
826 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE.getColumnBitmask()) != 0) {
827 Object[] args = new Object[] { listTypeModelImpl.getOriginalType() };
828
829 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TYPE, args);
830 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE,
831 args);
832
833 args = new Object[] { listTypeModelImpl.getType() };
834
835 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TYPE, args);
836 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE,
837 args);
838 }
839 }
840
841 EntityCacheUtil.putResult(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
842 ListTypeImpl.class, listType.getPrimaryKey(), listType, false);
843
844 listType.resetOriginalValues();
845
846 return listType;
847 }
848
849 protected ListType toUnwrappedModel(ListType listType) {
850 if (listType instanceof ListTypeImpl) {
851 return listType;
852 }
853
854 ListTypeImpl listTypeImpl = new ListTypeImpl();
855
856 listTypeImpl.setNew(listType.isNew());
857 listTypeImpl.setPrimaryKey(listType.getPrimaryKey());
858
859 listTypeImpl.setMvccVersion(listType.getMvccVersion());
860 listTypeImpl.setListTypeId(listType.getListTypeId());
861 listTypeImpl.setName(listType.getName());
862 listTypeImpl.setType(listType.getType());
863
864 return listTypeImpl;
865 }
866
867
874 @Override
875 public ListType findByPrimaryKey(Serializable primaryKey)
876 throws NoSuchListTypeException {
877 ListType listType = fetchByPrimaryKey(primaryKey);
878
879 if (listType == null) {
880 if (_log.isWarnEnabled()) {
881 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
882 }
883
884 throw new NoSuchListTypeException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
885 primaryKey);
886 }
887
888 return listType;
889 }
890
891
898 @Override
899 public ListType findByPrimaryKey(int listTypeId)
900 throws NoSuchListTypeException {
901 return findByPrimaryKey((Serializable)listTypeId);
902 }
903
904
910 @Override
911 public ListType fetchByPrimaryKey(Serializable primaryKey) {
912 ListType listType = (ListType)EntityCacheUtil.getResult(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
913 ListTypeImpl.class, primaryKey);
914
915 if (listType == _nullListType) {
916 return null;
917 }
918
919 if (listType == null) {
920 Session session = null;
921
922 try {
923 session = openSession();
924
925 listType = (ListType)session.get(ListTypeImpl.class, primaryKey);
926
927 if (listType != null) {
928 cacheResult(listType);
929 }
930 else {
931 EntityCacheUtil.putResult(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
932 ListTypeImpl.class, primaryKey, _nullListType);
933 }
934 }
935 catch (Exception e) {
936 EntityCacheUtil.removeResult(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
937 ListTypeImpl.class, primaryKey);
938
939 throw processException(e);
940 }
941 finally {
942 closeSession(session);
943 }
944 }
945
946 return listType;
947 }
948
949
955 @Override
956 public ListType fetchByPrimaryKey(int listTypeId) {
957 return fetchByPrimaryKey((Serializable)listTypeId);
958 }
959
960 @Override
961 public Map<Serializable, ListType> fetchByPrimaryKeys(
962 Set<Serializable> primaryKeys) {
963 if (primaryKeys.isEmpty()) {
964 return Collections.emptyMap();
965 }
966
967 Map<Serializable, ListType> map = new HashMap<Serializable, ListType>();
968
969 if (primaryKeys.size() == 1) {
970 Iterator<Serializable> iterator = primaryKeys.iterator();
971
972 Serializable primaryKey = iterator.next();
973
974 ListType listType = fetchByPrimaryKey(primaryKey);
975
976 if (listType != null) {
977 map.put(primaryKey, listType);
978 }
979
980 return map;
981 }
982
983 Set<Serializable> uncachedPrimaryKeys = null;
984
985 for (Serializable primaryKey : primaryKeys) {
986 ListType listType = (ListType)EntityCacheUtil.getResult(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
987 ListTypeImpl.class, primaryKey);
988
989 if (listType == null) {
990 if (uncachedPrimaryKeys == null) {
991 uncachedPrimaryKeys = new HashSet<Serializable>();
992 }
993
994 uncachedPrimaryKeys.add(primaryKey);
995 }
996 else {
997 map.put(primaryKey, listType);
998 }
999 }
1000
1001 if (uncachedPrimaryKeys == null) {
1002 return map;
1003 }
1004
1005 StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
1006 1);
1007
1008 query.append(_SQL_SELECT_LISTTYPE_WHERE_PKS_IN);
1009
1010 for (Serializable primaryKey : uncachedPrimaryKeys) {
1011 query.append(String.valueOf(primaryKey));
1012
1013 query.append(StringPool.COMMA);
1014 }
1015
1016 query.setIndex(query.index() - 1);
1017
1018 query.append(StringPool.CLOSE_PARENTHESIS);
1019
1020 String sql = query.toString();
1021
1022 Session session = null;
1023
1024 try {
1025 session = openSession();
1026
1027 Query q = session.createQuery(sql);
1028
1029 for (ListType listType : (List<ListType>)q.list()) {
1030 map.put(listType.getPrimaryKeyObj(), listType);
1031
1032 cacheResult(listType);
1033
1034 uncachedPrimaryKeys.remove(listType.getPrimaryKeyObj());
1035 }
1036
1037 for (Serializable primaryKey : uncachedPrimaryKeys) {
1038 EntityCacheUtil.putResult(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
1039 ListTypeImpl.class, primaryKey, _nullListType);
1040 }
1041 }
1042 catch (Exception e) {
1043 throw processException(e);
1044 }
1045 finally {
1046 closeSession(session);
1047 }
1048
1049 return map;
1050 }
1051
1052
1057 @Override
1058 public List<ListType> findAll() {
1059 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1060 }
1061
1062
1073 @Override
1074 public List<ListType> findAll(int start, int end) {
1075 return findAll(start, end, null);
1076 }
1077
1078
1090 @Override
1091 public List<ListType> findAll(int start, int end,
1092 OrderByComparator<ListType> orderByComparator) {
1093 boolean pagination = true;
1094 FinderPath finderPath = null;
1095 Object[] finderArgs = null;
1096
1097 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1098 (orderByComparator == null)) {
1099 pagination = false;
1100 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1101 finderArgs = FINDER_ARGS_EMPTY;
1102 }
1103 else {
1104 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1105 finderArgs = new Object[] { start, end, orderByComparator };
1106 }
1107
1108 List<ListType> list = (List<ListType>)FinderCacheUtil.getResult(finderPath,
1109 finderArgs, this);
1110
1111 if (list == null) {
1112 StringBundler query = null;
1113 String sql = null;
1114
1115 if (orderByComparator != null) {
1116 query = new StringBundler(2 +
1117 (orderByComparator.getOrderByFields().length * 3));
1118
1119 query.append(_SQL_SELECT_LISTTYPE);
1120
1121 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1122 orderByComparator);
1123
1124 sql = query.toString();
1125 }
1126 else {
1127 sql = _SQL_SELECT_LISTTYPE;
1128
1129 if (pagination) {
1130 sql = sql.concat(ListTypeModelImpl.ORDER_BY_JPQL);
1131 }
1132 }
1133
1134 Session session = null;
1135
1136 try {
1137 session = openSession();
1138
1139 Query q = session.createQuery(sql);
1140
1141 if (!pagination) {
1142 list = (List<ListType>)QueryUtil.list(q, getDialect(),
1143 start, end, false);
1144
1145 Collections.sort(list);
1146
1147 list = Collections.unmodifiableList(list);
1148 }
1149 else {
1150 list = (List<ListType>)QueryUtil.list(q, getDialect(),
1151 start, end);
1152 }
1153
1154 cacheResult(list);
1155
1156 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1157 }
1158 catch (Exception e) {
1159 FinderCacheUtil.removeResult(finderPath, finderArgs);
1160
1161 throw processException(e);
1162 }
1163 finally {
1164 closeSession(session);
1165 }
1166 }
1167
1168 return list;
1169 }
1170
1171
1175 @Override
1176 public void removeAll() {
1177 for (ListType listType : findAll()) {
1178 remove(listType);
1179 }
1180 }
1181
1182
1187 @Override
1188 public int countAll() {
1189 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1190 FINDER_ARGS_EMPTY, this);
1191
1192 if (count == null) {
1193 Session session = null;
1194
1195 try {
1196 session = openSession();
1197
1198 Query q = session.createQuery(_SQL_COUNT_LISTTYPE);
1199
1200 count = (Long)q.uniqueResult();
1201
1202 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1203 FINDER_ARGS_EMPTY, count);
1204 }
1205 catch (Exception e) {
1206 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
1207 FINDER_ARGS_EMPTY);
1208
1209 throw processException(e);
1210 }
1211 finally {
1212 closeSession(session);
1213 }
1214 }
1215
1216 return count.intValue();
1217 }
1218
1219 @Override
1220 protected Set<String> getBadColumnNames() {
1221 return _badColumnNames;
1222 }
1223
1224
1227 public void afterPropertiesSet() {
1228 }
1229
1230 public void destroy() {
1231 EntityCacheUtil.removeCache(ListTypeImpl.class.getName());
1232 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1233 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1234 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1235 }
1236
1237 private static final String _SQL_SELECT_LISTTYPE = "SELECT listType FROM ListType listType";
1238 private static final String _SQL_SELECT_LISTTYPE_WHERE_PKS_IN = "SELECT listType FROM ListType listType WHERE listTypeId IN (";
1239 private static final String _SQL_SELECT_LISTTYPE_WHERE = "SELECT listType FROM ListType listType WHERE ";
1240 private static final String _SQL_COUNT_LISTTYPE = "SELECT COUNT(listType) FROM ListType listType";
1241 private static final String _SQL_COUNT_LISTTYPE_WHERE = "SELECT COUNT(listType) FROM ListType listType WHERE ";
1242 private static final String _ORDER_BY_ENTITY_ALIAS = "listType.";
1243 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ListType exists with the primary key ";
1244 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ListType exists with the key {";
1245 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1246 private static final Log _log = LogFactoryUtil.getLog(ListTypePersistenceImpl.class);
1247 private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
1248 "type"
1249 });
1250 private static final ListType _nullListType = new ListTypeImpl() {
1251 @Override
1252 public Object clone() {
1253 return this;
1254 }
1255
1256 @Override
1257 public CacheModel<ListType> toCacheModel() {
1258 return _nullListTypeCacheModel;
1259 }
1260 };
1261
1262 private static final CacheModel<ListType> _nullListTypeCacheModel = new NullCacheModel();
1263
1264 private static class NullCacheModel implements CacheModel<ListType>,
1265 MVCCModel {
1266 @Override
1267 public long getMvccVersion() {
1268 return -1;
1269 }
1270
1271 @Override
1272 public void setMvccVersion(long mvccVersion) {
1273 }
1274
1275 @Override
1276 public ListType toEntityModel() {
1277 return _nullListType;
1278 }
1279 }
1280 }