001
014
015 package com.liferay.portal.service.persistence.impl;
016
017 import aQute.bnd.annotation.ProviderType;
018
019 import com.liferay.portal.exception.NoSuchListTypeException;
020 import com.liferay.portal.kernel.dao.orm.EntityCache;
021 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderCache;
023 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
024 import com.liferay.portal.kernel.dao.orm.FinderPath;
025 import com.liferay.portal.kernel.dao.orm.Query;
026 import com.liferay.portal.kernel.dao.orm.QueryPos;
027 import com.liferay.portal.kernel.dao.orm.QueryUtil;
028 import com.liferay.portal.kernel.dao.orm.Session;
029 import com.liferay.portal.kernel.log.Log;
030 import com.liferay.portal.kernel.log.LogFactoryUtil;
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.Validator;
037 import com.liferay.portal.model.CacheModel;
038 import com.liferay.portal.model.ListType;
039 import com.liferay.portal.model.MVCCModel;
040 import com.liferay.portal.model.impl.ListTypeImpl;
041 import com.liferay.portal.model.impl.ListTypeModelImpl;
042 import com.liferay.portal.service.persistence.ListTypePersistence;
043
044 import java.io.Serializable;
045
046 import java.util.Collections;
047 import java.util.HashMap;
048 import java.util.HashSet;
049 import java.util.Iterator;
050 import java.util.List;
051 import java.util.Map;
052 import java.util.Set;
053
054
066 @ProviderType
067 public class ListTypePersistenceImpl extends BasePersistenceImpl<ListType>
068 implements ListTypePersistence {
069
074 public static final String FINDER_CLASS_NAME_ENTITY = ListTypeImpl.class.getName();
075 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
076 ".List1";
077 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
078 ".List2";
079 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
080 ListTypeModelImpl.FINDER_CACHE_ENABLED, ListTypeImpl.class,
081 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
082 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
083 ListTypeModelImpl.FINDER_CACHE_ENABLED, ListTypeImpl.class,
084 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
085 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
086 ListTypeModelImpl.FINDER_CACHE_ENABLED, Long.class,
087 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
088 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_TYPE = new FinderPath(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
089 ListTypeModelImpl.FINDER_CACHE_ENABLED, ListTypeImpl.class,
090 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByType",
091 new String[] {
092 String.class.getName(),
093
094 Integer.class.getName(), Integer.class.getName(),
095 OrderByComparator.class.getName()
096 });
097 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE = new FinderPath(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
098 ListTypeModelImpl.FINDER_CACHE_ENABLED, ListTypeImpl.class,
099 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByType",
100 new String[] { String.class.getName() },
101 ListTypeModelImpl.TYPE_COLUMN_BITMASK |
102 ListTypeModelImpl.NAME_COLUMN_BITMASK);
103 public static final FinderPath FINDER_PATH_COUNT_BY_TYPE = new FinderPath(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
104 ListTypeModelImpl.FINDER_CACHE_ENABLED, Long.class,
105 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByType",
106 new String[] { String.class.getName() });
107
108
114 @Override
115 public List<ListType> findByType(String type) {
116 return findByType(type, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
117 }
118
119
131 @Override
132 public List<ListType> findByType(String type, int start, int end) {
133 return findByType(type, start, end, null);
134 }
135
136
149 @Override
150 public List<ListType> findByType(String type, int start, int end,
151 OrderByComparator<ListType> orderByComparator) {
152 return findByType(type, start, end, orderByComparator, true);
153 }
154
155
169 @Override
170 public List<ListType> findByType(String type, int start, int end,
171 OrderByComparator<ListType> orderByComparator, boolean retrieveFromCache) {
172 boolean pagination = true;
173 FinderPath finderPath = null;
174 Object[] finderArgs = null;
175
176 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
177 (orderByComparator == null)) {
178 pagination = false;
179 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE;
180 finderArgs = new Object[] { type };
181 }
182 else {
183 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_TYPE;
184 finderArgs = new Object[] { type, start, end, orderByComparator };
185 }
186
187 List<ListType> list = null;
188
189 if (retrieveFromCache) {
190 list = (List<ListType>)finderCache.getResult(finderPath,
191 finderArgs, this);
192
193 if ((list != null) && !list.isEmpty()) {
194 for (ListType listType : list) {
195 if (!Validator.equals(type, listType.getType())) {
196 list = null;
197
198 break;
199 }
200 }
201 }
202 }
203
204 if (list == null) {
205 StringBundler query = null;
206
207 if (orderByComparator != null) {
208 query = new StringBundler(3 +
209 (orderByComparator.getOrderByFields().length * 2));
210 }
211 else {
212 query = new StringBundler(3);
213 }
214
215 query.append(_SQL_SELECT_LISTTYPE_WHERE);
216
217 boolean bindType = false;
218
219 if (type == null) {
220 query.append(_FINDER_COLUMN_TYPE_TYPE_1);
221 }
222 else if (type.equals(StringPool.BLANK)) {
223 query.append(_FINDER_COLUMN_TYPE_TYPE_3);
224 }
225 else {
226 bindType = true;
227
228 query.append(_FINDER_COLUMN_TYPE_TYPE_2);
229 }
230
231 if (orderByComparator != null) {
232 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
233 orderByComparator);
234 }
235 else
236 if (pagination) {
237 query.append(ListTypeModelImpl.ORDER_BY_JPQL);
238 }
239
240 String sql = query.toString();
241
242 Session session = null;
243
244 try {
245 session = openSession();
246
247 Query q = session.createQuery(sql);
248
249 QueryPos qPos = QueryPos.getInstance(q);
250
251 if (bindType) {
252 qPos.add(type);
253 }
254
255 if (!pagination) {
256 list = (List<ListType>)QueryUtil.list(q, getDialect(),
257 start, end, false);
258
259 Collections.sort(list);
260
261 list = Collections.unmodifiableList(list);
262 }
263 else {
264 list = (List<ListType>)QueryUtil.list(q, getDialect(),
265 start, end);
266 }
267
268 cacheResult(list);
269
270 finderCache.putResult(finderPath, finderArgs, list);
271 }
272 catch (Exception e) {
273 finderCache.removeResult(finderPath, finderArgs);
274
275 throw processException(e);
276 }
277 finally {
278 closeSession(session);
279 }
280 }
281
282 return list;
283 }
284
285
293 @Override
294 public ListType findByType_First(String type,
295 OrderByComparator<ListType> orderByComparator)
296 throws NoSuchListTypeException {
297 ListType listType = fetchByType_First(type, orderByComparator);
298
299 if (listType != null) {
300 return listType;
301 }
302
303 StringBundler msg = new StringBundler(4);
304
305 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
306
307 msg.append("type=");
308 msg.append(type);
309
310 msg.append(StringPool.CLOSE_CURLY_BRACE);
311
312 throw new NoSuchListTypeException(msg.toString());
313 }
314
315
322 @Override
323 public ListType fetchByType_First(String type,
324 OrderByComparator<ListType> orderByComparator) {
325 List<ListType> list = findByType(type, 0, 1, orderByComparator);
326
327 if (!list.isEmpty()) {
328 return list.get(0);
329 }
330
331 return null;
332 }
333
334
342 @Override
343 public ListType findByType_Last(String type,
344 OrderByComparator<ListType> orderByComparator)
345 throws NoSuchListTypeException {
346 ListType listType = fetchByType_Last(type, orderByComparator);
347
348 if (listType != null) {
349 return listType;
350 }
351
352 StringBundler msg = new StringBundler(4);
353
354 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
355
356 msg.append("type=");
357 msg.append(type);
358
359 msg.append(StringPool.CLOSE_CURLY_BRACE);
360
361 throw new NoSuchListTypeException(msg.toString());
362 }
363
364
371 @Override
372 public ListType fetchByType_Last(String type,
373 OrderByComparator<ListType> orderByComparator) {
374 int count = countByType(type);
375
376 if (count == 0) {
377 return null;
378 }
379
380 List<ListType> list = findByType(type, count - 1, count,
381 orderByComparator);
382
383 if (!list.isEmpty()) {
384 return list.get(0);
385 }
386
387 return null;
388 }
389
390
399 @Override
400 public ListType[] findByType_PrevAndNext(long listTypeId, String type,
401 OrderByComparator<ListType> orderByComparator)
402 throws NoSuchListTypeException {
403 ListType listType = findByPrimaryKey(listTypeId);
404
405 Session session = null;
406
407 try {
408 session = openSession();
409
410 ListType[] array = new ListTypeImpl[3];
411
412 array[0] = getByType_PrevAndNext(session, listType, type,
413 orderByComparator, true);
414
415 array[1] = listType;
416
417 array[2] = getByType_PrevAndNext(session, listType, type,
418 orderByComparator, false);
419
420 return array;
421 }
422 catch (Exception e) {
423 throw processException(e);
424 }
425 finally {
426 closeSession(session);
427 }
428 }
429
430 protected ListType getByType_PrevAndNext(Session session,
431 ListType listType, String type,
432 OrderByComparator<ListType> orderByComparator, boolean previous) {
433 StringBundler query = null;
434
435 if (orderByComparator != null) {
436 query = new StringBundler(4 +
437 (orderByComparator.getOrderByConditionFields().length * 3) +
438 (orderByComparator.getOrderByFields().length * 3));
439 }
440 else {
441 query = new StringBundler(3);
442 }
443
444 query.append(_SQL_SELECT_LISTTYPE_WHERE);
445
446 boolean bindType = false;
447
448 if (type == null) {
449 query.append(_FINDER_COLUMN_TYPE_TYPE_1);
450 }
451 else if (type.equals(StringPool.BLANK)) {
452 query.append(_FINDER_COLUMN_TYPE_TYPE_3);
453 }
454 else {
455 bindType = true;
456
457 query.append(_FINDER_COLUMN_TYPE_TYPE_2);
458 }
459
460 if (orderByComparator != null) {
461 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
462
463 if (orderByConditionFields.length > 0) {
464 query.append(WHERE_AND);
465 }
466
467 for (int i = 0; i < orderByConditionFields.length; i++) {
468 query.append(_ORDER_BY_ENTITY_ALIAS);
469 query.append(orderByConditionFields[i]);
470
471 if ((i + 1) < orderByConditionFields.length) {
472 if (orderByComparator.isAscending() ^ previous) {
473 query.append(WHERE_GREATER_THAN_HAS_NEXT);
474 }
475 else {
476 query.append(WHERE_LESSER_THAN_HAS_NEXT);
477 }
478 }
479 else {
480 if (orderByComparator.isAscending() ^ previous) {
481 query.append(WHERE_GREATER_THAN);
482 }
483 else {
484 query.append(WHERE_LESSER_THAN);
485 }
486 }
487 }
488
489 query.append(ORDER_BY_CLAUSE);
490
491 String[] orderByFields = orderByComparator.getOrderByFields();
492
493 for (int i = 0; i < orderByFields.length; i++) {
494 query.append(_ORDER_BY_ENTITY_ALIAS);
495 query.append(orderByFields[i]);
496
497 if ((i + 1) < orderByFields.length) {
498 if (orderByComparator.isAscending() ^ previous) {
499 query.append(ORDER_BY_ASC_HAS_NEXT);
500 }
501 else {
502 query.append(ORDER_BY_DESC_HAS_NEXT);
503 }
504 }
505 else {
506 if (orderByComparator.isAscending() ^ previous) {
507 query.append(ORDER_BY_ASC);
508 }
509 else {
510 query.append(ORDER_BY_DESC);
511 }
512 }
513 }
514 }
515 else {
516 query.append(ListTypeModelImpl.ORDER_BY_JPQL);
517 }
518
519 String sql = query.toString();
520
521 Query q = session.createQuery(sql);
522
523 q.setFirstResult(0);
524 q.setMaxResults(2);
525
526 QueryPos qPos = QueryPos.getInstance(q);
527
528 if (bindType) {
529 qPos.add(type);
530 }
531
532 if (orderByComparator != null) {
533 Object[] values = orderByComparator.getOrderByConditionValues(listType);
534
535 for (Object value : values) {
536 qPos.add(value);
537 }
538 }
539
540 List<ListType> list = q.list();
541
542 if (list.size() == 2) {
543 return list.get(1);
544 }
545 else {
546 return null;
547 }
548 }
549
550
555 @Override
556 public void removeByType(String type) {
557 for (ListType listType : findByType(type, QueryUtil.ALL_POS,
558 QueryUtil.ALL_POS, null)) {
559 remove(listType);
560 }
561 }
562
563
569 @Override
570 public int countByType(String type) {
571 FinderPath finderPath = FINDER_PATH_COUNT_BY_TYPE;
572
573 Object[] finderArgs = new Object[] { type };
574
575 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
576
577 if (count == null) {
578 StringBundler query = new StringBundler(2);
579
580 query.append(_SQL_COUNT_LISTTYPE_WHERE);
581
582 boolean bindType = false;
583
584 if (type == null) {
585 query.append(_FINDER_COLUMN_TYPE_TYPE_1);
586 }
587 else if (type.equals(StringPool.BLANK)) {
588 query.append(_FINDER_COLUMN_TYPE_TYPE_3);
589 }
590 else {
591 bindType = true;
592
593 query.append(_FINDER_COLUMN_TYPE_TYPE_2);
594 }
595
596 String sql = query.toString();
597
598 Session session = null;
599
600 try {
601 session = openSession();
602
603 Query q = session.createQuery(sql);
604
605 QueryPos qPos = QueryPos.getInstance(q);
606
607 if (bindType) {
608 qPos.add(type);
609 }
610
611 count = (Long)q.uniqueResult();
612
613 finderCache.putResult(finderPath, finderArgs, count);
614 }
615 catch (Exception e) {
616 finderCache.removeResult(finderPath, finderArgs);
617
618 throw processException(e);
619 }
620 finally {
621 closeSession(session);
622 }
623 }
624
625 return count.intValue();
626 }
627
628 private static final String _FINDER_COLUMN_TYPE_TYPE_1 = "listType.type IS NULL";
629 private static final String _FINDER_COLUMN_TYPE_TYPE_2 = "listType.type = ?";
630 private static final String _FINDER_COLUMN_TYPE_TYPE_3 = "(listType.type IS NULL OR listType.type = '')";
631 public static final FinderPath FINDER_PATH_FETCH_BY_N_T = new FinderPath(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
632 ListTypeModelImpl.FINDER_CACHE_ENABLED, ListTypeImpl.class,
633 FINDER_CLASS_NAME_ENTITY, "fetchByN_T",
634 new String[] { String.class.getName(), String.class.getName() },
635 ListTypeModelImpl.NAME_COLUMN_BITMASK |
636 ListTypeModelImpl.TYPE_COLUMN_BITMASK);
637 public static final FinderPath FINDER_PATH_COUNT_BY_N_T = new FinderPath(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
638 ListTypeModelImpl.FINDER_CACHE_ENABLED, Long.class,
639 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByN_T",
640 new String[] { String.class.getName(), String.class.getName() });
641
642
650 @Override
651 public ListType findByN_T(String name, String type)
652 throws NoSuchListTypeException {
653 ListType listType = fetchByN_T(name, type);
654
655 if (listType == null) {
656 StringBundler msg = new StringBundler(6);
657
658 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
659
660 msg.append("name=");
661 msg.append(name);
662
663 msg.append(", type=");
664 msg.append(type);
665
666 msg.append(StringPool.CLOSE_CURLY_BRACE);
667
668 if (_log.isWarnEnabled()) {
669 _log.warn(msg.toString());
670 }
671
672 throw new NoSuchListTypeException(msg.toString());
673 }
674
675 return listType;
676 }
677
678
685 @Override
686 public ListType fetchByN_T(String name, String type) {
687 return fetchByN_T(name, type, true);
688 }
689
690
698 @Override
699 public ListType fetchByN_T(String name, String type,
700 boolean retrieveFromCache) {
701 Object[] finderArgs = new Object[] { name, type };
702
703 Object result = null;
704
705 if (retrieveFromCache) {
706 result = finderCache.getResult(FINDER_PATH_FETCH_BY_N_T,
707 finderArgs, this);
708 }
709
710 if (result instanceof ListType) {
711 ListType listType = (ListType)result;
712
713 if (!Validator.equals(name, listType.getName()) ||
714 !Validator.equals(type, listType.getType())) {
715 result = null;
716 }
717 }
718
719 if (result == null) {
720 StringBundler query = new StringBundler(4);
721
722 query.append(_SQL_SELECT_LISTTYPE_WHERE);
723
724 boolean bindName = false;
725
726 if (name == null) {
727 query.append(_FINDER_COLUMN_N_T_NAME_1);
728 }
729 else if (name.equals(StringPool.BLANK)) {
730 query.append(_FINDER_COLUMN_N_T_NAME_3);
731 }
732 else {
733 bindName = true;
734
735 query.append(_FINDER_COLUMN_N_T_NAME_2);
736 }
737
738 boolean bindType = false;
739
740 if (type == null) {
741 query.append(_FINDER_COLUMN_N_T_TYPE_1);
742 }
743 else if (type.equals(StringPool.BLANK)) {
744 query.append(_FINDER_COLUMN_N_T_TYPE_3);
745 }
746 else {
747 bindType = true;
748
749 query.append(_FINDER_COLUMN_N_T_TYPE_2);
750 }
751
752 String sql = query.toString();
753
754 Session session = null;
755
756 try {
757 session = openSession();
758
759 Query q = session.createQuery(sql);
760
761 QueryPos qPos = QueryPos.getInstance(q);
762
763 if (bindName) {
764 qPos.add(name);
765 }
766
767 if (bindType) {
768 qPos.add(type);
769 }
770
771 List<ListType> list = q.list();
772
773 if (list.isEmpty()) {
774 finderCache.putResult(FINDER_PATH_FETCH_BY_N_T, finderArgs,
775 list);
776 }
777 else {
778 if ((list.size() > 1) && _log.isWarnEnabled()) {
779 _log.warn(
780 "ListTypePersistenceImpl.fetchByN_T(String, String, boolean) with parameters (" +
781 StringUtil.merge(finderArgs) +
782 ") yields a result set with more than 1 result. This violates the logical unique restriction. There is no order guarantee on which result is returned by this finder.");
783 }
784
785 ListType listType = list.get(0);
786
787 result = listType;
788
789 cacheResult(listType);
790
791 if ((listType.getName() == null) ||
792 !listType.getName().equals(name) ||
793 (listType.getType() == null) ||
794 !listType.getType().equals(type)) {
795 finderCache.putResult(FINDER_PATH_FETCH_BY_N_T,
796 finderArgs, listType);
797 }
798 }
799 }
800 catch (Exception e) {
801 finderCache.removeResult(FINDER_PATH_FETCH_BY_N_T, finderArgs);
802
803 throw processException(e);
804 }
805 finally {
806 closeSession(session);
807 }
808 }
809
810 if (result instanceof List<?>) {
811 return null;
812 }
813 else {
814 return (ListType)result;
815 }
816 }
817
818
825 @Override
826 public ListType removeByN_T(String name, String type)
827 throws NoSuchListTypeException {
828 ListType listType = findByN_T(name, type);
829
830 return remove(listType);
831 }
832
833
840 @Override
841 public int countByN_T(String name, String type) {
842 FinderPath finderPath = FINDER_PATH_COUNT_BY_N_T;
843
844 Object[] finderArgs = new Object[] { name, type };
845
846 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
847
848 if (count == null) {
849 StringBundler query = new StringBundler(3);
850
851 query.append(_SQL_COUNT_LISTTYPE_WHERE);
852
853 boolean bindName = false;
854
855 if (name == null) {
856 query.append(_FINDER_COLUMN_N_T_NAME_1);
857 }
858 else if (name.equals(StringPool.BLANK)) {
859 query.append(_FINDER_COLUMN_N_T_NAME_3);
860 }
861 else {
862 bindName = true;
863
864 query.append(_FINDER_COLUMN_N_T_NAME_2);
865 }
866
867 boolean bindType = false;
868
869 if (type == null) {
870 query.append(_FINDER_COLUMN_N_T_TYPE_1);
871 }
872 else if (type.equals(StringPool.BLANK)) {
873 query.append(_FINDER_COLUMN_N_T_TYPE_3);
874 }
875 else {
876 bindType = true;
877
878 query.append(_FINDER_COLUMN_N_T_TYPE_2);
879 }
880
881 String sql = query.toString();
882
883 Session session = null;
884
885 try {
886 session = openSession();
887
888 Query q = session.createQuery(sql);
889
890 QueryPos qPos = QueryPos.getInstance(q);
891
892 if (bindName) {
893 qPos.add(name);
894 }
895
896 if (bindType) {
897 qPos.add(type);
898 }
899
900 count = (Long)q.uniqueResult();
901
902 finderCache.putResult(finderPath, finderArgs, count);
903 }
904 catch (Exception e) {
905 finderCache.removeResult(finderPath, finderArgs);
906
907 throw processException(e);
908 }
909 finally {
910 closeSession(session);
911 }
912 }
913
914 return count.intValue();
915 }
916
917 private static final String _FINDER_COLUMN_N_T_NAME_1 = "listType.name IS NULL AND ";
918 private static final String _FINDER_COLUMN_N_T_NAME_2 = "listType.name = ? AND ";
919 private static final String _FINDER_COLUMN_N_T_NAME_3 = "(listType.name IS NULL OR listType.name = '') AND ";
920 private static final String _FINDER_COLUMN_N_T_TYPE_1 = "listType.type IS NULL";
921 private static final String _FINDER_COLUMN_N_T_TYPE_2 = "listType.type = ?";
922 private static final String _FINDER_COLUMN_N_T_TYPE_3 = "(listType.type IS NULL OR listType.type = '')";
923
924 public ListTypePersistenceImpl() {
925 setModelClass(ListType.class);
926 }
927
928
933 @Override
934 public void cacheResult(ListType listType) {
935 entityCache.putResult(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
936 ListTypeImpl.class, listType.getPrimaryKey(), listType);
937
938 finderCache.putResult(FINDER_PATH_FETCH_BY_N_T,
939 new Object[] { listType.getName(), listType.getType() }, listType);
940
941 listType.resetOriginalValues();
942 }
943
944
949 @Override
950 public void cacheResult(List<ListType> listTypes) {
951 for (ListType listType : listTypes) {
952 if (entityCache.getResult(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
953 ListTypeImpl.class, listType.getPrimaryKey()) == null) {
954 cacheResult(listType);
955 }
956 else {
957 listType.resetOriginalValues();
958 }
959 }
960 }
961
962
969 @Override
970 public void clearCache() {
971 entityCache.clearCache(ListTypeImpl.class);
972
973 finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
974 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
975 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
976 }
977
978
985 @Override
986 public void clearCache(ListType listType) {
987 entityCache.removeResult(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
988 ListTypeImpl.class, listType.getPrimaryKey());
989
990 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
991 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
992
993 clearUniqueFindersCache((ListTypeModelImpl)listType);
994 }
995
996 @Override
997 public void clearCache(List<ListType> listTypes) {
998 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
999 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1000
1001 for (ListType listType : listTypes) {
1002 entityCache.removeResult(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
1003 ListTypeImpl.class, listType.getPrimaryKey());
1004
1005 clearUniqueFindersCache((ListTypeModelImpl)listType);
1006 }
1007 }
1008
1009 protected void cacheUniqueFindersCache(
1010 ListTypeModelImpl listTypeModelImpl, boolean isNew) {
1011 if (isNew) {
1012 Object[] args = new Object[] {
1013 listTypeModelImpl.getName(), listTypeModelImpl.getType()
1014 };
1015
1016 finderCache.putResult(FINDER_PATH_COUNT_BY_N_T, args,
1017 Long.valueOf(1));
1018 finderCache.putResult(FINDER_PATH_FETCH_BY_N_T, args,
1019 listTypeModelImpl);
1020 }
1021 else {
1022 if ((listTypeModelImpl.getColumnBitmask() &
1023 FINDER_PATH_FETCH_BY_N_T.getColumnBitmask()) != 0) {
1024 Object[] args = new Object[] {
1025 listTypeModelImpl.getName(), listTypeModelImpl.getType()
1026 };
1027
1028 finderCache.putResult(FINDER_PATH_COUNT_BY_N_T, args,
1029 Long.valueOf(1));
1030 finderCache.putResult(FINDER_PATH_FETCH_BY_N_T, args,
1031 listTypeModelImpl);
1032 }
1033 }
1034 }
1035
1036 protected void clearUniqueFindersCache(ListTypeModelImpl listTypeModelImpl) {
1037 Object[] args = new Object[] {
1038 listTypeModelImpl.getName(), listTypeModelImpl.getType()
1039 };
1040
1041 finderCache.removeResult(FINDER_PATH_COUNT_BY_N_T, args);
1042 finderCache.removeResult(FINDER_PATH_FETCH_BY_N_T, args);
1043
1044 if ((listTypeModelImpl.getColumnBitmask() &
1045 FINDER_PATH_FETCH_BY_N_T.getColumnBitmask()) != 0) {
1046 args = new Object[] {
1047 listTypeModelImpl.getOriginalName(),
1048 listTypeModelImpl.getOriginalType()
1049 };
1050
1051 finderCache.removeResult(FINDER_PATH_COUNT_BY_N_T, args);
1052 finderCache.removeResult(FINDER_PATH_FETCH_BY_N_T, args);
1053 }
1054 }
1055
1056
1062 @Override
1063 public ListType create(long listTypeId) {
1064 ListType listType = new ListTypeImpl();
1065
1066 listType.setNew(true);
1067 listType.setPrimaryKey(listTypeId);
1068
1069 return listType;
1070 }
1071
1072
1079 @Override
1080 public ListType remove(long listTypeId) throws NoSuchListTypeException {
1081 return remove((Serializable)listTypeId);
1082 }
1083
1084
1091 @Override
1092 public ListType remove(Serializable primaryKey)
1093 throws NoSuchListTypeException {
1094 Session session = null;
1095
1096 try {
1097 session = openSession();
1098
1099 ListType listType = (ListType)session.get(ListTypeImpl.class,
1100 primaryKey);
1101
1102 if (listType == null) {
1103 if (_log.isWarnEnabled()) {
1104 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1105 }
1106
1107 throw new NoSuchListTypeException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1108 primaryKey);
1109 }
1110
1111 return remove(listType);
1112 }
1113 catch (NoSuchListTypeException nsee) {
1114 throw nsee;
1115 }
1116 catch (Exception e) {
1117 throw processException(e);
1118 }
1119 finally {
1120 closeSession(session);
1121 }
1122 }
1123
1124 @Override
1125 protected ListType removeImpl(ListType listType) {
1126 listType = toUnwrappedModel(listType);
1127
1128 Session session = null;
1129
1130 try {
1131 session = openSession();
1132
1133 if (!session.contains(listType)) {
1134 listType = (ListType)session.get(ListTypeImpl.class,
1135 listType.getPrimaryKeyObj());
1136 }
1137
1138 if (listType != null) {
1139 session.delete(listType);
1140 }
1141 }
1142 catch (Exception e) {
1143 throw processException(e);
1144 }
1145 finally {
1146 closeSession(session);
1147 }
1148
1149 if (listType != null) {
1150 clearCache(listType);
1151 }
1152
1153 return listType;
1154 }
1155
1156 @Override
1157 public ListType updateImpl(ListType listType) {
1158 listType = toUnwrappedModel(listType);
1159
1160 boolean isNew = listType.isNew();
1161
1162 ListTypeModelImpl listTypeModelImpl = (ListTypeModelImpl)listType;
1163
1164 Session session = null;
1165
1166 try {
1167 session = openSession();
1168
1169 if (listType.isNew()) {
1170 session.save(listType);
1171
1172 listType.setNew(false);
1173 }
1174 else {
1175 listType = (ListType)session.merge(listType);
1176 }
1177 }
1178 catch (Exception e) {
1179 throw processException(e);
1180 }
1181 finally {
1182 closeSession(session);
1183 }
1184
1185 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1186
1187 if (isNew || !ListTypeModelImpl.COLUMN_BITMASK_ENABLED) {
1188 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1189 }
1190
1191 else {
1192 if ((listTypeModelImpl.getColumnBitmask() &
1193 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE.getColumnBitmask()) != 0) {
1194 Object[] args = new Object[] { listTypeModelImpl.getOriginalType() };
1195
1196 finderCache.removeResult(FINDER_PATH_COUNT_BY_TYPE, args);
1197 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE,
1198 args);
1199
1200 args = new Object[] { listTypeModelImpl.getType() };
1201
1202 finderCache.removeResult(FINDER_PATH_COUNT_BY_TYPE, args);
1203 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE,
1204 args);
1205 }
1206 }
1207
1208 entityCache.putResult(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
1209 ListTypeImpl.class, listType.getPrimaryKey(), listType, false);
1210
1211 clearUniqueFindersCache(listTypeModelImpl);
1212 cacheUniqueFindersCache(listTypeModelImpl, isNew);
1213
1214 listType.resetOriginalValues();
1215
1216 return listType;
1217 }
1218
1219 protected ListType toUnwrappedModel(ListType listType) {
1220 if (listType instanceof ListTypeImpl) {
1221 return listType;
1222 }
1223
1224 ListTypeImpl listTypeImpl = new ListTypeImpl();
1225
1226 listTypeImpl.setNew(listType.isNew());
1227 listTypeImpl.setPrimaryKey(listType.getPrimaryKey());
1228
1229 listTypeImpl.setMvccVersion(listType.getMvccVersion());
1230 listTypeImpl.setListTypeId(listType.getListTypeId());
1231 listTypeImpl.setName(listType.getName());
1232 listTypeImpl.setType(listType.getType());
1233
1234 return listTypeImpl;
1235 }
1236
1237
1244 @Override
1245 public ListType findByPrimaryKey(Serializable primaryKey)
1246 throws NoSuchListTypeException {
1247 ListType listType = fetchByPrimaryKey(primaryKey);
1248
1249 if (listType == null) {
1250 if (_log.isWarnEnabled()) {
1251 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1252 }
1253
1254 throw new NoSuchListTypeException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1255 primaryKey);
1256 }
1257
1258 return listType;
1259 }
1260
1261
1268 @Override
1269 public ListType findByPrimaryKey(long listTypeId)
1270 throws NoSuchListTypeException {
1271 return findByPrimaryKey((Serializable)listTypeId);
1272 }
1273
1274
1280 @Override
1281 public ListType fetchByPrimaryKey(Serializable primaryKey) {
1282 ListType listType = (ListType)entityCache.getResult(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
1283 ListTypeImpl.class, primaryKey);
1284
1285 if (listType == _nullListType) {
1286 return null;
1287 }
1288
1289 if (listType == null) {
1290 Session session = null;
1291
1292 try {
1293 session = openSession();
1294
1295 listType = (ListType)session.get(ListTypeImpl.class, primaryKey);
1296
1297 if (listType != null) {
1298 cacheResult(listType);
1299 }
1300 else {
1301 entityCache.putResult(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
1302 ListTypeImpl.class, primaryKey, _nullListType);
1303 }
1304 }
1305 catch (Exception e) {
1306 entityCache.removeResult(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
1307 ListTypeImpl.class, primaryKey);
1308
1309 throw processException(e);
1310 }
1311 finally {
1312 closeSession(session);
1313 }
1314 }
1315
1316 return listType;
1317 }
1318
1319
1325 @Override
1326 public ListType fetchByPrimaryKey(long listTypeId) {
1327 return fetchByPrimaryKey((Serializable)listTypeId);
1328 }
1329
1330 @Override
1331 public Map<Serializable, ListType> fetchByPrimaryKeys(
1332 Set<Serializable> primaryKeys) {
1333 if (primaryKeys.isEmpty()) {
1334 return Collections.emptyMap();
1335 }
1336
1337 Map<Serializable, ListType> map = new HashMap<Serializable, ListType>();
1338
1339 if (primaryKeys.size() == 1) {
1340 Iterator<Serializable> iterator = primaryKeys.iterator();
1341
1342 Serializable primaryKey = iterator.next();
1343
1344 ListType listType = fetchByPrimaryKey(primaryKey);
1345
1346 if (listType != null) {
1347 map.put(primaryKey, listType);
1348 }
1349
1350 return map;
1351 }
1352
1353 Set<Serializable> uncachedPrimaryKeys = null;
1354
1355 for (Serializable primaryKey : primaryKeys) {
1356 ListType listType = (ListType)entityCache.getResult(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
1357 ListTypeImpl.class, primaryKey);
1358
1359 if (listType == null) {
1360 if (uncachedPrimaryKeys == null) {
1361 uncachedPrimaryKeys = new HashSet<Serializable>();
1362 }
1363
1364 uncachedPrimaryKeys.add(primaryKey);
1365 }
1366 else {
1367 map.put(primaryKey, listType);
1368 }
1369 }
1370
1371 if (uncachedPrimaryKeys == null) {
1372 return map;
1373 }
1374
1375 StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
1376 1);
1377
1378 query.append(_SQL_SELECT_LISTTYPE_WHERE_PKS_IN);
1379
1380 for (Serializable primaryKey : uncachedPrimaryKeys) {
1381 query.append(String.valueOf(primaryKey));
1382
1383 query.append(StringPool.COMMA);
1384 }
1385
1386 query.setIndex(query.index() - 1);
1387
1388 query.append(StringPool.CLOSE_PARENTHESIS);
1389
1390 String sql = query.toString();
1391
1392 Session session = null;
1393
1394 try {
1395 session = openSession();
1396
1397 Query q = session.createQuery(sql);
1398
1399 for (ListType listType : (List<ListType>)q.list()) {
1400 map.put(listType.getPrimaryKeyObj(), listType);
1401
1402 cacheResult(listType);
1403
1404 uncachedPrimaryKeys.remove(listType.getPrimaryKeyObj());
1405 }
1406
1407 for (Serializable primaryKey : uncachedPrimaryKeys) {
1408 entityCache.putResult(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
1409 ListTypeImpl.class, primaryKey, _nullListType);
1410 }
1411 }
1412 catch (Exception e) {
1413 throw processException(e);
1414 }
1415 finally {
1416 closeSession(session);
1417 }
1418
1419 return map;
1420 }
1421
1422
1427 @Override
1428 public List<ListType> findAll() {
1429 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1430 }
1431
1432
1443 @Override
1444 public List<ListType> findAll(int start, int end) {
1445 return findAll(start, end, null);
1446 }
1447
1448
1460 @Override
1461 public List<ListType> findAll(int start, int end,
1462 OrderByComparator<ListType> orderByComparator) {
1463 return findAll(start, end, orderByComparator, true);
1464 }
1465
1466
1479 @Override
1480 public List<ListType> findAll(int start, int end,
1481 OrderByComparator<ListType> orderByComparator, boolean retrieveFromCache) {
1482 boolean pagination = true;
1483 FinderPath finderPath = null;
1484 Object[] finderArgs = null;
1485
1486 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1487 (orderByComparator == null)) {
1488 pagination = false;
1489 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1490 finderArgs = FINDER_ARGS_EMPTY;
1491 }
1492 else {
1493 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1494 finderArgs = new Object[] { start, end, orderByComparator };
1495 }
1496
1497 List<ListType> list = null;
1498
1499 if (retrieveFromCache) {
1500 list = (List<ListType>)finderCache.getResult(finderPath,
1501 finderArgs, this);
1502 }
1503
1504 if (list == null) {
1505 StringBundler query = null;
1506 String sql = null;
1507
1508 if (orderByComparator != null) {
1509 query = new StringBundler(2 +
1510 (orderByComparator.getOrderByFields().length * 2));
1511
1512 query.append(_SQL_SELECT_LISTTYPE);
1513
1514 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1515 orderByComparator);
1516
1517 sql = query.toString();
1518 }
1519 else {
1520 sql = _SQL_SELECT_LISTTYPE;
1521
1522 if (pagination) {
1523 sql = sql.concat(ListTypeModelImpl.ORDER_BY_JPQL);
1524 }
1525 }
1526
1527 Session session = null;
1528
1529 try {
1530 session = openSession();
1531
1532 Query q = session.createQuery(sql);
1533
1534 if (!pagination) {
1535 list = (List<ListType>)QueryUtil.list(q, getDialect(),
1536 start, end, false);
1537
1538 Collections.sort(list);
1539
1540 list = Collections.unmodifiableList(list);
1541 }
1542 else {
1543 list = (List<ListType>)QueryUtil.list(q, getDialect(),
1544 start, end);
1545 }
1546
1547 cacheResult(list);
1548
1549 finderCache.putResult(finderPath, finderArgs, list);
1550 }
1551 catch (Exception e) {
1552 finderCache.removeResult(finderPath, finderArgs);
1553
1554 throw processException(e);
1555 }
1556 finally {
1557 closeSession(session);
1558 }
1559 }
1560
1561 return list;
1562 }
1563
1564
1568 @Override
1569 public void removeAll() {
1570 for (ListType listType : findAll()) {
1571 remove(listType);
1572 }
1573 }
1574
1575
1580 @Override
1581 public int countAll() {
1582 Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
1583 FINDER_ARGS_EMPTY, this);
1584
1585 if (count == null) {
1586 Session session = null;
1587
1588 try {
1589 session = openSession();
1590
1591 Query q = session.createQuery(_SQL_COUNT_LISTTYPE);
1592
1593 count = (Long)q.uniqueResult();
1594
1595 finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
1596 count);
1597 }
1598 catch (Exception e) {
1599 finderCache.removeResult(FINDER_PATH_COUNT_ALL,
1600 FINDER_ARGS_EMPTY);
1601
1602 throw processException(e);
1603 }
1604 finally {
1605 closeSession(session);
1606 }
1607 }
1608
1609 return count.intValue();
1610 }
1611
1612 @Override
1613 public Set<String> getBadColumnNames() {
1614 return _badColumnNames;
1615 }
1616
1617 @Override
1618 protected Map<String, Integer> getTableColumnsMap() {
1619 return ListTypeModelImpl.TABLE_COLUMNS_MAP;
1620 }
1621
1622
1625 public void afterPropertiesSet() {
1626 }
1627
1628 public void destroy() {
1629 entityCache.removeCache(ListTypeImpl.class.getName());
1630 finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
1631 finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1632 finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1633 }
1634
1635 protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
1636 protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
1637 private static final String _SQL_SELECT_LISTTYPE = "SELECT listType FROM ListType listType";
1638 private static final String _SQL_SELECT_LISTTYPE_WHERE_PKS_IN = "SELECT listType FROM ListType listType WHERE listTypeId IN (";
1639 private static final String _SQL_SELECT_LISTTYPE_WHERE = "SELECT listType FROM ListType listType WHERE ";
1640 private static final String _SQL_COUNT_LISTTYPE = "SELECT COUNT(listType) FROM ListType listType";
1641 private static final String _SQL_COUNT_LISTTYPE_WHERE = "SELECT COUNT(listType) FROM ListType listType WHERE ";
1642 private static final String _ORDER_BY_ENTITY_ALIAS = "listType.";
1643 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ListType exists with the primary key ";
1644 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ListType exists with the key {";
1645 private static final Log _log = LogFactoryUtil.getLog(ListTypePersistenceImpl.class);
1646 private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
1647 "type"
1648 });
1649 private static final ListType _nullListType = new ListTypeImpl() {
1650 @Override
1651 public Object clone() {
1652 return this;
1653 }
1654
1655 @Override
1656 public CacheModel<ListType> toCacheModel() {
1657 return _nullListTypeCacheModel;
1658 }
1659 };
1660
1661 private static final CacheModel<ListType> _nullListTypeCacheModel = new NullCacheModel();
1662
1663 private static class NullCacheModel implements CacheModel<ListType>,
1664 MVCCModel {
1665 @Override
1666 public long getMvccVersion() {
1667 return -1;
1668 }
1669
1670 @Override
1671 public void setMvccVersion(long mvccVersion) {
1672 }
1673
1674 @Override
1675 public ListType toEntityModel() {
1676 return _nullListType;
1677 }
1678 }
1679 }