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 * 3));
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(6 +
437 (orderByComparator.getOrderByFields().length * 6));
438 }
439 else {
440 query = new StringBundler(3);
441 }
442
443 query.append(_SQL_SELECT_LISTTYPE_WHERE);
444
445 boolean bindType = false;
446
447 if (type == null) {
448 query.append(_FINDER_COLUMN_TYPE_TYPE_1);
449 }
450 else if (type.equals(StringPool.BLANK)) {
451 query.append(_FINDER_COLUMN_TYPE_TYPE_3);
452 }
453 else {
454 bindType = true;
455
456 query.append(_FINDER_COLUMN_TYPE_TYPE_2);
457 }
458
459 if (orderByComparator != null) {
460 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
461
462 if (orderByConditionFields.length > 0) {
463 query.append(WHERE_AND);
464 }
465
466 for (int i = 0; i < orderByConditionFields.length; i++) {
467 query.append(_ORDER_BY_ENTITY_ALIAS);
468 query.append(orderByConditionFields[i]);
469
470 if ((i + 1) < orderByConditionFields.length) {
471 if (orderByComparator.isAscending() ^ previous) {
472 query.append(WHERE_GREATER_THAN_HAS_NEXT);
473 }
474 else {
475 query.append(WHERE_LESSER_THAN_HAS_NEXT);
476 }
477 }
478 else {
479 if (orderByComparator.isAscending() ^ previous) {
480 query.append(WHERE_GREATER_THAN);
481 }
482 else {
483 query.append(WHERE_LESSER_THAN);
484 }
485 }
486 }
487
488 query.append(ORDER_BY_CLAUSE);
489
490 String[] orderByFields = orderByComparator.getOrderByFields();
491
492 for (int i = 0; i < orderByFields.length; i++) {
493 query.append(_ORDER_BY_ENTITY_ALIAS);
494 query.append(orderByFields[i]);
495
496 if ((i + 1) < orderByFields.length) {
497 if (orderByComparator.isAscending() ^ previous) {
498 query.append(ORDER_BY_ASC_HAS_NEXT);
499 }
500 else {
501 query.append(ORDER_BY_DESC_HAS_NEXT);
502 }
503 }
504 else {
505 if (orderByComparator.isAscending() ^ previous) {
506 query.append(ORDER_BY_ASC);
507 }
508 else {
509 query.append(ORDER_BY_DESC);
510 }
511 }
512 }
513 }
514 else {
515 query.append(ListTypeModelImpl.ORDER_BY_JPQL);
516 }
517
518 String sql = query.toString();
519
520 Query q = session.createQuery(sql);
521
522 q.setFirstResult(0);
523 q.setMaxResults(2);
524
525 QueryPos qPos = QueryPos.getInstance(q);
526
527 if (bindType) {
528 qPos.add(type);
529 }
530
531 if (orderByComparator != null) {
532 Object[] values = orderByComparator.getOrderByConditionValues(listType);
533
534 for (Object value : values) {
535 qPos.add(value);
536 }
537 }
538
539 List<ListType> list = q.list();
540
541 if (list.size() == 2) {
542 return list.get(1);
543 }
544 else {
545 return null;
546 }
547 }
548
549
554 @Override
555 public void removeByType(String type) {
556 for (ListType listType : findByType(type, QueryUtil.ALL_POS,
557 QueryUtil.ALL_POS, null)) {
558 remove(listType);
559 }
560 }
561
562
568 @Override
569 public int countByType(String type) {
570 FinderPath finderPath = FINDER_PATH_COUNT_BY_TYPE;
571
572 Object[] finderArgs = new Object[] { type };
573
574 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
575
576 if (count == null) {
577 StringBundler query = new StringBundler(2);
578
579 query.append(_SQL_COUNT_LISTTYPE_WHERE);
580
581 boolean bindType = false;
582
583 if (type == null) {
584 query.append(_FINDER_COLUMN_TYPE_TYPE_1);
585 }
586 else if (type.equals(StringPool.BLANK)) {
587 query.append(_FINDER_COLUMN_TYPE_TYPE_3);
588 }
589 else {
590 bindType = true;
591
592 query.append(_FINDER_COLUMN_TYPE_TYPE_2);
593 }
594
595 String sql = query.toString();
596
597 Session session = null;
598
599 try {
600 session = openSession();
601
602 Query q = session.createQuery(sql);
603
604 QueryPos qPos = QueryPos.getInstance(q);
605
606 if (bindType) {
607 qPos.add(type);
608 }
609
610 count = (Long)q.uniqueResult();
611
612 finderCache.putResult(finderPath, finderArgs, count);
613 }
614 catch (Exception e) {
615 finderCache.removeResult(finderPath, finderArgs);
616
617 throw processException(e);
618 }
619 finally {
620 closeSession(session);
621 }
622 }
623
624 return count.intValue();
625 }
626
627 private static final String _FINDER_COLUMN_TYPE_TYPE_1 = "listType.type IS NULL";
628 private static final String _FINDER_COLUMN_TYPE_TYPE_2 = "listType.type = ?";
629 private static final String _FINDER_COLUMN_TYPE_TYPE_3 = "(listType.type IS NULL OR listType.type = '')";
630 public static final FinderPath FINDER_PATH_FETCH_BY_N_T = new FinderPath(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
631 ListTypeModelImpl.FINDER_CACHE_ENABLED, ListTypeImpl.class,
632 FINDER_CLASS_NAME_ENTITY, "fetchByN_T",
633 new String[] { String.class.getName(), String.class.getName() },
634 ListTypeModelImpl.NAME_COLUMN_BITMASK |
635 ListTypeModelImpl.TYPE_COLUMN_BITMASK);
636 public static final FinderPath FINDER_PATH_COUNT_BY_N_T = new FinderPath(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
637 ListTypeModelImpl.FINDER_CACHE_ENABLED, Long.class,
638 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByN_T",
639 new String[] { String.class.getName(), String.class.getName() });
640
641
649 @Override
650 public ListType findByN_T(String name, String type)
651 throws NoSuchListTypeException {
652 ListType listType = fetchByN_T(name, type);
653
654 if (listType == null) {
655 StringBundler msg = new StringBundler(6);
656
657 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
658
659 msg.append("name=");
660 msg.append(name);
661
662 msg.append(", type=");
663 msg.append(type);
664
665 msg.append(StringPool.CLOSE_CURLY_BRACE);
666
667 if (_log.isWarnEnabled()) {
668 _log.warn(msg.toString());
669 }
670
671 throw new NoSuchListTypeException(msg.toString());
672 }
673
674 return listType;
675 }
676
677
684 @Override
685 public ListType fetchByN_T(String name, String type) {
686 return fetchByN_T(name, type, true);
687 }
688
689
697 @Override
698 public ListType fetchByN_T(String name, String type,
699 boolean retrieveFromCache) {
700 Object[] finderArgs = new Object[] { name, type };
701
702 Object result = null;
703
704 if (retrieveFromCache) {
705 result = finderCache.getResult(FINDER_PATH_FETCH_BY_N_T,
706 finderArgs, this);
707 }
708
709 if (result instanceof ListType) {
710 ListType listType = (ListType)result;
711
712 if (!Validator.equals(name, listType.getName()) ||
713 !Validator.equals(type, listType.getType())) {
714 result = null;
715 }
716 }
717
718 if (result == null) {
719 StringBundler query = new StringBundler(4);
720
721 query.append(_SQL_SELECT_LISTTYPE_WHERE);
722
723 boolean bindName = false;
724
725 if (name == null) {
726 query.append(_FINDER_COLUMN_N_T_NAME_1);
727 }
728 else if (name.equals(StringPool.BLANK)) {
729 query.append(_FINDER_COLUMN_N_T_NAME_3);
730 }
731 else {
732 bindName = true;
733
734 query.append(_FINDER_COLUMN_N_T_NAME_2);
735 }
736
737 boolean bindType = false;
738
739 if (type == null) {
740 query.append(_FINDER_COLUMN_N_T_TYPE_1);
741 }
742 else if (type.equals(StringPool.BLANK)) {
743 query.append(_FINDER_COLUMN_N_T_TYPE_3);
744 }
745 else {
746 bindType = true;
747
748 query.append(_FINDER_COLUMN_N_T_TYPE_2);
749 }
750
751 String sql = query.toString();
752
753 Session session = null;
754
755 try {
756 session = openSession();
757
758 Query q = session.createQuery(sql);
759
760 QueryPos qPos = QueryPos.getInstance(q);
761
762 if (bindName) {
763 qPos.add(name);
764 }
765
766 if (bindType) {
767 qPos.add(type);
768 }
769
770 List<ListType> list = q.list();
771
772 if (list.isEmpty()) {
773 finderCache.putResult(FINDER_PATH_FETCH_BY_N_T, finderArgs,
774 list);
775 }
776 else {
777 if ((list.size() > 1) && _log.isWarnEnabled()) {
778 _log.warn(
779 "ListTypePersistenceImpl.fetchByN_T(String, String, boolean) with parameters (" +
780 StringUtil.merge(finderArgs) +
781 ") 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.");
782 }
783
784 ListType listType = list.get(0);
785
786 result = listType;
787
788 cacheResult(listType);
789
790 if ((listType.getName() == null) ||
791 !listType.getName().equals(name) ||
792 (listType.getType() == null) ||
793 !listType.getType().equals(type)) {
794 finderCache.putResult(FINDER_PATH_FETCH_BY_N_T,
795 finderArgs, listType);
796 }
797 }
798 }
799 catch (Exception e) {
800 finderCache.removeResult(FINDER_PATH_FETCH_BY_N_T, finderArgs);
801
802 throw processException(e);
803 }
804 finally {
805 closeSession(session);
806 }
807 }
808
809 if (result instanceof List<?>) {
810 return null;
811 }
812 else {
813 return (ListType)result;
814 }
815 }
816
817
824 @Override
825 public ListType removeByN_T(String name, String type)
826 throws NoSuchListTypeException {
827 ListType listType = findByN_T(name, type);
828
829 return remove(listType);
830 }
831
832
839 @Override
840 public int countByN_T(String name, String type) {
841 FinderPath finderPath = FINDER_PATH_COUNT_BY_N_T;
842
843 Object[] finderArgs = new Object[] { name, type };
844
845 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
846
847 if (count == null) {
848 StringBundler query = new StringBundler(3);
849
850 query.append(_SQL_COUNT_LISTTYPE_WHERE);
851
852 boolean bindName = false;
853
854 if (name == null) {
855 query.append(_FINDER_COLUMN_N_T_NAME_1);
856 }
857 else if (name.equals(StringPool.BLANK)) {
858 query.append(_FINDER_COLUMN_N_T_NAME_3);
859 }
860 else {
861 bindName = true;
862
863 query.append(_FINDER_COLUMN_N_T_NAME_2);
864 }
865
866 boolean bindType = false;
867
868 if (type == null) {
869 query.append(_FINDER_COLUMN_N_T_TYPE_1);
870 }
871 else if (type.equals(StringPool.BLANK)) {
872 query.append(_FINDER_COLUMN_N_T_TYPE_3);
873 }
874 else {
875 bindType = true;
876
877 query.append(_FINDER_COLUMN_N_T_TYPE_2);
878 }
879
880 String sql = query.toString();
881
882 Session session = null;
883
884 try {
885 session = openSession();
886
887 Query q = session.createQuery(sql);
888
889 QueryPos qPos = QueryPos.getInstance(q);
890
891 if (bindName) {
892 qPos.add(name);
893 }
894
895 if (bindType) {
896 qPos.add(type);
897 }
898
899 count = (Long)q.uniqueResult();
900
901 finderCache.putResult(finderPath, finderArgs, count);
902 }
903 catch (Exception e) {
904 finderCache.removeResult(finderPath, finderArgs);
905
906 throw processException(e);
907 }
908 finally {
909 closeSession(session);
910 }
911 }
912
913 return count.intValue();
914 }
915
916 private static final String _FINDER_COLUMN_N_T_NAME_1 = "listType.name IS NULL AND ";
917 private static final String _FINDER_COLUMN_N_T_NAME_2 = "listType.name = ? AND ";
918 private static final String _FINDER_COLUMN_N_T_NAME_3 = "(listType.name IS NULL OR listType.name = '') AND ";
919 private static final String _FINDER_COLUMN_N_T_TYPE_1 = "listType.type IS NULL";
920 private static final String _FINDER_COLUMN_N_T_TYPE_2 = "listType.type = ?";
921 private static final String _FINDER_COLUMN_N_T_TYPE_3 = "(listType.type IS NULL OR listType.type = '')";
922
923 public ListTypePersistenceImpl() {
924 setModelClass(ListType.class);
925 }
926
927
932 @Override
933 public void cacheResult(ListType listType) {
934 entityCache.putResult(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
935 ListTypeImpl.class, listType.getPrimaryKey(), listType);
936
937 finderCache.putResult(FINDER_PATH_FETCH_BY_N_T,
938 new Object[] { listType.getName(), listType.getType() }, listType);
939
940 listType.resetOriginalValues();
941 }
942
943
948 @Override
949 public void cacheResult(List<ListType> listTypes) {
950 for (ListType listType : listTypes) {
951 if (entityCache.getResult(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
952 ListTypeImpl.class, listType.getPrimaryKey()) == null) {
953 cacheResult(listType);
954 }
955 else {
956 listType.resetOriginalValues();
957 }
958 }
959 }
960
961
968 @Override
969 public void clearCache() {
970 entityCache.clearCache(ListTypeImpl.class);
971
972 finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
973 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
974 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
975 }
976
977
984 @Override
985 public void clearCache(ListType listType) {
986 entityCache.removeResult(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
987 ListTypeImpl.class, listType.getPrimaryKey());
988
989 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
990 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
991
992 clearUniqueFindersCache((ListTypeModelImpl)listType);
993 }
994
995 @Override
996 public void clearCache(List<ListType> listTypes) {
997 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
998 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
999
1000 for (ListType listType : listTypes) {
1001 entityCache.removeResult(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
1002 ListTypeImpl.class, listType.getPrimaryKey());
1003
1004 clearUniqueFindersCache((ListTypeModelImpl)listType);
1005 }
1006 }
1007
1008 protected void cacheUniqueFindersCache(
1009 ListTypeModelImpl listTypeModelImpl, boolean isNew) {
1010 if (isNew) {
1011 Object[] args = new Object[] {
1012 listTypeModelImpl.getName(), listTypeModelImpl.getType()
1013 };
1014
1015 finderCache.putResult(FINDER_PATH_COUNT_BY_N_T, args,
1016 Long.valueOf(1));
1017 finderCache.putResult(FINDER_PATH_FETCH_BY_N_T, args,
1018 listTypeModelImpl);
1019 }
1020 else {
1021 if ((listTypeModelImpl.getColumnBitmask() &
1022 FINDER_PATH_FETCH_BY_N_T.getColumnBitmask()) != 0) {
1023 Object[] args = new Object[] {
1024 listTypeModelImpl.getName(), listTypeModelImpl.getType()
1025 };
1026
1027 finderCache.putResult(FINDER_PATH_COUNT_BY_N_T, args,
1028 Long.valueOf(1));
1029 finderCache.putResult(FINDER_PATH_FETCH_BY_N_T, args,
1030 listTypeModelImpl);
1031 }
1032 }
1033 }
1034
1035 protected void clearUniqueFindersCache(ListTypeModelImpl listTypeModelImpl) {
1036 Object[] args = new Object[] {
1037 listTypeModelImpl.getName(), listTypeModelImpl.getType()
1038 };
1039
1040 finderCache.removeResult(FINDER_PATH_COUNT_BY_N_T, args);
1041 finderCache.removeResult(FINDER_PATH_FETCH_BY_N_T, args);
1042
1043 if ((listTypeModelImpl.getColumnBitmask() &
1044 FINDER_PATH_FETCH_BY_N_T.getColumnBitmask()) != 0) {
1045 args = new Object[] {
1046 listTypeModelImpl.getOriginalName(),
1047 listTypeModelImpl.getOriginalType()
1048 };
1049
1050 finderCache.removeResult(FINDER_PATH_COUNT_BY_N_T, args);
1051 finderCache.removeResult(FINDER_PATH_FETCH_BY_N_T, args);
1052 }
1053 }
1054
1055
1061 @Override
1062 public ListType create(long listTypeId) {
1063 ListType listType = new ListTypeImpl();
1064
1065 listType.setNew(true);
1066 listType.setPrimaryKey(listTypeId);
1067
1068 return listType;
1069 }
1070
1071
1078 @Override
1079 public ListType remove(long listTypeId) throws NoSuchListTypeException {
1080 return remove((Serializable)listTypeId);
1081 }
1082
1083
1090 @Override
1091 public ListType remove(Serializable primaryKey)
1092 throws NoSuchListTypeException {
1093 Session session = null;
1094
1095 try {
1096 session = openSession();
1097
1098 ListType listType = (ListType)session.get(ListTypeImpl.class,
1099 primaryKey);
1100
1101 if (listType == null) {
1102 if (_log.isWarnEnabled()) {
1103 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1104 }
1105
1106 throw new NoSuchListTypeException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1107 primaryKey);
1108 }
1109
1110 return remove(listType);
1111 }
1112 catch (NoSuchListTypeException nsee) {
1113 throw nsee;
1114 }
1115 catch (Exception e) {
1116 throw processException(e);
1117 }
1118 finally {
1119 closeSession(session);
1120 }
1121 }
1122
1123 @Override
1124 protected ListType removeImpl(ListType listType) {
1125 listType = toUnwrappedModel(listType);
1126
1127 Session session = null;
1128
1129 try {
1130 session = openSession();
1131
1132 if (!session.contains(listType)) {
1133 listType = (ListType)session.get(ListTypeImpl.class,
1134 listType.getPrimaryKeyObj());
1135 }
1136
1137 if (listType != null) {
1138 session.delete(listType);
1139 }
1140 }
1141 catch (Exception e) {
1142 throw processException(e);
1143 }
1144 finally {
1145 closeSession(session);
1146 }
1147
1148 if (listType != null) {
1149 clearCache(listType);
1150 }
1151
1152 return listType;
1153 }
1154
1155 @Override
1156 public ListType updateImpl(ListType listType) {
1157 listType = toUnwrappedModel(listType);
1158
1159 boolean isNew = listType.isNew();
1160
1161 ListTypeModelImpl listTypeModelImpl = (ListTypeModelImpl)listType;
1162
1163 Session session = null;
1164
1165 try {
1166 session = openSession();
1167
1168 if (listType.isNew()) {
1169 session.save(listType);
1170
1171 listType.setNew(false);
1172 }
1173 else {
1174 listType = (ListType)session.merge(listType);
1175 }
1176 }
1177 catch (Exception e) {
1178 throw processException(e);
1179 }
1180 finally {
1181 closeSession(session);
1182 }
1183
1184 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1185
1186 if (isNew || !ListTypeModelImpl.COLUMN_BITMASK_ENABLED) {
1187 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1188 }
1189
1190 else {
1191 if ((listTypeModelImpl.getColumnBitmask() &
1192 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE.getColumnBitmask()) != 0) {
1193 Object[] args = new Object[] { listTypeModelImpl.getOriginalType() };
1194
1195 finderCache.removeResult(FINDER_PATH_COUNT_BY_TYPE, args);
1196 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE,
1197 args);
1198
1199 args = new Object[] { listTypeModelImpl.getType() };
1200
1201 finderCache.removeResult(FINDER_PATH_COUNT_BY_TYPE, args);
1202 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE,
1203 args);
1204 }
1205 }
1206
1207 entityCache.putResult(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
1208 ListTypeImpl.class, listType.getPrimaryKey(), listType, false);
1209
1210 clearUniqueFindersCache(listTypeModelImpl);
1211 cacheUniqueFindersCache(listTypeModelImpl, isNew);
1212
1213 listType.resetOriginalValues();
1214
1215 return listType;
1216 }
1217
1218 protected ListType toUnwrappedModel(ListType listType) {
1219 if (listType instanceof ListTypeImpl) {
1220 return listType;
1221 }
1222
1223 ListTypeImpl listTypeImpl = new ListTypeImpl();
1224
1225 listTypeImpl.setNew(listType.isNew());
1226 listTypeImpl.setPrimaryKey(listType.getPrimaryKey());
1227
1228 listTypeImpl.setMvccVersion(listType.getMvccVersion());
1229 listTypeImpl.setListTypeId(listType.getListTypeId());
1230 listTypeImpl.setName(listType.getName());
1231 listTypeImpl.setType(listType.getType());
1232
1233 return listTypeImpl;
1234 }
1235
1236
1243 @Override
1244 public ListType findByPrimaryKey(Serializable primaryKey)
1245 throws NoSuchListTypeException {
1246 ListType listType = fetchByPrimaryKey(primaryKey);
1247
1248 if (listType == null) {
1249 if (_log.isWarnEnabled()) {
1250 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1251 }
1252
1253 throw new NoSuchListTypeException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1254 primaryKey);
1255 }
1256
1257 return listType;
1258 }
1259
1260
1267 @Override
1268 public ListType findByPrimaryKey(long listTypeId)
1269 throws NoSuchListTypeException {
1270 return findByPrimaryKey((Serializable)listTypeId);
1271 }
1272
1273
1279 @Override
1280 public ListType fetchByPrimaryKey(Serializable primaryKey) {
1281 ListType listType = (ListType)entityCache.getResult(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
1282 ListTypeImpl.class, primaryKey);
1283
1284 if (listType == _nullListType) {
1285 return null;
1286 }
1287
1288 if (listType == null) {
1289 Session session = null;
1290
1291 try {
1292 session = openSession();
1293
1294 listType = (ListType)session.get(ListTypeImpl.class, primaryKey);
1295
1296 if (listType != null) {
1297 cacheResult(listType);
1298 }
1299 else {
1300 entityCache.putResult(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
1301 ListTypeImpl.class, primaryKey, _nullListType);
1302 }
1303 }
1304 catch (Exception e) {
1305 entityCache.removeResult(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
1306 ListTypeImpl.class, primaryKey);
1307
1308 throw processException(e);
1309 }
1310 finally {
1311 closeSession(session);
1312 }
1313 }
1314
1315 return listType;
1316 }
1317
1318
1324 @Override
1325 public ListType fetchByPrimaryKey(long listTypeId) {
1326 return fetchByPrimaryKey((Serializable)listTypeId);
1327 }
1328
1329 @Override
1330 public Map<Serializable, ListType> fetchByPrimaryKeys(
1331 Set<Serializable> primaryKeys) {
1332 if (primaryKeys.isEmpty()) {
1333 return Collections.emptyMap();
1334 }
1335
1336 Map<Serializable, ListType> map = new HashMap<Serializable, ListType>();
1337
1338 if (primaryKeys.size() == 1) {
1339 Iterator<Serializable> iterator = primaryKeys.iterator();
1340
1341 Serializable primaryKey = iterator.next();
1342
1343 ListType listType = fetchByPrimaryKey(primaryKey);
1344
1345 if (listType != null) {
1346 map.put(primaryKey, listType);
1347 }
1348
1349 return map;
1350 }
1351
1352 Set<Serializable> uncachedPrimaryKeys = null;
1353
1354 for (Serializable primaryKey : primaryKeys) {
1355 ListType listType = (ListType)entityCache.getResult(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
1356 ListTypeImpl.class, primaryKey);
1357
1358 if (listType == null) {
1359 if (uncachedPrimaryKeys == null) {
1360 uncachedPrimaryKeys = new HashSet<Serializable>();
1361 }
1362
1363 uncachedPrimaryKeys.add(primaryKey);
1364 }
1365 else {
1366 map.put(primaryKey, listType);
1367 }
1368 }
1369
1370 if (uncachedPrimaryKeys == null) {
1371 return map;
1372 }
1373
1374 StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
1375 1);
1376
1377 query.append(_SQL_SELECT_LISTTYPE_WHERE_PKS_IN);
1378
1379 for (Serializable primaryKey : uncachedPrimaryKeys) {
1380 query.append(String.valueOf(primaryKey));
1381
1382 query.append(StringPool.COMMA);
1383 }
1384
1385 query.setIndex(query.index() - 1);
1386
1387 query.append(StringPool.CLOSE_PARENTHESIS);
1388
1389 String sql = query.toString();
1390
1391 Session session = null;
1392
1393 try {
1394 session = openSession();
1395
1396 Query q = session.createQuery(sql);
1397
1398 for (ListType listType : (List<ListType>)q.list()) {
1399 map.put(listType.getPrimaryKeyObj(), listType);
1400
1401 cacheResult(listType);
1402
1403 uncachedPrimaryKeys.remove(listType.getPrimaryKeyObj());
1404 }
1405
1406 for (Serializable primaryKey : uncachedPrimaryKeys) {
1407 entityCache.putResult(ListTypeModelImpl.ENTITY_CACHE_ENABLED,
1408 ListTypeImpl.class, primaryKey, _nullListType);
1409 }
1410 }
1411 catch (Exception e) {
1412 throw processException(e);
1413 }
1414 finally {
1415 closeSession(session);
1416 }
1417
1418 return map;
1419 }
1420
1421
1426 @Override
1427 public List<ListType> findAll() {
1428 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1429 }
1430
1431
1442 @Override
1443 public List<ListType> findAll(int start, int end) {
1444 return findAll(start, end, null);
1445 }
1446
1447
1459 @Override
1460 public List<ListType> findAll(int start, int end,
1461 OrderByComparator<ListType> orderByComparator) {
1462 return findAll(start, end, orderByComparator, true);
1463 }
1464
1465
1478 @Override
1479 public List<ListType> findAll(int start, int end,
1480 OrderByComparator<ListType> orderByComparator, boolean retrieveFromCache) {
1481 boolean pagination = true;
1482 FinderPath finderPath = null;
1483 Object[] finderArgs = null;
1484
1485 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1486 (orderByComparator == null)) {
1487 pagination = false;
1488 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1489 finderArgs = FINDER_ARGS_EMPTY;
1490 }
1491 else {
1492 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1493 finderArgs = new Object[] { start, end, orderByComparator };
1494 }
1495
1496 List<ListType> list = null;
1497
1498 if (retrieveFromCache) {
1499 list = (List<ListType>)finderCache.getResult(finderPath,
1500 finderArgs, this);
1501 }
1502
1503 if (list == null) {
1504 StringBundler query = null;
1505 String sql = null;
1506
1507 if (orderByComparator != null) {
1508 query = new StringBundler(2 +
1509 (orderByComparator.getOrderByFields().length * 3));
1510
1511 query.append(_SQL_SELECT_LISTTYPE);
1512
1513 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1514 orderByComparator);
1515
1516 sql = query.toString();
1517 }
1518 else {
1519 sql = _SQL_SELECT_LISTTYPE;
1520
1521 if (pagination) {
1522 sql = sql.concat(ListTypeModelImpl.ORDER_BY_JPQL);
1523 }
1524 }
1525
1526 Session session = null;
1527
1528 try {
1529 session = openSession();
1530
1531 Query q = session.createQuery(sql);
1532
1533 if (!pagination) {
1534 list = (List<ListType>)QueryUtil.list(q, getDialect(),
1535 start, end, false);
1536
1537 Collections.sort(list);
1538
1539 list = Collections.unmodifiableList(list);
1540 }
1541 else {
1542 list = (List<ListType>)QueryUtil.list(q, getDialect(),
1543 start, end);
1544 }
1545
1546 cacheResult(list);
1547
1548 finderCache.putResult(finderPath, finderArgs, list);
1549 }
1550 catch (Exception e) {
1551 finderCache.removeResult(finderPath, finderArgs);
1552
1553 throw processException(e);
1554 }
1555 finally {
1556 closeSession(session);
1557 }
1558 }
1559
1560 return list;
1561 }
1562
1563
1567 @Override
1568 public void removeAll() {
1569 for (ListType listType : findAll()) {
1570 remove(listType);
1571 }
1572 }
1573
1574
1579 @Override
1580 public int countAll() {
1581 Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
1582 FINDER_ARGS_EMPTY, this);
1583
1584 if (count == null) {
1585 Session session = null;
1586
1587 try {
1588 session = openSession();
1589
1590 Query q = session.createQuery(_SQL_COUNT_LISTTYPE);
1591
1592 count = (Long)q.uniqueResult();
1593
1594 finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
1595 count);
1596 }
1597 catch (Exception e) {
1598 finderCache.removeResult(FINDER_PATH_COUNT_ALL,
1599 FINDER_ARGS_EMPTY);
1600
1601 throw processException(e);
1602 }
1603 finally {
1604 closeSession(session);
1605 }
1606 }
1607
1608 return count.intValue();
1609 }
1610
1611 @Override
1612 public Set<String> getBadColumnNames() {
1613 return _badColumnNames;
1614 }
1615
1616 @Override
1617 protected Map<String, Integer> getTableColumnsMap() {
1618 return ListTypeModelImpl.TABLE_COLUMNS_MAP;
1619 }
1620
1621
1624 public void afterPropertiesSet() {
1625 }
1626
1627 public void destroy() {
1628 entityCache.removeCache(ListTypeImpl.class.getName());
1629 finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
1630 finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1631 finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1632 }
1633
1634 protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
1635 protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
1636 private static final String _SQL_SELECT_LISTTYPE = "SELECT listType FROM ListType listType";
1637 private static final String _SQL_SELECT_LISTTYPE_WHERE_PKS_IN = "SELECT listType FROM ListType listType WHERE listTypeId IN (";
1638 private static final String _SQL_SELECT_LISTTYPE_WHERE = "SELECT listType FROM ListType listType WHERE ";
1639 private static final String _SQL_COUNT_LISTTYPE = "SELECT COUNT(listType) FROM ListType listType";
1640 private static final String _SQL_COUNT_LISTTYPE_WHERE = "SELECT COUNT(listType) FROM ListType listType WHERE ";
1641 private static final String _ORDER_BY_ENTITY_ALIAS = "listType.";
1642 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ListType exists with the primary key ";
1643 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ListType exists with the key {";
1644 private static final Log _log = LogFactoryUtil.getLog(ListTypePersistenceImpl.class);
1645 private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
1646 "type"
1647 });
1648 private static final ListType _nullListType = new ListTypeImpl() {
1649 @Override
1650 public Object clone() {
1651 return this;
1652 }
1653
1654 @Override
1655 public CacheModel<ListType> toCacheModel() {
1656 return _nullListTypeCacheModel;
1657 }
1658 };
1659
1660 private static final CacheModel<ListType> _nullListTypeCacheModel = new NullCacheModel();
1661
1662 private static class NullCacheModel implements CacheModel<ListType>,
1663 MVCCModel {
1664 @Override
1665 public long getMvccVersion() {
1666 return -1;
1667 }
1668
1669 @Override
1670 public void setMvccVersion(long mvccVersion) {
1671 }
1672
1673 @Override
1674 public ListType toEntityModel() {
1675 return _nullListType;
1676 }
1677 }
1678 }