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