001
014
015 package com.liferay.portlet.trash.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.log.Log;
029 import com.liferay.portal.kernel.log.LogFactoryUtil;
030 import com.liferay.portal.kernel.util.OrderByComparator;
031 import com.liferay.portal.kernel.util.StringBundler;
032 import com.liferay.portal.kernel.util.StringPool;
033 import com.liferay.portal.model.CacheModel;
034 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
035
036 import com.liferay.portlet.trash.NoSuchVersionException;
037 import com.liferay.portlet.trash.model.TrashVersion;
038 import com.liferay.portlet.trash.model.impl.TrashVersionImpl;
039 import com.liferay.portlet.trash.model.impl.TrashVersionModelImpl;
040 import com.liferay.portlet.trash.service.persistence.TrashVersionPersistence;
041
042 import java.io.Serializable;
043
044 import java.util.Collections;
045 import java.util.HashMap;
046 import java.util.HashSet;
047 import java.util.Iterator;
048 import java.util.List;
049 import java.util.Map;
050 import java.util.Set;
051
052
064 @ProviderType
065 public class TrashVersionPersistenceImpl extends BasePersistenceImpl<TrashVersion>
066 implements TrashVersionPersistence {
067
072 public static final String FINDER_CLASS_NAME_ENTITY = TrashVersionImpl.class.getName();
073 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
074 ".List1";
075 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
076 ".List2";
077 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
078 TrashVersionModelImpl.FINDER_CACHE_ENABLED, TrashVersionImpl.class,
079 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
080 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
081 TrashVersionModelImpl.FINDER_CACHE_ENABLED, TrashVersionImpl.class,
082 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
083 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
084 TrashVersionModelImpl.FINDER_CACHE_ENABLED, Long.class,
085 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
086 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_ENTRYID = new FinderPath(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
087 TrashVersionModelImpl.FINDER_CACHE_ENABLED, TrashVersionImpl.class,
088 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByEntryId",
089 new String[] {
090 Long.class.getName(),
091
092 Integer.class.getName(), Integer.class.getName(),
093 OrderByComparator.class.getName()
094 });
095 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ENTRYID =
096 new FinderPath(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
097 TrashVersionModelImpl.FINDER_CACHE_ENABLED, TrashVersionImpl.class,
098 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByEntryId",
099 new String[] { Long.class.getName() },
100 TrashVersionModelImpl.ENTRYID_COLUMN_BITMASK);
101 public static final FinderPath FINDER_PATH_COUNT_BY_ENTRYID = new FinderPath(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
102 TrashVersionModelImpl.FINDER_CACHE_ENABLED, Long.class,
103 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByEntryId",
104 new String[] { Long.class.getName() });
105
106
112 @Override
113 public List<TrashVersion> findByEntryId(long entryId) {
114 return findByEntryId(entryId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
115 }
116
117
129 @Override
130 public List<TrashVersion> findByEntryId(long entryId, int start, int end) {
131 return findByEntryId(entryId, start, end, null);
132 }
133
134
147 @Override
148 public List<TrashVersion> findByEntryId(long entryId, int start, int end,
149 OrderByComparator<TrashVersion> orderByComparator) {
150 return findByEntryId(entryId, start, end, orderByComparator, true);
151 }
152
153
167 @Override
168 public List<TrashVersion> findByEntryId(long entryId, int start, int end,
169 OrderByComparator<TrashVersion> orderByComparator,
170 boolean retrieveFromCache) {
171 boolean pagination = true;
172 FinderPath finderPath = null;
173 Object[] finderArgs = null;
174
175 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
176 (orderByComparator == null)) {
177 pagination = false;
178 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ENTRYID;
179 finderArgs = new Object[] { entryId };
180 }
181 else {
182 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_ENTRYID;
183 finderArgs = new Object[] { entryId, start, end, orderByComparator };
184 }
185
186 List<TrashVersion> list = null;
187
188 if (retrieveFromCache) {
189 list = (List<TrashVersion>)finderCache.getResult(finderPath,
190 finderArgs, this);
191
192 if ((list != null) && !list.isEmpty()) {
193 for (TrashVersion trashVersion : list) {
194 if ((entryId != trashVersion.getEntryId())) {
195 list = null;
196
197 break;
198 }
199 }
200 }
201 }
202
203 if (list == null) {
204 StringBundler query = null;
205
206 if (orderByComparator != null) {
207 query = new StringBundler(3 +
208 (orderByComparator.getOrderByFields().length * 3));
209 }
210 else {
211 query = new StringBundler(3);
212 }
213
214 query.append(_SQL_SELECT_TRASHVERSION_WHERE);
215
216 query.append(_FINDER_COLUMN_ENTRYID_ENTRYID_2);
217
218 if (orderByComparator != null) {
219 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
220 orderByComparator);
221 }
222 else
223 if (pagination) {
224 query.append(TrashVersionModelImpl.ORDER_BY_JPQL);
225 }
226
227 String sql = query.toString();
228
229 Session session = null;
230
231 try {
232 session = openSession();
233
234 Query q = session.createQuery(sql);
235
236 QueryPos qPos = QueryPos.getInstance(q);
237
238 qPos.add(entryId);
239
240 if (!pagination) {
241 list = (List<TrashVersion>)QueryUtil.list(q, getDialect(),
242 start, end, false);
243
244 Collections.sort(list);
245
246 list = Collections.unmodifiableList(list);
247 }
248 else {
249 list = (List<TrashVersion>)QueryUtil.list(q, getDialect(),
250 start, end);
251 }
252
253 cacheResult(list);
254
255 finderCache.putResult(finderPath, finderArgs, list);
256 }
257 catch (Exception e) {
258 finderCache.removeResult(finderPath, finderArgs);
259
260 throw processException(e);
261 }
262 finally {
263 closeSession(session);
264 }
265 }
266
267 return list;
268 }
269
270
278 @Override
279 public TrashVersion findByEntryId_First(long entryId,
280 OrderByComparator<TrashVersion> orderByComparator)
281 throws NoSuchVersionException {
282 TrashVersion trashVersion = fetchByEntryId_First(entryId,
283 orderByComparator);
284
285 if (trashVersion != null) {
286 return trashVersion;
287 }
288
289 StringBundler msg = new StringBundler(4);
290
291 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
292
293 msg.append("entryId=");
294 msg.append(entryId);
295
296 msg.append(StringPool.CLOSE_CURLY_BRACE);
297
298 throw new NoSuchVersionException(msg.toString());
299 }
300
301
308 @Override
309 public TrashVersion fetchByEntryId_First(long entryId,
310 OrderByComparator<TrashVersion> orderByComparator) {
311 List<TrashVersion> list = findByEntryId(entryId, 0, 1, orderByComparator);
312
313 if (!list.isEmpty()) {
314 return list.get(0);
315 }
316
317 return null;
318 }
319
320
328 @Override
329 public TrashVersion findByEntryId_Last(long entryId,
330 OrderByComparator<TrashVersion> orderByComparator)
331 throws NoSuchVersionException {
332 TrashVersion trashVersion = fetchByEntryId_Last(entryId,
333 orderByComparator);
334
335 if (trashVersion != null) {
336 return trashVersion;
337 }
338
339 StringBundler msg = new StringBundler(4);
340
341 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
342
343 msg.append("entryId=");
344 msg.append(entryId);
345
346 msg.append(StringPool.CLOSE_CURLY_BRACE);
347
348 throw new NoSuchVersionException(msg.toString());
349 }
350
351
358 @Override
359 public TrashVersion fetchByEntryId_Last(long entryId,
360 OrderByComparator<TrashVersion> orderByComparator) {
361 int count = countByEntryId(entryId);
362
363 if (count == 0) {
364 return null;
365 }
366
367 List<TrashVersion> list = findByEntryId(entryId, count - 1, count,
368 orderByComparator);
369
370 if (!list.isEmpty()) {
371 return list.get(0);
372 }
373
374 return null;
375 }
376
377
386 @Override
387 public TrashVersion[] findByEntryId_PrevAndNext(long versionId,
388 long entryId, OrderByComparator<TrashVersion> orderByComparator)
389 throws NoSuchVersionException {
390 TrashVersion trashVersion = findByPrimaryKey(versionId);
391
392 Session session = null;
393
394 try {
395 session = openSession();
396
397 TrashVersion[] array = new TrashVersionImpl[3];
398
399 array[0] = getByEntryId_PrevAndNext(session, trashVersion, entryId,
400 orderByComparator, true);
401
402 array[1] = trashVersion;
403
404 array[2] = getByEntryId_PrevAndNext(session, trashVersion, entryId,
405 orderByComparator, false);
406
407 return array;
408 }
409 catch (Exception e) {
410 throw processException(e);
411 }
412 finally {
413 closeSession(session);
414 }
415 }
416
417 protected TrashVersion getByEntryId_PrevAndNext(Session session,
418 TrashVersion trashVersion, long entryId,
419 OrderByComparator<TrashVersion> orderByComparator, boolean previous) {
420 StringBundler query = null;
421
422 if (orderByComparator != null) {
423 query = new StringBundler(6 +
424 (orderByComparator.getOrderByFields().length * 6));
425 }
426 else {
427 query = new StringBundler(3);
428 }
429
430 query.append(_SQL_SELECT_TRASHVERSION_WHERE);
431
432 query.append(_FINDER_COLUMN_ENTRYID_ENTRYID_2);
433
434 if (orderByComparator != null) {
435 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
436
437 if (orderByConditionFields.length > 0) {
438 query.append(WHERE_AND);
439 }
440
441 for (int i = 0; i < orderByConditionFields.length; i++) {
442 query.append(_ORDER_BY_ENTITY_ALIAS);
443 query.append(orderByConditionFields[i]);
444
445 if ((i + 1) < orderByConditionFields.length) {
446 if (orderByComparator.isAscending() ^ previous) {
447 query.append(WHERE_GREATER_THAN_HAS_NEXT);
448 }
449 else {
450 query.append(WHERE_LESSER_THAN_HAS_NEXT);
451 }
452 }
453 else {
454 if (orderByComparator.isAscending() ^ previous) {
455 query.append(WHERE_GREATER_THAN);
456 }
457 else {
458 query.append(WHERE_LESSER_THAN);
459 }
460 }
461 }
462
463 query.append(ORDER_BY_CLAUSE);
464
465 String[] orderByFields = orderByComparator.getOrderByFields();
466
467 for (int i = 0; i < orderByFields.length; i++) {
468 query.append(_ORDER_BY_ENTITY_ALIAS);
469 query.append(orderByFields[i]);
470
471 if ((i + 1) < orderByFields.length) {
472 if (orderByComparator.isAscending() ^ previous) {
473 query.append(ORDER_BY_ASC_HAS_NEXT);
474 }
475 else {
476 query.append(ORDER_BY_DESC_HAS_NEXT);
477 }
478 }
479 else {
480 if (orderByComparator.isAscending() ^ previous) {
481 query.append(ORDER_BY_ASC);
482 }
483 else {
484 query.append(ORDER_BY_DESC);
485 }
486 }
487 }
488 }
489 else {
490 query.append(TrashVersionModelImpl.ORDER_BY_JPQL);
491 }
492
493 String sql = query.toString();
494
495 Query q = session.createQuery(sql);
496
497 q.setFirstResult(0);
498 q.setMaxResults(2);
499
500 QueryPos qPos = QueryPos.getInstance(q);
501
502 qPos.add(entryId);
503
504 if (orderByComparator != null) {
505 Object[] values = orderByComparator.getOrderByConditionValues(trashVersion);
506
507 for (Object value : values) {
508 qPos.add(value);
509 }
510 }
511
512 List<TrashVersion> list = q.list();
513
514 if (list.size() == 2) {
515 return list.get(1);
516 }
517 else {
518 return null;
519 }
520 }
521
522
527 @Override
528 public void removeByEntryId(long entryId) {
529 for (TrashVersion trashVersion : findByEntryId(entryId,
530 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
531 remove(trashVersion);
532 }
533 }
534
535
541 @Override
542 public int countByEntryId(long entryId) {
543 FinderPath finderPath = FINDER_PATH_COUNT_BY_ENTRYID;
544
545 Object[] finderArgs = new Object[] { entryId };
546
547 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
548
549 if (count == null) {
550 StringBundler query = new StringBundler(2);
551
552 query.append(_SQL_COUNT_TRASHVERSION_WHERE);
553
554 query.append(_FINDER_COLUMN_ENTRYID_ENTRYID_2);
555
556 String sql = query.toString();
557
558 Session session = null;
559
560 try {
561 session = openSession();
562
563 Query q = session.createQuery(sql);
564
565 QueryPos qPos = QueryPos.getInstance(q);
566
567 qPos.add(entryId);
568
569 count = (Long)q.uniqueResult();
570
571 finderCache.putResult(finderPath, finderArgs, count);
572 }
573 catch (Exception e) {
574 finderCache.removeResult(finderPath, finderArgs);
575
576 throw processException(e);
577 }
578 finally {
579 closeSession(session);
580 }
581 }
582
583 return count.intValue();
584 }
585
586 private static final String _FINDER_COLUMN_ENTRYID_ENTRYID_2 = "trashVersion.entryId = ?";
587 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_E_C = new FinderPath(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
588 TrashVersionModelImpl.FINDER_CACHE_ENABLED, TrashVersionImpl.class,
589 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByE_C",
590 new String[] {
591 Long.class.getName(), Long.class.getName(),
592
593 Integer.class.getName(), Integer.class.getName(),
594 OrderByComparator.class.getName()
595 });
596 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_E_C = new FinderPath(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
597 TrashVersionModelImpl.FINDER_CACHE_ENABLED, TrashVersionImpl.class,
598 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByE_C",
599 new String[] { Long.class.getName(), Long.class.getName() },
600 TrashVersionModelImpl.ENTRYID_COLUMN_BITMASK |
601 TrashVersionModelImpl.CLASSNAMEID_COLUMN_BITMASK);
602 public static final FinderPath FINDER_PATH_COUNT_BY_E_C = new FinderPath(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
603 TrashVersionModelImpl.FINDER_CACHE_ENABLED, Long.class,
604 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByE_C",
605 new String[] { Long.class.getName(), Long.class.getName() });
606
607
614 @Override
615 public List<TrashVersion> findByE_C(long entryId, long classNameId) {
616 return findByE_C(entryId, classNameId, QueryUtil.ALL_POS,
617 QueryUtil.ALL_POS, null);
618 }
619
620
633 @Override
634 public List<TrashVersion> findByE_C(long entryId, long classNameId,
635 int start, int end) {
636 return findByE_C(entryId, classNameId, start, end, null);
637 }
638
639
653 @Override
654 public List<TrashVersion> findByE_C(long entryId, long classNameId,
655 int start, int end, OrderByComparator<TrashVersion> orderByComparator) {
656 return findByE_C(entryId, classNameId, start, end, orderByComparator,
657 true);
658 }
659
660
675 @Override
676 public List<TrashVersion> findByE_C(long entryId, long classNameId,
677 int start, int end, OrderByComparator<TrashVersion> orderByComparator,
678 boolean retrieveFromCache) {
679 boolean pagination = true;
680 FinderPath finderPath = null;
681 Object[] finderArgs = null;
682
683 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
684 (orderByComparator == null)) {
685 pagination = false;
686 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_E_C;
687 finderArgs = new Object[] { entryId, classNameId };
688 }
689 else {
690 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_E_C;
691 finderArgs = new Object[] {
692 entryId, classNameId,
693
694 start, end, orderByComparator
695 };
696 }
697
698 List<TrashVersion> list = null;
699
700 if (retrieveFromCache) {
701 list = (List<TrashVersion>)finderCache.getResult(finderPath,
702 finderArgs, this);
703
704 if ((list != null) && !list.isEmpty()) {
705 for (TrashVersion trashVersion : list) {
706 if ((entryId != trashVersion.getEntryId()) ||
707 (classNameId != trashVersion.getClassNameId())) {
708 list = null;
709
710 break;
711 }
712 }
713 }
714 }
715
716 if (list == null) {
717 StringBundler query = null;
718
719 if (orderByComparator != null) {
720 query = new StringBundler(4 +
721 (orderByComparator.getOrderByFields().length * 3));
722 }
723 else {
724 query = new StringBundler(4);
725 }
726
727 query.append(_SQL_SELECT_TRASHVERSION_WHERE);
728
729 query.append(_FINDER_COLUMN_E_C_ENTRYID_2);
730
731 query.append(_FINDER_COLUMN_E_C_CLASSNAMEID_2);
732
733 if (orderByComparator != null) {
734 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
735 orderByComparator);
736 }
737 else
738 if (pagination) {
739 query.append(TrashVersionModelImpl.ORDER_BY_JPQL);
740 }
741
742 String sql = query.toString();
743
744 Session session = null;
745
746 try {
747 session = openSession();
748
749 Query q = session.createQuery(sql);
750
751 QueryPos qPos = QueryPos.getInstance(q);
752
753 qPos.add(entryId);
754
755 qPos.add(classNameId);
756
757 if (!pagination) {
758 list = (List<TrashVersion>)QueryUtil.list(q, getDialect(),
759 start, end, false);
760
761 Collections.sort(list);
762
763 list = Collections.unmodifiableList(list);
764 }
765 else {
766 list = (List<TrashVersion>)QueryUtil.list(q, getDialect(),
767 start, end);
768 }
769
770 cacheResult(list);
771
772 finderCache.putResult(finderPath, finderArgs, list);
773 }
774 catch (Exception e) {
775 finderCache.removeResult(finderPath, finderArgs);
776
777 throw processException(e);
778 }
779 finally {
780 closeSession(session);
781 }
782 }
783
784 return list;
785 }
786
787
796 @Override
797 public TrashVersion findByE_C_First(long entryId, long classNameId,
798 OrderByComparator<TrashVersion> orderByComparator)
799 throws NoSuchVersionException {
800 TrashVersion trashVersion = fetchByE_C_First(entryId, classNameId,
801 orderByComparator);
802
803 if (trashVersion != null) {
804 return trashVersion;
805 }
806
807 StringBundler msg = new StringBundler(6);
808
809 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
810
811 msg.append("entryId=");
812 msg.append(entryId);
813
814 msg.append(", classNameId=");
815 msg.append(classNameId);
816
817 msg.append(StringPool.CLOSE_CURLY_BRACE);
818
819 throw new NoSuchVersionException(msg.toString());
820 }
821
822
830 @Override
831 public TrashVersion fetchByE_C_First(long entryId, long classNameId,
832 OrderByComparator<TrashVersion> orderByComparator) {
833 List<TrashVersion> list = findByE_C(entryId, classNameId, 0, 1,
834 orderByComparator);
835
836 if (!list.isEmpty()) {
837 return list.get(0);
838 }
839
840 return null;
841 }
842
843
852 @Override
853 public TrashVersion findByE_C_Last(long entryId, long classNameId,
854 OrderByComparator<TrashVersion> orderByComparator)
855 throws NoSuchVersionException {
856 TrashVersion trashVersion = fetchByE_C_Last(entryId, classNameId,
857 orderByComparator);
858
859 if (trashVersion != null) {
860 return trashVersion;
861 }
862
863 StringBundler msg = new StringBundler(6);
864
865 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
866
867 msg.append("entryId=");
868 msg.append(entryId);
869
870 msg.append(", classNameId=");
871 msg.append(classNameId);
872
873 msg.append(StringPool.CLOSE_CURLY_BRACE);
874
875 throw new NoSuchVersionException(msg.toString());
876 }
877
878
886 @Override
887 public TrashVersion fetchByE_C_Last(long entryId, long classNameId,
888 OrderByComparator<TrashVersion> orderByComparator) {
889 int count = countByE_C(entryId, classNameId);
890
891 if (count == 0) {
892 return null;
893 }
894
895 List<TrashVersion> list = findByE_C(entryId, classNameId, count - 1,
896 count, orderByComparator);
897
898 if (!list.isEmpty()) {
899 return list.get(0);
900 }
901
902 return null;
903 }
904
905
915 @Override
916 public TrashVersion[] findByE_C_PrevAndNext(long versionId, long entryId,
917 long classNameId, OrderByComparator<TrashVersion> orderByComparator)
918 throws NoSuchVersionException {
919 TrashVersion trashVersion = findByPrimaryKey(versionId);
920
921 Session session = null;
922
923 try {
924 session = openSession();
925
926 TrashVersion[] array = new TrashVersionImpl[3];
927
928 array[0] = getByE_C_PrevAndNext(session, trashVersion, entryId,
929 classNameId, orderByComparator, true);
930
931 array[1] = trashVersion;
932
933 array[2] = getByE_C_PrevAndNext(session, trashVersion, entryId,
934 classNameId, orderByComparator, false);
935
936 return array;
937 }
938 catch (Exception e) {
939 throw processException(e);
940 }
941 finally {
942 closeSession(session);
943 }
944 }
945
946 protected TrashVersion getByE_C_PrevAndNext(Session session,
947 TrashVersion trashVersion, long entryId, long classNameId,
948 OrderByComparator<TrashVersion> orderByComparator, boolean previous) {
949 StringBundler query = null;
950
951 if (orderByComparator != null) {
952 query = new StringBundler(6 +
953 (orderByComparator.getOrderByFields().length * 6));
954 }
955 else {
956 query = new StringBundler(3);
957 }
958
959 query.append(_SQL_SELECT_TRASHVERSION_WHERE);
960
961 query.append(_FINDER_COLUMN_E_C_ENTRYID_2);
962
963 query.append(_FINDER_COLUMN_E_C_CLASSNAMEID_2);
964
965 if (orderByComparator != null) {
966 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
967
968 if (orderByConditionFields.length > 0) {
969 query.append(WHERE_AND);
970 }
971
972 for (int i = 0; i < orderByConditionFields.length; i++) {
973 query.append(_ORDER_BY_ENTITY_ALIAS);
974 query.append(orderByConditionFields[i]);
975
976 if ((i + 1) < orderByConditionFields.length) {
977 if (orderByComparator.isAscending() ^ previous) {
978 query.append(WHERE_GREATER_THAN_HAS_NEXT);
979 }
980 else {
981 query.append(WHERE_LESSER_THAN_HAS_NEXT);
982 }
983 }
984 else {
985 if (orderByComparator.isAscending() ^ previous) {
986 query.append(WHERE_GREATER_THAN);
987 }
988 else {
989 query.append(WHERE_LESSER_THAN);
990 }
991 }
992 }
993
994 query.append(ORDER_BY_CLAUSE);
995
996 String[] orderByFields = orderByComparator.getOrderByFields();
997
998 for (int i = 0; i < orderByFields.length; i++) {
999 query.append(_ORDER_BY_ENTITY_ALIAS);
1000 query.append(orderByFields[i]);
1001
1002 if ((i + 1) < orderByFields.length) {
1003 if (orderByComparator.isAscending() ^ previous) {
1004 query.append(ORDER_BY_ASC_HAS_NEXT);
1005 }
1006 else {
1007 query.append(ORDER_BY_DESC_HAS_NEXT);
1008 }
1009 }
1010 else {
1011 if (orderByComparator.isAscending() ^ previous) {
1012 query.append(ORDER_BY_ASC);
1013 }
1014 else {
1015 query.append(ORDER_BY_DESC);
1016 }
1017 }
1018 }
1019 }
1020 else {
1021 query.append(TrashVersionModelImpl.ORDER_BY_JPQL);
1022 }
1023
1024 String sql = query.toString();
1025
1026 Query q = session.createQuery(sql);
1027
1028 q.setFirstResult(0);
1029 q.setMaxResults(2);
1030
1031 QueryPos qPos = QueryPos.getInstance(q);
1032
1033 qPos.add(entryId);
1034
1035 qPos.add(classNameId);
1036
1037 if (orderByComparator != null) {
1038 Object[] values = orderByComparator.getOrderByConditionValues(trashVersion);
1039
1040 for (Object value : values) {
1041 qPos.add(value);
1042 }
1043 }
1044
1045 List<TrashVersion> list = q.list();
1046
1047 if (list.size() == 2) {
1048 return list.get(1);
1049 }
1050 else {
1051 return null;
1052 }
1053 }
1054
1055
1061 @Override
1062 public void removeByE_C(long entryId, long classNameId) {
1063 for (TrashVersion trashVersion : findByE_C(entryId, classNameId,
1064 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1065 remove(trashVersion);
1066 }
1067 }
1068
1069
1076 @Override
1077 public int countByE_C(long entryId, long classNameId) {
1078 FinderPath finderPath = FINDER_PATH_COUNT_BY_E_C;
1079
1080 Object[] finderArgs = new Object[] { entryId, classNameId };
1081
1082 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1083
1084 if (count == null) {
1085 StringBundler query = new StringBundler(3);
1086
1087 query.append(_SQL_COUNT_TRASHVERSION_WHERE);
1088
1089 query.append(_FINDER_COLUMN_E_C_ENTRYID_2);
1090
1091 query.append(_FINDER_COLUMN_E_C_CLASSNAMEID_2);
1092
1093 String sql = query.toString();
1094
1095 Session session = null;
1096
1097 try {
1098 session = openSession();
1099
1100 Query q = session.createQuery(sql);
1101
1102 QueryPos qPos = QueryPos.getInstance(q);
1103
1104 qPos.add(entryId);
1105
1106 qPos.add(classNameId);
1107
1108 count = (Long)q.uniqueResult();
1109
1110 finderCache.putResult(finderPath, finderArgs, count);
1111 }
1112 catch (Exception e) {
1113 finderCache.removeResult(finderPath, finderArgs);
1114
1115 throw processException(e);
1116 }
1117 finally {
1118 closeSession(session);
1119 }
1120 }
1121
1122 return count.intValue();
1123 }
1124
1125 private static final String _FINDER_COLUMN_E_C_ENTRYID_2 = "trashVersion.entryId = ? AND ";
1126 private static final String _FINDER_COLUMN_E_C_CLASSNAMEID_2 = "trashVersion.classNameId = ?";
1127 public static final FinderPath FINDER_PATH_FETCH_BY_C_C = new FinderPath(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
1128 TrashVersionModelImpl.FINDER_CACHE_ENABLED, TrashVersionImpl.class,
1129 FINDER_CLASS_NAME_ENTITY, "fetchByC_C",
1130 new String[] { Long.class.getName(), Long.class.getName() },
1131 TrashVersionModelImpl.CLASSNAMEID_COLUMN_BITMASK |
1132 TrashVersionModelImpl.CLASSPK_COLUMN_BITMASK);
1133 public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
1134 TrashVersionModelImpl.FINDER_CACHE_ENABLED, Long.class,
1135 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C",
1136 new String[] { Long.class.getName(), Long.class.getName() });
1137
1138
1146 @Override
1147 public TrashVersion findByC_C(long classNameId, long classPK)
1148 throws NoSuchVersionException {
1149 TrashVersion trashVersion = fetchByC_C(classNameId, classPK);
1150
1151 if (trashVersion == null) {
1152 StringBundler msg = new StringBundler(6);
1153
1154 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1155
1156 msg.append("classNameId=");
1157 msg.append(classNameId);
1158
1159 msg.append(", classPK=");
1160 msg.append(classPK);
1161
1162 msg.append(StringPool.CLOSE_CURLY_BRACE);
1163
1164 if (_log.isWarnEnabled()) {
1165 _log.warn(msg.toString());
1166 }
1167
1168 throw new NoSuchVersionException(msg.toString());
1169 }
1170
1171 return trashVersion;
1172 }
1173
1174
1181 @Override
1182 public TrashVersion fetchByC_C(long classNameId, long classPK) {
1183 return fetchByC_C(classNameId, classPK, true);
1184 }
1185
1186
1194 @Override
1195 public TrashVersion fetchByC_C(long classNameId, long classPK,
1196 boolean retrieveFromCache) {
1197 Object[] finderArgs = new Object[] { classNameId, classPK };
1198
1199 Object result = null;
1200
1201 if (retrieveFromCache) {
1202 result = finderCache.getResult(FINDER_PATH_FETCH_BY_C_C,
1203 finderArgs, this);
1204 }
1205
1206 if (result instanceof TrashVersion) {
1207 TrashVersion trashVersion = (TrashVersion)result;
1208
1209 if ((classNameId != trashVersion.getClassNameId()) ||
1210 (classPK != trashVersion.getClassPK())) {
1211 result = null;
1212 }
1213 }
1214
1215 if (result == null) {
1216 StringBundler query = new StringBundler(4);
1217
1218 query.append(_SQL_SELECT_TRASHVERSION_WHERE);
1219
1220 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
1221
1222 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
1223
1224 String sql = query.toString();
1225
1226 Session session = null;
1227
1228 try {
1229 session = openSession();
1230
1231 Query q = session.createQuery(sql);
1232
1233 QueryPos qPos = QueryPos.getInstance(q);
1234
1235 qPos.add(classNameId);
1236
1237 qPos.add(classPK);
1238
1239 List<TrashVersion> list = q.list();
1240
1241 if (list.isEmpty()) {
1242 finderCache.putResult(FINDER_PATH_FETCH_BY_C_C, finderArgs,
1243 list);
1244 }
1245 else {
1246 TrashVersion trashVersion = list.get(0);
1247
1248 result = trashVersion;
1249
1250 cacheResult(trashVersion);
1251
1252 if ((trashVersion.getClassNameId() != classNameId) ||
1253 (trashVersion.getClassPK() != classPK)) {
1254 finderCache.putResult(FINDER_PATH_FETCH_BY_C_C,
1255 finderArgs, trashVersion);
1256 }
1257 }
1258 }
1259 catch (Exception e) {
1260 finderCache.removeResult(FINDER_PATH_FETCH_BY_C_C, finderArgs);
1261
1262 throw processException(e);
1263 }
1264 finally {
1265 closeSession(session);
1266 }
1267 }
1268
1269 if (result instanceof List<?>) {
1270 return null;
1271 }
1272 else {
1273 return (TrashVersion)result;
1274 }
1275 }
1276
1277
1284 @Override
1285 public TrashVersion removeByC_C(long classNameId, long classPK)
1286 throws NoSuchVersionException {
1287 TrashVersion trashVersion = findByC_C(classNameId, classPK);
1288
1289 return remove(trashVersion);
1290 }
1291
1292
1299 @Override
1300 public int countByC_C(long classNameId, long classPK) {
1301 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C;
1302
1303 Object[] finderArgs = new Object[] { classNameId, classPK };
1304
1305 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1306
1307 if (count == null) {
1308 StringBundler query = new StringBundler(3);
1309
1310 query.append(_SQL_COUNT_TRASHVERSION_WHERE);
1311
1312 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
1313
1314 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
1315
1316 String sql = query.toString();
1317
1318 Session session = null;
1319
1320 try {
1321 session = openSession();
1322
1323 Query q = session.createQuery(sql);
1324
1325 QueryPos qPos = QueryPos.getInstance(q);
1326
1327 qPos.add(classNameId);
1328
1329 qPos.add(classPK);
1330
1331 count = (Long)q.uniqueResult();
1332
1333 finderCache.putResult(finderPath, finderArgs, count);
1334 }
1335 catch (Exception e) {
1336 finderCache.removeResult(finderPath, finderArgs);
1337
1338 throw processException(e);
1339 }
1340 finally {
1341 closeSession(session);
1342 }
1343 }
1344
1345 return count.intValue();
1346 }
1347
1348 private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "trashVersion.classNameId = ? AND ";
1349 private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "trashVersion.classPK = ?";
1350
1351 public TrashVersionPersistenceImpl() {
1352 setModelClass(TrashVersion.class);
1353 }
1354
1355
1360 @Override
1361 public void cacheResult(TrashVersion trashVersion) {
1362 entityCache.putResult(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
1363 TrashVersionImpl.class, trashVersion.getPrimaryKey(), trashVersion);
1364
1365 finderCache.putResult(FINDER_PATH_FETCH_BY_C_C,
1366 new Object[] {
1367 trashVersion.getClassNameId(), trashVersion.getClassPK()
1368 }, trashVersion);
1369
1370 trashVersion.resetOriginalValues();
1371 }
1372
1373
1378 @Override
1379 public void cacheResult(List<TrashVersion> trashVersions) {
1380 for (TrashVersion trashVersion : trashVersions) {
1381 if (entityCache.getResult(
1382 TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
1383 TrashVersionImpl.class, trashVersion.getPrimaryKey()) == null) {
1384 cacheResult(trashVersion);
1385 }
1386 else {
1387 trashVersion.resetOriginalValues();
1388 }
1389 }
1390 }
1391
1392
1399 @Override
1400 public void clearCache() {
1401 entityCache.clearCache(TrashVersionImpl.class);
1402
1403 finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
1404 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1405 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1406 }
1407
1408
1415 @Override
1416 public void clearCache(TrashVersion trashVersion) {
1417 entityCache.removeResult(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
1418 TrashVersionImpl.class, trashVersion.getPrimaryKey());
1419
1420 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1421 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1422
1423 clearUniqueFindersCache((TrashVersionModelImpl)trashVersion);
1424 }
1425
1426 @Override
1427 public void clearCache(List<TrashVersion> trashVersions) {
1428 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1429 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1430
1431 for (TrashVersion trashVersion : trashVersions) {
1432 entityCache.removeResult(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
1433 TrashVersionImpl.class, trashVersion.getPrimaryKey());
1434
1435 clearUniqueFindersCache((TrashVersionModelImpl)trashVersion);
1436 }
1437 }
1438
1439 protected void cacheUniqueFindersCache(
1440 TrashVersionModelImpl trashVersionModelImpl, boolean isNew) {
1441 if (isNew) {
1442 Object[] args = new Object[] {
1443 trashVersionModelImpl.getClassNameId(),
1444 trashVersionModelImpl.getClassPK()
1445 };
1446
1447 finderCache.putResult(FINDER_PATH_COUNT_BY_C_C, args,
1448 Long.valueOf(1));
1449 finderCache.putResult(FINDER_PATH_FETCH_BY_C_C, args,
1450 trashVersionModelImpl);
1451 }
1452 else {
1453 if ((trashVersionModelImpl.getColumnBitmask() &
1454 FINDER_PATH_FETCH_BY_C_C.getColumnBitmask()) != 0) {
1455 Object[] args = new Object[] {
1456 trashVersionModelImpl.getClassNameId(),
1457 trashVersionModelImpl.getClassPK()
1458 };
1459
1460 finderCache.putResult(FINDER_PATH_COUNT_BY_C_C, args,
1461 Long.valueOf(1));
1462 finderCache.putResult(FINDER_PATH_FETCH_BY_C_C, args,
1463 trashVersionModelImpl);
1464 }
1465 }
1466 }
1467
1468 protected void clearUniqueFindersCache(
1469 TrashVersionModelImpl trashVersionModelImpl) {
1470 Object[] args = new Object[] {
1471 trashVersionModelImpl.getClassNameId(),
1472 trashVersionModelImpl.getClassPK()
1473 };
1474
1475 finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
1476 finderCache.removeResult(FINDER_PATH_FETCH_BY_C_C, args);
1477
1478 if ((trashVersionModelImpl.getColumnBitmask() &
1479 FINDER_PATH_FETCH_BY_C_C.getColumnBitmask()) != 0) {
1480 args = new Object[] {
1481 trashVersionModelImpl.getOriginalClassNameId(),
1482 trashVersionModelImpl.getOriginalClassPK()
1483 };
1484
1485 finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
1486 finderCache.removeResult(FINDER_PATH_FETCH_BY_C_C, args);
1487 }
1488 }
1489
1490
1496 @Override
1497 public TrashVersion create(long versionId) {
1498 TrashVersion trashVersion = new TrashVersionImpl();
1499
1500 trashVersion.setNew(true);
1501 trashVersion.setPrimaryKey(versionId);
1502
1503 return trashVersion;
1504 }
1505
1506
1513 @Override
1514 public TrashVersion remove(long versionId) throws NoSuchVersionException {
1515 return remove((Serializable)versionId);
1516 }
1517
1518
1525 @Override
1526 public TrashVersion remove(Serializable primaryKey)
1527 throws NoSuchVersionException {
1528 Session session = null;
1529
1530 try {
1531 session = openSession();
1532
1533 TrashVersion trashVersion = (TrashVersion)session.get(TrashVersionImpl.class,
1534 primaryKey);
1535
1536 if (trashVersion == null) {
1537 if (_log.isWarnEnabled()) {
1538 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1539 }
1540
1541 throw new NoSuchVersionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1542 primaryKey);
1543 }
1544
1545 return remove(trashVersion);
1546 }
1547 catch (NoSuchVersionException nsee) {
1548 throw nsee;
1549 }
1550 catch (Exception e) {
1551 throw processException(e);
1552 }
1553 finally {
1554 closeSession(session);
1555 }
1556 }
1557
1558 @Override
1559 protected TrashVersion removeImpl(TrashVersion trashVersion) {
1560 trashVersion = toUnwrappedModel(trashVersion);
1561
1562 Session session = null;
1563
1564 try {
1565 session = openSession();
1566
1567 if (!session.contains(trashVersion)) {
1568 trashVersion = (TrashVersion)session.get(TrashVersionImpl.class,
1569 trashVersion.getPrimaryKeyObj());
1570 }
1571
1572 if (trashVersion != null) {
1573 session.delete(trashVersion);
1574 }
1575 }
1576 catch (Exception e) {
1577 throw processException(e);
1578 }
1579 finally {
1580 closeSession(session);
1581 }
1582
1583 if (trashVersion != null) {
1584 clearCache(trashVersion);
1585 }
1586
1587 return trashVersion;
1588 }
1589
1590 @Override
1591 public TrashVersion updateImpl(TrashVersion trashVersion) {
1592 trashVersion = toUnwrappedModel(trashVersion);
1593
1594 boolean isNew = trashVersion.isNew();
1595
1596 TrashVersionModelImpl trashVersionModelImpl = (TrashVersionModelImpl)trashVersion;
1597
1598 Session session = null;
1599
1600 try {
1601 session = openSession();
1602
1603 if (trashVersion.isNew()) {
1604 session.save(trashVersion);
1605
1606 trashVersion.setNew(false);
1607 }
1608 else {
1609 trashVersion = (TrashVersion)session.merge(trashVersion);
1610 }
1611 }
1612 catch (Exception e) {
1613 throw processException(e);
1614 }
1615 finally {
1616 closeSession(session);
1617 }
1618
1619 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1620
1621 if (isNew || !TrashVersionModelImpl.COLUMN_BITMASK_ENABLED) {
1622 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1623 }
1624
1625 else {
1626 if ((trashVersionModelImpl.getColumnBitmask() &
1627 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ENTRYID.getColumnBitmask()) != 0) {
1628 Object[] args = new Object[] {
1629 trashVersionModelImpl.getOriginalEntryId()
1630 };
1631
1632 finderCache.removeResult(FINDER_PATH_COUNT_BY_ENTRYID, args);
1633 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ENTRYID,
1634 args);
1635
1636 args = new Object[] { trashVersionModelImpl.getEntryId() };
1637
1638 finderCache.removeResult(FINDER_PATH_COUNT_BY_ENTRYID, args);
1639 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ENTRYID,
1640 args);
1641 }
1642
1643 if ((trashVersionModelImpl.getColumnBitmask() &
1644 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_E_C.getColumnBitmask()) != 0) {
1645 Object[] args = new Object[] {
1646 trashVersionModelImpl.getOriginalEntryId(),
1647 trashVersionModelImpl.getOriginalClassNameId()
1648 };
1649
1650 finderCache.removeResult(FINDER_PATH_COUNT_BY_E_C, args);
1651 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_E_C,
1652 args);
1653
1654 args = new Object[] {
1655 trashVersionModelImpl.getEntryId(),
1656 trashVersionModelImpl.getClassNameId()
1657 };
1658
1659 finderCache.removeResult(FINDER_PATH_COUNT_BY_E_C, args);
1660 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_E_C,
1661 args);
1662 }
1663 }
1664
1665 entityCache.putResult(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
1666 TrashVersionImpl.class, trashVersion.getPrimaryKey(), trashVersion,
1667 false);
1668
1669 clearUniqueFindersCache(trashVersionModelImpl);
1670 cacheUniqueFindersCache(trashVersionModelImpl, isNew);
1671
1672 trashVersion.resetOriginalValues();
1673
1674 return trashVersion;
1675 }
1676
1677 protected TrashVersion toUnwrappedModel(TrashVersion trashVersion) {
1678 if (trashVersion instanceof TrashVersionImpl) {
1679 return trashVersion;
1680 }
1681
1682 TrashVersionImpl trashVersionImpl = new TrashVersionImpl();
1683
1684 trashVersionImpl.setNew(trashVersion.isNew());
1685 trashVersionImpl.setPrimaryKey(trashVersion.getPrimaryKey());
1686
1687 trashVersionImpl.setVersionId(trashVersion.getVersionId());
1688 trashVersionImpl.setCompanyId(trashVersion.getCompanyId());
1689 trashVersionImpl.setEntryId(trashVersion.getEntryId());
1690 trashVersionImpl.setClassNameId(trashVersion.getClassNameId());
1691 trashVersionImpl.setClassPK(trashVersion.getClassPK());
1692 trashVersionImpl.setTypeSettings(trashVersion.getTypeSettings());
1693 trashVersionImpl.setStatus(trashVersion.getStatus());
1694
1695 return trashVersionImpl;
1696 }
1697
1698
1705 @Override
1706 public TrashVersion findByPrimaryKey(Serializable primaryKey)
1707 throws NoSuchVersionException {
1708 TrashVersion trashVersion = fetchByPrimaryKey(primaryKey);
1709
1710 if (trashVersion == null) {
1711 if (_log.isWarnEnabled()) {
1712 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1713 }
1714
1715 throw new NoSuchVersionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1716 primaryKey);
1717 }
1718
1719 return trashVersion;
1720 }
1721
1722
1729 @Override
1730 public TrashVersion findByPrimaryKey(long versionId)
1731 throws NoSuchVersionException {
1732 return findByPrimaryKey((Serializable)versionId);
1733 }
1734
1735
1741 @Override
1742 public TrashVersion fetchByPrimaryKey(Serializable primaryKey) {
1743 TrashVersion trashVersion = (TrashVersion)entityCache.getResult(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
1744 TrashVersionImpl.class, primaryKey);
1745
1746 if (trashVersion == _nullTrashVersion) {
1747 return null;
1748 }
1749
1750 if (trashVersion == null) {
1751 Session session = null;
1752
1753 try {
1754 session = openSession();
1755
1756 trashVersion = (TrashVersion)session.get(TrashVersionImpl.class,
1757 primaryKey);
1758
1759 if (trashVersion != null) {
1760 cacheResult(trashVersion);
1761 }
1762 else {
1763 entityCache.putResult(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
1764 TrashVersionImpl.class, primaryKey, _nullTrashVersion);
1765 }
1766 }
1767 catch (Exception e) {
1768 entityCache.removeResult(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
1769 TrashVersionImpl.class, primaryKey);
1770
1771 throw processException(e);
1772 }
1773 finally {
1774 closeSession(session);
1775 }
1776 }
1777
1778 return trashVersion;
1779 }
1780
1781
1787 @Override
1788 public TrashVersion fetchByPrimaryKey(long versionId) {
1789 return fetchByPrimaryKey((Serializable)versionId);
1790 }
1791
1792 @Override
1793 public Map<Serializable, TrashVersion> fetchByPrimaryKeys(
1794 Set<Serializable> primaryKeys) {
1795 if (primaryKeys.isEmpty()) {
1796 return Collections.emptyMap();
1797 }
1798
1799 Map<Serializable, TrashVersion> map = new HashMap<Serializable, TrashVersion>();
1800
1801 if (primaryKeys.size() == 1) {
1802 Iterator<Serializable> iterator = primaryKeys.iterator();
1803
1804 Serializable primaryKey = iterator.next();
1805
1806 TrashVersion trashVersion = fetchByPrimaryKey(primaryKey);
1807
1808 if (trashVersion != null) {
1809 map.put(primaryKey, trashVersion);
1810 }
1811
1812 return map;
1813 }
1814
1815 Set<Serializable> uncachedPrimaryKeys = null;
1816
1817 for (Serializable primaryKey : primaryKeys) {
1818 TrashVersion trashVersion = (TrashVersion)entityCache.getResult(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
1819 TrashVersionImpl.class, primaryKey);
1820
1821 if (trashVersion == null) {
1822 if (uncachedPrimaryKeys == null) {
1823 uncachedPrimaryKeys = new HashSet<Serializable>();
1824 }
1825
1826 uncachedPrimaryKeys.add(primaryKey);
1827 }
1828 else {
1829 map.put(primaryKey, trashVersion);
1830 }
1831 }
1832
1833 if (uncachedPrimaryKeys == null) {
1834 return map;
1835 }
1836
1837 StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
1838 1);
1839
1840 query.append(_SQL_SELECT_TRASHVERSION_WHERE_PKS_IN);
1841
1842 for (Serializable primaryKey : uncachedPrimaryKeys) {
1843 query.append(String.valueOf(primaryKey));
1844
1845 query.append(StringPool.COMMA);
1846 }
1847
1848 query.setIndex(query.index() - 1);
1849
1850 query.append(StringPool.CLOSE_PARENTHESIS);
1851
1852 String sql = query.toString();
1853
1854 Session session = null;
1855
1856 try {
1857 session = openSession();
1858
1859 Query q = session.createQuery(sql);
1860
1861 for (TrashVersion trashVersion : (List<TrashVersion>)q.list()) {
1862 map.put(trashVersion.getPrimaryKeyObj(), trashVersion);
1863
1864 cacheResult(trashVersion);
1865
1866 uncachedPrimaryKeys.remove(trashVersion.getPrimaryKeyObj());
1867 }
1868
1869 for (Serializable primaryKey : uncachedPrimaryKeys) {
1870 entityCache.putResult(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
1871 TrashVersionImpl.class, primaryKey, _nullTrashVersion);
1872 }
1873 }
1874 catch (Exception e) {
1875 throw processException(e);
1876 }
1877 finally {
1878 closeSession(session);
1879 }
1880
1881 return map;
1882 }
1883
1884
1889 @Override
1890 public List<TrashVersion> findAll() {
1891 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1892 }
1893
1894
1905 @Override
1906 public List<TrashVersion> findAll(int start, int end) {
1907 return findAll(start, end, null);
1908 }
1909
1910
1922 @Override
1923 public List<TrashVersion> findAll(int start, int end,
1924 OrderByComparator<TrashVersion> orderByComparator) {
1925 return findAll(start, end, orderByComparator, true);
1926 }
1927
1928
1941 @Override
1942 public List<TrashVersion> findAll(int start, int end,
1943 OrderByComparator<TrashVersion> orderByComparator,
1944 boolean retrieveFromCache) {
1945 boolean pagination = true;
1946 FinderPath finderPath = null;
1947 Object[] finderArgs = null;
1948
1949 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1950 (orderByComparator == null)) {
1951 pagination = false;
1952 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1953 finderArgs = FINDER_ARGS_EMPTY;
1954 }
1955 else {
1956 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1957 finderArgs = new Object[] { start, end, orderByComparator };
1958 }
1959
1960 List<TrashVersion> list = null;
1961
1962 if (retrieveFromCache) {
1963 list = (List<TrashVersion>)finderCache.getResult(finderPath,
1964 finderArgs, this);
1965 }
1966
1967 if (list == null) {
1968 StringBundler query = null;
1969 String sql = null;
1970
1971 if (orderByComparator != null) {
1972 query = new StringBundler(2 +
1973 (orderByComparator.getOrderByFields().length * 3));
1974
1975 query.append(_SQL_SELECT_TRASHVERSION);
1976
1977 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1978 orderByComparator);
1979
1980 sql = query.toString();
1981 }
1982 else {
1983 sql = _SQL_SELECT_TRASHVERSION;
1984
1985 if (pagination) {
1986 sql = sql.concat(TrashVersionModelImpl.ORDER_BY_JPQL);
1987 }
1988 }
1989
1990 Session session = null;
1991
1992 try {
1993 session = openSession();
1994
1995 Query q = session.createQuery(sql);
1996
1997 if (!pagination) {
1998 list = (List<TrashVersion>)QueryUtil.list(q, getDialect(),
1999 start, end, false);
2000
2001 Collections.sort(list);
2002
2003 list = Collections.unmodifiableList(list);
2004 }
2005 else {
2006 list = (List<TrashVersion>)QueryUtil.list(q, getDialect(),
2007 start, end);
2008 }
2009
2010 cacheResult(list);
2011
2012 finderCache.putResult(finderPath, finderArgs, list);
2013 }
2014 catch (Exception e) {
2015 finderCache.removeResult(finderPath, finderArgs);
2016
2017 throw processException(e);
2018 }
2019 finally {
2020 closeSession(session);
2021 }
2022 }
2023
2024 return list;
2025 }
2026
2027
2031 @Override
2032 public void removeAll() {
2033 for (TrashVersion trashVersion : findAll()) {
2034 remove(trashVersion);
2035 }
2036 }
2037
2038
2043 @Override
2044 public int countAll() {
2045 Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
2046 FINDER_ARGS_EMPTY, this);
2047
2048 if (count == null) {
2049 Session session = null;
2050
2051 try {
2052 session = openSession();
2053
2054 Query q = session.createQuery(_SQL_COUNT_TRASHVERSION);
2055
2056 count = (Long)q.uniqueResult();
2057
2058 finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
2059 count);
2060 }
2061 catch (Exception e) {
2062 finderCache.removeResult(FINDER_PATH_COUNT_ALL,
2063 FINDER_ARGS_EMPTY);
2064
2065 throw processException(e);
2066 }
2067 finally {
2068 closeSession(session);
2069 }
2070 }
2071
2072 return count.intValue();
2073 }
2074
2075 @Override
2076 protected Map<String, Integer> getTableColumnsMap() {
2077 return TrashVersionModelImpl.TABLE_COLUMNS_MAP;
2078 }
2079
2080
2083 public void afterPropertiesSet() {
2084 }
2085
2086 public void destroy() {
2087 entityCache.removeCache(TrashVersionImpl.class.getName());
2088 finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
2089 finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2090 finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2091 }
2092
2093 protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
2094 protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
2095 private static final String _SQL_SELECT_TRASHVERSION = "SELECT trashVersion FROM TrashVersion trashVersion";
2096 private static final String _SQL_SELECT_TRASHVERSION_WHERE_PKS_IN = "SELECT trashVersion FROM TrashVersion trashVersion WHERE versionId IN (";
2097 private static final String _SQL_SELECT_TRASHVERSION_WHERE = "SELECT trashVersion FROM TrashVersion trashVersion WHERE ";
2098 private static final String _SQL_COUNT_TRASHVERSION = "SELECT COUNT(trashVersion) FROM TrashVersion trashVersion";
2099 private static final String _SQL_COUNT_TRASHVERSION_WHERE = "SELECT COUNT(trashVersion) FROM TrashVersion trashVersion WHERE ";
2100 private static final String _ORDER_BY_ENTITY_ALIAS = "trashVersion.";
2101 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No TrashVersion exists with the primary key ";
2102 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No TrashVersion exists with the key {";
2103 private static final Log _log = LogFactoryUtil.getLog(TrashVersionPersistenceImpl.class);
2104 private static final TrashVersion _nullTrashVersion = new TrashVersionImpl() {
2105 @Override
2106 public Object clone() {
2107 return this;
2108 }
2109
2110 @Override
2111 public CacheModel<TrashVersion> toCacheModel() {
2112 return _nullTrashVersionCacheModel;
2113 }
2114 };
2115
2116 private static final CacheModel<TrashVersion> _nullTrashVersionCacheModel = new CacheModel<TrashVersion>() {
2117 @Override
2118 public TrashVersion toEntityModel() {
2119 return _nullTrashVersion;
2120 }
2121 };
2122 }