001
014
015 package com.liferay.portlet.trash.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.kernel.bean.BeanReference;
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.exception.SystemException;
028 import com.liferay.portal.kernel.log.Log;
029 import com.liferay.portal.kernel.log.LogFactoryUtil;
030 import com.liferay.portal.kernel.util.GetterUtil;
031 import com.liferay.portal.kernel.util.InstanceFactory;
032 import com.liferay.portal.kernel.util.OrderByComparator;
033 import com.liferay.portal.kernel.util.StringBundler;
034 import com.liferay.portal.kernel.util.StringPool;
035 import com.liferay.portal.kernel.util.StringUtil;
036 import com.liferay.portal.model.CacheModel;
037 import com.liferay.portal.model.ModelListener;
038 import com.liferay.portal.service.persistence.UserPersistence;
039 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
040
041 import com.liferay.portlet.trash.NoSuchVersionException;
042 import com.liferay.portlet.trash.model.TrashVersion;
043 import com.liferay.portlet.trash.model.impl.TrashVersionImpl;
044 import com.liferay.portlet.trash.model.impl.TrashVersionModelImpl;
045
046 import java.io.Serializable;
047
048 import java.util.ArrayList;
049 import java.util.Collections;
050 import java.util.List;
051
052
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_BY_ENTRYID = new FinderPath(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
077 TrashVersionModelImpl.FINDER_CACHE_ENABLED, TrashVersionImpl.class,
078 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByEntryId",
079 new String[] {
080 Long.class.getName(),
081
082 "java.lang.Integer", "java.lang.Integer",
083 "com.liferay.portal.kernel.util.OrderByComparator"
084 });
085 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ENTRYID =
086 new FinderPath(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
087 TrashVersionModelImpl.FINDER_CACHE_ENABLED, TrashVersionImpl.class,
088 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByEntryId",
089 new String[] { Long.class.getName() },
090 TrashVersionModelImpl.ENTRYID_COLUMN_BITMASK);
091 public static final FinderPath FINDER_PATH_COUNT_BY_ENTRYID = new FinderPath(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
092 TrashVersionModelImpl.FINDER_CACHE_ENABLED, Long.class,
093 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByEntryId",
094 new String[] { Long.class.getName() });
095 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C = new FinderPath(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
096 TrashVersionModelImpl.FINDER_CACHE_ENABLED, TrashVersionImpl.class,
097 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C",
098 new String[] {
099 Long.class.getName(), Long.class.getName(),
100
101 "java.lang.Integer", "java.lang.Integer",
102 "com.liferay.portal.kernel.util.OrderByComparator"
103 });
104 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C = new FinderPath(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
105 TrashVersionModelImpl.FINDER_CACHE_ENABLED, TrashVersionImpl.class,
106 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C",
107 new String[] { Long.class.getName(), Long.class.getName() },
108 TrashVersionModelImpl.CLASSNAMEID_COLUMN_BITMASK |
109 TrashVersionModelImpl.CLASSPK_COLUMN_BITMASK);
110 public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
111 TrashVersionModelImpl.FINDER_CACHE_ENABLED, Long.class,
112 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C",
113 new String[] { Long.class.getName(), Long.class.getName() });
114 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
115 TrashVersionModelImpl.FINDER_CACHE_ENABLED, TrashVersionImpl.class,
116 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
117 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
118 TrashVersionModelImpl.FINDER_CACHE_ENABLED, TrashVersionImpl.class,
119 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
120 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
121 TrashVersionModelImpl.FINDER_CACHE_ENABLED, Long.class,
122 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
123
124
129 public void cacheResult(TrashVersion trashVersion) {
130 EntityCacheUtil.putResult(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
131 TrashVersionImpl.class, trashVersion.getPrimaryKey(), trashVersion);
132
133 trashVersion.resetOriginalValues();
134 }
135
136
141 public void cacheResult(List<TrashVersion> trashVersions) {
142 for (TrashVersion trashVersion : trashVersions) {
143 if (EntityCacheUtil.getResult(
144 TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
145 TrashVersionImpl.class, trashVersion.getPrimaryKey()) == null) {
146 cacheResult(trashVersion);
147 }
148 else {
149 trashVersion.resetOriginalValues();
150 }
151 }
152 }
153
154
161 @Override
162 public void clearCache() {
163 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
164 CacheRegistryUtil.clear(TrashVersionImpl.class.getName());
165 }
166
167 EntityCacheUtil.clearCache(TrashVersionImpl.class.getName());
168
169 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
170 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
171 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
172 }
173
174
181 @Override
182 public void clearCache(TrashVersion trashVersion) {
183 EntityCacheUtil.removeResult(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
184 TrashVersionImpl.class, trashVersion.getPrimaryKey());
185
186 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
187 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
188 }
189
190 @Override
191 public void clearCache(List<TrashVersion> trashVersions) {
192 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
193 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
194
195 for (TrashVersion trashVersion : trashVersions) {
196 EntityCacheUtil.removeResult(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
197 TrashVersionImpl.class, trashVersion.getPrimaryKey());
198 }
199 }
200
201
207 public TrashVersion create(long versionId) {
208 TrashVersion trashVersion = new TrashVersionImpl();
209
210 trashVersion.setNew(true);
211 trashVersion.setPrimaryKey(versionId);
212
213 return trashVersion;
214 }
215
216
224 public TrashVersion remove(long versionId)
225 throws NoSuchVersionException, SystemException {
226 return remove(Long.valueOf(versionId));
227 }
228
229
237 @Override
238 public TrashVersion remove(Serializable primaryKey)
239 throws NoSuchVersionException, SystemException {
240 Session session = null;
241
242 try {
243 session = openSession();
244
245 TrashVersion trashVersion = (TrashVersion)session.get(TrashVersionImpl.class,
246 primaryKey);
247
248 if (trashVersion == null) {
249 if (_log.isWarnEnabled()) {
250 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
251 }
252
253 throw new NoSuchVersionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
254 primaryKey);
255 }
256
257 return remove(trashVersion);
258 }
259 catch (NoSuchVersionException nsee) {
260 throw nsee;
261 }
262 catch (Exception e) {
263 throw processException(e);
264 }
265 finally {
266 closeSession(session);
267 }
268 }
269
270 @Override
271 protected TrashVersion removeImpl(TrashVersion trashVersion)
272 throws SystemException {
273 trashVersion = toUnwrappedModel(trashVersion);
274
275 Session session = null;
276
277 try {
278 session = openSession();
279
280 if (trashVersion.isCachedModel()) {
281 trashVersion = (TrashVersion)session.get(TrashVersionImpl.class,
282 trashVersion.getPrimaryKeyObj());
283 }
284
285 session.delete(trashVersion);
286 }
287 catch (Exception e) {
288 throw processException(e);
289 }
290 finally {
291 closeSession(session);
292 }
293
294 clearCache(trashVersion);
295
296 return trashVersion;
297 }
298
299 @Override
300 public TrashVersion updateImpl(
301 com.liferay.portlet.trash.model.TrashVersion trashVersion)
302 throws SystemException {
303 trashVersion = toUnwrappedModel(trashVersion);
304
305 boolean isNew = trashVersion.isNew();
306
307 TrashVersionModelImpl trashVersionModelImpl = (TrashVersionModelImpl)trashVersion;
308
309 Session session = null;
310
311 try {
312 session = openSession();
313
314 if (trashVersion.isNew()) {
315 session.save(trashVersion);
316
317 trashVersion.setNew(false);
318 }
319 else {
320 session.merge(trashVersion);
321 }
322 }
323 catch (Exception e) {
324 throw processException(e);
325 }
326 finally {
327 closeSession(session);
328 }
329
330 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
331
332 if (isNew || !TrashVersionModelImpl.COLUMN_BITMASK_ENABLED) {
333 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
334 }
335
336 else {
337 if ((trashVersionModelImpl.getColumnBitmask() &
338 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ENTRYID.getColumnBitmask()) != 0) {
339 Object[] args = new Object[] {
340 Long.valueOf(trashVersionModelImpl.getOriginalEntryId())
341 };
342
343 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ENTRYID, args);
344 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ENTRYID,
345 args);
346
347 args = new Object[] {
348 Long.valueOf(trashVersionModelImpl.getEntryId())
349 };
350
351 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ENTRYID, args);
352 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ENTRYID,
353 args);
354 }
355
356 if ((trashVersionModelImpl.getColumnBitmask() &
357 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C.getColumnBitmask()) != 0) {
358 Object[] args = new Object[] {
359 Long.valueOf(trashVersionModelImpl.getOriginalClassNameId()),
360 Long.valueOf(trashVersionModelImpl.getOriginalClassPK())
361 };
362
363 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
364 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
365 args);
366
367 args = new Object[] {
368 Long.valueOf(trashVersionModelImpl.getClassNameId()),
369 Long.valueOf(trashVersionModelImpl.getClassPK())
370 };
371
372 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
373 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
374 args);
375 }
376 }
377
378 EntityCacheUtil.putResult(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
379 TrashVersionImpl.class, trashVersion.getPrimaryKey(), trashVersion);
380
381 return trashVersion;
382 }
383
384 protected TrashVersion toUnwrappedModel(TrashVersion trashVersion) {
385 if (trashVersion instanceof TrashVersionImpl) {
386 return trashVersion;
387 }
388
389 TrashVersionImpl trashVersionImpl = new TrashVersionImpl();
390
391 trashVersionImpl.setNew(trashVersion.isNew());
392 trashVersionImpl.setPrimaryKey(trashVersion.getPrimaryKey());
393
394 trashVersionImpl.setVersionId(trashVersion.getVersionId());
395 trashVersionImpl.setEntryId(trashVersion.getEntryId());
396 trashVersionImpl.setClassNameId(trashVersion.getClassNameId());
397 trashVersionImpl.setClassPK(trashVersion.getClassPK());
398 trashVersionImpl.setStatus(trashVersion.getStatus());
399
400 return trashVersionImpl;
401 }
402
403
411 @Override
412 public TrashVersion findByPrimaryKey(Serializable primaryKey)
413 throws NoSuchModelException, SystemException {
414 return findByPrimaryKey(((Long)primaryKey).longValue());
415 }
416
417
425 public TrashVersion findByPrimaryKey(long versionId)
426 throws NoSuchVersionException, SystemException {
427 TrashVersion trashVersion = fetchByPrimaryKey(versionId);
428
429 if (trashVersion == null) {
430 if (_log.isWarnEnabled()) {
431 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + versionId);
432 }
433
434 throw new NoSuchVersionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
435 versionId);
436 }
437
438 return trashVersion;
439 }
440
441
448 @Override
449 public TrashVersion fetchByPrimaryKey(Serializable primaryKey)
450 throws SystemException {
451 return fetchByPrimaryKey(((Long)primaryKey).longValue());
452 }
453
454
461 public TrashVersion fetchByPrimaryKey(long versionId)
462 throws SystemException {
463 TrashVersion trashVersion = (TrashVersion)EntityCacheUtil.getResult(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
464 TrashVersionImpl.class, versionId);
465
466 if (trashVersion == _nullTrashVersion) {
467 return null;
468 }
469
470 if (trashVersion == null) {
471 Session session = null;
472
473 boolean hasException = false;
474
475 try {
476 session = openSession();
477
478 trashVersion = (TrashVersion)session.get(TrashVersionImpl.class,
479 Long.valueOf(versionId));
480 }
481 catch (Exception e) {
482 hasException = true;
483
484 throw processException(e);
485 }
486 finally {
487 if (trashVersion != null) {
488 cacheResult(trashVersion);
489 }
490 else if (!hasException) {
491 EntityCacheUtil.putResult(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
492 TrashVersionImpl.class, versionId, _nullTrashVersion);
493 }
494
495 closeSession(session);
496 }
497 }
498
499 return trashVersion;
500 }
501
502
509 public List<TrashVersion> findByEntryId(long entryId)
510 throws SystemException {
511 return findByEntryId(entryId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
512 }
513
514
527 public List<TrashVersion> findByEntryId(long entryId, int start, int end)
528 throws SystemException {
529 return findByEntryId(entryId, start, end, null);
530 }
531
532
546 public List<TrashVersion> findByEntryId(long entryId, int start, int end,
547 OrderByComparator orderByComparator) throws SystemException {
548 FinderPath finderPath = null;
549 Object[] finderArgs = null;
550
551 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
552 (orderByComparator == null)) {
553 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ENTRYID;
554 finderArgs = new Object[] { entryId };
555 }
556 else {
557 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_ENTRYID;
558 finderArgs = new Object[] { entryId, start, end, orderByComparator };
559 }
560
561 List<TrashVersion> list = (List<TrashVersion>)FinderCacheUtil.getResult(finderPath,
562 finderArgs, this);
563
564 if ((list != null) && !list.isEmpty()) {
565 for (TrashVersion trashVersion : list) {
566 if ((entryId != trashVersion.getEntryId())) {
567 list = null;
568
569 break;
570 }
571 }
572 }
573
574 if (list == null) {
575 StringBundler query = null;
576
577 if (orderByComparator != null) {
578 query = new StringBundler(3 +
579 (orderByComparator.getOrderByFields().length * 3));
580 }
581 else {
582 query = new StringBundler(2);
583 }
584
585 query.append(_SQL_SELECT_TRASHVERSION_WHERE);
586
587 query.append(_FINDER_COLUMN_ENTRYID_ENTRYID_2);
588
589 if (orderByComparator != null) {
590 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
591 orderByComparator);
592 }
593
594 String sql = query.toString();
595
596 Session session = null;
597
598 try {
599 session = openSession();
600
601 Query q = session.createQuery(sql);
602
603 QueryPos qPos = QueryPos.getInstance(q);
604
605 qPos.add(entryId);
606
607 list = (List<TrashVersion>)QueryUtil.list(q, getDialect(),
608 start, end);
609 }
610 catch (Exception e) {
611 throw processException(e);
612 }
613 finally {
614 if (list == null) {
615 FinderCacheUtil.removeResult(finderPath, finderArgs);
616 }
617 else {
618 cacheResult(list);
619
620 FinderCacheUtil.putResult(finderPath, finderArgs, list);
621 }
622
623 closeSession(session);
624 }
625 }
626
627 return list;
628 }
629
630
639 public TrashVersion findByEntryId_First(long entryId,
640 OrderByComparator orderByComparator)
641 throws NoSuchVersionException, SystemException {
642 TrashVersion trashVersion = fetchByEntryId_First(entryId,
643 orderByComparator);
644
645 if (trashVersion != null) {
646 return trashVersion;
647 }
648
649 StringBundler msg = new StringBundler(4);
650
651 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
652
653 msg.append("entryId=");
654 msg.append(entryId);
655
656 msg.append(StringPool.CLOSE_CURLY_BRACE);
657
658 throw new NoSuchVersionException(msg.toString());
659 }
660
661
669 public TrashVersion fetchByEntryId_First(long entryId,
670 OrderByComparator orderByComparator) throws SystemException {
671 List<TrashVersion> list = findByEntryId(entryId, 0, 1, orderByComparator);
672
673 if (!list.isEmpty()) {
674 return list.get(0);
675 }
676
677 return null;
678 }
679
680
689 public TrashVersion findByEntryId_Last(long entryId,
690 OrderByComparator orderByComparator)
691 throws NoSuchVersionException, SystemException {
692 TrashVersion trashVersion = fetchByEntryId_Last(entryId,
693 orderByComparator);
694
695 if (trashVersion != null) {
696 return trashVersion;
697 }
698
699 StringBundler msg = new StringBundler(4);
700
701 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
702
703 msg.append("entryId=");
704 msg.append(entryId);
705
706 msg.append(StringPool.CLOSE_CURLY_BRACE);
707
708 throw new NoSuchVersionException(msg.toString());
709 }
710
711
719 public TrashVersion fetchByEntryId_Last(long entryId,
720 OrderByComparator orderByComparator) throws SystemException {
721 int count = countByEntryId(entryId);
722
723 List<TrashVersion> list = findByEntryId(entryId, count - 1, count,
724 orderByComparator);
725
726 if (!list.isEmpty()) {
727 return list.get(0);
728 }
729
730 return null;
731 }
732
733
743 public TrashVersion[] findByEntryId_PrevAndNext(long versionId,
744 long entryId, OrderByComparator orderByComparator)
745 throws NoSuchVersionException, SystemException {
746 TrashVersion trashVersion = findByPrimaryKey(versionId);
747
748 Session session = null;
749
750 try {
751 session = openSession();
752
753 TrashVersion[] array = new TrashVersionImpl[3];
754
755 array[0] = getByEntryId_PrevAndNext(session, trashVersion, entryId,
756 orderByComparator, true);
757
758 array[1] = trashVersion;
759
760 array[2] = getByEntryId_PrevAndNext(session, trashVersion, entryId,
761 orderByComparator, false);
762
763 return array;
764 }
765 catch (Exception e) {
766 throw processException(e);
767 }
768 finally {
769 closeSession(session);
770 }
771 }
772
773 protected TrashVersion getByEntryId_PrevAndNext(Session session,
774 TrashVersion trashVersion, long entryId,
775 OrderByComparator orderByComparator, boolean previous) {
776 StringBundler query = null;
777
778 if (orderByComparator != null) {
779 query = new StringBundler(6 +
780 (orderByComparator.getOrderByFields().length * 6));
781 }
782 else {
783 query = new StringBundler(3);
784 }
785
786 query.append(_SQL_SELECT_TRASHVERSION_WHERE);
787
788 query.append(_FINDER_COLUMN_ENTRYID_ENTRYID_2);
789
790 if (orderByComparator != null) {
791 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
792
793 if (orderByConditionFields.length > 0) {
794 query.append(WHERE_AND);
795 }
796
797 for (int i = 0; i < orderByConditionFields.length; i++) {
798 query.append(_ORDER_BY_ENTITY_ALIAS);
799 query.append(orderByConditionFields[i]);
800
801 if ((i + 1) < orderByConditionFields.length) {
802 if (orderByComparator.isAscending() ^ previous) {
803 query.append(WHERE_GREATER_THAN_HAS_NEXT);
804 }
805 else {
806 query.append(WHERE_LESSER_THAN_HAS_NEXT);
807 }
808 }
809 else {
810 if (orderByComparator.isAscending() ^ previous) {
811 query.append(WHERE_GREATER_THAN);
812 }
813 else {
814 query.append(WHERE_LESSER_THAN);
815 }
816 }
817 }
818
819 query.append(ORDER_BY_CLAUSE);
820
821 String[] orderByFields = orderByComparator.getOrderByFields();
822
823 for (int i = 0; i < orderByFields.length; i++) {
824 query.append(_ORDER_BY_ENTITY_ALIAS);
825 query.append(orderByFields[i]);
826
827 if ((i + 1) < orderByFields.length) {
828 if (orderByComparator.isAscending() ^ previous) {
829 query.append(ORDER_BY_ASC_HAS_NEXT);
830 }
831 else {
832 query.append(ORDER_BY_DESC_HAS_NEXT);
833 }
834 }
835 else {
836 if (orderByComparator.isAscending() ^ previous) {
837 query.append(ORDER_BY_ASC);
838 }
839 else {
840 query.append(ORDER_BY_DESC);
841 }
842 }
843 }
844 }
845
846 String sql = query.toString();
847
848 Query q = session.createQuery(sql);
849
850 q.setFirstResult(0);
851 q.setMaxResults(2);
852
853 QueryPos qPos = QueryPos.getInstance(q);
854
855 qPos.add(entryId);
856
857 if (orderByComparator != null) {
858 Object[] values = orderByComparator.getOrderByConditionValues(trashVersion);
859
860 for (Object value : values) {
861 qPos.add(value);
862 }
863 }
864
865 List<TrashVersion> list = q.list();
866
867 if (list.size() == 2) {
868 return list.get(1);
869 }
870 else {
871 return null;
872 }
873 }
874
875
883 public List<TrashVersion> findByC_C(long classNameId, long classPK)
884 throws SystemException {
885 return findByC_C(classNameId, classPK, QueryUtil.ALL_POS,
886 QueryUtil.ALL_POS, null);
887 }
888
889
903 public List<TrashVersion> findByC_C(long classNameId, long classPK,
904 int start, int end) throws SystemException {
905 return findByC_C(classNameId, classPK, start, end, null);
906 }
907
908
923 public List<TrashVersion> findByC_C(long classNameId, long classPK,
924 int start, int end, OrderByComparator orderByComparator)
925 throws SystemException {
926 FinderPath finderPath = null;
927 Object[] finderArgs = null;
928
929 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
930 (orderByComparator == null)) {
931 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C;
932 finderArgs = new Object[] { classNameId, classPK };
933 }
934 else {
935 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C;
936 finderArgs = new Object[] {
937 classNameId, classPK,
938
939 start, end, orderByComparator
940 };
941 }
942
943 List<TrashVersion> list = (List<TrashVersion>)FinderCacheUtil.getResult(finderPath,
944 finderArgs, this);
945
946 if ((list != null) && !list.isEmpty()) {
947 for (TrashVersion trashVersion : list) {
948 if ((classNameId != trashVersion.getClassNameId()) ||
949 (classPK != trashVersion.getClassPK())) {
950 list = null;
951
952 break;
953 }
954 }
955 }
956
957 if (list == null) {
958 StringBundler query = null;
959
960 if (orderByComparator != null) {
961 query = new StringBundler(4 +
962 (orderByComparator.getOrderByFields().length * 3));
963 }
964 else {
965 query = new StringBundler(3);
966 }
967
968 query.append(_SQL_SELECT_TRASHVERSION_WHERE);
969
970 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
971
972 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
973
974 if (orderByComparator != null) {
975 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
976 orderByComparator);
977 }
978
979 String sql = query.toString();
980
981 Session session = null;
982
983 try {
984 session = openSession();
985
986 Query q = session.createQuery(sql);
987
988 QueryPos qPos = QueryPos.getInstance(q);
989
990 qPos.add(classNameId);
991
992 qPos.add(classPK);
993
994 list = (List<TrashVersion>)QueryUtil.list(q, getDialect(),
995 start, end);
996 }
997 catch (Exception e) {
998 throw processException(e);
999 }
1000 finally {
1001 if (list == null) {
1002 FinderCacheUtil.removeResult(finderPath, finderArgs);
1003 }
1004 else {
1005 cacheResult(list);
1006
1007 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1008 }
1009
1010 closeSession(session);
1011 }
1012 }
1013
1014 return list;
1015 }
1016
1017
1027 public TrashVersion findByC_C_First(long classNameId, long classPK,
1028 OrderByComparator orderByComparator)
1029 throws NoSuchVersionException, SystemException {
1030 TrashVersion trashVersion = fetchByC_C_First(classNameId, classPK,
1031 orderByComparator);
1032
1033 if (trashVersion != null) {
1034 return trashVersion;
1035 }
1036
1037 StringBundler msg = new StringBundler(6);
1038
1039 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1040
1041 msg.append("classNameId=");
1042 msg.append(classNameId);
1043
1044 msg.append(", classPK=");
1045 msg.append(classPK);
1046
1047 msg.append(StringPool.CLOSE_CURLY_BRACE);
1048
1049 throw new NoSuchVersionException(msg.toString());
1050 }
1051
1052
1061 public TrashVersion fetchByC_C_First(long classNameId, long classPK,
1062 OrderByComparator orderByComparator) throws SystemException {
1063 List<TrashVersion> list = findByC_C(classNameId, classPK, 0, 1,
1064 orderByComparator);
1065
1066 if (!list.isEmpty()) {
1067 return list.get(0);
1068 }
1069
1070 return null;
1071 }
1072
1073
1083 public TrashVersion findByC_C_Last(long classNameId, long classPK,
1084 OrderByComparator orderByComparator)
1085 throws NoSuchVersionException, SystemException {
1086 TrashVersion trashVersion = fetchByC_C_Last(classNameId, classPK,
1087 orderByComparator);
1088
1089 if (trashVersion != null) {
1090 return trashVersion;
1091 }
1092
1093 StringBundler msg = new StringBundler(6);
1094
1095 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1096
1097 msg.append("classNameId=");
1098 msg.append(classNameId);
1099
1100 msg.append(", classPK=");
1101 msg.append(classPK);
1102
1103 msg.append(StringPool.CLOSE_CURLY_BRACE);
1104
1105 throw new NoSuchVersionException(msg.toString());
1106 }
1107
1108
1117 public TrashVersion fetchByC_C_Last(long classNameId, long classPK,
1118 OrderByComparator orderByComparator) throws SystemException {
1119 int count = countByC_C(classNameId, classPK);
1120
1121 List<TrashVersion> list = findByC_C(classNameId, classPK, count - 1,
1122 count, orderByComparator);
1123
1124 if (!list.isEmpty()) {
1125 return list.get(0);
1126 }
1127
1128 return null;
1129 }
1130
1131
1142 public TrashVersion[] findByC_C_PrevAndNext(long versionId,
1143 long classNameId, long classPK, OrderByComparator orderByComparator)
1144 throws NoSuchVersionException, SystemException {
1145 TrashVersion trashVersion = findByPrimaryKey(versionId);
1146
1147 Session session = null;
1148
1149 try {
1150 session = openSession();
1151
1152 TrashVersion[] array = new TrashVersionImpl[3];
1153
1154 array[0] = getByC_C_PrevAndNext(session, trashVersion, classNameId,
1155 classPK, orderByComparator, true);
1156
1157 array[1] = trashVersion;
1158
1159 array[2] = getByC_C_PrevAndNext(session, trashVersion, classNameId,
1160 classPK, orderByComparator, false);
1161
1162 return array;
1163 }
1164 catch (Exception e) {
1165 throw processException(e);
1166 }
1167 finally {
1168 closeSession(session);
1169 }
1170 }
1171
1172 protected TrashVersion getByC_C_PrevAndNext(Session session,
1173 TrashVersion trashVersion, long classNameId, long classPK,
1174 OrderByComparator orderByComparator, boolean previous) {
1175 StringBundler query = null;
1176
1177 if (orderByComparator != null) {
1178 query = new StringBundler(6 +
1179 (orderByComparator.getOrderByFields().length * 6));
1180 }
1181 else {
1182 query = new StringBundler(3);
1183 }
1184
1185 query.append(_SQL_SELECT_TRASHVERSION_WHERE);
1186
1187 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
1188
1189 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
1190
1191 if (orderByComparator != null) {
1192 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1193
1194 if (orderByConditionFields.length > 0) {
1195 query.append(WHERE_AND);
1196 }
1197
1198 for (int i = 0; i < orderByConditionFields.length; i++) {
1199 query.append(_ORDER_BY_ENTITY_ALIAS);
1200 query.append(orderByConditionFields[i]);
1201
1202 if ((i + 1) < orderByConditionFields.length) {
1203 if (orderByComparator.isAscending() ^ previous) {
1204 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1205 }
1206 else {
1207 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1208 }
1209 }
1210 else {
1211 if (orderByComparator.isAscending() ^ previous) {
1212 query.append(WHERE_GREATER_THAN);
1213 }
1214 else {
1215 query.append(WHERE_LESSER_THAN);
1216 }
1217 }
1218 }
1219
1220 query.append(ORDER_BY_CLAUSE);
1221
1222 String[] orderByFields = orderByComparator.getOrderByFields();
1223
1224 for (int i = 0; i < orderByFields.length; i++) {
1225 query.append(_ORDER_BY_ENTITY_ALIAS);
1226 query.append(orderByFields[i]);
1227
1228 if ((i + 1) < orderByFields.length) {
1229 if (orderByComparator.isAscending() ^ previous) {
1230 query.append(ORDER_BY_ASC_HAS_NEXT);
1231 }
1232 else {
1233 query.append(ORDER_BY_DESC_HAS_NEXT);
1234 }
1235 }
1236 else {
1237 if (orderByComparator.isAscending() ^ previous) {
1238 query.append(ORDER_BY_ASC);
1239 }
1240 else {
1241 query.append(ORDER_BY_DESC);
1242 }
1243 }
1244 }
1245 }
1246
1247 String sql = query.toString();
1248
1249 Query q = session.createQuery(sql);
1250
1251 q.setFirstResult(0);
1252 q.setMaxResults(2);
1253
1254 QueryPos qPos = QueryPos.getInstance(q);
1255
1256 qPos.add(classNameId);
1257
1258 qPos.add(classPK);
1259
1260 if (orderByComparator != null) {
1261 Object[] values = orderByComparator.getOrderByConditionValues(trashVersion);
1262
1263 for (Object value : values) {
1264 qPos.add(value);
1265 }
1266 }
1267
1268 List<TrashVersion> list = q.list();
1269
1270 if (list.size() == 2) {
1271 return list.get(1);
1272 }
1273 else {
1274 return null;
1275 }
1276 }
1277
1278
1284 public List<TrashVersion> findAll() throws SystemException {
1285 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1286 }
1287
1288
1300 public List<TrashVersion> findAll(int start, int end)
1301 throws SystemException {
1302 return findAll(start, end, null);
1303 }
1304
1305
1318 public List<TrashVersion> findAll(int start, int end,
1319 OrderByComparator orderByComparator) throws SystemException {
1320 FinderPath finderPath = null;
1321 Object[] finderArgs = new Object[] { start, end, orderByComparator };
1322
1323 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1324 (orderByComparator == null)) {
1325 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1326 finderArgs = FINDER_ARGS_EMPTY;
1327 }
1328 else {
1329 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1330 finderArgs = new Object[] { start, end, orderByComparator };
1331 }
1332
1333 List<TrashVersion> list = (List<TrashVersion>)FinderCacheUtil.getResult(finderPath,
1334 finderArgs, this);
1335
1336 if (list == null) {
1337 StringBundler query = null;
1338 String sql = null;
1339
1340 if (orderByComparator != null) {
1341 query = new StringBundler(2 +
1342 (orderByComparator.getOrderByFields().length * 3));
1343
1344 query.append(_SQL_SELECT_TRASHVERSION);
1345
1346 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1347 orderByComparator);
1348
1349 sql = query.toString();
1350 }
1351 else {
1352 sql = _SQL_SELECT_TRASHVERSION;
1353 }
1354
1355 Session session = null;
1356
1357 try {
1358 session = openSession();
1359
1360 Query q = session.createQuery(sql);
1361
1362 if (orderByComparator == null) {
1363 list = (List<TrashVersion>)QueryUtil.list(q, getDialect(),
1364 start, end, false);
1365
1366 Collections.sort(list);
1367 }
1368 else {
1369 list = (List<TrashVersion>)QueryUtil.list(q, getDialect(),
1370 start, end);
1371 }
1372 }
1373 catch (Exception e) {
1374 throw processException(e);
1375 }
1376 finally {
1377 if (list == null) {
1378 FinderCacheUtil.removeResult(finderPath, finderArgs);
1379 }
1380 else {
1381 cacheResult(list);
1382
1383 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1384 }
1385
1386 closeSession(session);
1387 }
1388 }
1389
1390 return list;
1391 }
1392
1393
1399 public void removeByEntryId(long entryId) throws SystemException {
1400 for (TrashVersion trashVersion : findByEntryId(entryId)) {
1401 remove(trashVersion);
1402 }
1403 }
1404
1405
1412 public void removeByC_C(long classNameId, long classPK)
1413 throws SystemException {
1414 for (TrashVersion trashVersion : findByC_C(classNameId, classPK)) {
1415 remove(trashVersion);
1416 }
1417 }
1418
1419
1424 public void removeAll() throws SystemException {
1425 for (TrashVersion trashVersion : findAll()) {
1426 remove(trashVersion);
1427 }
1428 }
1429
1430
1437 public int countByEntryId(long entryId) throws SystemException {
1438 Object[] finderArgs = new Object[] { entryId };
1439
1440 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_ENTRYID,
1441 finderArgs, this);
1442
1443 if (count == null) {
1444 StringBundler query = new StringBundler(2);
1445
1446 query.append(_SQL_COUNT_TRASHVERSION_WHERE);
1447
1448 query.append(_FINDER_COLUMN_ENTRYID_ENTRYID_2);
1449
1450 String sql = query.toString();
1451
1452 Session session = null;
1453
1454 try {
1455 session = openSession();
1456
1457 Query q = session.createQuery(sql);
1458
1459 QueryPos qPos = QueryPos.getInstance(q);
1460
1461 qPos.add(entryId);
1462
1463 count = (Long)q.uniqueResult();
1464 }
1465 catch (Exception e) {
1466 throw processException(e);
1467 }
1468 finally {
1469 if (count == null) {
1470 count = Long.valueOf(0);
1471 }
1472
1473 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ENTRYID,
1474 finderArgs, count);
1475
1476 closeSession(session);
1477 }
1478 }
1479
1480 return count.intValue();
1481 }
1482
1483
1491 public int countByC_C(long classNameId, long classPK)
1492 throws SystemException {
1493 Object[] finderArgs = new Object[] { classNameId, classPK };
1494
1495 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C,
1496 finderArgs, this);
1497
1498 if (count == null) {
1499 StringBundler query = new StringBundler(3);
1500
1501 query.append(_SQL_COUNT_TRASHVERSION_WHERE);
1502
1503 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
1504
1505 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
1506
1507 String sql = query.toString();
1508
1509 Session session = null;
1510
1511 try {
1512 session = openSession();
1513
1514 Query q = session.createQuery(sql);
1515
1516 QueryPos qPos = QueryPos.getInstance(q);
1517
1518 qPos.add(classNameId);
1519
1520 qPos.add(classPK);
1521
1522 count = (Long)q.uniqueResult();
1523 }
1524 catch (Exception e) {
1525 throw processException(e);
1526 }
1527 finally {
1528 if (count == null) {
1529 count = Long.valueOf(0);
1530 }
1531
1532 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, finderArgs,
1533 count);
1534
1535 closeSession(session);
1536 }
1537 }
1538
1539 return count.intValue();
1540 }
1541
1542
1548 public int countAll() throws SystemException {
1549 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1550 FINDER_ARGS_EMPTY, this);
1551
1552 if (count == null) {
1553 Session session = null;
1554
1555 try {
1556 session = openSession();
1557
1558 Query q = session.createQuery(_SQL_COUNT_TRASHVERSION);
1559
1560 count = (Long)q.uniqueResult();
1561 }
1562 catch (Exception e) {
1563 throw processException(e);
1564 }
1565 finally {
1566 if (count == null) {
1567 count = Long.valueOf(0);
1568 }
1569
1570 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1571 FINDER_ARGS_EMPTY, count);
1572
1573 closeSession(session);
1574 }
1575 }
1576
1577 return count.intValue();
1578 }
1579
1580
1583 public void afterPropertiesSet() {
1584 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1585 com.liferay.portal.util.PropsUtil.get(
1586 "value.object.listener.com.liferay.portlet.trash.model.TrashVersion")));
1587
1588 if (listenerClassNames.length > 0) {
1589 try {
1590 List<ModelListener<TrashVersion>> listenersList = new ArrayList<ModelListener<TrashVersion>>();
1591
1592 for (String listenerClassName : listenerClassNames) {
1593 listenersList.add((ModelListener<TrashVersion>)InstanceFactory.newInstance(
1594 listenerClassName));
1595 }
1596
1597 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1598 }
1599 catch (Exception e) {
1600 _log.error(e);
1601 }
1602 }
1603 }
1604
1605 public void destroy() {
1606 EntityCacheUtil.removeCache(TrashVersionImpl.class.getName());
1607 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1608 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1609 }
1610
1611 @BeanReference(type = TrashEntryPersistence.class)
1612 protected TrashEntryPersistence trashEntryPersistence;
1613 @BeanReference(type = TrashVersionPersistence.class)
1614 protected TrashVersionPersistence trashVersionPersistence;
1615 @BeanReference(type = UserPersistence.class)
1616 protected UserPersistence userPersistence;
1617 private static final String _SQL_SELECT_TRASHVERSION = "SELECT trashVersion FROM TrashVersion trashVersion";
1618 private static final String _SQL_SELECT_TRASHVERSION_WHERE = "SELECT trashVersion FROM TrashVersion trashVersion WHERE ";
1619 private static final String _SQL_COUNT_TRASHVERSION = "SELECT COUNT(trashVersion) FROM TrashVersion trashVersion";
1620 private static final String _SQL_COUNT_TRASHVERSION_WHERE = "SELECT COUNT(trashVersion) FROM TrashVersion trashVersion WHERE ";
1621 private static final String _FINDER_COLUMN_ENTRYID_ENTRYID_2 = "trashVersion.entryId = ?";
1622 private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "trashVersion.classNameId = ? AND ";
1623 private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "trashVersion.classPK = ?";
1624 private static final String _ORDER_BY_ENTITY_ALIAS = "trashVersion.";
1625 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No TrashVersion exists with the primary key ";
1626 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No TrashVersion exists with the key {";
1627 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1628 private static Log _log = LogFactoryUtil.getLog(TrashVersionPersistenceImpl.class);
1629 private static TrashVersion _nullTrashVersion = new TrashVersionImpl() {
1630 @Override
1631 public Object clone() {
1632 return this;
1633 }
1634
1635 @Override
1636 public CacheModel<TrashVersion> toCacheModel() {
1637 return _nullTrashVersionCacheModel;
1638 }
1639 };
1640
1641 private static CacheModel<TrashVersion> _nullTrashVersionCacheModel = new CacheModel<TrashVersion>() {
1642 public TrashVersion toEntityModel() {
1643 return _nullTrashVersion;
1644 }
1645 };
1646 }