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.cache.CacheRegistryUtil;
020 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderPath;
023 import com.liferay.portal.kernel.dao.orm.Query;
024 import com.liferay.portal.kernel.dao.orm.QueryPos;
025 import com.liferay.portal.kernel.dao.orm.QueryUtil;
026 import com.liferay.portal.kernel.dao.orm.Session;
027 import com.liferay.portal.kernel.log.Log;
028 import com.liferay.portal.kernel.log.LogFactoryUtil;
029 import com.liferay.portal.kernel.util.OrderByComparator;
030 import com.liferay.portal.kernel.util.StringBundler;
031 import com.liferay.portal.kernel.util.StringPool;
032 import com.liferay.portal.model.CacheModel;
033 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
034
035 import com.liferay.portlet.trash.NoSuchVersionException;
036 import com.liferay.portlet.trash.model.TrashVersion;
037 import com.liferay.portlet.trash.model.impl.TrashVersionImpl;
038 import com.liferay.portlet.trash.model.impl.TrashVersionModelImpl;
039 import com.liferay.portlet.trash.service.persistence.TrashVersionPersistence;
040
041 import java.io.Serializable;
042
043 import java.util.Collections;
044 import java.util.HashMap;
045 import java.util.HashSet;
046 import java.util.Iterator;
047 import java.util.List;
048 import java.util.Map;
049 import java.util.Set;
050
051
063 @ProviderType
064 public class TrashVersionPersistenceImpl extends BasePersistenceImpl<TrashVersion>
065 implements TrashVersionPersistence {
066
071 public static final String FINDER_CLASS_NAME_ENTITY = TrashVersionImpl.class.getName();
072 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
073 ".List1";
074 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
075 ".List2";
076 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
077 TrashVersionModelImpl.FINDER_CACHE_ENABLED, TrashVersionImpl.class,
078 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
079 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
080 TrashVersionModelImpl.FINDER_CACHE_ENABLED, TrashVersionImpl.class,
081 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
082 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
083 TrashVersionModelImpl.FINDER_CACHE_ENABLED, Long.class,
084 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
085 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_ENTRYID = new FinderPath(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
086 TrashVersionModelImpl.FINDER_CACHE_ENABLED, TrashVersionImpl.class,
087 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByEntryId",
088 new String[] {
089 Long.class.getName(),
090
091 Integer.class.getName(), Integer.class.getName(),
092 OrderByComparator.class.getName()
093 });
094 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ENTRYID =
095 new FinderPath(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
096 TrashVersionModelImpl.FINDER_CACHE_ENABLED, TrashVersionImpl.class,
097 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByEntryId",
098 new String[] { Long.class.getName() },
099 TrashVersionModelImpl.ENTRYID_COLUMN_BITMASK);
100 public static final FinderPath FINDER_PATH_COUNT_BY_ENTRYID = new FinderPath(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
101 TrashVersionModelImpl.FINDER_CACHE_ENABLED, Long.class,
102 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByEntryId",
103 new String[] { Long.class.getName() });
104
105
111 @Override
112 public List<TrashVersion> findByEntryId(long entryId) {
113 return findByEntryId(entryId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
114 }
115
116
128 @Override
129 public List<TrashVersion> findByEntryId(long entryId, int start, int end) {
130 return findByEntryId(entryId, start, end, null);
131 }
132
133
146 @Override
147 public List<TrashVersion> findByEntryId(long entryId, int start, int end,
148 OrderByComparator<TrashVersion> orderByComparator) {
149 boolean pagination = true;
150 FinderPath finderPath = null;
151 Object[] finderArgs = null;
152
153 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
154 (orderByComparator == null)) {
155 pagination = false;
156 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ENTRYID;
157 finderArgs = new Object[] { entryId };
158 }
159 else {
160 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_ENTRYID;
161 finderArgs = new Object[] { entryId, start, end, orderByComparator };
162 }
163
164 List<TrashVersion> list = (List<TrashVersion>)FinderCacheUtil.getResult(finderPath,
165 finderArgs, this);
166
167 if ((list != null) && !list.isEmpty()) {
168 for (TrashVersion trashVersion : list) {
169 if ((entryId != trashVersion.getEntryId())) {
170 list = null;
171
172 break;
173 }
174 }
175 }
176
177 if (list == null) {
178 StringBundler query = null;
179
180 if (orderByComparator != null) {
181 query = new StringBundler(3 +
182 (orderByComparator.getOrderByFields().length * 3));
183 }
184 else {
185 query = new StringBundler(3);
186 }
187
188 query.append(_SQL_SELECT_TRASHVERSION_WHERE);
189
190 query.append(_FINDER_COLUMN_ENTRYID_ENTRYID_2);
191
192 if (orderByComparator != null) {
193 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
194 orderByComparator);
195 }
196 else
197 if (pagination) {
198 query.append(TrashVersionModelImpl.ORDER_BY_JPQL);
199 }
200
201 String sql = query.toString();
202
203 Session session = null;
204
205 try {
206 session = openSession();
207
208 Query q = session.createQuery(sql);
209
210 QueryPos qPos = QueryPos.getInstance(q);
211
212 qPos.add(entryId);
213
214 if (!pagination) {
215 list = (List<TrashVersion>)QueryUtil.list(q, getDialect(),
216 start, end, false);
217
218 Collections.sort(list);
219
220 list = Collections.unmodifiableList(list);
221 }
222 else {
223 list = (List<TrashVersion>)QueryUtil.list(q, getDialect(),
224 start, end);
225 }
226
227 cacheResult(list);
228
229 FinderCacheUtil.putResult(finderPath, finderArgs, list);
230 }
231 catch (Exception e) {
232 FinderCacheUtil.removeResult(finderPath, finderArgs);
233
234 throw processException(e);
235 }
236 finally {
237 closeSession(session);
238 }
239 }
240
241 return list;
242 }
243
244
252 @Override
253 public TrashVersion findByEntryId_First(long entryId,
254 OrderByComparator<TrashVersion> orderByComparator)
255 throws NoSuchVersionException {
256 TrashVersion trashVersion = fetchByEntryId_First(entryId,
257 orderByComparator);
258
259 if (trashVersion != null) {
260 return trashVersion;
261 }
262
263 StringBundler msg = new StringBundler(4);
264
265 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
266
267 msg.append("entryId=");
268 msg.append(entryId);
269
270 msg.append(StringPool.CLOSE_CURLY_BRACE);
271
272 throw new NoSuchVersionException(msg.toString());
273 }
274
275
282 @Override
283 public TrashVersion fetchByEntryId_First(long entryId,
284 OrderByComparator<TrashVersion> orderByComparator) {
285 List<TrashVersion> list = findByEntryId(entryId, 0, 1, orderByComparator);
286
287 if (!list.isEmpty()) {
288 return list.get(0);
289 }
290
291 return null;
292 }
293
294
302 @Override
303 public TrashVersion findByEntryId_Last(long entryId,
304 OrderByComparator<TrashVersion> orderByComparator)
305 throws NoSuchVersionException {
306 TrashVersion trashVersion = fetchByEntryId_Last(entryId,
307 orderByComparator);
308
309 if (trashVersion != null) {
310 return trashVersion;
311 }
312
313 StringBundler msg = new StringBundler(4);
314
315 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
316
317 msg.append("entryId=");
318 msg.append(entryId);
319
320 msg.append(StringPool.CLOSE_CURLY_BRACE);
321
322 throw new NoSuchVersionException(msg.toString());
323 }
324
325
332 @Override
333 public TrashVersion fetchByEntryId_Last(long entryId,
334 OrderByComparator<TrashVersion> orderByComparator) {
335 int count = countByEntryId(entryId);
336
337 if (count == 0) {
338 return null;
339 }
340
341 List<TrashVersion> list = findByEntryId(entryId, count - 1, count,
342 orderByComparator);
343
344 if (!list.isEmpty()) {
345 return list.get(0);
346 }
347
348 return null;
349 }
350
351
360 @Override
361 public TrashVersion[] findByEntryId_PrevAndNext(long versionId,
362 long entryId, OrderByComparator<TrashVersion> orderByComparator)
363 throws NoSuchVersionException {
364 TrashVersion trashVersion = findByPrimaryKey(versionId);
365
366 Session session = null;
367
368 try {
369 session = openSession();
370
371 TrashVersion[] array = new TrashVersionImpl[3];
372
373 array[0] = getByEntryId_PrevAndNext(session, trashVersion, entryId,
374 orderByComparator, true);
375
376 array[1] = trashVersion;
377
378 array[2] = getByEntryId_PrevAndNext(session, trashVersion, entryId,
379 orderByComparator, false);
380
381 return array;
382 }
383 catch (Exception e) {
384 throw processException(e);
385 }
386 finally {
387 closeSession(session);
388 }
389 }
390
391 protected TrashVersion getByEntryId_PrevAndNext(Session session,
392 TrashVersion trashVersion, long entryId,
393 OrderByComparator<TrashVersion> orderByComparator, boolean previous) {
394 StringBundler query = null;
395
396 if (orderByComparator != null) {
397 query = new StringBundler(6 +
398 (orderByComparator.getOrderByFields().length * 6));
399 }
400 else {
401 query = new StringBundler(3);
402 }
403
404 query.append(_SQL_SELECT_TRASHVERSION_WHERE);
405
406 query.append(_FINDER_COLUMN_ENTRYID_ENTRYID_2);
407
408 if (orderByComparator != null) {
409 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
410
411 if (orderByConditionFields.length > 0) {
412 query.append(WHERE_AND);
413 }
414
415 for (int i = 0; i < orderByConditionFields.length; i++) {
416 query.append(_ORDER_BY_ENTITY_ALIAS);
417 query.append(orderByConditionFields[i]);
418
419 if ((i + 1) < orderByConditionFields.length) {
420 if (orderByComparator.isAscending() ^ previous) {
421 query.append(WHERE_GREATER_THAN_HAS_NEXT);
422 }
423 else {
424 query.append(WHERE_LESSER_THAN_HAS_NEXT);
425 }
426 }
427 else {
428 if (orderByComparator.isAscending() ^ previous) {
429 query.append(WHERE_GREATER_THAN);
430 }
431 else {
432 query.append(WHERE_LESSER_THAN);
433 }
434 }
435 }
436
437 query.append(ORDER_BY_CLAUSE);
438
439 String[] orderByFields = orderByComparator.getOrderByFields();
440
441 for (int i = 0; i < orderByFields.length; i++) {
442 query.append(_ORDER_BY_ENTITY_ALIAS);
443 query.append(orderByFields[i]);
444
445 if ((i + 1) < orderByFields.length) {
446 if (orderByComparator.isAscending() ^ previous) {
447 query.append(ORDER_BY_ASC_HAS_NEXT);
448 }
449 else {
450 query.append(ORDER_BY_DESC_HAS_NEXT);
451 }
452 }
453 else {
454 if (orderByComparator.isAscending() ^ previous) {
455 query.append(ORDER_BY_ASC);
456 }
457 else {
458 query.append(ORDER_BY_DESC);
459 }
460 }
461 }
462 }
463 else {
464 query.append(TrashVersionModelImpl.ORDER_BY_JPQL);
465 }
466
467 String sql = query.toString();
468
469 Query q = session.createQuery(sql);
470
471 q.setFirstResult(0);
472 q.setMaxResults(2);
473
474 QueryPos qPos = QueryPos.getInstance(q);
475
476 qPos.add(entryId);
477
478 if (orderByComparator != null) {
479 Object[] values = orderByComparator.getOrderByConditionValues(trashVersion);
480
481 for (Object value : values) {
482 qPos.add(value);
483 }
484 }
485
486 List<TrashVersion> list = q.list();
487
488 if (list.size() == 2) {
489 return list.get(1);
490 }
491 else {
492 return null;
493 }
494 }
495
496
501 @Override
502 public void removeByEntryId(long entryId) {
503 for (TrashVersion trashVersion : findByEntryId(entryId,
504 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
505 remove(trashVersion);
506 }
507 }
508
509
515 @Override
516 public int countByEntryId(long entryId) {
517 FinderPath finderPath = FINDER_PATH_COUNT_BY_ENTRYID;
518
519 Object[] finderArgs = new Object[] { entryId };
520
521 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
522 this);
523
524 if (count == null) {
525 StringBundler query = new StringBundler(2);
526
527 query.append(_SQL_COUNT_TRASHVERSION_WHERE);
528
529 query.append(_FINDER_COLUMN_ENTRYID_ENTRYID_2);
530
531 String sql = query.toString();
532
533 Session session = null;
534
535 try {
536 session = openSession();
537
538 Query q = session.createQuery(sql);
539
540 QueryPos qPos = QueryPos.getInstance(q);
541
542 qPos.add(entryId);
543
544 count = (Long)q.uniqueResult();
545
546 FinderCacheUtil.putResult(finderPath, finderArgs, count);
547 }
548 catch (Exception e) {
549 FinderCacheUtil.removeResult(finderPath, finderArgs);
550
551 throw processException(e);
552 }
553 finally {
554 closeSession(session);
555 }
556 }
557
558 return count.intValue();
559 }
560
561 private static final String _FINDER_COLUMN_ENTRYID_ENTRYID_2 = "trashVersion.entryId = ?";
562 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_E_C = new FinderPath(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
563 TrashVersionModelImpl.FINDER_CACHE_ENABLED, TrashVersionImpl.class,
564 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByE_C",
565 new String[] {
566 Long.class.getName(), Long.class.getName(),
567
568 Integer.class.getName(), Integer.class.getName(),
569 OrderByComparator.class.getName()
570 });
571 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_E_C = new FinderPath(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
572 TrashVersionModelImpl.FINDER_CACHE_ENABLED, TrashVersionImpl.class,
573 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByE_C",
574 new String[] { Long.class.getName(), Long.class.getName() },
575 TrashVersionModelImpl.ENTRYID_COLUMN_BITMASK |
576 TrashVersionModelImpl.CLASSNAMEID_COLUMN_BITMASK);
577 public static final FinderPath FINDER_PATH_COUNT_BY_E_C = new FinderPath(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
578 TrashVersionModelImpl.FINDER_CACHE_ENABLED, Long.class,
579 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByE_C",
580 new String[] { Long.class.getName(), Long.class.getName() });
581
582
589 @Override
590 public List<TrashVersion> findByE_C(long entryId, long classNameId) {
591 return findByE_C(entryId, classNameId, QueryUtil.ALL_POS,
592 QueryUtil.ALL_POS, null);
593 }
594
595
608 @Override
609 public List<TrashVersion> findByE_C(long entryId, long classNameId,
610 int start, int end) {
611 return findByE_C(entryId, classNameId, start, end, null);
612 }
613
614
628 @Override
629 public List<TrashVersion> findByE_C(long entryId, long classNameId,
630 int start, int end, OrderByComparator<TrashVersion> orderByComparator) {
631 boolean pagination = true;
632 FinderPath finderPath = null;
633 Object[] finderArgs = null;
634
635 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
636 (orderByComparator == null)) {
637 pagination = false;
638 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_E_C;
639 finderArgs = new Object[] { entryId, classNameId };
640 }
641 else {
642 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_E_C;
643 finderArgs = new Object[] {
644 entryId, classNameId,
645
646 start, end, orderByComparator
647 };
648 }
649
650 List<TrashVersion> list = (List<TrashVersion>)FinderCacheUtil.getResult(finderPath,
651 finderArgs, this);
652
653 if ((list != null) && !list.isEmpty()) {
654 for (TrashVersion trashVersion : list) {
655 if ((entryId != trashVersion.getEntryId()) ||
656 (classNameId != trashVersion.getClassNameId())) {
657 list = null;
658
659 break;
660 }
661 }
662 }
663
664 if (list == null) {
665 StringBundler query = null;
666
667 if (orderByComparator != null) {
668 query = new StringBundler(4 +
669 (orderByComparator.getOrderByFields().length * 3));
670 }
671 else {
672 query = new StringBundler(4);
673 }
674
675 query.append(_SQL_SELECT_TRASHVERSION_WHERE);
676
677 query.append(_FINDER_COLUMN_E_C_ENTRYID_2);
678
679 query.append(_FINDER_COLUMN_E_C_CLASSNAMEID_2);
680
681 if (orderByComparator != null) {
682 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
683 orderByComparator);
684 }
685 else
686 if (pagination) {
687 query.append(TrashVersionModelImpl.ORDER_BY_JPQL);
688 }
689
690 String sql = query.toString();
691
692 Session session = null;
693
694 try {
695 session = openSession();
696
697 Query q = session.createQuery(sql);
698
699 QueryPos qPos = QueryPos.getInstance(q);
700
701 qPos.add(entryId);
702
703 qPos.add(classNameId);
704
705 if (!pagination) {
706 list = (List<TrashVersion>)QueryUtil.list(q, getDialect(),
707 start, end, false);
708
709 Collections.sort(list);
710
711 list = Collections.unmodifiableList(list);
712 }
713 else {
714 list = (List<TrashVersion>)QueryUtil.list(q, getDialect(),
715 start, end);
716 }
717
718 cacheResult(list);
719
720 FinderCacheUtil.putResult(finderPath, finderArgs, list);
721 }
722 catch (Exception e) {
723 FinderCacheUtil.removeResult(finderPath, finderArgs);
724
725 throw processException(e);
726 }
727 finally {
728 closeSession(session);
729 }
730 }
731
732 return list;
733 }
734
735
744 @Override
745 public TrashVersion findByE_C_First(long entryId, long classNameId,
746 OrderByComparator<TrashVersion> orderByComparator)
747 throws NoSuchVersionException {
748 TrashVersion trashVersion = fetchByE_C_First(entryId, classNameId,
749 orderByComparator);
750
751 if (trashVersion != null) {
752 return trashVersion;
753 }
754
755 StringBundler msg = new StringBundler(6);
756
757 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
758
759 msg.append("entryId=");
760 msg.append(entryId);
761
762 msg.append(", classNameId=");
763 msg.append(classNameId);
764
765 msg.append(StringPool.CLOSE_CURLY_BRACE);
766
767 throw new NoSuchVersionException(msg.toString());
768 }
769
770
778 @Override
779 public TrashVersion fetchByE_C_First(long entryId, long classNameId,
780 OrderByComparator<TrashVersion> orderByComparator) {
781 List<TrashVersion> list = findByE_C(entryId, classNameId, 0, 1,
782 orderByComparator);
783
784 if (!list.isEmpty()) {
785 return list.get(0);
786 }
787
788 return null;
789 }
790
791
800 @Override
801 public TrashVersion findByE_C_Last(long entryId, long classNameId,
802 OrderByComparator<TrashVersion> orderByComparator)
803 throws NoSuchVersionException {
804 TrashVersion trashVersion = fetchByE_C_Last(entryId, classNameId,
805 orderByComparator);
806
807 if (trashVersion != null) {
808 return trashVersion;
809 }
810
811 StringBundler msg = new StringBundler(6);
812
813 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
814
815 msg.append("entryId=");
816 msg.append(entryId);
817
818 msg.append(", classNameId=");
819 msg.append(classNameId);
820
821 msg.append(StringPool.CLOSE_CURLY_BRACE);
822
823 throw new NoSuchVersionException(msg.toString());
824 }
825
826
834 @Override
835 public TrashVersion fetchByE_C_Last(long entryId, long classNameId,
836 OrderByComparator<TrashVersion> orderByComparator) {
837 int count = countByE_C(entryId, classNameId);
838
839 if (count == 0) {
840 return null;
841 }
842
843 List<TrashVersion> list = findByE_C(entryId, classNameId, count - 1,
844 count, orderByComparator);
845
846 if (!list.isEmpty()) {
847 return list.get(0);
848 }
849
850 return null;
851 }
852
853
863 @Override
864 public TrashVersion[] findByE_C_PrevAndNext(long versionId, long entryId,
865 long classNameId, OrderByComparator<TrashVersion> orderByComparator)
866 throws NoSuchVersionException {
867 TrashVersion trashVersion = findByPrimaryKey(versionId);
868
869 Session session = null;
870
871 try {
872 session = openSession();
873
874 TrashVersion[] array = new TrashVersionImpl[3];
875
876 array[0] = getByE_C_PrevAndNext(session, trashVersion, entryId,
877 classNameId, orderByComparator, true);
878
879 array[1] = trashVersion;
880
881 array[2] = getByE_C_PrevAndNext(session, trashVersion, entryId,
882 classNameId, orderByComparator, false);
883
884 return array;
885 }
886 catch (Exception e) {
887 throw processException(e);
888 }
889 finally {
890 closeSession(session);
891 }
892 }
893
894 protected TrashVersion getByE_C_PrevAndNext(Session session,
895 TrashVersion trashVersion, long entryId, long classNameId,
896 OrderByComparator<TrashVersion> orderByComparator, boolean previous) {
897 StringBundler query = null;
898
899 if (orderByComparator != null) {
900 query = new StringBundler(6 +
901 (orderByComparator.getOrderByFields().length * 6));
902 }
903 else {
904 query = new StringBundler(3);
905 }
906
907 query.append(_SQL_SELECT_TRASHVERSION_WHERE);
908
909 query.append(_FINDER_COLUMN_E_C_ENTRYID_2);
910
911 query.append(_FINDER_COLUMN_E_C_CLASSNAMEID_2);
912
913 if (orderByComparator != null) {
914 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
915
916 if (orderByConditionFields.length > 0) {
917 query.append(WHERE_AND);
918 }
919
920 for (int i = 0; i < orderByConditionFields.length; i++) {
921 query.append(_ORDER_BY_ENTITY_ALIAS);
922 query.append(orderByConditionFields[i]);
923
924 if ((i + 1) < orderByConditionFields.length) {
925 if (orderByComparator.isAscending() ^ previous) {
926 query.append(WHERE_GREATER_THAN_HAS_NEXT);
927 }
928 else {
929 query.append(WHERE_LESSER_THAN_HAS_NEXT);
930 }
931 }
932 else {
933 if (orderByComparator.isAscending() ^ previous) {
934 query.append(WHERE_GREATER_THAN);
935 }
936 else {
937 query.append(WHERE_LESSER_THAN);
938 }
939 }
940 }
941
942 query.append(ORDER_BY_CLAUSE);
943
944 String[] orderByFields = orderByComparator.getOrderByFields();
945
946 for (int i = 0; i < orderByFields.length; i++) {
947 query.append(_ORDER_BY_ENTITY_ALIAS);
948 query.append(orderByFields[i]);
949
950 if ((i + 1) < orderByFields.length) {
951 if (orderByComparator.isAscending() ^ previous) {
952 query.append(ORDER_BY_ASC_HAS_NEXT);
953 }
954 else {
955 query.append(ORDER_BY_DESC_HAS_NEXT);
956 }
957 }
958 else {
959 if (orderByComparator.isAscending() ^ previous) {
960 query.append(ORDER_BY_ASC);
961 }
962 else {
963 query.append(ORDER_BY_DESC);
964 }
965 }
966 }
967 }
968 else {
969 query.append(TrashVersionModelImpl.ORDER_BY_JPQL);
970 }
971
972 String sql = query.toString();
973
974 Query q = session.createQuery(sql);
975
976 q.setFirstResult(0);
977 q.setMaxResults(2);
978
979 QueryPos qPos = QueryPos.getInstance(q);
980
981 qPos.add(entryId);
982
983 qPos.add(classNameId);
984
985 if (orderByComparator != null) {
986 Object[] values = orderByComparator.getOrderByConditionValues(trashVersion);
987
988 for (Object value : values) {
989 qPos.add(value);
990 }
991 }
992
993 List<TrashVersion> list = q.list();
994
995 if (list.size() == 2) {
996 return list.get(1);
997 }
998 else {
999 return null;
1000 }
1001 }
1002
1003
1009 @Override
1010 public void removeByE_C(long entryId, long classNameId) {
1011 for (TrashVersion trashVersion : findByE_C(entryId, classNameId,
1012 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1013 remove(trashVersion);
1014 }
1015 }
1016
1017
1024 @Override
1025 public int countByE_C(long entryId, long classNameId) {
1026 FinderPath finderPath = FINDER_PATH_COUNT_BY_E_C;
1027
1028 Object[] finderArgs = new Object[] { entryId, classNameId };
1029
1030 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1031 this);
1032
1033 if (count == null) {
1034 StringBundler query = new StringBundler(3);
1035
1036 query.append(_SQL_COUNT_TRASHVERSION_WHERE);
1037
1038 query.append(_FINDER_COLUMN_E_C_ENTRYID_2);
1039
1040 query.append(_FINDER_COLUMN_E_C_CLASSNAMEID_2);
1041
1042 String sql = query.toString();
1043
1044 Session session = null;
1045
1046 try {
1047 session = openSession();
1048
1049 Query q = session.createQuery(sql);
1050
1051 QueryPos qPos = QueryPos.getInstance(q);
1052
1053 qPos.add(entryId);
1054
1055 qPos.add(classNameId);
1056
1057 count = (Long)q.uniqueResult();
1058
1059 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1060 }
1061 catch (Exception e) {
1062 FinderCacheUtil.removeResult(finderPath, finderArgs);
1063
1064 throw processException(e);
1065 }
1066 finally {
1067 closeSession(session);
1068 }
1069 }
1070
1071 return count.intValue();
1072 }
1073
1074 private static final String _FINDER_COLUMN_E_C_ENTRYID_2 = "trashVersion.entryId = ? AND ";
1075 private static final String _FINDER_COLUMN_E_C_CLASSNAMEID_2 = "trashVersion.classNameId = ?";
1076 public static final FinderPath FINDER_PATH_FETCH_BY_C_C = new FinderPath(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
1077 TrashVersionModelImpl.FINDER_CACHE_ENABLED, TrashVersionImpl.class,
1078 FINDER_CLASS_NAME_ENTITY, "fetchByC_C",
1079 new String[] { Long.class.getName(), Long.class.getName() },
1080 TrashVersionModelImpl.CLASSNAMEID_COLUMN_BITMASK |
1081 TrashVersionModelImpl.CLASSPK_COLUMN_BITMASK);
1082 public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
1083 TrashVersionModelImpl.FINDER_CACHE_ENABLED, Long.class,
1084 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C",
1085 new String[] { Long.class.getName(), Long.class.getName() });
1086
1087
1095 @Override
1096 public TrashVersion findByC_C(long classNameId, long classPK)
1097 throws NoSuchVersionException {
1098 TrashVersion trashVersion = fetchByC_C(classNameId, classPK);
1099
1100 if (trashVersion == null) {
1101 StringBundler msg = new StringBundler(6);
1102
1103 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1104
1105 msg.append("classNameId=");
1106 msg.append(classNameId);
1107
1108 msg.append(", classPK=");
1109 msg.append(classPK);
1110
1111 msg.append(StringPool.CLOSE_CURLY_BRACE);
1112
1113 if (_log.isWarnEnabled()) {
1114 _log.warn(msg.toString());
1115 }
1116
1117 throw new NoSuchVersionException(msg.toString());
1118 }
1119
1120 return trashVersion;
1121 }
1122
1123
1130 @Override
1131 public TrashVersion fetchByC_C(long classNameId, long classPK) {
1132 return fetchByC_C(classNameId, classPK, true);
1133 }
1134
1135
1143 @Override
1144 public TrashVersion fetchByC_C(long classNameId, long classPK,
1145 boolean retrieveFromCache) {
1146 Object[] finderArgs = new Object[] { classNameId, classPK };
1147
1148 Object result = null;
1149
1150 if (retrieveFromCache) {
1151 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_C,
1152 finderArgs, this);
1153 }
1154
1155 if (result instanceof TrashVersion) {
1156 TrashVersion trashVersion = (TrashVersion)result;
1157
1158 if ((classNameId != trashVersion.getClassNameId()) ||
1159 (classPK != trashVersion.getClassPK())) {
1160 result = null;
1161 }
1162 }
1163
1164 if (result == null) {
1165 StringBundler query = new StringBundler(4);
1166
1167 query.append(_SQL_SELECT_TRASHVERSION_WHERE);
1168
1169 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
1170
1171 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
1172
1173 String sql = query.toString();
1174
1175 Session session = null;
1176
1177 try {
1178 session = openSession();
1179
1180 Query q = session.createQuery(sql);
1181
1182 QueryPos qPos = QueryPos.getInstance(q);
1183
1184 qPos.add(classNameId);
1185
1186 qPos.add(classPK);
1187
1188 List<TrashVersion> list = q.list();
1189
1190 if (list.isEmpty()) {
1191 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
1192 finderArgs, list);
1193 }
1194 else {
1195 TrashVersion trashVersion = list.get(0);
1196
1197 result = trashVersion;
1198
1199 cacheResult(trashVersion);
1200
1201 if ((trashVersion.getClassNameId() != classNameId) ||
1202 (trashVersion.getClassPK() != classPK)) {
1203 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
1204 finderArgs, trashVersion);
1205 }
1206 }
1207 }
1208 catch (Exception e) {
1209 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C,
1210 finderArgs);
1211
1212 throw processException(e);
1213 }
1214 finally {
1215 closeSession(session);
1216 }
1217 }
1218
1219 if (result instanceof List<?>) {
1220 return null;
1221 }
1222 else {
1223 return (TrashVersion)result;
1224 }
1225 }
1226
1227
1234 @Override
1235 public TrashVersion removeByC_C(long classNameId, long classPK)
1236 throws NoSuchVersionException {
1237 TrashVersion trashVersion = findByC_C(classNameId, classPK);
1238
1239 return remove(trashVersion);
1240 }
1241
1242
1249 @Override
1250 public int countByC_C(long classNameId, long classPK) {
1251 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C;
1252
1253 Object[] finderArgs = new Object[] { classNameId, classPK };
1254
1255 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1256 this);
1257
1258 if (count == null) {
1259 StringBundler query = new StringBundler(3);
1260
1261 query.append(_SQL_COUNT_TRASHVERSION_WHERE);
1262
1263 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
1264
1265 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
1266
1267 String sql = query.toString();
1268
1269 Session session = null;
1270
1271 try {
1272 session = openSession();
1273
1274 Query q = session.createQuery(sql);
1275
1276 QueryPos qPos = QueryPos.getInstance(q);
1277
1278 qPos.add(classNameId);
1279
1280 qPos.add(classPK);
1281
1282 count = (Long)q.uniqueResult();
1283
1284 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1285 }
1286 catch (Exception e) {
1287 FinderCacheUtil.removeResult(finderPath, finderArgs);
1288
1289 throw processException(e);
1290 }
1291 finally {
1292 closeSession(session);
1293 }
1294 }
1295
1296 return count.intValue();
1297 }
1298
1299 private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "trashVersion.classNameId = ? AND ";
1300 private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "trashVersion.classPK = ?";
1301
1302 public TrashVersionPersistenceImpl() {
1303 setModelClass(TrashVersion.class);
1304 }
1305
1306
1311 @Override
1312 public void cacheResult(TrashVersion trashVersion) {
1313 EntityCacheUtil.putResult(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
1314 TrashVersionImpl.class, trashVersion.getPrimaryKey(), trashVersion);
1315
1316 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
1317 new Object[] {
1318 trashVersion.getClassNameId(), trashVersion.getClassPK()
1319 }, trashVersion);
1320
1321 trashVersion.resetOriginalValues();
1322 }
1323
1324
1329 @Override
1330 public void cacheResult(List<TrashVersion> trashVersions) {
1331 for (TrashVersion trashVersion : trashVersions) {
1332 if (EntityCacheUtil.getResult(
1333 TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
1334 TrashVersionImpl.class, trashVersion.getPrimaryKey()) == null) {
1335 cacheResult(trashVersion);
1336 }
1337 else {
1338 trashVersion.resetOriginalValues();
1339 }
1340 }
1341 }
1342
1343
1350 @Override
1351 public void clearCache() {
1352 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
1353 CacheRegistryUtil.clear(TrashVersionImpl.class.getName());
1354 }
1355
1356 EntityCacheUtil.clearCache(TrashVersionImpl.class);
1357
1358 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
1359 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1360 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1361 }
1362
1363
1370 @Override
1371 public void clearCache(TrashVersion trashVersion) {
1372 EntityCacheUtil.removeResult(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
1373 TrashVersionImpl.class, trashVersion.getPrimaryKey());
1374
1375 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1376 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1377
1378 clearUniqueFindersCache(trashVersion);
1379 }
1380
1381 @Override
1382 public void clearCache(List<TrashVersion> trashVersions) {
1383 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1384 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1385
1386 for (TrashVersion trashVersion : trashVersions) {
1387 EntityCacheUtil.removeResult(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
1388 TrashVersionImpl.class, trashVersion.getPrimaryKey());
1389
1390 clearUniqueFindersCache(trashVersion);
1391 }
1392 }
1393
1394 protected void cacheUniqueFindersCache(TrashVersion trashVersion) {
1395 if (trashVersion.isNew()) {
1396 Object[] args = new Object[] {
1397 trashVersion.getClassNameId(), trashVersion.getClassPK()
1398 };
1399
1400 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, args,
1401 Long.valueOf(1));
1402 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C, args,
1403 trashVersion);
1404 }
1405 else {
1406 TrashVersionModelImpl trashVersionModelImpl = (TrashVersionModelImpl)trashVersion;
1407
1408 if ((trashVersionModelImpl.getColumnBitmask() &
1409 FINDER_PATH_FETCH_BY_C_C.getColumnBitmask()) != 0) {
1410 Object[] args = new Object[] {
1411 trashVersion.getClassNameId(), trashVersion.getClassPK()
1412 };
1413
1414 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, args,
1415 Long.valueOf(1));
1416 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C, args,
1417 trashVersion);
1418 }
1419 }
1420 }
1421
1422 protected void clearUniqueFindersCache(TrashVersion trashVersion) {
1423 TrashVersionModelImpl trashVersionModelImpl = (TrashVersionModelImpl)trashVersion;
1424
1425 Object[] args = new Object[] {
1426 trashVersion.getClassNameId(), trashVersion.getClassPK()
1427 };
1428
1429 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
1430 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C, args);
1431
1432 if ((trashVersionModelImpl.getColumnBitmask() &
1433 FINDER_PATH_FETCH_BY_C_C.getColumnBitmask()) != 0) {
1434 args = new Object[] {
1435 trashVersionModelImpl.getOriginalClassNameId(),
1436 trashVersionModelImpl.getOriginalClassPK()
1437 };
1438
1439 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
1440 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C, args);
1441 }
1442 }
1443
1444
1450 @Override
1451 public TrashVersion create(long versionId) {
1452 TrashVersion trashVersion = new TrashVersionImpl();
1453
1454 trashVersion.setNew(true);
1455 trashVersion.setPrimaryKey(versionId);
1456
1457 return trashVersion;
1458 }
1459
1460
1467 @Override
1468 public TrashVersion remove(long versionId) throws NoSuchVersionException {
1469 return remove((Serializable)versionId);
1470 }
1471
1472
1479 @Override
1480 public TrashVersion remove(Serializable primaryKey)
1481 throws NoSuchVersionException {
1482 Session session = null;
1483
1484 try {
1485 session = openSession();
1486
1487 TrashVersion trashVersion = (TrashVersion)session.get(TrashVersionImpl.class,
1488 primaryKey);
1489
1490 if (trashVersion == null) {
1491 if (_log.isWarnEnabled()) {
1492 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1493 }
1494
1495 throw new NoSuchVersionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1496 primaryKey);
1497 }
1498
1499 return remove(trashVersion);
1500 }
1501 catch (NoSuchVersionException nsee) {
1502 throw nsee;
1503 }
1504 catch (Exception e) {
1505 throw processException(e);
1506 }
1507 finally {
1508 closeSession(session);
1509 }
1510 }
1511
1512 @Override
1513 protected TrashVersion removeImpl(TrashVersion trashVersion) {
1514 trashVersion = toUnwrappedModel(trashVersion);
1515
1516 Session session = null;
1517
1518 try {
1519 session = openSession();
1520
1521 if (!session.contains(trashVersion)) {
1522 trashVersion = (TrashVersion)session.get(TrashVersionImpl.class,
1523 trashVersion.getPrimaryKeyObj());
1524 }
1525
1526 if (trashVersion != null) {
1527 session.delete(trashVersion);
1528 }
1529 }
1530 catch (Exception e) {
1531 throw processException(e);
1532 }
1533 finally {
1534 closeSession(session);
1535 }
1536
1537 if (trashVersion != null) {
1538 clearCache(trashVersion);
1539 }
1540
1541 return trashVersion;
1542 }
1543
1544 @Override
1545 public TrashVersion updateImpl(
1546 com.liferay.portlet.trash.model.TrashVersion trashVersion) {
1547 trashVersion = toUnwrappedModel(trashVersion);
1548
1549 boolean isNew = trashVersion.isNew();
1550
1551 TrashVersionModelImpl trashVersionModelImpl = (TrashVersionModelImpl)trashVersion;
1552
1553 Session session = null;
1554
1555 try {
1556 session = openSession();
1557
1558 if (trashVersion.isNew()) {
1559 session.save(trashVersion);
1560
1561 trashVersion.setNew(false);
1562 }
1563 else {
1564 session.merge(trashVersion);
1565 }
1566 }
1567 catch (Exception e) {
1568 throw processException(e);
1569 }
1570 finally {
1571 closeSession(session);
1572 }
1573
1574 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1575
1576 if (isNew || !TrashVersionModelImpl.COLUMN_BITMASK_ENABLED) {
1577 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1578 }
1579
1580 else {
1581 if ((trashVersionModelImpl.getColumnBitmask() &
1582 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ENTRYID.getColumnBitmask()) != 0) {
1583 Object[] args = new Object[] {
1584 trashVersionModelImpl.getOriginalEntryId()
1585 };
1586
1587 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ENTRYID, args);
1588 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ENTRYID,
1589 args);
1590
1591 args = new Object[] { trashVersionModelImpl.getEntryId() };
1592
1593 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ENTRYID, args);
1594 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ENTRYID,
1595 args);
1596 }
1597
1598 if ((trashVersionModelImpl.getColumnBitmask() &
1599 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_E_C.getColumnBitmask()) != 0) {
1600 Object[] args = new Object[] {
1601 trashVersionModelImpl.getOriginalEntryId(),
1602 trashVersionModelImpl.getOriginalClassNameId()
1603 };
1604
1605 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_E_C, args);
1606 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_E_C,
1607 args);
1608
1609 args = new Object[] {
1610 trashVersionModelImpl.getEntryId(),
1611 trashVersionModelImpl.getClassNameId()
1612 };
1613
1614 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_E_C, args);
1615 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_E_C,
1616 args);
1617 }
1618 }
1619
1620 EntityCacheUtil.putResult(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
1621 TrashVersionImpl.class, trashVersion.getPrimaryKey(), trashVersion,
1622 false);
1623
1624 clearUniqueFindersCache(trashVersion);
1625 cacheUniqueFindersCache(trashVersion);
1626
1627 trashVersion.resetOriginalValues();
1628
1629 return trashVersion;
1630 }
1631
1632 protected TrashVersion toUnwrappedModel(TrashVersion trashVersion) {
1633 if (trashVersion instanceof TrashVersionImpl) {
1634 return trashVersion;
1635 }
1636
1637 TrashVersionImpl trashVersionImpl = new TrashVersionImpl();
1638
1639 trashVersionImpl.setNew(trashVersion.isNew());
1640 trashVersionImpl.setPrimaryKey(trashVersion.getPrimaryKey());
1641
1642 trashVersionImpl.setVersionId(trashVersion.getVersionId());
1643 trashVersionImpl.setEntryId(trashVersion.getEntryId());
1644 trashVersionImpl.setClassNameId(trashVersion.getClassNameId());
1645 trashVersionImpl.setClassPK(trashVersion.getClassPK());
1646 trashVersionImpl.setTypeSettings(trashVersion.getTypeSettings());
1647 trashVersionImpl.setStatus(trashVersion.getStatus());
1648
1649 return trashVersionImpl;
1650 }
1651
1652
1659 @Override
1660 public TrashVersion findByPrimaryKey(Serializable primaryKey)
1661 throws NoSuchVersionException {
1662 TrashVersion trashVersion = fetchByPrimaryKey(primaryKey);
1663
1664 if (trashVersion == null) {
1665 if (_log.isWarnEnabled()) {
1666 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1667 }
1668
1669 throw new NoSuchVersionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1670 primaryKey);
1671 }
1672
1673 return trashVersion;
1674 }
1675
1676
1683 @Override
1684 public TrashVersion findByPrimaryKey(long versionId)
1685 throws NoSuchVersionException {
1686 return findByPrimaryKey((Serializable)versionId);
1687 }
1688
1689
1695 @Override
1696 public TrashVersion fetchByPrimaryKey(Serializable primaryKey) {
1697 TrashVersion trashVersion = (TrashVersion)EntityCacheUtil.getResult(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
1698 TrashVersionImpl.class, primaryKey);
1699
1700 if (trashVersion == _nullTrashVersion) {
1701 return null;
1702 }
1703
1704 if (trashVersion == null) {
1705 Session session = null;
1706
1707 try {
1708 session = openSession();
1709
1710 trashVersion = (TrashVersion)session.get(TrashVersionImpl.class,
1711 primaryKey);
1712
1713 if (trashVersion != null) {
1714 cacheResult(trashVersion);
1715 }
1716 else {
1717 EntityCacheUtil.putResult(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
1718 TrashVersionImpl.class, primaryKey, _nullTrashVersion);
1719 }
1720 }
1721 catch (Exception e) {
1722 EntityCacheUtil.removeResult(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
1723 TrashVersionImpl.class, primaryKey);
1724
1725 throw processException(e);
1726 }
1727 finally {
1728 closeSession(session);
1729 }
1730 }
1731
1732 return trashVersion;
1733 }
1734
1735
1741 @Override
1742 public TrashVersion fetchByPrimaryKey(long versionId) {
1743 return fetchByPrimaryKey((Serializable)versionId);
1744 }
1745
1746 @Override
1747 public Map<Serializable, TrashVersion> fetchByPrimaryKeys(
1748 Set<Serializable> primaryKeys) {
1749 if (primaryKeys.isEmpty()) {
1750 return Collections.emptyMap();
1751 }
1752
1753 Map<Serializable, TrashVersion> map = new HashMap<Serializable, TrashVersion>();
1754
1755 if (primaryKeys.size() == 1) {
1756 Iterator<Serializable> iterator = primaryKeys.iterator();
1757
1758 Serializable primaryKey = iterator.next();
1759
1760 TrashVersion trashVersion = fetchByPrimaryKey(primaryKey);
1761
1762 if (trashVersion != null) {
1763 map.put(primaryKey, trashVersion);
1764 }
1765
1766 return map;
1767 }
1768
1769 Set<Serializable> uncachedPrimaryKeys = null;
1770
1771 for (Serializable primaryKey : primaryKeys) {
1772 TrashVersion trashVersion = (TrashVersion)EntityCacheUtil.getResult(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
1773 TrashVersionImpl.class, primaryKey);
1774
1775 if (trashVersion == null) {
1776 if (uncachedPrimaryKeys == null) {
1777 uncachedPrimaryKeys = new HashSet<Serializable>();
1778 }
1779
1780 uncachedPrimaryKeys.add(primaryKey);
1781 }
1782 else {
1783 map.put(primaryKey, trashVersion);
1784 }
1785 }
1786
1787 if (uncachedPrimaryKeys == null) {
1788 return map;
1789 }
1790
1791 StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
1792 1);
1793
1794 query.append(_SQL_SELECT_TRASHVERSION_WHERE_PKS_IN);
1795
1796 for (Serializable primaryKey : uncachedPrimaryKeys) {
1797 query.append(String.valueOf(primaryKey));
1798
1799 query.append(StringPool.COMMA);
1800 }
1801
1802 query.setIndex(query.index() - 1);
1803
1804 query.append(StringPool.CLOSE_PARENTHESIS);
1805
1806 String sql = query.toString();
1807
1808 Session session = null;
1809
1810 try {
1811 session = openSession();
1812
1813 Query q = session.createQuery(sql);
1814
1815 for (TrashVersion trashVersion : (List<TrashVersion>)q.list()) {
1816 map.put(trashVersion.getPrimaryKeyObj(), trashVersion);
1817
1818 cacheResult(trashVersion);
1819
1820 uncachedPrimaryKeys.remove(trashVersion.getPrimaryKeyObj());
1821 }
1822
1823 for (Serializable primaryKey : uncachedPrimaryKeys) {
1824 EntityCacheUtil.putResult(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
1825 TrashVersionImpl.class, primaryKey, _nullTrashVersion);
1826 }
1827 }
1828 catch (Exception e) {
1829 throw processException(e);
1830 }
1831 finally {
1832 closeSession(session);
1833 }
1834
1835 return map;
1836 }
1837
1838
1843 @Override
1844 public List<TrashVersion> findAll() {
1845 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1846 }
1847
1848
1859 @Override
1860 public List<TrashVersion> findAll(int start, int end) {
1861 return findAll(start, end, null);
1862 }
1863
1864
1876 @Override
1877 public List<TrashVersion> findAll(int start, int end,
1878 OrderByComparator<TrashVersion> orderByComparator) {
1879 boolean pagination = true;
1880 FinderPath finderPath = null;
1881 Object[] finderArgs = null;
1882
1883 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1884 (orderByComparator == null)) {
1885 pagination = false;
1886 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1887 finderArgs = FINDER_ARGS_EMPTY;
1888 }
1889 else {
1890 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1891 finderArgs = new Object[] { start, end, orderByComparator };
1892 }
1893
1894 List<TrashVersion> list = (List<TrashVersion>)FinderCacheUtil.getResult(finderPath,
1895 finderArgs, this);
1896
1897 if (list == null) {
1898 StringBundler query = null;
1899 String sql = null;
1900
1901 if (orderByComparator != null) {
1902 query = new StringBundler(2 +
1903 (orderByComparator.getOrderByFields().length * 3));
1904
1905 query.append(_SQL_SELECT_TRASHVERSION);
1906
1907 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1908 orderByComparator);
1909
1910 sql = query.toString();
1911 }
1912 else {
1913 sql = _SQL_SELECT_TRASHVERSION;
1914
1915 if (pagination) {
1916 sql = sql.concat(TrashVersionModelImpl.ORDER_BY_JPQL);
1917 }
1918 }
1919
1920 Session session = null;
1921
1922 try {
1923 session = openSession();
1924
1925 Query q = session.createQuery(sql);
1926
1927 if (!pagination) {
1928 list = (List<TrashVersion>)QueryUtil.list(q, getDialect(),
1929 start, end, false);
1930
1931 Collections.sort(list);
1932
1933 list = Collections.unmodifiableList(list);
1934 }
1935 else {
1936 list = (List<TrashVersion>)QueryUtil.list(q, getDialect(),
1937 start, end);
1938 }
1939
1940 cacheResult(list);
1941
1942 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1943 }
1944 catch (Exception e) {
1945 FinderCacheUtil.removeResult(finderPath, finderArgs);
1946
1947 throw processException(e);
1948 }
1949 finally {
1950 closeSession(session);
1951 }
1952 }
1953
1954 return list;
1955 }
1956
1957
1961 @Override
1962 public void removeAll() {
1963 for (TrashVersion trashVersion : findAll()) {
1964 remove(trashVersion);
1965 }
1966 }
1967
1968
1973 @Override
1974 public int countAll() {
1975 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1976 FINDER_ARGS_EMPTY, this);
1977
1978 if (count == null) {
1979 Session session = null;
1980
1981 try {
1982 session = openSession();
1983
1984 Query q = session.createQuery(_SQL_COUNT_TRASHVERSION);
1985
1986 count = (Long)q.uniqueResult();
1987
1988 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1989 FINDER_ARGS_EMPTY, count);
1990 }
1991 catch (Exception e) {
1992 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
1993 FINDER_ARGS_EMPTY);
1994
1995 throw processException(e);
1996 }
1997 finally {
1998 closeSession(session);
1999 }
2000 }
2001
2002 return count.intValue();
2003 }
2004
2005
2008 public void afterPropertiesSet() {
2009 }
2010
2011 public void destroy() {
2012 EntityCacheUtil.removeCache(TrashVersionImpl.class.getName());
2013 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2014 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2015 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2016 }
2017
2018 private static final String _SQL_SELECT_TRASHVERSION = "SELECT trashVersion FROM TrashVersion trashVersion";
2019 private static final String _SQL_SELECT_TRASHVERSION_WHERE_PKS_IN = "SELECT trashVersion FROM TrashVersion trashVersion WHERE versionId IN (";
2020 private static final String _SQL_SELECT_TRASHVERSION_WHERE = "SELECT trashVersion FROM TrashVersion trashVersion WHERE ";
2021 private static final String _SQL_COUNT_TRASHVERSION = "SELECT COUNT(trashVersion) FROM TrashVersion trashVersion";
2022 private static final String _SQL_COUNT_TRASHVERSION_WHERE = "SELECT COUNT(trashVersion) FROM TrashVersion trashVersion WHERE ";
2023 private static final String _ORDER_BY_ENTITY_ALIAS = "trashVersion.";
2024 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No TrashVersion exists with the primary key ";
2025 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No TrashVersion exists with the key {";
2026 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2027 private static final Log _log = LogFactoryUtil.getLog(TrashVersionPersistenceImpl.class);
2028 private static final TrashVersion _nullTrashVersion = new TrashVersionImpl() {
2029 @Override
2030 public Object clone() {
2031 return this;
2032 }
2033
2034 @Override
2035 public CacheModel<TrashVersion> toCacheModel() {
2036 return _nullTrashVersionCacheModel;
2037 }
2038 };
2039
2040 private static final CacheModel<TrashVersion> _nullTrashVersionCacheModel = new CacheModel<TrashVersion>() {
2041 @Override
2042 public TrashVersion toEntityModel() {
2043 return _nullTrashVersion;
2044 }
2045 };
2046 }