001
014
015 package com.liferay.portlet.documentlibrary.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.SetUtil;
031 import com.liferay.portal.kernel.util.StringBundler;
032 import com.liferay.portal.kernel.util.StringPool;
033 import com.liferay.portal.kernel.util.Validator;
034 import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
035 import com.liferay.portal.model.CacheModel;
036 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
037
038 import com.liferay.portlet.documentlibrary.NoSuchFileVersionException;
039 import com.liferay.portlet.documentlibrary.model.DLFileVersion;
040 import com.liferay.portlet.documentlibrary.model.impl.DLFileVersionImpl;
041 import com.liferay.portlet.documentlibrary.model.impl.DLFileVersionModelImpl;
042 import com.liferay.portlet.documentlibrary.service.persistence.DLFileVersionPersistence;
043
044 import java.io.Serializable;
045
046 import java.util.Collections;
047 import java.util.HashMap;
048 import java.util.HashSet;
049 import java.util.Iterator;
050 import java.util.List;
051 import java.util.Map;
052 import java.util.Set;
053
054
066 @ProviderType
067 public class DLFileVersionPersistenceImpl extends BasePersistenceImpl<DLFileVersion>
068 implements DLFileVersionPersistence {
069
074 public static final String FINDER_CLASS_NAME_ENTITY = DLFileVersionImpl.class.getName();
075 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
076 ".List1";
077 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
078 ".List2";
079 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
080 DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
081 DLFileVersionImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
082 "findAll", new String[0]);
083 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
084 DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
085 DLFileVersionImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
086 "findAll", new String[0]);
087 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
088 DLFileVersionModelImpl.FINDER_CACHE_ENABLED, Long.class,
089 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
090 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
091 DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
092 DLFileVersionImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
093 "findByUuid",
094 new String[] {
095 String.class.getName(),
096
097 Integer.class.getName(), Integer.class.getName(),
098 OrderByComparator.class.getName()
099 });
100 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
101 DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
102 DLFileVersionImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
103 "findByUuid", new String[] { String.class.getName() },
104 DLFileVersionModelImpl.UUID_COLUMN_BITMASK |
105 DLFileVersionModelImpl.FILEENTRYID_COLUMN_BITMASK |
106 DLFileVersionModelImpl.CREATEDATE_COLUMN_BITMASK);
107 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
108 DLFileVersionModelImpl.FINDER_CACHE_ENABLED, Long.class,
109 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
110 new String[] { String.class.getName() });
111
112
118 @Override
119 public List<DLFileVersion> findByUuid(String uuid) {
120 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
121 }
122
123
135 @Override
136 public List<DLFileVersion> findByUuid(String uuid, int start, int end) {
137 return findByUuid(uuid, start, end, null);
138 }
139
140
153 @Override
154 public List<DLFileVersion> findByUuid(String uuid, int start, int end,
155 OrderByComparator<DLFileVersion> orderByComparator) {
156 boolean pagination = true;
157 FinderPath finderPath = null;
158 Object[] finderArgs = null;
159
160 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
161 (orderByComparator == null)) {
162 pagination = false;
163 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
164 finderArgs = new Object[] { uuid };
165 }
166 else {
167 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
168 finderArgs = new Object[] { uuid, start, end, orderByComparator };
169 }
170
171 List<DLFileVersion> list = (List<DLFileVersion>)FinderCacheUtil.getResult(finderPath,
172 finderArgs, this);
173
174 if ((list != null) && !list.isEmpty()) {
175 for (DLFileVersion dlFileVersion : list) {
176 if (!Validator.equals(uuid, dlFileVersion.getUuid())) {
177 list = null;
178
179 break;
180 }
181 }
182 }
183
184 if (list == null) {
185 StringBundler query = null;
186
187 if (orderByComparator != null) {
188 query = new StringBundler(3 +
189 (orderByComparator.getOrderByFields().length * 3));
190 }
191 else {
192 query = new StringBundler(3);
193 }
194
195 query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
196
197 boolean bindUuid = false;
198
199 if (uuid == null) {
200 query.append(_FINDER_COLUMN_UUID_UUID_1);
201 }
202 else if (uuid.equals(StringPool.BLANK)) {
203 query.append(_FINDER_COLUMN_UUID_UUID_3);
204 }
205 else {
206 bindUuid = true;
207
208 query.append(_FINDER_COLUMN_UUID_UUID_2);
209 }
210
211 if (orderByComparator != null) {
212 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
213 orderByComparator);
214 }
215 else
216 if (pagination) {
217 query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
218 }
219
220 String sql = query.toString();
221
222 Session session = null;
223
224 try {
225 session = openSession();
226
227 Query q = session.createQuery(sql);
228
229 QueryPos qPos = QueryPos.getInstance(q);
230
231 if (bindUuid) {
232 qPos.add(uuid);
233 }
234
235 if (!pagination) {
236 list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
237 start, end, false);
238
239 Collections.sort(list);
240
241 list = Collections.unmodifiableList(list);
242 }
243 else {
244 list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
245 start, end);
246 }
247
248 cacheResult(list);
249
250 FinderCacheUtil.putResult(finderPath, finderArgs, list);
251 }
252 catch (Exception e) {
253 FinderCacheUtil.removeResult(finderPath, finderArgs);
254
255 throw processException(e);
256 }
257 finally {
258 closeSession(session);
259 }
260 }
261
262 return list;
263 }
264
265
273 @Override
274 public DLFileVersion findByUuid_First(String uuid,
275 OrderByComparator<DLFileVersion> orderByComparator)
276 throws NoSuchFileVersionException {
277 DLFileVersion dlFileVersion = fetchByUuid_First(uuid, orderByComparator);
278
279 if (dlFileVersion != null) {
280 return dlFileVersion;
281 }
282
283 StringBundler msg = new StringBundler(4);
284
285 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
286
287 msg.append("uuid=");
288 msg.append(uuid);
289
290 msg.append(StringPool.CLOSE_CURLY_BRACE);
291
292 throw new NoSuchFileVersionException(msg.toString());
293 }
294
295
302 @Override
303 public DLFileVersion fetchByUuid_First(String uuid,
304 OrderByComparator<DLFileVersion> orderByComparator) {
305 List<DLFileVersion> list = findByUuid(uuid, 0, 1, orderByComparator);
306
307 if (!list.isEmpty()) {
308 return list.get(0);
309 }
310
311 return null;
312 }
313
314
322 @Override
323 public DLFileVersion findByUuid_Last(String uuid,
324 OrderByComparator<DLFileVersion> orderByComparator)
325 throws NoSuchFileVersionException {
326 DLFileVersion dlFileVersion = fetchByUuid_Last(uuid, orderByComparator);
327
328 if (dlFileVersion != null) {
329 return dlFileVersion;
330 }
331
332 StringBundler msg = new StringBundler(4);
333
334 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
335
336 msg.append("uuid=");
337 msg.append(uuid);
338
339 msg.append(StringPool.CLOSE_CURLY_BRACE);
340
341 throw new NoSuchFileVersionException(msg.toString());
342 }
343
344
351 @Override
352 public DLFileVersion fetchByUuid_Last(String uuid,
353 OrderByComparator<DLFileVersion> orderByComparator) {
354 int count = countByUuid(uuid);
355
356 if (count == 0) {
357 return null;
358 }
359
360 List<DLFileVersion> list = findByUuid(uuid, count - 1, count,
361 orderByComparator);
362
363 if (!list.isEmpty()) {
364 return list.get(0);
365 }
366
367 return null;
368 }
369
370
379 @Override
380 public DLFileVersion[] findByUuid_PrevAndNext(long fileVersionId,
381 String uuid, OrderByComparator<DLFileVersion> orderByComparator)
382 throws NoSuchFileVersionException {
383 DLFileVersion dlFileVersion = findByPrimaryKey(fileVersionId);
384
385 Session session = null;
386
387 try {
388 session = openSession();
389
390 DLFileVersion[] array = new DLFileVersionImpl[3];
391
392 array[0] = getByUuid_PrevAndNext(session, dlFileVersion, uuid,
393 orderByComparator, true);
394
395 array[1] = dlFileVersion;
396
397 array[2] = getByUuid_PrevAndNext(session, dlFileVersion, uuid,
398 orderByComparator, false);
399
400 return array;
401 }
402 catch (Exception e) {
403 throw processException(e);
404 }
405 finally {
406 closeSession(session);
407 }
408 }
409
410 protected DLFileVersion getByUuid_PrevAndNext(Session session,
411 DLFileVersion dlFileVersion, String uuid,
412 OrderByComparator<DLFileVersion> orderByComparator, boolean previous) {
413 StringBundler query = null;
414
415 if (orderByComparator != null) {
416 query = new StringBundler(6 +
417 (orderByComparator.getOrderByFields().length * 6));
418 }
419 else {
420 query = new StringBundler(3);
421 }
422
423 query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
424
425 boolean bindUuid = false;
426
427 if (uuid == null) {
428 query.append(_FINDER_COLUMN_UUID_UUID_1);
429 }
430 else if (uuid.equals(StringPool.BLANK)) {
431 query.append(_FINDER_COLUMN_UUID_UUID_3);
432 }
433 else {
434 bindUuid = true;
435
436 query.append(_FINDER_COLUMN_UUID_UUID_2);
437 }
438
439 if (orderByComparator != null) {
440 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
441
442 if (orderByConditionFields.length > 0) {
443 query.append(WHERE_AND);
444 }
445
446 for (int i = 0; i < orderByConditionFields.length; i++) {
447 query.append(_ORDER_BY_ENTITY_ALIAS);
448 query.append(orderByConditionFields[i]);
449
450 if ((i + 1) < orderByConditionFields.length) {
451 if (orderByComparator.isAscending() ^ previous) {
452 query.append(WHERE_GREATER_THAN_HAS_NEXT);
453 }
454 else {
455 query.append(WHERE_LESSER_THAN_HAS_NEXT);
456 }
457 }
458 else {
459 if (orderByComparator.isAscending() ^ previous) {
460 query.append(WHERE_GREATER_THAN);
461 }
462 else {
463 query.append(WHERE_LESSER_THAN);
464 }
465 }
466 }
467
468 query.append(ORDER_BY_CLAUSE);
469
470 String[] orderByFields = orderByComparator.getOrderByFields();
471
472 for (int i = 0; i < orderByFields.length; i++) {
473 query.append(_ORDER_BY_ENTITY_ALIAS);
474 query.append(orderByFields[i]);
475
476 if ((i + 1) < orderByFields.length) {
477 if (orderByComparator.isAscending() ^ previous) {
478 query.append(ORDER_BY_ASC_HAS_NEXT);
479 }
480 else {
481 query.append(ORDER_BY_DESC_HAS_NEXT);
482 }
483 }
484 else {
485 if (orderByComparator.isAscending() ^ previous) {
486 query.append(ORDER_BY_ASC);
487 }
488 else {
489 query.append(ORDER_BY_DESC);
490 }
491 }
492 }
493 }
494 else {
495 query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
496 }
497
498 String sql = query.toString();
499
500 Query q = session.createQuery(sql);
501
502 q.setFirstResult(0);
503 q.setMaxResults(2);
504
505 QueryPos qPos = QueryPos.getInstance(q);
506
507 if (bindUuid) {
508 qPos.add(uuid);
509 }
510
511 if (orderByComparator != null) {
512 Object[] values = orderByComparator.getOrderByConditionValues(dlFileVersion);
513
514 for (Object value : values) {
515 qPos.add(value);
516 }
517 }
518
519 List<DLFileVersion> list = q.list();
520
521 if (list.size() == 2) {
522 return list.get(1);
523 }
524 else {
525 return null;
526 }
527 }
528
529
534 @Override
535 public void removeByUuid(String uuid) {
536 for (DLFileVersion dlFileVersion : findByUuid(uuid, QueryUtil.ALL_POS,
537 QueryUtil.ALL_POS, null)) {
538 remove(dlFileVersion);
539 }
540 }
541
542
548 @Override
549 public int countByUuid(String uuid) {
550 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
551
552 Object[] finderArgs = new Object[] { uuid };
553
554 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
555 this);
556
557 if (count == null) {
558 StringBundler query = new StringBundler(2);
559
560 query.append(_SQL_COUNT_DLFILEVERSION_WHERE);
561
562 boolean bindUuid = false;
563
564 if (uuid == null) {
565 query.append(_FINDER_COLUMN_UUID_UUID_1);
566 }
567 else if (uuid.equals(StringPool.BLANK)) {
568 query.append(_FINDER_COLUMN_UUID_UUID_3);
569 }
570 else {
571 bindUuid = true;
572
573 query.append(_FINDER_COLUMN_UUID_UUID_2);
574 }
575
576 String sql = query.toString();
577
578 Session session = null;
579
580 try {
581 session = openSession();
582
583 Query q = session.createQuery(sql);
584
585 QueryPos qPos = QueryPos.getInstance(q);
586
587 if (bindUuid) {
588 qPos.add(uuid);
589 }
590
591 count = (Long)q.uniqueResult();
592
593 FinderCacheUtil.putResult(finderPath, finderArgs, count);
594 }
595 catch (Exception e) {
596 FinderCacheUtil.removeResult(finderPath, finderArgs);
597
598 throw processException(e);
599 }
600 finally {
601 closeSession(session);
602 }
603 }
604
605 return count.intValue();
606 }
607
608 private static final String _FINDER_COLUMN_UUID_UUID_1 = "dlFileVersion.uuid IS NULL";
609 private static final String _FINDER_COLUMN_UUID_UUID_2 = "dlFileVersion.uuid = ?";
610 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(dlFileVersion.uuid IS NULL OR dlFileVersion.uuid = '')";
611 public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
612 DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
613 DLFileVersionImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
614 new String[] { String.class.getName(), Long.class.getName() },
615 DLFileVersionModelImpl.UUID_COLUMN_BITMASK |
616 DLFileVersionModelImpl.GROUPID_COLUMN_BITMASK);
617 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
618 DLFileVersionModelImpl.FINDER_CACHE_ENABLED, Long.class,
619 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
620 new String[] { String.class.getName(), Long.class.getName() });
621
622
630 @Override
631 public DLFileVersion findByUUID_G(String uuid, long groupId)
632 throws NoSuchFileVersionException {
633 DLFileVersion dlFileVersion = fetchByUUID_G(uuid, groupId);
634
635 if (dlFileVersion == null) {
636 StringBundler msg = new StringBundler(6);
637
638 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
639
640 msg.append("uuid=");
641 msg.append(uuid);
642
643 msg.append(", groupId=");
644 msg.append(groupId);
645
646 msg.append(StringPool.CLOSE_CURLY_BRACE);
647
648 if (_log.isWarnEnabled()) {
649 _log.warn(msg.toString());
650 }
651
652 throw new NoSuchFileVersionException(msg.toString());
653 }
654
655 return dlFileVersion;
656 }
657
658
665 @Override
666 public DLFileVersion fetchByUUID_G(String uuid, long groupId) {
667 return fetchByUUID_G(uuid, groupId, true);
668 }
669
670
678 @Override
679 public DLFileVersion fetchByUUID_G(String uuid, long groupId,
680 boolean retrieveFromCache) {
681 Object[] finderArgs = new Object[] { uuid, groupId };
682
683 Object result = null;
684
685 if (retrieveFromCache) {
686 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
687 finderArgs, this);
688 }
689
690 if (result instanceof DLFileVersion) {
691 DLFileVersion dlFileVersion = (DLFileVersion)result;
692
693 if (!Validator.equals(uuid, dlFileVersion.getUuid()) ||
694 (groupId != dlFileVersion.getGroupId())) {
695 result = null;
696 }
697 }
698
699 if (result == null) {
700 StringBundler query = new StringBundler(4);
701
702 query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
703
704 boolean bindUuid = false;
705
706 if (uuid == null) {
707 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
708 }
709 else if (uuid.equals(StringPool.BLANK)) {
710 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
711 }
712 else {
713 bindUuid = true;
714
715 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
716 }
717
718 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
719
720 String sql = query.toString();
721
722 Session session = null;
723
724 try {
725 session = openSession();
726
727 Query q = session.createQuery(sql);
728
729 QueryPos qPos = QueryPos.getInstance(q);
730
731 if (bindUuid) {
732 qPos.add(uuid);
733 }
734
735 qPos.add(groupId);
736
737 List<DLFileVersion> list = q.list();
738
739 if (list.isEmpty()) {
740 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
741 finderArgs, list);
742 }
743 else {
744 DLFileVersion dlFileVersion = list.get(0);
745
746 result = dlFileVersion;
747
748 cacheResult(dlFileVersion);
749
750 if ((dlFileVersion.getUuid() == null) ||
751 !dlFileVersion.getUuid().equals(uuid) ||
752 (dlFileVersion.getGroupId() != groupId)) {
753 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
754 finderArgs, dlFileVersion);
755 }
756 }
757 }
758 catch (Exception e) {
759 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
760 finderArgs);
761
762 throw processException(e);
763 }
764 finally {
765 closeSession(session);
766 }
767 }
768
769 if (result instanceof List<?>) {
770 return null;
771 }
772 else {
773 return (DLFileVersion)result;
774 }
775 }
776
777
784 @Override
785 public DLFileVersion removeByUUID_G(String uuid, long groupId)
786 throws NoSuchFileVersionException {
787 DLFileVersion dlFileVersion = findByUUID_G(uuid, groupId);
788
789 return remove(dlFileVersion);
790 }
791
792
799 @Override
800 public int countByUUID_G(String uuid, long groupId) {
801 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G;
802
803 Object[] finderArgs = new Object[] { uuid, groupId };
804
805 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
806 this);
807
808 if (count == null) {
809 StringBundler query = new StringBundler(3);
810
811 query.append(_SQL_COUNT_DLFILEVERSION_WHERE);
812
813 boolean bindUuid = false;
814
815 if (uuid == null) {
816 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
817 }
818 else if (uuid.equals(StringPool.BLANK)) {
819 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
820 }
821 else {
822 bindUuid = true;
823
824 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
825 }
826
827 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
828
829 String sql = query.toString();
830
831 Session session = null;
832
833 try {
834 session = openSession();
835
836 Query q = session.createQuery(sql);
837
838 QueryPos qPos = QueryPos.getInstance(q);
839
840 if (bindUuid) {
841 qPos.add(uuid);
842 }
843
844 qPos.add(groupId);
845
846 count = (Long)q.uniqueResult();
847
848 FinderCacheUtil.putResult(finderPath, finderArgs, count);
849 }
850 catch (Exception e) {
851 FinderCacheUtil.removeResult(finderPath, finderArgs);
852
853 throw processException(e);
854 }
855 finally {
856 closeSession(session);
857 }
858 }
859
860 return count.intValue();
861 }
862
863 private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "dlFileVersion.uuid IS NULL AND ";
864 private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "dlFileVersion.uuid = ? AND ";
865 private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(dlFileVersion.uuid IS NULL OR dlFileVersion.uuid = '') AND ";
866 private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "dlFileVersion.groupId = ?";
867 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
868 DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
869 DLFileVersionImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
870 "findByUuid_C",
871 new String[] {
872 String.class.getName(), Long.class.getName(),
873
874 Integer.class.getName(), Integer.class.getName(),
875 OrderByComparator.class.getName()
876 });
877 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
878 new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
879 DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
880 DLFileVersionImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
881 "findByUuid_C",
882 new String[] { String.class.getName(), Long.class.getName() },
883 DLFileVersionModelImpl.UUID_COLUMN_BITMASK |
884 DLFileVersionModelImpl.COMPANYID_COLUMN_BITMASK |
885 DLFileVersionModelImpl.FILEENTRYID_COLUMN_BITMASK |
886 DLFileVersionModelImpl.CREATEDATE_COLUMN_BITMASK);
887 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
888 DLFileVersionModelImpl.FINDER_CACHE_ENABLED, Long.class,
889 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
890 new String[] { String.class.getName(), Long.class.getName() });
891
892
899 @Override
900 public List<DLFileVersion> findByUuid_C(String uuid, long companyId) {
901 return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
902 QueryUtil.ALL_POS, null);
903 }
904
905
918 @Override
919 public List<DLFileVersion> findByUuid_C(String uuid, long companyId,
920 int start, int end) {
921 return findByUuid_C(uuid, companyId, start, end, null);
922 }
923
924
938 @Override
939 public List<DLFileVersion> findByUuid_C(String uuid, long companyId,
940 int start, int end, OrderByComparator<DLFileVersion> orderByComparator) {
941 boolean pagination = true;
942 FinderPath finderPath = null;
943 Object[] finderArgs = null;
944
945 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
946 (orderByComparator == null)) {
947 pagination = false;
948 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
949 finderArgs = new Object[] { uuid, companyId };
950 }
951 else {
952 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
953 finderArgs = new Object[] {
954 uuid, companyId,
955
956 start, end, orderByComparator
957 };
958 }
959
960 List<DLFileVersion> list = (List<DLFileVersion>)FinderCacheUtil.getResult(finderPath,
961 finderArgs, this);
962
963 if ((list != null) && !list.isEmpty()) {
964 for (DLFileVersion dlFileVersion : list) {
965 if (!Validator.equals(uuid, dlFileVersion.getUuid()) ||
966 (companyId != dlFileVersion.getCompanyId())) {
967 list = null;
968
969 break;
970 }
971 }
972 }
973
974 if (list == null) {
975 StringBundler query = null;
976
977 if (orderByComparator != null) {
978 query = new StringBundler(4 +
979 (orderByComparator.getOrderByFields().length * 3));
980 }
981 else {
982 query = new StringBundler(4);
983 }
984
985 query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
986
987 boolean bindUuid = false;
988
989 if (uuid == null) {
990 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
991 }
992 else if (uuid.equals(StringPool.BLANK)) {
993 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
994 }
995 else {
996 bindUuid = true;
997
998 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
999 }
1000
1001 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1002
1003 if (orderByComparator != null) {
1004 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1005 orderByComparator);
1006 }
1007 else
1008 if (pagination) {
1009 query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
1010 }
1011
1012 String sql = query.toString();
1013
1014 Session session = null;
1015
1016 try {
1017 session = openSession();
1018
1019 Query q = session.createQuery(sql);
1020
1021 QueryPos qPos = QueryPos.getInstance(q);
1022
1023 if (bindUuid) {
1024 qPos.add(uuid);
1025 }
1026
1027 qPos.add(companyId);
1028
1029 if (!pagination) {
1030 list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
1031 start, end, false);
1032
1033 Collections.sort(list);
1034
1035 list = Collections.unmodifiableList(list);
1036 }
1037 else {
1038 list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
1039 start, end);
1040 }
1041
1042 cacheResult(list);
1043
1044 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1045 }
1046 catch (Exception e) {
1047 FinderCacheUtil.removeResult(finderPath, finderArgs);
1048
1049 throw processException(e);
1050 }
1051 finally {
1052 closeSession(session);
1053 }
1054 }
1055
1056 return list;
1057 }
1058
1059
1068 @Override
1069 public DLFileVersion findByUuid_C_First(String uuid, long companyId,
1070 OrderByComparator<DLFileVersion> orderByComparator)
1071 throws NoSuchFileVersionException {
1072 DLFileVersion dlFileVersion = fetchByUuid_C_First(uuid, companyId,
1073 orderByComparator);
1074
1075 if (dlFileVersion != null) {
1076 return dlFileVersion;
1077 }
1078
1079 StringBundler msg = new StringBundler(6);
1080
1081 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1082
1083 msg.append("uuid=");
1084 msg.append(uuid);
1085
1086 msg.append(", companyId=");
1087 msg.append(companyId);
1088
1089 msg.append(StringPool.CLOSE_CURLY_BRACE);
1090
1091 throw new NoSuchFileVersionException(msg.toString());
1092 }
1093
1094
1102 @Override
1103 public DLFileVersion fetchByUuid_C_First(String uuid, long companyId,
1104 OrderByComparator<DLFileVersion> orderByComparator) {
1105 List<DLFileVersion> list = findByUuid_C(uuid, companyId, 0, 1,
1106 orderByComparator);
1107
1108 if (!list.isEmpty()) {
1109 return list.get(0);
1110 }
1111
1112 return null;
1113 }
1114
1115
1124 @Override
1125 public DLFileVersion findByUuid_C_Last(String uuid, long companyId,
1126 OrderByComparator<DLFileVersion> orderByComparator)
1127 throws NoSuchFileVersionException {
1128 DLFileVersion dlFileVersion = fetchByUuid_C_Last(uuid, companyId,
1129 orderByComparator);
1130
1131 if (dlFileVersion != null) {
1132 return dlFileVersion;
1133 }
1134
1135 StringBundler msg = new StringBundler(6);
1136
1137 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1138
1139 msg.append("uuid=");
1140 msg.append(uuid);
1141
1142 msg.append(", companyId=");
1143 msg.append(companyId);
1144
1145 msg.append(StringPool.CLOSE_CURLY_BRACE);
1146
1147 throw new NoSuchFileVersionException(msg.toString());
1148 }
1149
1150
1158 @Override
1159 public DLFileVersion fetchByUuid_C_Last(String uuid, long companyId,
1160 OrderByComparator<DLFileVersion> orderByComparator) {
1161 int count = countByUuid_C(uuid, companyId);
1162
1163 if (count == 0) {
1164 return null;
1165 }
1166
1167 List<DLFileVersion> list = findByUuid_C(uuid, companyId, count - 1,
1168 count, orderByComparator);
1169
1170 if (!list.isEmpty()) {
1171 return list.get(0);
1172 }
1173
1174 return null;
1175 }
1176
1177
1187 @Override
1188 public DLFileVersion[] findByUuid_C_PrevAndNext(long fileVersionId,
1189 String uuid, long companyId,
1190 OrderByComparator<DLFileVersion> orderByComparator)
1191 throws NoSuchFileVersionException {
1192 DLFileVersion dlFileVersion = findByPrimaryKey(fileVersionId);
1193
1194 Session session = null;
1195
1196 try {
1197 session = openSession();
1198
1199 DLFileVersion[] array = new DLFileVersionImpl[3];
1200
1201 array[0] = getByUuid_C_PrevAndNext(session, dlFileVersion, uuid,
1202 companyId, orderByComparator, true);
1203
1204 array[1] = dlFileVersion;
1205
1206 array[2] = getByUuid_C_PrevAndNext(session, dlFileVersion, uuid,
1207 companyId, orderByComparator, false);
1208
1209 return array;
1210 }
1211 catch (Exception e) {
1212 throw processException(e);
1213 }
1214 finally {
1215 closeSession(session);
1216 }
1217 }
1218
1219 protected DLFileVersion getByUuid_C_PrevAndNext(Session session,
1220 DLFileVersion dlFileVersion, String uuid, long companyId,
1221 OrderByComparator<DLFileVersion> orderByComparator, boolean previous) {
1222 StringBundler query = null;
1223
1224 if (orderByComparator != null) {
1225 query = new StringBundler(6 +
1226 (orderByComparator.getOrderByFields().length * 6));
1227 }
1228 else {
1229 query = new StringBundler(3);
1230 }
1231
1232 query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
1233
1234 boolean bindUuid = false;
1235
1236 if (uuid == null) {
1237 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1238 }
1239 else if (uuid.equals(StringPool.BLANK)) {
1240 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1241 }
1242 else {
1243 bindUuid = true;
1244
1245 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1246 }
1247
1248 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1249
1250 if (orderByComparator != null) {
1251 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1252
1253 if (orderByConditionFields.length > 0) {
1254 query.append(WHERE_AND);
1255 }
1256
1257 for (int i = 0; i < orderByConditionFields.length; i++) {
1258 query.append(_ORDER_BY_ENTITY_ALIAS);
1259 query.append(orderByConditionFields[i]);
1260
1261 if ((i + 1) < orderByConditionFields.length) {
1262 if (orderByComparator.isAscending() ^ previous) {
1263 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1264 }
1265 else {
1266 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1267 }
1268 }
1269 else {
1270 if (orderByComparator.isAscending() ^ previous) {
1271 query.append(WHERE_GREATER_THAN);
1272 }
1273 else {
1274 query.append(WHERE_LESSER_THAN);
1275 }
1276 }
1277 }
1278
1279 query.append(ORDER_BY_CLAUSE);
1280
1281 String[] orderByFields = orderByComparator.getOrderByFields();
1282
1283 for (int i = 0; i < orderByFields.length; i++) {
1284 query.append(_ORDER_BY_ENTITY_ALIAS);
1285 query.append(orderByFields[i]);
1286
1287 if ((i + 1) < orderByFields.length) {
1288 if (orderByComparator.isAscending() ^ previous) {
1289 query.append(ORDER_BY_ASC_HAS_NEXT);
1290 }
1291 else {
1292 query.append(ORDER_BY_DESC_HAS_NEXT);
1293 }
1294 }
1295 else {
1296 if (orderByComparator.isAscending() ^ previous) {
1297 query.append(ORDER_BY_ASC);
1298 }
1299 else {
1300 query.append(ORDER_BY_DESC);
1301 }
1302 }
1303 }
1304 }
1305 else {
1306 query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
1307 }
1308
1309 String sql = query.toString();
1310
1311 Query q = session.createQuery(sql);
1312
1313 q.setFirstResult(0);
1314 q.setMaxResults(2);
1315
1316 QueryPos qPos = QueryPos.getInstance(q);
1317
1318 if (bindUuid) {
1319 qPos.add(uuid);
1320 }
1321
1322 qPos.add(companyId);
1323
1324 if (orderByComparator != null) {
1325 Object[] values = orderByComparator.getOrderByConditionValues(dlFileVersion);
1326
1327 for (Object value : values) {
1328 qPos.add(value);
1329 }
1330 }
1331
1332 List<DLFileVersion> list = q.list();
1333
1334 if (list.size() == 2) {
1335 return list.get(1);
1336 }
1337 else {
1338 return null;
1339 }
1340 }
1341
1342
1348 @Override
1349 public void removeByUuid_C(String uuid, long companyId) {
1350 for (DLFileVersion dlFileVersion : findByUuid_C(uuid, companyId,
1351 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1352 remove(dlFileVersion);
1353 }
1354 }
1355
1356
1363 @Override
1364 public int countByUuid_C(String uuid, long companyId) {
1365 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1366
1367 Object[] finderArgs = new Object[] { uuid, companyId };
1368
1369 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1370 this);
1371
1372 if (count == null) {
1373 StringBundler query = new StringBundler(3);
1374
1375 query.append(_SQL_COUNT_DLFILEVERSION_WHERE);
1376
1377 boolean bindUuid = false;
1378
1379 if (uuid == null) {
1380 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1381 }
1382 else if (uuid.equals(StringPool.BLANK)) {
1383 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1384 }
1385 else {
1386 bindUuid = true;
1387
1388 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1389 }
1390
1391 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1392
1393 String sql = query.toString();
1394
1395 Session session = null;
1396
1397 try {
1398 session = openSession();
1399
1400 Query q = session.createQuery(sql);
1401
1402 QueryPos qPos = QueryPos.getInstance(q);
1403
1404 if (bindUuid) {
1405 qPos.add(uuid);
1406 }
1407
1408 qPos.add(companyId);
1409
1410 count = (Long)q.uniqueResult();
1411
1412 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1413 }
1414 catch (Exception e) {
1415 FinderCacheUtil.removeResult(finderPath, finderArgs);
1416
1417 throw processException(e);
1418 }
1419 finally {
1420 closeSession(session);
1421 }
1422 }
1423
1424 return count.intValue();
1425 }
1426
1427 private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "dlFileVersion.uuid IS NULL AND ";
1428 private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "dlFileVersion.uuid = ? AND ";
1429 private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(dlFileVersion.uuid IS NULL OR dlFileVersion.uuid = '') AND ";
1430 private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "dlFileVersion.companyId = ?";
1431 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
1432 new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
1433 DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
1434 DLFileVersionImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
1435 "findByCompanyId",
1436 new String[] {
1437 Long.class.getName(),
1438
1439 Integer.class.getName(), Integer.class.getName(),
1440 OrderByComparator.class.getName()
1441 });
1442 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
1443 new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
1444 DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
1445 DLFileVersionImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
1446 "findByCompanyId", new String[] { Long.class.getName() },
1447 DLFileVersionModelImpl.COMPANYID_COLUMN_BITMASK |
1448 DLFileVersionModelImpl.FILEENTRYID_COLUMN_BITMASK |
1449 DLFileVersionModelImpl.CREATEDATE_COLUMN_BITMASK);
1450 public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
1451 DLFileVersionModelImpl.FINDER_CACHE_ENABLED, Long.class,
1452 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
1453 new String[] { Long.class.getName() });
1454
1455
1461 @Override
1462 public List<DLFileVersion> findByCompanyId(long companyId) {
1463 return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1464 null);
1465 }
1466
1467
1479 @Override
1480 public List<DLFileVersion> findByCompanyId(long companyId, int start,
1481 int end) {
1482 return findByCompanyId(companyId, start, end, null);
1483 }
1484
1485
1498 @Override
1499 public List<DLFileVersion> findByCompanyId(long companyId, int start,
1500 int end, OrderByComparator<DLFileVersion> orderByComparator) {
1501 boolean pagination = true;
1502 FinderPath finderPath = null;
1503 Object[] finderArgs = null;
1504
1505 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1506 (orderByComparator == null)) {
1507 pagination = false;
1508 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
1509 finderArgs = new Object[] { companyId };
1510 }
1511 else {
1512 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
1513 finderArgs = new Object[] { companyId, start, end, orderByComparator };
1514 }
1515
1516 List<DLFileVersion> list = (List<DLFileVersion>)FinderCacheUtil.getResult(finderPath,
1517 finderArgs, this);
1518
1519 if ((list != null) && !list.isEmpty()) {
1520 for (DLFileVersion dlFileVersion : list) {
1521 if ((companyId != dlFileVersion.getCompanyId())) {
1522 list = null;
1523
1524 break;
1525 }
1526 }
1527 }
1528
1529 if (list == null) {
1530 StringBundler query = null;
1531
1532 if (orderByComparator != null) {
1533 query = new StringBundler(3 +
1534 (orderByComparator.getOrderByFields().length * 3));
1535 }
1536 else {
1537 query = new StringBundler(3);
1538 }
1539
1540 query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
1541
1542 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1543
1544 if (orderByComparator != null) {
1545 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1546 orderByComparator);
1547 }
1548 else
1549 if (pagination) {
1550 query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
1551 }
1552
1553 String sql = query.toString();
1554
1555 Session session = null;
1556
1557 try {
1558 session = openSession();
1559
1560 Query q = session.createQuery(sql);
1561
1562 QueryPos qPos = QueryPos.getInstance(q);
1563
1564 qPos.add(companyId);
1565
1566 if (!pagination) {
1567 list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
1568 start, end, false);
1569
1570 Collections.sort(list);
1571
1572 list = Collections.unmodifiableList(list);
1573 }
1574 else {
1575 list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
1576 start, end);
1577 }
1578
1579 cacheResult(list);
1580
1581 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1582 }
1583 catch (Exception e) {
1584 FinderCacheUtil.removeResult(finderPath, finderArgs);
1585
1586 throw processException(e);
1587 }
1588 finally {
1589 closeSession(session);
1590 }
1591 }
1592
1593 return list;
1594 }
1595
1596
1604 @Override
1605 public DLFileVersion findByCompanyId_First(long companyId,
1606 OrderByComparator<DLFileVersion> orderByComparator)
1607 throws NoSuchFileVersionException {
1608 DLFileVersion dlFileVersion = fetchByCompanyId_First(companyId,
1609 orderByComparator);
1610
1611 if (dlFileVersion != null) {
1612 return dlFileVersion;
1613 }
1614
1615 StringBundler msg = new StringBundler(4);
1616
1617 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1618
1619 msg.append("companyId=");
1620 msg.append(companyId);
1621
1622 msg.append(StringPool.CLOSE_CURLY_BRACE);
1623
1624 throw new NoSuchFileVersionException(msg.toString());
1625 }
1626
1627
1634 @Override
1635 public DLFileVersion fetchByCompanyId_First(long companyId,
1636 OrderByComparator<DLFileVersion> orderByComparator) {
1637 List<DLFileVersion> list = findByCompanyId(companyId, 0, 1,
1638 orderByComparator);
1639
1640 if (!list.isEmpty()) {
1641 return list.get(0);
1642 }
1643
1644 return null;
1645 }
1646
1647
1655 @Override
1656 public DLFileVersion findByCompanyId_Last(long companyId,
1657 OrderByComparator<DLFileVersion> orderByComparator)
1658 throws NoSuchFileVersionException {
1659 DLFileVersion dlFileVersion = fetchByCompanyId_Last(companyId,
1660 orderByComparator);
1661
1662 if (dlFileVersion != null) {
1663 return dlFileVersion;
1664 }
1665
1666 StringBundler msg = new StringBundler(4);
1667
1668 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1669
1670 msg.append("companyId=");
1671 msg.append(companyId);
1672
1673 msg.append(StringPool.CLOSE_CURLY_BRACE);
1674
1675 throw new NoSuchFileVersionException(msg.toString());
1676 }
1677
1678
1685 @Override
1686 public DLFileVersion fetchByCompanyId_Last(long companyId,
1687 OrderByComparator<DLFileVersion> orderByComparator) {
1688 int count = countByCompanyId(companyId);
1689
1690 if (count == 0) {
1691 return null;
1692 }
1693
1694 List<DLFileVersion> list = findByCompanyId(companyId, count - 1, count,
1695 orderByComparator);
1696
1697 if (!list.isEmpty()) {
1698 return list.get(0);
1699 }
1700
1701 return null;
1702 }
1703
1704
1713 @Override
1714 public DLFileVersion[] findByCompanyId_PrevAndNext(long fileVersionId,
1715 long companyId, OrderByComparator<DLFileVersion> orderByComparator)
1716 throws NoSuchFileVersionException {
1717 DLFileVersion dlFileVersion = findByPrimaryKey(fileVersionId);
1718
1719 Session session = null;
1720
1721 try {
1722 session = openSession();
1723
1724 DLFileVersion[] array = new DLFileVersionImpl[3];
1725
1726 array[0] = getByCompanyId_PrevAndNext(session, dlFileVersion,
1727 companyId, orderByComparator, true);
1728
1729 array[1] = dlFileVersion;
1730
1731 array[2] = getByCompanyId_PrevAndNext(session, dlFileVersion,
1732 companyId, orderByComparator, false);
1733
1734 return array;
1735 }
1736 catch (Exception e) {
1737 throw processException(e);
1738 }
1739 finally {
1740 closeSession(session);
1741 }
1742 }
1743
1744 protected DLFileVersion getByCompanyId_PrevAndNext(Session session,
1745 DLFileVersion dlFileVersion, long companyId,
1746 OrderByComparator<DLFileVersion> orderByComparator, boolean previous) {
1747 StringBundler query = null;
1748
1749 if (orderByComparator != null) {
1750 query = new StringBundler(6 +
1751 (orderByComparator.getOrderByFields().length * 6));
1752 }
1753 else {
1754 query = new StringBundler(3);
1755 }
1756
1757 query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
1758
1759 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1760
1761 if (orderByComparator != null) {
1762 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1763
1764 if (orderByConditionFields.length > 0) {
1765 query.append(WHERE_AND);
1766 }
1767
1768 for (int i = 0; i < orderByConditionFields.length; i++) {
1769 query.append(_ORDER_BY_ENTITY_ALIAS);
1770 query.append(orderByConditionFields[i]);
1771
1772 if ((i + 1) < orderByConditionFields.length) {
1773 if (orderByComparator.isAscending() ^ previous) {
1774 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1775 }
1776 else {
1777 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1778 }
1779 }
1780 else {
1781 if (orderByComparator.isAscending() ^ previous) {
1782 query.append(WHERE_GREATER_THAN);
1783 }
1784 else {
1785 query.append(WHERE_LESSER_THAN);
1786 }
1787 }
1788 }
1789
1790 query.append(ORDER_BY_CLAUSE);
1791
1792 String[] orderByFields = orderByComparator.getOrderByFields();
1793
1794 for (int i = 0; i < orderByFields.length; i++) {
1795 query.append(_ORDER_BY_ENTITY_ALIAS);
1796 query.append(orderByFields[i]);
1797
1798 if ((i + 1) < orderByFields.length) {
1799 if (orderByComparator.isAscending() ^ previous) {
1800 query.append(ORDER_BY_ASC_HAS_NEXT);
1801 }
1802 else {
1803 query.append(ORDER_BY_DESC_HAS_NEXT);
1804 }
1805 }
1806 else {
1807 if (orderByComparator.isAscending() ^ previous) {
1808 query.append(ORDER_BY_ASC);
1809 }
1810 else {
1811 query.append(ORDER_BY_DESC);
1812 }
1813 }
1814 }
1815 }
1816 else {
1817 query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
1818 }
1819
1820 String sql = query.toString();
1821
1822 Query q = session.createQuery(sql);
1823
1824 q.setFirstResult(0);
1825 q.setMaxResults(2);
1826
1827 QueryPos qPos = QueryPos.getInstance(q);
1828
1829 qPos.add(companyId);
1830
1831 if (orderByComparator != null) {
1832 Object[] values = orderByComparator.getOrderByConditionValues(dlFileVersion);
1833
1834 for (Object value : values) {
1835 qPos.add(value);
1836 }
1837 }
1838
1839 List<DLFileVersion> list = q.list();
1840
1841 if (list.size() == 2) {
1842 return list.get(1);
1843 }
1844 else {
1845 return null;
1846 }
1847 }
1848
1849
1854 @Override
1855 public void removeByCompanyId(long companyId) {
1856 for (DLFileVersion dlFileVersion : findByCompanyId(companyId,
1857 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1858 remove(dlFileVersion);
1859 }
1860 }
1861
1862
1868 @Override
1869 public int countByCompanyId(long companyId) {
1870 FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
1871
1872 Object[] finderArgs = new Object[] { companyId };
1873
1874 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1875 this);
1876
1877 if (count == null) {
1878 StringBundler query = new StringBundler(2);
1879
1880 query.append(_SQL_COUNT_DLFILEVERSION_WHERE);
1881
1882 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1883
1884 String sql = query.toString();
1885
1886 Session session = null;
1887
1888 try {
1889 session = openSession();
1890
1891 Query q = session.createQuery(sql);
1892
1893 QueryPos qPos = QueryPos.getInstance(q);
1894
1895 qPos.add(companyId);
1896
1897 count = (Long)q.uniqueResult();
1898
1899 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1900 }
1901 catch (Exception e) {
1902 FinderCacheUtil.removeResult(finderPath, finderArgs);
1903
1904 throw processException(e);
1905 }
1906 finally {
1907 closeSession(session);
1908 }
1909 }
1910
1911 return count.intValue();
1912 }
1913
1914 private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "dlFileVersion.companyId = ?";
1915 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_FILEENTRYID =
1916 new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
1917 DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
1918 DLFileVersionImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
1919 "findByFileEntryId",
1920 new String[] {
1921 Long.class.getName(),
1922
1923 Integer.class.getName(), Integer.class.getName(),
1924 OrderByComparator.class.getName()
1925 });
1926 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FILEENTRYID =
1927 new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
1928 DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
1929 DLFileVersionImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
1930 "findByFileEntryId", new String[] { Long.class.getName() },
1931 DLFileVersionModelImpl.FILEENTRYID_COLUMN_BITMASK |
1932 DLFileVersionModelImpl.CREATEDATE_COLUMN_BITMASK);
1933 public static final FinderPath FINDER_PATH_COUNT_BY_FILEENTRYID = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
1934 DLFileVersionModelImpl.FINDER_CACHE_ENABLED, Long.class,
1935 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByFileEntryId",
1936 new String[] { Long.class.getName() });
1937
1938
1944 @Override
1945 public List<DLFileVersion> findByFileEntryId(long fileEntryId) {
1946 return findByFileEntryId(fileEntryId, QueryUtil.ALL_POS,
1947 QueryUtil.ALL_POS, null);
1948 }
1949
1950
1962 @Override
1963 public List<DLFileVersion> findByFileEntryId(long fileEntryId, int start,
1964 int end) {
1965 return findByFileEntryId(fileEntryId, start, end, null);
1966 }
1967
1968
1981 @Override
1982 public List<DLFileVersion> findByFileEntryId(long fileEntryId, int start,
1983 int end, OrderByComparator<DLFileVersion> orderByComparator) {
1984 boolean pagination = true;
1985 FinderPath finderPath = null;
1986 Object[] finderArgs = null;
1987
1988 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1989 (orderByComparator == null)) {
1990 pagination = false;
1991 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FILEENTRYID;
1992 finderArgs = new Object[] { fileEntryId };
1993 }
1994 else {
1995 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_FILEENTRYID;
1996 finderArgs = new Object[] { fileEntryId, start, end, orderByComparator };
1997 }
1998
1999 List<DLFileVersion> list = (List<DLFileVersion>)FinderCacheUtil.getResult(finderPath,
2000 finderArgs, this);
2001
2002 if ((list != null) && !list.isEmpty()) {
2003 for (DLFileVersion dlFileVersion : list) {
2004 if ((fileEntryId != dlFileVersion.getFileEntryId())) {
2005 list = null;
2006
2007 break;
2008 }
2009 }
2010 }
2011
2012 if (list == null) {
2013 StringBundler query = null;
2014
2015 if (orderByComparator != null) {
2016 query = new StringBundler(3 +
2017 (orderByComparator.getOrderByFields().length * 3));
2018 }
2019 else {
2020 query = new StringBundler(3);
2021 }
2022
2023 query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
2024
2025 query.append(_FINDER_COLUMN_FILEENTRYID_FILEENTRYID_2);
2026
2027 if (orderByComparator != null) {
2028 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2029 orderByComparator);
2030 }
2031 else
2032 if (pagination) {
2033 query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
2034 }
2035
2036 String sql = query.toString();
2037
2038 Session session = null;
2039
2040 try {
2041 session = openSession();
2042
2043 Query q = session.createQuery(sql);
2044
2045 QueryPos qPos = QueryPos.getInstance(q);
2046
2047 qPos.add(fileEntryId);
2048
2049 if (!pagination) {
2050 list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
2051 start, end, false);
2052
2053 Collections.sort(list);
2054
2055 list = Collections.unmodifiableList(list);
2056 }
2057 else {
2058 list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
2059 start, end);
2060 }
2061
2062 cacheResult(list);
2063
2064 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2065 }
2066 catch (Exception e) {
2067 FinderCacheUtil.removeResult(finderPath, finderArgs);
2068
2069 throw processException(e);
2070 }
2071 finally {
2072 closeSession(session);
2073 }
2074 }
2075
2076 return list;
2077 }
2078
2079
2087 @Override
2088 public DLFileVersion findByFileEntryId_First(long fileEntryId,
2089 OrderByComparator<DLFileVersion> orderByComparator)
2090 throws NoSuchFileVersionException {
2091 DLFileVersion dlFileVersion = fetchByFileEntryId_First(fileEntryId,
2092 orderByComparator);
2093
2094 if (dlFileVersion != null) {
2095 return dlFileVersion;
2096 }
2097
2098 StringBundler msg = new StringBundler(4);
2099
2100 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2101
2102 msg.append("fileEntryId=");
2103 msg.append(fileEntryId);
2104
2105 msg.append(StringPool.CLOSE_CURLY_BRACE);
2106
2107 throw new NoSuchFileVersionException(msg.toString());
2108 }
2109
2110
2117 @Override
2118 public DLFileVersion fetchByFileEntryId_First(long fileEntryId,
2119 OrderByComparator<DLFileVersion> orderByComparator) {
2120 List<DLFileVersion> list = findByFileEntryId(fileEntryId, 0, 1,
2121 orderByComparator);
2122
2123 if (!list.isEmpty()) {
2124 return list.get(0);
2125 }
2126
2127 return null;
2128 }
2129
2130
2138 @Override
2139 public DLFileVersion findByFileEntryId_Last(long fileEntryId,
2140 OrderByComparator<DLFileVersion> orderByComparator)
2141 throws NoSuchFileVersionException {
2142 DLFileVersion dlFileVersion = fetchByFileEntryId_Last(fileEntryId,
2143 orderByComparator);
2144
2145 if (dlFileVersion != null) {
2146 return dlFileVersion;
2147 }
2148
2149 StringBundler msg = new StringBundler(4);
2150
2151 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2152
2153 msg.append("fileEntryId=");
2154 msg.append(fileEntryId);
2155
2156 msg.append(StringPool.CLOSE_CURLY_BRACE);
2157
2158 throw new NoSuchFileVersionException(msg.toString());
2159 }
2160
2161
2168 @Override
2169 public DLFileVersion fetchByFileEntryId_Last(long fileEntryId,
2170 OrderByComparator<DLFileVersion> orderByComparator) {
2171 int count = countByFileEntryId(fileEntryId);
2172
2173 if (count == 0) {
2174 return null;
2175 }
2176
2177 List<DLFileVersion> list = findByFileEntryId(fileEntryId, count - 1,
2178 count, orderByComparator);
2179
2180 if (!list.isEmpty()) {
2181 return list.get(0);
2182 }
2183
2184 return null;
2185 }
2186
2187
2196 @Override
2197 public DLFileVersion[] findByFileEntryId_PrevAndNext(long fileVersionId,
2198 long fileEntryId, OrderByComparator<DLFileVersion> orderByComparator)
2199 throws NoSuchFileVersionException {
2200 DLFileVersion dlFileVersion = findByPrimaryKey(fileVersionId);
2201
2202 Session session = null;
2203
2204 try {
2205 session = openSession();
2206
2207 DLFileVersion[] array = new DLFileVersionImpl[3];
2208
2209 array[0] = getByFileEntryId_PrevAndNext(session, dlFileVersion,
2210 fileEntryId, orderByComparator, true);
2211
2212 array[1] = dlFileVersion;
2213
2214 array[2] = getByFileEntryId_PrevAndNext(session, dlFileVersion,
2215 fileEntryId, orderByComparator, false);
2216
2217 return array;
2218 }
2219 catch (Exception e) {
2220 throw processException(e);
2221 }
2222 finally {
2223 closeSession(session);
2224 }
2225 }
2226
2227 protected DLFileVersion getByFileEntryId_PrevAndNext(Session session,
2228 DLFileVersion dlFileVersion, long fileEntryId,
2229 OrderByComparator<DLFileVersion> orderByComparator, boolean previous) {
2230 StringBundler query = null;
2231
2232 if (orderByComparator != null) {
2233 query = new StringBundler(6 +
2234 (orderByComparator.getOrderByFields().length * 6));
2235 }
2236 else {
2237 query = new StringBundler(3);
2238 }
2239
2240 query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
2241
2242 query.append(_FINDER_COLUMN_FILEENTRYID_FILEENTRYID_2);
2243
2244 if (orderByComparator != null) {
2245 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2246
2247 if (orderByConditionFields.length > 0) {
2248 query.append(WHERE_AND);
2249 }
2250
2251 for (int i = 0; i < orderByConditionFields.length; i++) {
2252 query.append(_ORDER_BY_ENTITY_ALIAS);
2253 query.append(orderByConditionFields[i]);
2254
2255 if ((i + 1) < orderByConditionFields.length) {
2256 if (orderByComparator.isAscending() ^ previous) {
2257 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2258 }
2259 else {
2260 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2261 }
2262 }
2263 else {
2264 if (orderByComparator.isAscending() ^ previous) {
2265 query.append(WHERE_GREATER_THAN);
2266 }
2267 else {
2268 query.append(WHERE_LESSER_THAN);
2269 }
2270 }
2271 }
2272
2273 query.append(ORDER_BY_CLAUSE);
2274
2275 String[] orderByFields = orderByComparator.getOrderByFields();
2276
2277 for (int i = 0; i < orderByFields.length; i++) {
2278 query.append(_ORDER_BY_ENTITY_ALIAS);
2279 query.append(orderByFields[i]);
2280
2281 if ((i + 1) < orderByFields.length) {
2282 if (orderByComparator.isAscending() ^ previous) {
2283 query.append(ORDER_BY_ASC_HAS_NEXT);
2284 }
2285 else {
2286 query.append(ORDER_BY_DESC_HAS_NEXT);
2287 }
2288 }
2289 else {
2290 if (orderByComparator.isAscending() ^ previous) {
2291 query.append(ORDER_BY_ASC);
2292 }
2293 else {
2294 query.append(ORDER_BY_DESC);
2295 }
2296 }
2297 }
2298 }
2299 else {
2300 query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
2301 }
2302
2303 String sql = query.toString();
2304
2305 Query q = session.createQuery(sql);
2306
2307 q.setFirstResult(0);
2308 q.setMaxResults(2);
2309
2310 QueryPos qPos = QueryPos.getInstance(q);
2311
2312 qPos.add(fileEntryId);
2313
2314 if (orderByComparator != null) {
2315 Object[] values = orderByComparator.getOrderByConditionValues(dlFileVersion);
2316
2317 for (Object value : values) {
2318 qPos.add(value);
2319 }
2320 }
2321
2322 List<DLFileVersion> list = q.list();
2323
2324 if (list.size() == 2) {
2325 return list.get(1);
2326 }
2327 else {
2328 return null;
2329 }
2330 }
2331
2332
2337 @Override
2338 public void removeByFileEntryId(long fileEntryId) {
2339 for (DLFileVersion dlFileVersion : findByFileEntryId(fileEntryId,
2340 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2341 remove(dlFileVersion);
2342 }
2343 }
2344
2345
2351 @Override
2352 public int countByFileEntryId(long fileEntryId) {
2353 FinderPath finderPath = FINDER_PATH_COUNT_BY_FILEENTRYID;
2354
2355 Object[] finderArgs = new Object[] { fileEntryId };
2356
2357 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2358 this);
2359
2360 if (count == null) {
2361 StringBundler query = new StringBundler(2);
2362
2363 query.append(_SQL_COUNT_DLFILEVERSION_WHERE);
2364
2365 query.append(_FINDER_COLUMN_FILEENTRYID_FILEENTRYID_2);
2366
2367 String sql = query.toString();
2368
2369 Session session = null;
2370
2371 try {
2372 session = openSession();
2373
2374 Query q = session.createQuery(sql);
2375
2376 QueryPos qPos = QueryPos.getInstance(q);
2377
2378 qPos.add(fileEntryId);
2379
2380 count = (Long)q.uniqueResult();
2381
2382 FinderCacheUtil.putResult(finderPath, finderArgs, count);
2383 }
2384 catch (Exception e) {
2385 FinderCacheUtil.removeResult(finderPath, finderArgs);
2386
2387 throw processException(e);
2388 }
2389 finally {
2390 closeSession(session);
2391 }
2392 }
2393
2394 return count.intValue();
2395 }
2396
2397 private static final String _FINDER_COLUMN_FILEENTRYID_FILEENTRYID_2 = "dlFileVersion.fileEntryId = ?";
2398 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_MIMETYPE = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
2399 DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
2400 DLFileVersionImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
2401 "findByMimeType",
2402 new String[] {
2403 String.class.getName(),
2404
2405 Integer.class.getName(), Integer.class.getName(),
2406 OrderByComparator.class.getName()
2407 });
2408 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_MIMETYPE =
2409 new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
2410 DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
2411 DLFileVersionImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
2412 "findByMimeType", new String[] { String.class.getName() },
2413 DLFileVersionModelImpl.MIMETYPE_COLUMN_BITMASK |
2414 DLFileVersionModelImpl.FILEENTRYID_COLUMN_BITMASK |
2415 DLFileVersionModelImpl.CREATEDATE_COLUMN_BITMASK);
2416 public static final FinderPath FINDER_PATH_COUNT_BY_MIMETYPE = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
2417 DLFileVersionModelImpl.FINDER_CACHE_ENABLED, Long.class,
2418 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByMimeType",
2419 new String[] { String.class.getName() });
2420
2421
2427 @Override
2428 public List<DLFileVersion> findByMimeType(String mimeType) {
2429 return findByMimeType(mimeType, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2430 null);
2431 }
2432
2433
2445 @Override
2446 public List<DLFileVersion> findByMimeType(String mimeType, int start,
2447 int end) {
2448 return findByMimeType(mimeType, start, end, null);
2449 }
2450
2451
2464 @Override
2465 public List<DLFileVersion> findByMimeType(String mimeType, int start,
2466 int end, OrderByComparator<DLFileVersion> orderByComparator) {
2467 boolean pagination = true;
2468 FinderPath finderPath = null;
2469 Object[] finderArgs = null;
2470
2471 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2472 (orderByComparator == null)) {
2473 pagination = false;
2474 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_MIMETYPE;
2475 finderArgs = new Object[] { mimeType };
2476 }
2477 else {
2478 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_MIMETYPE;
2479 finderArgs = new Object[] { mimeType, start, end, orderByComparator };
2480 }
2481
2482 List<DLFileVersion> list = (List<DLFileVersion>)FinderCacheUtil.getResult(finderPath,
2483 finderArgs, this);
2484
2485 if ((list != null) && !list.isEmpty()) {
2486 for (DLFileVersion dlFileVersion : list) {
2487 if (!Validator.equals(mimeType, dlFileVersion.getMimeType())) {
2488 list = null;
2489
2490 break;
2491 }
2492 }
2493 }
2494
2495 if (list == null) {
2496 StringBundler query = null;
2497
2498 if (orderByComparator != null) {
2499 query = new StringBundler(3 +
2500 (orderByComparator.getOrderByFields().length * 3));
2501 }
2502 else {
2503 query = new StringBundler(3);
2504 }
2505
2506 query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
2507
2508 boolean bindMimeType = false;
2509
2510 if (mimeType == null) {
2511 query.append(_FINDER_COLUMN_MIMETYPE_MIMETYPE_1);
2512 }
2513 else if (mimeType.equals(StringPool.BLANK)) {
2514 query.append(_FINDER_COLUMN_MIMETYPE_MIMETYPE_3);
2515 }
2516 else {
2517 bindMimeType = true;
2518
2519 query.append(_FINDER_COLUMN_MIMETYPE_MIMETYPE_2);
2520 }
2521
2522 if (orderByComparator != null) {
2523 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2524 orderByComparator);
2525 }
2526 else
2527 if (pagination) {
2528 query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
2529 }
2530
2531 String sql = query.toString();
2532
2533 Session session = null;
2534
2535 try {
2536 session = openSession();
2537
2538 Query q = session.createQuery(sql);
2539
2540 QueryPos qPos = QueryPos.getInstance(q);
2541
2542 if (bindMimeType) {
2543 qPos.add(mimeType);
2544 }
2545
2546 if (!pagination) {
2547 list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
2548 start, end, false);
2549
2550 Collections.sort(list);
2551
2552 list = Collections.unmodifiableList(list);
2553 }
2554 else {
2555 list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
2556 start, end);
2557 }
2558
2559 cacheResult(list);
2560
2561 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2562 }
2563 catch (Exception e) {
2564 FinderCacheUtil.removeResult(finderPath, finderArgs);
2565
2566 throw processException(e);
2567 }
2568 finally {
2569 closeSession(session);
2570 }
2571 }
2572
2573 return list;
2574 }
2575
2576
2584 @Override
2585 public DLFileVersion findByMimeType_First(String mimeType,
2586 OrderByComparator<DLFileVersion> orderByComparator)
2587 throws NoSuchFileVersionException {
2588 DLFileVersion dlFileVersion = fetchByMimeType_First(mimeType,
2589 orderByComparator);
2590
2591 if (dlFileVersion != null) {
2592 return dlFileVersion;
2593 }
2594
2595 StringBundler msg = new StringBundler(4);
2596
2597 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2598
2599 msg.append("mimeType=");
2600 msg.append(mimeType);
2601
2602 msg.append(StringPool.CLOSE_CURLY_BRACE);
2603
2604 throw new NoSuchFileVersionException(msg.toString());
2605 }
2606
2607
2614 @Override
2615 public DLFileVersion fetchByMimeType_First(String mimeType,
2616 OrderByComparator<DLFileVersion> orderByComparator) {
2617 List<DLFileVersion> list = findByMimeType(mimeType, 0, 1,
2618 orderByComparator);
2619
2620 if (!list.isEmpty()) {
2621 return list.get(0);
2622 }
2623
2624 return null;
2625 }
2626
2627
2635 @Override
2636 public DLFileVersion findByMimeType_Last(String mimeType,
2637 OrderByComparator<DLFileVersion> orderByComparator)
2638 throws NoSuchFileVersionException {
2639 DLFileVersion dlFileVersion = fetchByMimeType_Last(mimeType,
2640 orderByComparator);
2641
2642 if (dlFileVersion != null) {
2643 return dlFileVersion;
2644 }
2645
2646 StringBundler msg = new StringBundler(4);
2647
2648 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2649
2650 msg.append("mimeType=");
2651 msg.append(mimeType);
2652
2653 msg.append(StringPool.CLOSE_CURLY_BRACE);
2654
2655 throw new NoSuchFileVersionException(msg.toString());
2656 }
2657
2658
2665 @Override
2666 public DLFileVersion fetchByMimeType_Last(String mimeType,
2667 OrderByComparator<DLFileVersion> orderByComparator) {
2668 int count = countByMimeType(mimeType);
2669
2670 if (count == 0) {
2671 return null;
2672 }
2673
2674 List<DLFileVersion> list = findByMimeType(mimeType, count - 1, count,
2675 orderByComparator);
2676
2677 if (!list.isEmpty()) {
2678 return list.get(0);
2679 }
2680
2681 return null;
2682 }
2683
2684
2693 @Override
2694 public DLFileVersion[] findByMimeType_PrevAndNext(long fileVersionId,
2695 String mimeType, OrderByComparator<DLFileVersion> orderByComparator)
2696 throws NoSuchFileVersionException {
2697 DLFileVersion dlFileVersion = findByPrimaryKey(fileVersionId);
2698
2699 Session session = null;
2700
2701 try {
2702 session = openSession();
2703
2704 DLFileVersion[] array = new DLFileVersionImpl[3];
2705
2706 array[0] = getByMimeType_PrevAndNext(session, dlFileVersion,
2707 mimeType, orderByComparator, true);
2708
2709 array[1] = dlFileVersion;
2710
2711 array[2] = getByMimeType_PrevAndNext(session, dlFileVersion,
2712 mimeType, orderByComparator, false);
2713
2714 return array;
2715 }
2716 catch (Exception e) {
2717 throw processException(e);
2718 }
2719 finally {
2720 closeSession(session);
2721 }
2722 }
2723
2724 protected DLFileVersion getByMimeType_PrevAndNext(Session session,
2725 DLFileVersion dlFileVersion, String mimeType,
2726 OrderByComparator<DLFileVersion> orderByComparator, boolean previous) {
2727 StringBundler query = null;
2728
2729 if (orderByComparator != null) {
2730 query = new StringBundler(6 +
2731 (orderByComparator.getOrderByFields().length * 6));
2732 }
2733 else {
2734 query = new StringBundler(3);
2735 }
2736
2737 query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
2738
2739 boolean bindMimeType = false;
2740
2741 if (mimeType == null) {
2742 query.append(_FINDER_COLUMN_MIMETYPE_MIMETYPE_1);
2743 }
2744 else if (mimeType.equals(StringPool.BLANK)) {
2745 query.append(_FINDER_COLUMN_MIMETYPE_MIMETYPE_3);
2746 }
2747 else {
2748 bindMimeType = true;
2749
2750 query.append(_FINDER_COLUMN_MIMETYPE_MIMETYPE_2);
2751 }
2752
2753 if (orderByComparator != null) {
2754 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2755
2756 if (orderByConditionFields.length > 0) {
2757 query.append(WHERE_AND);
2758 }
2759
2760 for (int i = 0; i < orderByConditionFields.length; i++) {
2761 query.append(_ORDER_BY_ENTITY_ALIAS);
2762 query.append(orderByConditionFields[i]);
2763
2764 if ((i + 1) < orderByConditionFields.length) {
2765 if (orderByComparator.isAscending() ^ previous) {
2766 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2767 }
2768 else {
2769 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2770 }
2771 }
2772 else {
2773 if (orderByComparator.isAscending() ^ previous) {
2774 query.append(WHERE_GREATER_THAN);
2775 }
2776 else {
2777 query.append(WHERE_LESSER_THAN);
2778 }
2779 }
2780 }
2781
2782 query.append(ORDER_BY_CLAUSE);
2783
2784 String[] orderByFields = orderByComparator.getOrderByFields();
2785
2786 for (int i = 0; i < orderByFields.length; i++) {
2787 query.append(_ORDER_BY_ENTITY_ALIAS);
2788 query.append(orderByFields[i]);
2789
2790 if ((i + 1) < orderByFields.length) {
2791 if (orderByComparator.isAscending() ^ previous) {
2792 query.append(ORDER_BY_ASC_HAS_NEXT);
2793 }
2794 else {
2795 query.append(ORDER_BY_DESC_HAS_NEXT);
2796 }
2797 }
2798 else {
2799 if (orderByComparator.isAscending() ^ previous) {
2800 query.append(ORDER_BY_ASC);
2801 }
2802 else {
2803 query.append(ORDER_BY_DESC);
2804 }
2805 }
2806 }
2807 }
2808 else {
2809 query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
2810 }
2811
2812 String sql = query.toString();
2813
2814 Query q = session.createQuery(sql);
2815
2816 q.setFirstResult(0);
2817 q.setMaxResults(2);
2818
2819 QueryPos qPos = QueryPos.getInstance(q);
2820
2821 if (bindMimeType) {
2822 qPos.add(mimeType);
2823 }
2824
2825 if (orderByComparator != null) {
2826 Object[] values = orderByComparator.getOrderByConditionValues(dlFileVersion);
2827
2828 for (Object value : values) {
2829 qPos.add(value);
2830 }
2831 }
2832
2833 List<DLFileVersion> list = q.list();
2834
2835 if (list.size() == 2) {
2836 return list.get(1);
2837 }
2838 else {
2839 return null;
2840 }
2841 }
2842
2843
2848 @Override
2849 public void removeByMimeType(String mimeType) {
2850 for (DLFileVersion dlFileVersion : findByMimeType(mimeType,
2851 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2852 remove(dlFileVersion);
2853 }
2854 }
2855
2856
2862 @Override
2863 public int countByMimeType(String mimeType) {
2864 FinderPath finderPath = FINDER_PATH_COUNT_BY_MIMETYPE;
2865
2866 Object[] finderArgs = new Object[] { mimeType };
2867
2868 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2869 this);
2870
2871 if (count == null) {
2872 StringBundler query = new StringBundler(2);
2873
2874 query.append(_SQL_COUNT_DLFILEVERSION_WHERE);
2875
2876 boolean bindMimeType = false;
2877
2878 if (mimeType == null) {
2879 query.append(_FINDER_COLUMN_MIMETYPE_MIMETYPE_1);
2880 }
2881 else if (mimeType.equals(StringPool.BLANK)) {
2882 query.append(_FINDER_COLUMN_MIMETYPE_MIMETYPE_3);
2883 }
2884 else {
2885 bindMimeType = true;
2886
2887 query.append(_FINDER_COLUMN_MIMETYPE_MIMETYPE_2);
2888 }
2889
2890 String sql = query.toString();
2891
2892 Session session = null;
2893
2894 try {
2895 session = openSession();
2896
2897 Query q = session.createQuery(sql);
2898
2899 QueryPos qPos = QueryPos.getInstance(q);
2900
2901 if (bindMimeType) {
2902 qPos.add(mimeType);
2903 }
2904
2905 count = (Long)q.uniqueResult();
2906
2907 FinderCacheUtil.putResult(finderPath, finderArgs, count);
2908 }
2909 catch (Exception e) {
2910 FinderCacheUtil.removeResult(finderPath, finderArgs);
2911
2912 throw processException(e);
2913 }
2914 finally {
2915 closeSession(session);
2916 }
2917 }
2918
2919 return count.intValue();
2920 }
2921
2922 private static final String _FINDER_COLUMN_MIMETYPE_MIMETYPE_1 = "dlFileVersion.mimeType IS NULL";
2923 private static final String _FINDER_COLUMN_MIMETYPE_MIMETYPE_2 = "dlFileVersion.mimeType = ?";
2924 private static final String _FINDER_COLUMN_MIMETYPE_MIMETYPE_3 = "(dlFileVersion.mimeType IS NULL OR dlFileVersion.mimeType = '')";
2925 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_NOTS = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
2926 DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
2927 DLFileVersionImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
2928 "findByC_NotS",
2929 new String[] {
2930 Long.class.getName(), Integer.class.getName(),
2931
2932 Integer.class.getName(), Integer.class.getName(),
2933 OrderByComparator.class.getName()
2934 });
2935 public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_NOTS = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
2936 DLFileVersionModelImpl.FINDER_CACHE_ENABLED, Long.class,
2937 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByC_NotS",
2938 new String[] { Long.class.getName(), Integer.class.getName() });
2939
2940
2947 @Override
2948 public List<DLFileVersion> findByC_NotS(long companyId, int status) {
2949 return findByC_NotS(companyId, status, QueryUtil.ALL_POS,
2950 QueryUtil.ALL_POS, null);
2951 }
2952
2953
2966 @Override
2967 public List<DLFileVersion> findByC_NotS(long companyId, int status,
2968 int start, int end) {
2969 return findByC_NotS(companyId, status, start, end, null);
2970 }
2971
2972
2986 @Override
2987 public List<DLFileVersion> findByC_NotS(long companyId, int status,
2988 int start, int end, OrderByComparator<DLFileVersion> orderByComparator) {
2989 boolean pagination = true;
2990 FinderPath finderPath = null;
2991 Object[] finderArgs = null;
2992
2993 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_NOTS;
2994 finderArgs = new Object[] {
2995 companyId, status,
2996
2997 start, end, orderByComparator
2998 };
2999
3000 List<DLFileVersion> list = (List<DLFileVersion>)FinderCacheUtil.getResult(finderPath,
3001 finderArgs, this);
3002
3003 if ((list != null) && !list.isEmpty()) {
3004 for (DLFileVersion dlFileVersion : list) {
3005 if ((companyId != dlFileVersion.getCompanyId()) ||
3006 (status == dlFileVersion.getStatus())) {
3007 list = null;
3008
3009 break;
3010 }
3011 }
3012 }
3013
3014 if (list == null) {
3015 StringBundler query = null;
3016
3017 if (orderByComparator != null) {
3018 query = new StringBundler(4 +
3019 (orderByComparator.getOrderByFields().length * 3));
3020 }
3021 else {
3022 query = new StringBundler(4);
3023 }
3024
3025 query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
3026
3027 query.append(_FINDER_COLUMN_C_NOTS_COMPANYID_2);
3028
3029 query.append(_FINDER_COLUMN_C_NOTS_STATUS_2);
3030
3031 if (orderByComparator != null) {
3032 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3033 orderByComparator);
3034 }
3035 else
3036 if (pagination) {
3037 query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
3038 }
3039
3040 String sql = query.toString();
3041
3042 Session session = null;
3043
3044 try {
3045 session = openSession();
3046
3047 Query q = session.createQuery(sql);
3048
3049 QueryPos qPos = QueryPos.getInstance(q);
3050
3051 qPos.add(companyId);
3052
3053 qPos.add(status);
3054
3055 if (!pagination) {
3056 list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
3057 start, end, false);
3058
3059 Collections.sort(list);
3060
3061 list = Collections.unmodifiableList(list);
3062 }
3063 else {
3064 list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
3065 start, end);
3066 }
3067
3068 cacheResult(list);
3069
3070 FinderCacheUtil.putResult(finderPath, finderArgs, list);
3071 }
3072 catch (Exception e) {
3073 FinderCacheUtil.removeResult(finderPath, finderArgs);
3074
3075 throw processException(e);
3076 }
3077 finally {
3078 closeSession(session);
3079 }
3080 }
3081
3082 return list;
3083 }
3084
3085
3094 @Override
3095 public DLFileVersion findByC_NotS_First(long companyId, int status,
3096 OrderByComparator<DLFileVersion> orderByComparator)
3097 throws NoSuchFileVersionException {
3098 DLFileVersion dlFileVersion = fetchByC_NotS_First(companyId, status,
3099 orderByComparator);
3100
3101 if (dlFileVersion != null) {
3102 return dlFileVersion;
3103 }
3104
3105 StringBundler msg = new StringBundler(6);
3106
3107 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3108
3109 msg.append("companyId=");
3110 msg.append(companyId);
3111
3112 msg.append(", status=");
3113 msg.append(status);
3114
3115 msg.append(StringPool.CLOSE_CURLY_BRACE);
3116
3117 throw new NoSuchFileVersionException(msg.toString());
3118 }
3119
3120
3128 @Override
3129 public DLFileVersion fetchByC_NotS_First(long companyId, int status,
3130 OrderByComparator<DLFileVersion> orderByComparator) {
3131 List<DLFileVersion> list = findByC_NotS(companyId, status, 0, 1,
3132 orderByComparator);
3133
3134 if (!list.isEmpty()) {
3135 return list.get(0);
3136 }
3137
3138 return null;
3139 }
3140
3141
3150 @Override
3151 public DLFileVersion findByC_NotS_Last(long companyId, int status,
3152 OrderByComparator<DLFileVersion> orderByComparator)
3153 throws NoSuchFileVersionException {
3154 DLFileVersion dlFileVersion = fetchByC_NotS_Last(companyId, status,
3155 orderByComparator);
3156
3157 if (dlFileVersion != null) {
3158 return dlFileVersion;
3159 }
3160
3161 StringBundler msg = new StringBundler(6);
3162
3163 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3164
3165 msg.append("companyId=");
3166 msg.append(companyId);
3167
3168 msg.append(", status=");
3169 msg.append(status);
3170
3171 msg.append(StringPool.CLOSE_CURLY_BRACE);
3172
3173 throw new NoSuchFileVersionException(msg.toString());
3174 }
3175
3176
3184 @Override
3185 public DLFileVersion fetchByC_NotS_Last(long companyId, int status,
3186 OrderByComparator<DLFileVersion> orderByComparator) {
3187 int count = countByC_NotS(companyId, status);
3188
3189 if (count == 0) {
3190 return null;
3191 }
3192
3193 List<DLFileVersion> list = findByC_NotS(companyId, status, count - 1,
3194 count, orderByComparator);
3195
3196 if (!list.isEmpty()) {
3197 return list.get(0);
3198 }
3199
3200 return null;
3201 }
3202
3203
3213 @Override
3214 public DLFileVersion[] findByC_NotS_PrevAndNext(long fileVersionId,
3215 long companyId, int status,
3216 OrderByComparator<DLFileVersion> orderByComparator)
3217 throws NoSuchFileVersionException {
3218 DLFileVersion dlFileVersion = findByPrimaryKey(fileVersionId);
3219
3220 Session session = null;
3221
3222 try {
3223 session = openSession();
3224
3225 DLFileVersion[] array = new DLFileVersionImpl[3];
3226
3227 array[0] = getByC_NotS_PrevAndNext(session, dlFileVersion,
3228 companyId, status, orderByComparator, true);
3229
3230 array[1] = dlFileVersion;
3231
3232 array[2] = getByC_NotS_PrevAndNext(session, dlFileVersion,
3233 companyId, status, orderByComparator, false);
3234
3235 return array;
3236 }
3237 catch (Exception e) {
3238 throw processException(e);
3239 }
3240 finally {
3241 closeSession(session);
3242 }
3243 }
3244
3245 protected DLFileVersion getByC_NotS_PrevAndNext(Session session,
3246 DLFileVersion dlFileVersion, long companyId, int status,
3247 OrderByComparator<DLFileVersion> orderByComparator, boolean previous) {
3248 StringBundler query = null;
3249
3250 if (orderByComparator != null) {
3251 query = new StringBundler(6 +
3252 (orderByComparator.getOrderByFields().length * 6));
3253 }
3254 else {
3255 query = new StringBundler(3);
3256 }
3257
3258 query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
3259
3260 query.append(_FINDER_COLUMN_C_NOTS_COMPANYID_2);
3261
3262 query.append(_FINDER_COLUMN_C_NOTS_STATUS_2);
3263
3264 if (orderByComparator != null) {
3265 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3266
3267 if (orderByConditionFields.length > 0) {
3268 query.append(WHERE_AND);
3269 }
3270
3271 for (int i = 0; i < orderByConditionFields.length; i++) {
3272 query.append(_ORDER_BY_ENTITY_ALIAS);
3273 query.append(orderByConditionFields[i]);
3274
3275 if ((i + 1) < orderByConditionFields.length) {
3276 if (orderByComparator.isAscending() ^ previous) {
3277 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3278 }
3279 else {
3280 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3281 }
3282 }
3283 else {
3284 if (orderByComparator.isAscending() ^ previous) {
3285 query.append(WHERE_GREATER_THAN);
3286 }
3287 else {
3288 query.append(WHERE_LESSER_THAN);
3289 }
3290 }
3291 }
3292
3293 query.append(ORDER_BY_CLAUSE);
3294
3295 String[] orderByFields = orderByComparator.getOrderByFields();
3296
3297 for (int i = 0; i < orderByFields.length; i++) {
3298 query.append(_ORDER_BY_ENTITY_ALIAS);
3299 query.append(orderByFields[i]);
3300
3301 if ((i + 1) < orderByFields.length) {
3302 if (orderByComparator.isAscending() ^ previous) {
3303 query.append(ORDER_BY_ASC_HAS_NEXT);
3304 }
3305 else {
3306 query.append(ORDER_BY_DESC_HAS_NEXT);
3307 }
3308 }
3309 else {
3310 if (orderByComparator.isAscending() ^ previous) {
3311 query.append(ORDER_BY_ASC);
3312 }
3313 else {
3314 query.append(ORDER_BY_DESC);
3315 }
3316 }
3317 }
3318 }
3319 else {
3320 query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
3321 }
3322
3323 String sql = query.toString();
3324
3325 Query q = session.createQuery(sql);
3326
3327 q.setFirstResult(0);
3328 q.setMaxResults(2);
3329
3330 QueryPos qPos = QueryPos.getInstance(q);
3331
3332 qPos.add(companyId);
3333
3334 qPos.add(status);
3335
3336 if (orderByComparator != null) {
3337 Object[] values = orderByComparator.getOrderByConditionValues(dlFileVersion);
3338
3339 for (Object value : values) {
3340 qPos.add(value);
3341 }
3342 }
3343
3344 List<DLFileVersion> list = q.list();
3345
3346 if (list.size() == 2) {
3347 return list.get(1);
3348 }
3349 else {
3350 return null;
3351 }
3352 }
3353
3354
3360 @Override
3361 public void removeByC_NotS(long companyId, int status) {
3362 for (DLFileVersion dlFileVersion : findByC_NotS(companyId, status,
3363 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3364 remove(dlFileVersion);
3365 }
3366 }
3367
3368
3375 @Override
3376 public int countByC_NotS(long companyId, int status) {
3377 FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_NOTS;
3378
3379 Object[] finderArgs = new Object[] { companyId, status };
3380
3381 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3382 this);
3383
3384 if (count == null) {
3385 StringBundler query = new StringBundler(3);
3386
3387 query.append(_SQL_COUNT_DLFILEVERSION_WHERE);
3388
3389 query.append(_FINDER_COLUMN_C_NOTS_COMPANYID_2);
3390
3391 query.append(_FINDER_COLUMN_C_NOTS_STATUS_2);
3392
3393 String sql = query.toString();
3394
3395 Session session = null;
3396
3397 try {
3398 session = openSession();
3399
3400 Query q = session.createQuery(sql);
3401
3402 QueryPos qPos = QueryPos.getInstance(q);
3403
3404 qPos.add(companyId);
3405
3406 qPos.add(status);
3407
3408 count = (Long)q.uniqueResult();
3409
3410 FinderCacheUtil.putResult(finderPath, finderArgs, count);
3411 }
3412 catch (Exception e) {
3413 FinderCacheUtil.removeResult(finderPath, finderArgs);
3414
3415 throw processException(e);
3416 }
3417 finally {
3418 closeSession(session);
3419 }
3420 }
3421
3422 return count.intValue();
3423 }
3424
3425 private static final String _FINDER_COLUMN_C_NOTS_COMPANYID_2 = "dlFileVersion.companyId = ? AND ";
3426 private static final String _FINDER_COLUMN_C_NOTS_STATUS_2 = "dlFileVersion.status != ?";
3427 public static final FinderPath FINDER_PATH_FETCH_BY_F_V = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
3428 DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
3429 DLFileVersionImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByF_V",
3430 new String[] { Long.class.getName(), String.class.getName() },
3431 DLFileVersionModelImpl.FILEENTRYID_COLUMN_BITMASK |
3432 DLFileVersionModelImpl.VERSION_COLUMN_BITMASK);
3433 public static final FinderPath FINDER_PATH_COUNT_BY_F_V = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
3434 DLFileVersionModelImpl.FINDER_CACHE_ENABLED, Long.class,
3435 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByF_V",
3436 new String[] { Long.class.getName(), String.class.getName() });
3437
3438
3446 @Override
3447 public DLFileVersion findByF_V(long fileEntryId, String version)
3448 throws NoSuchFileVersionException {
3449 DLFileVersion dlFileVersion = fetchByF_V(fileEntryId, version);
3450
3451 if (dlFileVersion == null) {
3452 StringBundler msg = new StringBundler(6);
3453
3454 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3455
3456 msg.append("fileEntryId=");
3457 msg.append(fileEntryId);
3458
3459 msg.append(", version=");
3460 msg.append(version);
3461
3462 msg.append(StringPool.CLOSE_CURLY_BRACE);
3463
3464 if (_log.isWarnEnabled()) {
3465 _log.warn(msg.toString());
3466 }
3467
3468 throw new NoSuchFileVersionException(msg.toString());
3469 }
3470
3471 return dlFileVersion;
3472 }
3473
3474
3481 @Override
3482 public DLFileVersion fetchByF_V(long fileEntryId, String version) {
3483 return fetchByF_V(fileEntryId, version, true);
3484 }
3485
3486
3494 @Override
3495 public DLFileVersion fetchByF_V(long fileEntryId, String version,
3496 boolean retrieveFromCache) {
3497 Object[] finderArgs = new Object[] { fileEntryId, version };
3498
3499 Object result = null;
3500
3501 if (retrieveFromCache) {
3502 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_F_V,
3503 finderArgs, this);
3504 }
3505
3506 if (result instanceof DLFileVersion) {
3507 DLFileVersion dlFileVersion = (DLFileVersion)result;
3508
3509 if ((fileEntryId != dlFileVersion.getFileEntryId()) ||
3510 !Validator.equals(version, dlFileVersion.getVersion())) {
3511 result = null;
3512 }
3513 }
3514
3515 if (result == null) {
3516 StringBundler query = new StringBundler(4);
3517
3518 query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
3519
3520 query.append(_FINDER_COLUMN_F_V_FILEENTRYID_2);
3521
3522 boolean bindVersion = false;
3523
3524 if (version == null) {
3525 query.append(_FINDER_COLUMN_F_V_VERSION_1);
3526 }
3527 else if (version.equals(StringPool.BLANK)) {
3528 query.append(_FINDER_COLUMN_F_V_VERSION_3);
3529 }
3530 else {
3531 bindVersion = true;
3532
3533 query.append(_FINDER_COLUMN_F_V_VERSION_2);
3534 }
3535
3536 String sql = query.toString();
3537
3538 Session session = null;
3539
3540 try {
3541 session = openSession();
3542
3543 Query q = session.createQuery(sql);
3544
3545 QueryPos qPos = QueryPos.getInstance(q);
3546
3547 qPos.add(fileEntryId);
3548
3549 if (bindVersion) {
3550 qPos.add(version);
3551 }
3552
3553 List<DLFileVersion> list = q.list();
3554
3555 if (list.isEmpty()) {
3556 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_F_V,
3557 finderArgs, list);
3558 }
3559 else {
3560 DLFileVersion dlFileVersion = list.get(0);
3561
3562 result = dlFileVersion;
3563
3564 cacheResult(dlFileVersion);
3565
3566 if ((dlFileVersion.getFileEntryId() != fileEntryId) ||
3567 (dlFileVersion.getVersion() == null) ||
3568 !dlFileVersion.getVersion().equals(version)) {
3569 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_F_V,
3570 finderArgs, dlFileVersion);
3571 }
3572 }
3573 }
3574 catch (Exception e) {
3575 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_F_V,
3576 finderArgs);
3577
3578 throw processException(e);
3579 }
3580 finally {
3581 closeSession(session);
3582 }
3583 }
3584
3585 if (result instanceof List<?>) {
3586 return null;
3587 }
3588 else {
3589 return (DLFileVersion)result;
3590 }
3591 }
3592
3593
3600 @Override
3601 public DLFileVersion removeByF_V(long fileEntryId, String version)
3602 throws NoSuchFileVersionException {
3603 DLFileVersion dlFileVersion = findByF_V(fileEntryId, version);
3604
3605 return remove(dlFileVersion);
3606 }
3607
3608
3615 @Override
3616 public int countByF_V(long fileEntryId, String version) {
3617 FinderPath finderPath = FINDER_PATH_COUNT_BY_F_V;
3618
3619 Object[] finderArgs = new Object[] { fileEntryId, version };
3620
3621 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3622 this);
3623
3624 if (count == null) {
3625 StringBundler query = new StringBundler(3);
3626
3627 query.append(_SQL_COUNT_DLFILEVERSION_WHERE);
3628
3629 query.append(_FINDER_COLUMN_F_V_FILEENTRYID_2);
3630
3631 boolean bindVersion = false;
3632
3633 if (version == null) {
3634 query.append(_FINDER_COLUMN_F_V_VERSION_1);
3635 }
3636 else if (version.equals(StringPool.BLANK)) {
3637 query.append(_FINDER_COLUMN_F_V_VERSION_3);
3638 }
3639 else {
3640 bindVersion = true;
3641
3642 query.append(_FINDER_COLUMN_F_V_VERSION_2);
3643 }
3644
3645 String sql = query.toString();
3646
3647 Session session = null;
3648
3649 try {
3650 session = openSession();
3651
3652 Query q = session.createQuery(sql);
3653
3654 QueryPos qPos = QueryPos.getInstance(q);
3655
3656 qPos.add(fileEntryId);
3657
3658 if (bindVersion) {
3659 qPos.add(version);
3660 }
3661
3662 count = (Long)q.uniqueResult();
3663
3664 FinderCacheUtil.putResult(finderPath, finderArgs, count);
3665 }
3666 catch (Exception e) {
3667 FinderCacheUtil.removeResult(finderPath, finderArgs);
3668
3669 throw processException(e);
3670 }
3671 finally {
3672 closeSession(session);
3673 }
3674 }
3675
3676 return count.intValue();
3677 }
3678
3679 private static final String _FINDER_COLUMN_F_V_FILEENTRYID_2 = "dlFileVersion.fileEntryId = ? AND ";
3680 private static final String _FINDER_COLUMN_F_V_VERSION_1 = "dlFileVersion.version IS NULL";
3681 private static final String _FINDER_COLUMN_F_V_VERSION_2 = "dlFileVersion.version = ?";
3682 private static final String _FINDER_COLUMN_F_V_VERSION_3 = "(dlFileVersion.version IS NULL OR dlFileVersion.version = '')";
3683 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_F_S = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
3684 DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
3685 DLFileVersionImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
3686 "findByF_S",
3687 new String[] {
3688 Long.class.getName(), Integer.class.getName(),
3689
3690 Integer.class.getName(), Integer.class.getName(),
3691 OrderByComparator.class.getName()
3692 });
3693 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_F_S = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
3694 DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
3695 DLFileVersionImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
3696 "findByF_S",
3697 new String[] { Long.class.getName(), Integer.class.getName() },
3698 DLFileVersionModelImpl.FILEENTRYID_COLUMN_BITMASK |
3699 DLFileVersionModelImpl.STATUS_COLUMN_BITMASK |
3700 DLFileVersionModelImpl.CREATEDATE_COLUMN_BITMASK);
3701 public static final FinderPath FINDER_PATH_COUNT_BY_F_S = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
3702 DLFileVersionModelImpl.FINDER_CACHE_ENABLED, Long.class,
3703 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByF_S",
3704 new String[] { Long.class.getName(), Integer.class.getName() });
3705
3706
3713 @Override
3714 public List<DLFileVersion> findByF_S(long fileEntryId, int status) {
3715 return findByF_S(fileEntryId, status, QueryUtil.ALL_POS,
3716 QueryUtil.ALL_POS, null);
3717 }
3718
3719
3732 @Override
3733 public List<DLFileVersion> findByF_S(long fileEntryId, int status,
3734 int start, int end) {
3735 return findByF_S(fileEntryId, status, start, end, null);
3736 }
3737
3738
3752 @Override
3753 public List<DLFileVersion> findByF_S(long fileEntryId, int status,
3754 int start, int end, OrderByComparator<DLFileVersion> orderByComparator) {
3755 boolean pagination = true;
3756 FinderPath finderPath = null;
3757 Object[] finderArgs = null;
3758
3759 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3760 (orderByComparator == null)) {
3761 pagination = false;
3762 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_F_S;
3763 finderArgs = new Object[] { fileEntryId, status };
3764 }
3765 else {
3766 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_F_S;
3767 finderArgs = new Object[] {
3768 fileEntryId, status,
3769
3770 start, end, orderByComparator
3771 };
3772 }
3773
3774 List<DLFileVersion> list = (List<DLFileVersion>)FinderCacheUtil.getResult(finderPath,
3775 finderArgs, this);
3776
3777 if ((list != null) && !list.isEmpty()) {
3778 for (DLFileVersion dlFileVersion : list) {
3779 if ((fileEntryId != dlFileVersion.getFileEntryId()) ||
3780 (status != dlFileVersion.getStatus())) {
3781 list = null;
3782
3783 break;
3784 }
3785 }
3786 }
3787
3788 if (list == null) {
3789 StringBundler query = null;
3790
3791 if (orderByComparator != null) {
3792 query = new StringBundler(4 +
3793 (orderByComparator.getOrderByFields().length * 3));
3794 }
3795 else {
3796 query = new StringBundler(4);
3797 }
3798
3799 query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
3800
3801 query.append(_FINDER_COLUMN_F_S_FILEENTRYID_2);
3802
3803 query.append(_FINDER_COLUMN_F_S_STATUS_2);
3804
3805 if (orderByComparator != null) {
3806 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3807 orderByComparator);
3808 }
3809 else
3810 if (pagination) {
3811 query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
3812 }
3813
3814 String sql = query.toString();
3815
3816 Session session = null;
3817
3818 try {
3819 session = openSession();
3820
3821 Query q = session.createQuery(sql);
3822
3823 QueryPos qPos = QueryPos.getInstance(q);
3824
3825 qPos.add(fileEntryId);
3826
3827 qPos.add(status);
3828
3829 if (!pagination) {
3830 list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
3831 start, end, false);
3832
3833 Collections.sort(list);
3834
3835 list = Collections.unmodifiableList(list);
3836 }
3837 else {
3838 list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
3839 start, end);
3840 }
3841
3842 cacheResult(list);
3843
3844 FinderCacheUtil.putResult(finderPath, finderArgs, list);
3845 }
3846 catch (Exception e) {
3847 FinderCacheUtil.removeResult(finderPath, finderArgs);
3848
3849 throw processException(e);
3850 }
3851 finally {
3852 closeSession(session);
3853 }
3854 }
3855
3856 return list;
3857 }
3858
3859
3868 @Override
3869 public DLFileVersion findByF_S_First(long fileEntryId, int status,
3870 OrderByComparator<DLFileVersion> orderByComparator)
3871 throws NoSuchFileVersionException {
3872 DLFileVersion dlFileVersion = fetchByF_S_First(fileEntryId, status,
3873 orderByComparator);
3874
3875 if (dlFileVersion != null) {
3876 return dlFileVersion;
3877 }
3878
3879 StringBundler msg = new StringBundler(6);
3880
3881 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3882
3883 msg.append("fileEntryId=");
3884 msg.append(fileEntryId);
3885
3886 msg.append(", status=");
3887 msg.append(status);
3888
3889 msg.append(StringPool.CLOSE_CURLY_BRACE);
3890
3891 throw new NoSuchFileVersionException(msg.toString());
3892 }
3893
3894
3902 @Override
3903 public DLFileVersion fetchByF_S_First(long fileEntryId, int status,
3904 OrderByComparator<DLFileVersion> orderByComparator) {
3905 List<DLFileVersion> list = findByF_S(fileEntryId, status, 0, 1,
3906 orderByComparator);
3907
3908 if (!list.isEmpty()) {
3909 return list.get(0);
3910 }
3911
3912 return null;
3913 }
3914
3915
3924 @Override
3925 public DLFileVersion findByF_S_Last(long fileEntryId, int status,
3926 OrderByComparator<DLFileVersion> orderByComparator)
3927 throws NoSuchFileVersionException {
3928 DLFileVersion dlFileVersion = fetchByF_S_Last(fileEntryId, status,
3929 orderByComparator);
3930
3931 if (dlFileVersion != null) {
3932 return dlFileVersion;
3933 }
3934
3935 StringBundler msg = new StringBundler(6);
3936
3937 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3938
3939 msg.append("fileEntryId=");
3940 msg.append(fileEntryId);
3941
3942 msg.append(", status=");
3943 msg.append(status);
3944
3945 msg.append(StringPool.CLOSE_CURLY_BRACE);
3946
3947 throw new NoSuchFileVersionException(msg.toString());
3948 }
3949
3950
3958 @Override
3959 public DLFileVersion fetchByF_S_Last(long fileEntryId, int status,
3960 OrderByComparator<DLFileVersion> orderByComparator) {
3961 int count = countByF_S(fileEntryId, status);
3962
3963 if (count == 0) {
3964 return null;
3965 }
3966
3967 List<DLFileVersion> list = findByF_S(fileEntryId, status, count - 1,
3968 count, orderByComparator);
3969
3970 if (!list.isEmpty()) {
3971 return list.get(0);
3972 }
3973
3974 return null;
3975 }
3976
3977
3987 @Override
3988 public DLFileVersion[] findByF_S_PrevAndNext(long fileVersionId,
3989 long fileEntryId, int status,
3990 OrderByComparator<DLFileVersion> orderByComparator)
3991 throws NoSuchFileVersionException {
3992 DLFileVersion dlFileVersion = findByPrimaryKey(fileVersionId);
3993
3994 Session session = null;
3995
3996 try {
3997 session = openSession();
3998
3999 DLFileVersion[] array = new DLFileVersionImpl[3];
4000
4001 array[0] = getByF_S_PrevAndNext(session, dlFileVersion,
4002 fileEntryId, status, orderByComparator, true);
4003
4004 array[1] = dlFileVersion;
4005
4006 array[2] = getByF_S_PrevAndNext(session, dlFileVersion,
4007 fileEntryId, status, orderByComparator, false);
4008
4009 return array;
4010 }
4011 catch (Exception e) {
4012 throw processException(e);
4013 }
4014 finally {
4015 closeSession(session);
4016 }
4017 }
4018
4019 protected DLFileVersion getByF_S_PrevAndNext(Session session,
4020 DLFileVersion dlFileVersion, long fileEntryId, int status,
4021 OrderByComparator<DLFileVersion> orderByComparator, boolean previous) {
4022 StringBundler query = null;
4023
4024 if (orderByComparator != null) {
4025 query = new StringBundler(6 +
4026 (orderByComparator.getOrderByFields().length * 6));
4027 }
4028 else {
4029 query = new StringBundler(3);
4030 }
4031
4032 query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
4033
4034 query.append(_FINDER_COLUMN_F_S_FILEENTRYID_2);
4035
4036 query.append(_FINDER_COLUMN_F_S_STATUS_2);
4037
4038 if (orderByComparator != null) {
4039 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4040
4041 if (orderByConditionFields.length > 0) {
4042 query.append(WHERE_AND);
4043 }
4044
4045 for (int i = 0; i < orderByConditionFields.length; i++) {
4046 query.append(_ORDER_BY_ENTITY_ALIAS);
4047 query.append(orderByConditionFields[i]);
4048
4049 if ((i + 1) < orderByConditionFields.length) {
4050 if (orderByComparator.isAscending() ^ previous) {
4051 query.append(WHERE_GREATER_THAN_HAS_NEXT);
4052 }
4053 else {
4054 query.append(WHERE_LESSER_THAN_HAS_NEXT);
4055 }
4056 }
4057 else {
4058 if (orderByComparator.isAscending() ^ previous) {
4059 query.append(WHERE_GREATER_THAN);
4060 }
4061 else {
4062 query.append(WHERE_LESSER_THAN);
4063 }
4064 }
4065 }
4066
4067 query.append(ORDER_BY_CLAUSE);
4068
4069 String[] orderByFields = orderByComparator.getOrderByFields();
4070
4071 for (int i = 0; i < orderByFields.length; i++) {
4072 query.append(_ORDER_BY_ENTITY_ALIAS);
4073 query.append(orderByFields[i]);
4074
4075 if ((i + 1) < orderByFields.length) {
4076 if (orderByComparator.isAscending() ^ previous) {
4077 query.append(ORDER_BY_ASC_HAS_NEXT);
4078 }
4079 else {
4080 query.append(ORDER_BY_DESC_HAS_NEXT);
4081 }
4082 }
4083 else {
4084 if (orderByComparator.isAscending() ^ previous) {
4085 query.append(ORDER_BY_ASC);
4086 }
4087 else {
4088 query.append(ORDER_BY_DESC);
4089 }
4090 }
4091 }
4092 }
4093 else {
4094 query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
4095 }
4096
4097 String sql = query.toString();
4098
4099 Query q = session.createQuery(sql);
4100
4101 q.setFirstResult(0);
4102 q.setMaxResults(2);
4103
4104 QueryPos qPos = QueryPos.getInstance(q);
4105
4106 qPos.add(fileEntryId);
4107
4108 qPos.add(status);
4109
4110 if (orderByComparator != null) {
4111 Object[] values = orderByComparator.getOrderByConditionValues(dlFileVersion);
4112
4113 for (Object value : values) {
4114 qPos.add(value);
4115 }
4116 }
4117
4118 List<DLFileVersion> list = q.list();
4119
4120 if (list.size() == 2) {
4121 return list.get(1);
4122 }
4123 else {
4124 return null;
4125 }
4126 }
4127
4128
4134 @Override
4135 public void removeByF_S(long fileEntryId, int status) {
4136 for (DLFileVersion dlFileVersion : findByF_S(fileEntryId, status,
4137 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4138 remove(dlFileVersion);
4139 }
4140 }
4141
4142
4149 @Override
4150 public int countByF_S(long fileEntryId, int status) {
4151 FinderPath finderPath = FINDER_PATH_COUNT_BY_F_S;
4152
4153 Object[] finderArgs = new Object[] { fileEntryId, status };
4154
4155 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4156 this);
4157
4158 if (count == null) {
4159 StringBundler query = new StringBundler(3);
4160
4161 query.append(_SQL_COUNT_DLFILEVERSION_WHERE);
4162
4163 query.append(_FINDER_COLUMN_F_S_FILEENTRYID_2);
4164
4165 query.append(_FINDER_COLUMN_F_S_STATUS_2);
4166
4167 String sql = query.toString();
4168
4169 Session session = null;
4170
4171 try {
4172 session = openSession();
4173
4174 Query q = session.createQuery(sql);
4175
4176 QueryPos qPos = QueryPos.getInstance(q);
4177
4178 qPos.add(fileEntryId);
4179
4180 qPos.add(status);
4181
4182 count = (Long)q.uniqueResult();
4183
4184 FinderCacheUtil.putResult(finderPath, finderArgs, count);
4185 }
4186 catch (Exception e) {
4187 FinderCacheUtil.removeResult(finderPath, finderArgs);
4188
4189 throw processException(e);
4190 }
4191 finally {
4192 closeSession(session);
4193 }
4194 }
4195
4196 return count.intValue();
4197 }
4198
4199 private static final String _FINDER_COLUMN_F_S_FILEENTRYID_2 = "dlFileVersion.fileEntryId = ? AND ";
4200 private static final String _FINDER_COLUMN_F_S_STATUS_2 = "dlFileVersion.status = ?";
4201 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_F_S = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
4202 DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
4203 DLFileVersionImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
4204 "findByG_F_S",
4205 new String[] {
4206 Long.class.getName(), Long.class.getName(),
4207 Integer.class.getName(),
4208
4209 Integer.class.getName(), Integer.class.getName(),
4210 OrderByComparator.class.getName()
4211 });
4212 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_F_S = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
4213 DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
4214 DLFileVersionImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
4215 "findByG_F_S",
4216 new String[] {
4217 Long.class.getName(), Long.class.getName(),
4218 Integer.class.getName()
4219 },
4220 DLFileVersionModelImpl.GROUPID_COLUMN_BITMASK |
4221 DLFileVersionModelImpl.FOLDERID_COLUMN_BITMASK |
4222 DLFileVersionModelImpl.STATUS_COLUMN_BITMASK |
4223 DLFileVersionModelImpl.FILEENTRYID_COLUMN_BITMASK |
4224 DLFileVersionModelImpl.CREATEDATE_COLUMN_BITMASK);
4225 public static final FinderPath FINDER_PATH_COUNT_BY_G_F_S = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
4226 DLFileVersionModelImpl.FINDER_CACHE_ENABLED, Long.class,
4227 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_F_S",
4228 new String[] {
4229 Long.class.getName(), Long.class.getName(),
4230 Integer.class.getName()
4231 });
4232
4233
4241 @Override
4242 public List<DLFileVersion> findByG_F_S(long groupId, long folderId,
4243 int status) {
4244 return findByG_F_S(groupId, folderId, status, QueryUtil.ALL_POS,
4245 QueryUtil.ALL_POS, null);
4246 }
4247
4248
4262 @Override
4263 public List<DLFileVersion> findByG_F_S(long groupId, long folderId,
4264 int status, int start, int end) {
4265 return findByG_F_S(groupId, folderId, status, start, end, null);
4266 }
4267
4268
4283 @Override
4284 public List<DLFileVersion> findByG_F_S(long groupId, long folderId,
4285 int status, int start, int end,
4286 OrderByComparator<DLFileVersion> orderByComparator) {
4287 boolean pagination = true;
4288 FinderPath finderPath = null;
4289 Object[] finderArgs = null;
4290
4291 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4292 (orderByComparator == null)) {
4293 pagination = false;
4294 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_F_S;
4295 finderArgs = new Object[] { groupId, folderId, status };
4296 }
4297 else {
4298 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_F_S;
4299 finderArgs = new Object[] {
4300 groupId, folderId, status,
4301
4302 start, end, orderByComparator
4303 };
4304 }
4305
4306 List<DLFileVersion> list = (List<DLFileVersion>)FinderCacheUtil.getResult(finderPath,
4307 finderArgs, this);
4308
4309 if ((list != null) && !list.isEmpty()) {
4310 for (DLFileVersion dlFileVersion : list) {
4311 if ((groupId != dlFileVersion.getGroupId()) ||
4312 (folderId != dlFileVersion.getFolderId()) ||
4313 (status != dlFileVersion.getStatus())) {
4314 list = null;
4315
4316 break;
4317 }
4318 }
4319 }
4320
4321 if (list == null) {
4322 StringBundler query = null;
4323
4324 if (orderByComparator != null) {
4325 query = new StringBundler(5 +
4326 (orderByComparator.getOrderByFields().length * 3));
4327 }
4328 else {
4329 query = new StringBundler(5);
4330 }
4331
4332 query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
4333
4334 query.append(_FINDER_COLUMN_G_F_S_GROUPID_2);
4335
4336 query.append(_FINDER_COLUMN_G_F_S_FOLDERID_2);
4337
4338 query.append(_FINDER_COLUMN_G_F_S_STATUS_2);
4339
4340 if (orderByComparator != null) {
4341 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4342 orderByComparator);
4343 }
4344 else
4345 if (pagination) {
4346 query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
4347 }
4348
4349 String sql = query.toString();
4350
4351 Session session = null;
4352
4353 try {
4354 session = openSession();
4355
4356 Query q = session.createQuery(sql);
4357
4358 QueryPos qPos = QueryPos.getInstance(q);
4359
4360 qPos.add(groupId);
4361
4362 qPos.add(folderId);
4363
4364 qPos.add(status);
4365
4366 if (!pagination) {
4367 list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
4368 start, end, false);
4369
4370 Collections.sort(list);
4371
4372 list = Collections.unmodifiableList(list);
4373 }
4374 else {
4375 list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
4376 start, end);
4377 }
4378
4379 cacheResult(list);
4380
4381 FinderCacheUtil.putResult(finderPath, finderArgs, list);
4382 }
4383 catch (Exception e) {
4384 FinderCacheUtil.removeResult(finderPath, finderArgs);
4385
4386 throw processException(e);
4387 }
4388 finally {
4389 closeSession(session);
4390 }
4391 }
4392
4393 return list;
4394 }
4395
4396
4406 @Override
4407 public DLFileVersion findByG_F_S_First(long groupId, long folderId,
4408 int status, OrderByComparator<DLFileVersion> orderByComparator)
4409 throws NoSuchFileVersionException {
4410 DLFileVersion dlFileVersion = fetchByG_F_S_First(groupId, folderId,
4411 status, orderByComparator);
4412
4413 if (dlFileVersion != null) {
4414 return dlFileVersion;
4415 }
4416
4417 StringBundler msg = new StringBundler(8);
4418
4419 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4420
4421 msg.append("groupId=");
4422 msg.append(groupId);
4423
4424 msg.append(", folderId=");
4425 msg.append(folderId);
4426
4427 msg.append(", status=");
4428 msg.append(status);
4429
4430 msg.append(StringPool.CLOSE_CURLY_BRACE);
4431
4432 throw new NoSuchFileVersionException(msg.toString());
4433 }
4434
4435
4444 @Override
4445 public DLFileVersion fetchByG_F_S_First(long groupId, long folderId,
4446 int status, OrderByComparator<DLFileVersion> orderByComparator) {
4447 List<DLFileVersion> list = findByG_F_S(groupId, folderId, status, 0, 1,
4448 orderByComparator);
4449
4450 if (!list.isEmpty()) {
4451 return list.get(0);
4452 }
4453
4454 return null;
4455 }
4456
4457
4467 @Override
4468 public DLFileVersion findByG_F_S_Last(long groupId, long folderId,
4469 int status, OrderByComparator<DLFileVersion> orderByComparator)
4470 throws NoSuchFileVersionException {
4471 DLFileVersion dlFileVersion = fetchByG_F_S_Last(groupId, folderId,
4472 status, orderByComparator);
4473
4474 if (dlFileVersion != null) {
4475 return dlFileVersion;
4476 }
4477
4478 StringBundler msg = new StringBundler(8);
4479
4480 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4481
4482 msg.append("groupId=");
4483 msg.append(groupId);
4484
4485 msg.append(", folderId=");
4486 msg.append(folderId);
4487
4488 msg.append(", status=");
4489 msg.append(status);
4490
4491 msg.append(StringPool.CLOSE_CURLY_BRACE);
4492
4493 throw new NoSuchFileVersionException(msg.toString());
4494 }
4495
4496
4505 @Override
4506 public DLFileVersion fetchByG_F_S_Last(long groupId, long folderId,
4507 int status, OrderByComparator<DLFileVersion> orderByComparator) {
4508 int count = countByG_F_S(groupId, folderId, status);
4509
4510 if (count == 0) {
4511 return null;
4512 }
4513
4514 List<DLFileVersion> list = findByG_F_S(groupId, folderId, status,
4515 count - 1, count, orderByComparator);
4516
4517 if (!list.isEmpty()) {
4518 return list.get(0);
4519 }
4520
4521 return null;
4522 }
4523
4524
4535 @Override
4536 public DLFileVersion[] findByG_F_S_PrevAndNext(long fileVersionId,
4537 long groupId, long folderId, int status,
4538 OrderByComparator<DLFileVersion> orderByComparator)
4539 throws NoSuchFileVersionException {
4540 DLFileVersion dlFileVersion = findByPrimaryKey(fileVersionId);
4541
4542 Session session = null;
4543
4544 try {
4545 session = openSession();
4546
4547 DLFileVersion[] array = new DLFileVersionImpl[3];
4548
4549 array[0] = getByG_F_S_PrevAndNext(session, dlFileVersion, groupId,
4550 folderId, status, orderByComparator, true);
4551
4552 array[1] = dlFileVersion;
4553
4554 array[2] = getByG_F_S_PrevAndNext(session, dlFileVersion, groupId,
4555 folderId, status, orderByComparator, false);
4556
4557 return array;
4558 }
4559 catch (Exception e) {
4560 throw processException(e);
4561 }
4562 finally {
4563 closeSession(session);
4564 }
4565 }
4566
4567 protected DLFileVersion getByG_F_S_PrevAndNext(Session session,
4568 DLFileVersion dlFileVersion, long groupId, long folderId, int status,
4569 OrderByComparator<DLFileVersion> orderByComparator, boolean previous) {
4570 StringBundler query = null;
4571
4572 if (orderByComparator != null) {
4573 query = new StringBundler(6 +
4574 (orderByComparator.getOrderByFields().length * 6));
4575 }
4576 else {
4577 query = new StringBundler(3);
4578 }
4579
4580 query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
4581
4582 query.append(_FINDER_COLUMN_G_F_S_GROUPID_2);
4583
4584 query.append(_FINDER_COLUMN_G_F_S_FOLDERID_2);
4585
4586 query.append(_FINDER_COLUMN_G_F_S_STATUS_2);
4587
4588 if (orderByComparator != null) {
4589 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4590
4591 if (orderByConditionFields.length > 0) {
4592 query.append(WHERE_AND);
4593 }
4594
4595 for (int i = 0; i < orderByConditionFields.length; i++) {
4596 query.append(_ORDER_BY_ENTITY_ALIAS);
4597 query.append(orderByConditionFields[i]);
4598
4599 if ((i + 1) < orderByConditionFields.length) {
4600 if (orderByComparator.isAscending() ^ previous) {
4601 query.append(WHERE_GREATER_THAN_HAS_NEXT);
4602 }
4603 else {
4604 query.append(WHERE_LESSER_THAN_HAS_NEXT);
4605 }
4606 }
4607 else {
4608 if (orderByComparator.isAscending() ^ previous) {
4609 query.append(WHERE_GREATER_THAN);
4610 }
4611 else {
4612 query.append(WHERE_LESSER_THAN);
4613 }
4614 }
4615 }
4616
4617 query.append(ORDER_BY_CLAUSE);
4618
4619 String[] orderByFields = orderByComparator.getOrderByFields();
4620
4621 for (int i = 0; i < orderByFields.length; i++) {
4622 query.append(_ORDER_BY_ENTITY_ALIAS);
4623 query.append(orderByFields[i]);
4624
4625 if ((i + 1) < orderByFields.length) {
4626 if (orderByComparator.isAscending() ^ previous) {
4627 query.append(ORDER_BY_ASC_HAS_NEXT);
4628 }
4629 else {
4630 query.append(ORDER_BY_DESC_HAS_NEXT);
4631 }
4632 }
4633 else {
4634 if (orderByComparator.isAscending() ^ previous) {
4635 query.append(ORDER_BY_ASC);
4636 }
4637 else {
4638 query.append(ORDER_BY_DESC);
4639 }
4640 }
4641 }
4642 }
4643 else {
4644 query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
4645 }
4646
4647 String sql = query.toString();
4648
4649 Query q = session.createQuery(sql);
4650
4651 q.setFirstResult(0);
4652 q.setMaxResults(2);
4653
4654 QueryPos qPos = QueryPos.getInstance(q);
4655
4656 qPos.add(groupId);
4657
4658 qPos.add(folderId);
4659
4660 qPos.add(status);
4661
4662 if (orderByComparator != null) {
4663 Object[] values = orderByComparator.getOrderByConditionValues(dlFileVersion);
4664
4665 for (Object value : values) {
4666 qPos.add(value);
4667 }
4668 }
4669
4670 List<DLFileVersion> list = q.list();
4671
4672 if (list.size() == 2) {
4673 return list.get(1);
4674 }
4675 else {
4676 return null;
4677 }
4678 }
4679
4680
4687 @Override
4688 public void removeByG_F_S(long groupId, long folderId, int status) {
4689 for (DLFileVersion dlFileVersion : findByG_F_S(groupId, folderId,
4690 status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4691 remove(dlFileVersion);
4692 }
4693 }
4694
4695
4703 @Override
4704 public int countByG_F_S(long groupId, long folderId, int status) {
4705 FinderPath finderPath = FINDER_PATH_COUNT_BY_G_F_S;
4706
4707 Object[] finderArgs = new Object[] { groupId, folderId, status };
4708
4709 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4710 this);
4711
4712 if (count == null) {
4713 StringBundler query = new StringBundler(4);
4714
4715 query.append(_SQL_COUNT_DLFILEVERSION_WHERE);
4716
4717 query.append(_FINDER_COLUMN_G_F_S_GROUPID_2);
4718
4719 query.append(_FINDER_COLUMN_G_F_S_FOLDERID_2);
4720
4721 query.append(_FINDER_COLUMN_G_F_S_STATUS_2);
4722
4723 String sql = query.toString();
4724
4725 Session session = null;
4726
4727 try {
4728 session = openSession();
4729
4730 Query q = session.createQuery(sql);
4731
4732 QueryPos qPos = QueryPos.getInstance(q);
4733
4734 qPos.add(groupId);
4735
4736 qPos.add(folderId);
4737
4738 qPos.add(status);
4739
4740 count = (Long)q.uniqueResult();
4741
4742 FinderCacheUtil.putResult(finderPath, finderArgs, count);
4743 }
4744 catch (Exception e) {
4745 FinderCacheUtil.removeResult(finderPath, finderArgs);
4746
4747 throw processException(e);
4748 }
4749 finally {
4750 closeSession(session);
4751 }
4752 }
4753
4754 return count.intValue();
4755 }
4756
4757 private static final String _FINDER_COLUMN_G_F_S_GROUPID_2 = "dlFileVersion.groupId = ? AND ";
4758 private static final String _FINDER_COLUMN_G_F_S_FOLDERID_2 = "dlFileVersion.folderId = ? AND ";
4759 private static final String _FINDER_COLUMN_G_F_S_STATUS_2 = "dlFileVersion.status = ?";
4760 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_F_T_V = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
4761 DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
4762 DLFileVersionImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
4763 "findByG_F_T_V",
4764 new String[] {
4765 Long.class.getName(), Long.class.getName(),
4766 String.class.getName(), String.class.getName(),
4767
4768 Integer.class.getName(), Integer.class.getName(),
4769 OrderByComparator.class.getName()
4770 });
4771 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_F_T_V =
4772 new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
4773 DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
4774 DLFileVersionImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
4775 "findByG_F_T_V",
4776 new String[] {
4777 Long.class.getName(), Long.class.getName(),
4778 String.class.getName(), String.class.getName()
4779 },
4780 DLFileVersionModelImpl.GROUPID_COLUMN_BITMASK |
4781 DLFileVersionModelImpl.FOLDERID_COLUMN_BITMASK |
4782 DLFileVersionModelImpl.TITLE_COLUMN_BITMASK |
4783 DLFileVersionModelImpl.VERSION_COLUMN_BITMASK |
4784 DLFileVersionModelImpl.FILEENTRYID_COLUMN_BITMASK |
4785 DLFileVersionModelImpl.CREATEDATE_COLUMN_BITMASK);
4786 public static final FinderPath FINDER_PATH_COUNT_BY_G_F_T_V = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
4787 DLFileVersionModelImpl.FINDER_CACHE_ENABLED, Long.class,
4788 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_F_T_V",
4789 new String[] {
4790 Long.class.getName(), Long.class.getName(),
4791 String.class.getName(), String.class.getName()
4792 });
4793
4794
4803 @Override
4804 public List<DLFileVersion> findByG_F_T_V(long groupId, long folderId,
4805 String title, String version) {
4806 return findByG_F_T_V(groupId, folderId, title, version,
4807 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
4808 }
4809
4810
4825 @Override
4826 public List<DLFileVersion> findByG_F_T_V(long groupId, long folderId,
4827 String title, String version, int start, int end) {
4828 return findByG_F_T_V(groupId, folderId, title, version, start, end, null);
4829 }
4830
4831
4847 @Override
4848 public List<DLFileVersion> findByG_F_T_V(long groupId, long folderId,
4849 String title, String version, int start, int end,
4850 OrderByComparator<DLFileVersion> orderByComparator) {
4851 boolean pagination = true;
4852 FinderPath finderPath = null;
4853 Object[] finderArgs = null;
4854
4855 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4856 (orderByComparator == null)) {
4857 pagination = false;
4858 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_F_T_V;
4859 finderArgs = new Object[] { groupId, folderId, title, version };
4860 }
4861 else {
4862 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_F_T_V;
4863 finderArgs = new Object[] {
4864 groupId, folderId, title, version,
4865
4866 start, end, orderByComparator
4867 };
4868 }
4869
4870 List<DLFileVersion> list = (List<DLFileVersion>)FinderCacheUtil.getResult(finderPath,
4871 finderArgs, this);
4872
4873 if ((list != null) && !list.isEmpty()) {
4874 for (DLFileVersion dlFileVersion : list) {
4875 if ((groupId != dlFileVersion.getGroupId()) ||
4876 (folderId != dlFileVersion.getFolderId()) ||
4877 !Validator.equals(title, dlFileVersion.getTitle()) ||
4878 !Validator.equals(version, dlFileVersion.getVersion())) {
4879 list = null;
4880
4881 break;
4882 }
4883 }
4884 }
4885
4886 if (list == null) {
4887 StringBundler query = null;
4888
4889 if (orderByComparator != null) {
4890 query = new StringBundler(6 +
4891 (orderByComparator.getOrderByFields().length * 3));
4892 }
4893 else {
4894 query = new StringBundler(6);
4895 }
4896
4897 query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
4898
4899 query.append(_FINDER_COLUMN_G_F_T_V_GROUPID_2);
4900
4901 query.append(_FINDER_COLUMN_G_F_T_V_FOLDERID_2);
4902
4903 boolean bindTitle = false;
4904
4905 if (title == null) {
4906 query.append(_FINDER_COLUMN_G_F_T_V_TITLE_1);
4907 }
4908 else if (title.equals(StringPool.BLANK)) {
4909 query.append(_FINDER_COLUMN_G_F_T_V_TITLE_3);
4910 }
4911 else {
4912 bindTitle = true;
4913
4914 query.append(_FINDER_COLUMN_G_F_T_V_TITLE_2);
4915 }
4916
4917 boolean bindVersion = false;
4918
4919 if (version == null) {
4920 query.append(_FINDER_COLUMN_G_F_T_V_VERSION_1);
4921 }
4922 else if (version.equals(StringPool.BLANK)) {
4923 query.append(_FINDER_COLUMN_G_F_T_V_VERSION_3);
4924 }
4925 else {
4926 bindVersion = true;
4927
4928 query.append(_FINDER_COLUMN_G_F_T_V_VERSION_2);
4929 }
4930
4931 if (orderByComparator != null) {
4932 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4933 orderByComparator);
4934 }
4935 else
4936 if (pagination) {
4937 query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
4938 }
4939
4940 String sql = query.toString();
4941
4942 Session session = null;
4943
4944 try {
4945 session = openSession();
4946
4947 Query q = session.createQuery(sql);
4948
4949 QueryPos qPos = QueryPos.getInstance(q);
4950
4951 qPos.add(groupId);
4952
4953 qPos.add(folderId);
4954
4955 if (bindTitle) {
4956 qPos.add(title);
4957 }
4958
4959 if (bindVersion) {
4960 qPos.add(version);
4961 }
4962
4963 if (!pagination) {
4964 list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
4965 start, end, false);
4966
4967 Collections.sort(list);
4968
4969 list = Collections.unmodifiableList(list);
4970 }
4971 else {
4972 list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
4973 start, end);
4974 }
4975
4976 cacheResult(list);
4977
4978 FinderCacheUtil.putResult(finderPath, finderArgs, list);
4979 }
4980 catch (Exception e) {
4981 FinderCacheUtil.removeResult(finderPath, finderArgs);
4982
4983 throw processException(e);
4984 }
4985 finally {
4986 closeSession(session);
4987 }
4988 }
4989
4990 return list;
4991 }
4992
4993
5004 @Override
5005 public DLFileVersion findByG_F_T_V_First(long groupId, long folderId,
5006 String title, String version,
5007 OrderByComparator<DLFileVersion> orderByComparator)
5008 throws NoSuchFileVersionException {
5009 DLFileVersion dlFileVersion = fetchByG_F_T_V_First(groupId, folderId,
5010 title, version, orderByComparator);
5011
5012 if (dlFileVersion != null) {
5013 return dlFileVersion;
5014 }
5015
5016 StringBundler msg = new StringBundler(10);
5017
5018 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5019
5020 msg.append("groupId=");
5021 msg.append(groupId);
5022
5023 msg.append(", folderId=");
5024 msg.append(folderId);
5025
5026 msg.append(", title=");
5027 msg.append(title);
5028
5029 msg.append(", version=");
5030 msg.append(version);
5031
5032 msg.append(StringPool.CLOSE_CURLY_BRACE);
5033
5034 throw new NoSuchFileVersionException(msg.toString());
5035 }
5036
5037
5047 @Override
5048 public DLFileVersion fetchByG_F_T_V_First(long groupId, long folderId,
5049 String title, String version,
5050 OrderByComparator<DLFileVersion> orderByComparator) {
5051 List<DLFileVersion> list = findByG_F_T_V(groupId, folderId, title,
5052 version, 0, 1, orderByComparator);
5053
5054 if (!list.isEmpty()) {
5055 return list.get(0);
5056 }
5057
5058 return null;
5059 }
5060
5061
5072 @Override
5073 public DLFileVersion findByG_F_T_V_Last(long groupId, long folderId,
5074 String title, String version,
5075 OrderByComparator<DLFileVersion> orderByComparator)
5076 throws NoSuchFileVersionException {
5077 DLFileVersion dlFileVersion = fetchByG_F_T_V_Last(groupId, folderId,
5078 title, version, orderByComparator);
5079
5080 if (dlFileVersion != null) {
5081 return dlFileVersion;
5082 }
5083
5084 StringBundler msg = new StringBundler(10);
5085
5086 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5087
5088 msg.append("groupId=");
5089 msg.append(groupId);
5090
5091 msg.append(", folderId=");
5092 msg.append(folderId);
5093
5094 msg.append(", title=");
5095 msg.append(title);
5096
5097 msg.append(", version=");
5098 msg.append(version);
5099
5100 msg.append(StringPool.CLOSE_CURLY_BRACE);
5101
5102 throw new NoSuchFileVersionException(msg.toString());
5103 }
5104
5105
5115 @Override
5116 public DLFileVersion fetchByG_F_T_V_Last(long groupId, long folderId,
5117 String title, String version,
5118 OrderByComparator<DLFileVersion> orderByComparator) {
5119 int count = countByG_F_T_V(groupId, folderId, title, version);
5120
5121 if (count == 0) {
5122 return null;
5123 }
5124
5125 List<DLFileVersion> list = findByG_F_T_V(groupId, folderId, title,
5126 version, count - 1, count, orderByComparator);
5127
5128 if (!list.isEmpty()) {
5129 return list.get(0);
5130 }
5131
5132 return null;
5133 }
5134
5135
5147 @Override
5148 public DLFileVersion[] findByG_F_T_V_PrevAndNext(long fileVersionId,
5149 long groupId, long folderId, String title, String version,
5150 OrderByComparator<DLFileVersion> orderByComparator)
5151 throws NoSuchFileVersionException {
5152 DLFileVersion dlFileVersion = findByPrimaryKey(fileVersionId);
5153
5154 Session session = null;
5155
5156 try {
5157 session = openSession();
5158
5159 DLFileVersion[] array = new DLFileVersionImpl[3];
5160
5161 array[0] = getByG_F_T_V_PrevAndNext(session, dlFileVersion,
5162 groupId, folderId, title, version, orderByComparator, true);
5163
5164 array[1] = dlFileVersion;
5165
5166 array[2] = getByG_F_T_V_PrevAndNext(session, dlFileVersion,
5167 groupId, folderId, title, version, orderByComparator, false);
5168
5169 return array;
5170 }
5171 catch (Exception e) {
5172 throw processException(e);
5173 }
5174 finally {
5175 closeSession(session);
5176 }
5177 }
5178
5179 protected DLFileVersion getByG_F_T_V_PrevAndNext(Session session,
5180 DLFileVersion dlFileVersion, long groupId, long folderId, String title,
5181 String version, OrderByComparator<DLFileVersion> orderByComparator,
5182 boolean previous) {
5183 StringBundler query = null;
5184
5185 if (orderByComparator != null) {
5186 query = new StringBundler(6 +
5187 (orderByComparator.getOrderByFields().length * 6));
5188 }
5189 else {
5190 query = new StringBundler(3);
5191 }
5192
5193 query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
5194
5195 query.append(_FINDER_COLUMN_G_F_T_V_GROUPID_2);
5196
5197 query.append(_FINDER_COLUMN_G_F_T_V_FOLDERID_2);
5198
5199 boolean bindTitle = false;
5200
5201 if (title == null) {
5202 query.append(_FINDER_COLUMN_G_F_T_V_TITLE_1);
5203 }
5204 else if (title.equals(StringPool.BLANK)) {
5205 query.append(_FINDER_COLUMN_G_F_T_V_TITLE_3);
5206 }
5207 else {
5208 bindTitle = true;
5209
5210 query.append(_FINDER_COLUMN_G_F_T_V_TITLE_2);
5211 }
5212
5213 boolean bindVersion = false;
5214
5215 if (version == null) {
5216 query.append(_FINDER_COLUMN_G_F_T_V_VERSION_1);
5217 }
5218 else if (version.equals(StringPool.BLANK)) {
5219 query.append(_FINDER_COLUMN_G_F_T_V_VERSION_3);
5220 }
5221 else {
5222 bindVersion = true;
5223
5224 query.append(_FINDER_COLUMN_G_F_T_V_VERSION_2);
5225 }
5226
5227 if (orderByComparator != null) {
5228 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5229
5230 if (orderByConditionFields.length > 0) {
5231 query.append(WHERE_AND);
5232 }
5233
5234 for (int i = 0; i < orderByConditionFields.length; i++) {
5235 query.append(_ORDER_BY_ENTITY_ALIAS);
5236 query.append(orderByConditionFields[i]);
5237
5238 if ((i + 1) < orderByConditionFields.length) {
5239 if (orderByComparator.isAscending() ^ previous) {
5240 query.append(WHERE_GREATER_THAN_HAS_NEXT);
5241 }
5242 else {
5243 query.append(WHERE_LESSER_THAN_HAS_NEXT);
5244 }
5245 }
5246 else {
5247 if (orderByComparator.isAscending() ^ previous) {
5248 query.append(WHERE_GREATER_THAN);
5249 }
5250 else {
5251 query.append(WHERE_LESSER_THAN);
5252 }
5253 }
5254 }
5255
5256 query.append(ORDER_BY_CLAUSE);
5257
5258 String[] orderByFields = orderByComparator.getOrderByFields();
5259
5260 for (int i = 0; i < orderByFields.length; i++) {
5261 query.append(_ORDER_BY_ENTITY_ALIAS);
5262 query.append(orderByFields[i]);
5263
5264 if ((i + 1) < orderByFields.length) {
5265 if (orderByComparator.isAscending() ^ previous) {
5266 query.append(ORDER_BY_ASC_HAS_NEXT);
5267 }
5268 else {
5269 query.append(ORDER_BY_DESC_HAS_NEXT);
5270 }
5271 }
5272 else {
5273 if (orderByComparator.isAscending() ^ previous) {
5274 query.append(ORDER_BY_ASC);
5275 }
5276 else {
5277 query.append(ORDER_BY_DESC);
5278 }
5279 }
5280 }
5281 }
5282 else {
5283 query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
5284 }
5285
5286 String sql = query.toString();
5287
5288 Query q = session.createQuery(sql);
5289
5290 q.setFirstResult(0);
5291 q.setMaxResults(2);
5292
5293 QueryPos qPos = QueryPos.getInstance(q);
5294
5295 qPos.add(groupId);
5296
5297 qPos.add(folderId);
5298
5299 if (bindTitle) {
5300 qPos.add(title);
5301 }
5302
5303 if (bindVersion) {
5304 qPos.add(version);
5305 }
5306
5307 if (orderByComparator != null) {
5308 Object[] values = orderByComparator.getOrderByConditionValues(dlFileVersion);
5309
5310 for (Object value : values) {
5311 qPos.add(value);
5312 }
5313 }
5314
5315 List<DLFileVersion> list = q.list();
5316
5317 if (list.size() == 2) {
5318 return list.get(1);
5319 }
5320 else {
5321 return null;
5322 }
5323 }
5324
5325
5333 @Override
5334 public void removeByG_F_T_V(long groupId, long folderId, String title,
5335 String version) {
5336 for (DLFileVersion dlFileVersion : findByG_F_T_V(groupId, folderId,
5337 title, version, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
5338 remove(dlFileVersion);
5339 }
5340 }
5341
5342
5351 @Override
5352 public int countByG_F_T_V(long groupId, long folderId, String title,
5353 String version) {
5354 FinderPath finderPath = FINDER_PATH_COUNT_BY_G_F_T_V;
5355
5356 Object[] finderArgs = new Object[] { groupId, folderId, title, version };
5357
5358 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5359 this);
5360
5361 if (count == null) {
5362 StringBundler query = new StringBundler(5);
5363
5364 query.append(_SQL_COUNT_DLFILEVERSION_WHERE);
5365
5366 query.append(_FINDER_COLUMN_G_F_T_V_GROUPID_2);
5367
5368 query.append(_FINDER_COLUMN_G_F_T_V_FOLDERID_2);
5369
5370 boolean bindTitle = false;
5371
5372 if (title == null) {
5373 query.append(_FINDER_COLUMN_G_F_T_V_TITLE_1);
5374 }
5375 else if (title.equals(StringPool.BLANK)) {
5376 query.append(_FINDER_COLUMN_G_F_T_V_TITLE_3);
5377 }
5378 else {
5379 bindTitle = true;
5380
5381 query.append(_FINDER_COLUMN_G_F_T_V_TITLE_2);
5382 }
5383
5384 boolean bindVersion = false;
5385
5386 if (version == null) {
5387 query.append(_FINDER_COLUMN_G_F_T_V_VERSION_1);
5388 }
5389 else if (version.equals(StringPool.BLANK)) {
5390 query.append(_FINDER_COLUMN_G_F_T_V_VERSION_3);
5391 }
5392 else {
5393 bindVersion = true;
5394
5395 query.append(_FINDER_COLUMN_G_F_T_V_VERSION_2);
5396 }
5397
5398 String sql = query.toString();
5399
5400 Session session = null;
5401
5402 try {
5403 session = openSession();
5404
5405 Query q = session.createQuery(sql);
5406
5407 QueryPos qPos = QueryPos.getInstance(q);
5408
5409 qPos.add(groupId);
5410
5411 qPos.add(folderId);
5412
5413 if (bindTitle) {
5414 qPos.add(title);
5415 }
5416
5417 if (bindVersion) {
5418 qPos.add(version);
5419 }
5420
5421 count = (Long)q.uniqueResult();
5422
5423 FinderCacheUtil.putResult(finderPath, finderArgs, count);
5424 }
5425 catch (Exception e) {
5426 FinderCacheUtil.removeResult(finderPath, finderArgs);
5427
5428 throw processException(e);
5429 }
5430 finally {
5431 closeSession(session);
5432 }
5433 }
5434
5435 return count.intValue();
5436 }
5437
5438 private static final String _FINDER_COLUMN_G_F_T_V_GROUPID_2 = "dlFileVersion.groupId = ? AND ";
5439 private static final String _FINDER_COLUMN_G_F_T_V_FOLDERID_2 = "dlFileVersion.folderId = ? AND ";
5440 private static final String _FINDER_COLUMN_G_F_T_V_TITLE_1 = "dlFileVersion.title IS NULL AND ";
5441 private static final String _FINDER_COLUMN_G_F_T_V_TITLE_2 = "dlFileVersion.title = ? AND ";
5442 private static final String _FINDER_COLUMN_G_F_T_V_TITLE_3 = "(dlFileVersion.title IS NULL OR dlFileVersion.title = '') AND ";
5443 private static final String _FINDER_COLUMN_G_F_T_V_VERSION_1 = "dlFileVersion.version IS NULL";
5444 private static final String _FINDER_COLUMN_G_F_T_V_VERSION_2 = "dlFileVersion.version = ?";
5445 private static final String _FINDER_COLUMN_G_F_T_V_VERSION_3 = "(dlFileVersion.version IS NULL OR dlFileVersion.version = '')";
5446
5447 public DLFileVersionPersistenceImpl() {
5448 setModelClass(DLFileVersion.class);
5449 }
5450
5451
5456 @Override
5457 public void cacheResult(DLFileVersion dlFileVersion) {
5458 EntityCacheUtil.putResult(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
5459 DLFileVersionImpl.class, dlFileVersion.getPrimaryKey(),
5460 dlFileVersion);
5461
5462 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
5463 new Object[] { dlFileVersion.getUuid(), dlFileVersion.getGroupId() },
5464 dlFileVersion);
5465
5466 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_F_V,
5467 new Object[] {
5468 dlFileVersion.getFileEntryId(), dlFileVersion.getVersion()
5469 }, dlFileVersion);
5470
5471 dlFileVersion.resetOriginalValues();
5472 }
5473
5474
5479 @Override
5480 public void cacheResult(List<DLFileVersion> dlFileVersions) {
5481 for (DLFileVersion dlFileVersion : dlFileVersions) {
5482 if (EntityCacheUtil.getResult(
5483 DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
5484 DLFileVersionImpl.class, dlFileVersion.getPrimaryKey()) == null) {
5485 cacheResult(dlFileVersion);
5486 }
5487 else {
5488 dlFileVersion.resetOriginalValues();
5489 }
5490 }
5491 }
5492
5493
5500 @Override
5501 public void clearCache() {
5502 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
5503 CacheRegistryUtil.clear(DLFileVersionImpl.class.getName());
5504 }
5505
5506 EntityCacheUtil.clearCache(DLFileVersionImpl.class);
5507
5508 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
5509 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
5510 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
5511 }
5512
5513
5520 @Override
5521 public void clearCache(DLFileVersion dlFileVersion) {
5522 EntityCacheUtil.removeResult(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
5523 DLFileVersionImpl.class, dlFileVersion.getPrimaryKey());
5524
5525 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
5526 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
5527
5528 clearUniqueFindersCache(dlFileVersion);
5529 }
5530
5531 @Override
5532 public void clearCache(List<DLFileVersion> dlFileVersions) {
5533 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
5534 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
5535
5536 for (DLFileVersion dlFileVersion : dlFileVersions) {
5537 EntityCacheUtil.removeResult(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
5538 DLFileVersionImpl.class, dlFileVersion.getPrimaryKey());
5539
5540 clearUniqueFindersCache(dlFileVersion);
5541 }
5542 }
5543
5544 protected void cacheUniqueFindersCache(DLFileVersion dlFileVersion) {
5545 if (dlFileVersion.isNew()) {
5546 Object[] args = new Object[] {
5547 dlFileVersion.getUuid(), dlFileVersion.getGroupId()
5548 };
5549
5550 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
5551 Long.valueOf(1));
5552 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
5553 dlFileVersion);
5554
5555 args = new Object[] {
5556 dlFileVersion.getFileEntryId(), dlFileVersion.getVersion()
5557 };
5558
5559 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_F_V, args,
5560 Long.valueOf(1));
5561 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_F_V, args,
5562 dlFileVersion);
5563 }
5564 else {
5565 DLFileVersionModelImpl dlFileVersionModelImpl = (DLFileVersionModelImpl)dlFileVersion;
5566
5567 if ((dlFileVersionModelImpl.getColumnBitmask() &
5568 FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
5569 Object[] args = new Object[] {
5570 dlFileVersion.getUuid(), dlFileVersion.getGroupId()
5571 };
5572
5573 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
5574 Long.valueOf(1));
5575 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
5576 dlFileVersion);
5577 }
5578
5579 if ((dlFileVersionModelImpl.getColumnBitmask() &
5580 FINDER_PATH_FETCH_BY_F_V.getColumnBitmask()) != 0) {
5581 Object[] args = new Object[] {
5582 dlFileVersion.getFileEntryId(),
5583 dlFileVersion.getVersion()
5584 };
5585
5586 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_F_V, args,
5587 Long.valueOf(1));
5588 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_F_V, args,
5589 dlFileVersion);
5590 }
5591 }
5592 }
5593
5594 protected void clearUniqueFindersCache(DLFileVersion dlFileVersion) {
5595 DLFileVersionModelImpl dlFileVersionModelImpl = (DLFileVersionModelImpl)dlFileVersion;
5596
5597 Object[] args = new Object[] {
5598 dlFileVersion.getUuid(), dlFileVersion.getGroupId()
5599 };
5600
5601 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
5602 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
5603
5604 if ((dlFileVersionModelImpl.getColumnBitmask() &
5605 FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
5606 args = new Object[] {
5607 dlFileVersionModelImpl.getOriginalUuid(),
5608 dlFileVersionModelImpl.getOriginalGroupId()
5609 };
5610
5611 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
5612 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
5613 }
5614
5615 args = new Object[] {
5616 dlFileVersion.getFileEntryId(), dlFileVersion.getVersion()
5617 };
5618
5619 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_F_V, args);
5620 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_F_V, args);
5621
5622 if ((dlFileVersionModelImpl.getColumnBitmask() &
5623 FINDER_PATH_FETCH_BY_F_V.getColumnBitmask()) != 0) {
5624 args = new Object[] {
5625 dlFileVersionModelImpl.getOriginalFileEntryId(),
5626 dlFileVersionModelImpl.getOriginalVersion()
5627 };
5628
5629 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_F_V, args);
5630 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_F_V, args);
5631 }
5632 }
5633
5634
5640 @Override
5641 public DLFileVersion create(long fileVersionId) {
5642 DLFileVersion dlFileVersion = new DLFileVersionImpl();
5643
5644 dlFileVersion.setNew(true);
5645 dlFileVersion.setPrimaryKey(fileVersionId);
5646
5647 String uuid = PortalUUIDUtil.generate();
5648
5649 dlFileVersion.setUuid(uuid);
5650
5651 return dlFileVersion;
5652 }
5653
5654
5661 @Override
5662 public DLFileVersion remove(long fileVersionId)
5663 throws NoSuchFileVersionException {
5664 return remove((Serializable)fileVersionId);
5665 }
5666
5667
5674 @Override
5675 public DLFileVersion remove(Serializable primaryKey)
5676 throws NoSuchFileVersionException {
5677 Session session = null;
5678
5679 try {
5680 session = openSession();
5681
5682 DLFileVersion dlFileVersion = (DLFileVersion)session.get(DLFileVersionImpl.class,
5683 primaryKey);
5684
5685 if (dlFileVersion == null) {
5686 if (_log.isWarnEnabled()) {
5687 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
5688 }
5689
5690 throw new NoSuchFileVersionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
5691 primaryKey);
5692 }
5693
5694 return remove(dlFileVersion);
5695 }
5696 catch (NoSuchFileVersionException nsee) {
5697 throw nsee;
5698 }
5699 catch (Exception e) {
5700 throw processException(e);
5701 }
5702 finally {
5703 closeSession(session);
5704 }
5705 }
5706
5707 @Override
5708 protected DLFileVersion removeImpl(DLFileVersion dlFileVersion) {
5709 dlFileVersion = toUnwrappedModel(dlFileVersion);
5710
5711 Session session = null;
5712
5713 try {
5714 session = openSession();
5715
5716 if (!session.contains(dlFileVersion)) {
5717 dlFileVersion = (DLFileVersion)session.get(DLFileVersionImpl.class,
5718 dlFileVersion.getPrimaryKeyObj());
5719 }
5720
5721 if (dlFileVersion != null) {
5722 session.delete(dlFileVersion);
5723 }
5724 }
5725 catch (Exception e) {
5726 throw processException(e);
5727 }
5728 finally {
5729 closeSession(session);
5730 }
5731
5732 if (dlFileVersion != null) {
5733 clearCache(dlFileVersion);
5734 }
5735
5736 return dlFileVersion;
5737 }
5738
5739 @Override
5740 public DLFileVersion updateImpl(
5741 com.liferay.portlet.documentlibrary.model.DLFileVersion dlFileVersion) {
5742 dlFileVersion = toUnwrappedModel(dlFileVersion);
5743
5744 boolean isNew = dlFileVersion.isNew();
5745
5746 DLFileVersionModelImpl dlFileVersionModelImpl = (DLFileVersionModelImpl)dlFileVersion;
5747
5748 if (Validator.isNull(dlFileVersion.getUuid())) {
5749 String uuid = PortalUUIDUtil.generate();
5750
5751 dlFileVersion.setUuid(uuid);
5752 }
5753
5754 Session session = null;
5755
5756 try {
5757 session = openSession();
5758
5759 if (dlFileVersion.isNew()) {
5760 session.save(dlFileVersion);
5761
5762 dlFileVersion.setNew(false);
5763 }
5764 else {
5765 session.merge(dlFileVersion);
5766 }
5767 }
5768 catch (Exception e) {
5769 throw processException(e);
5770 }
5771 finally {
5772 closeSession(session);
5773 }
5774
5775 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
5776
5777 if (isNew || !DLFileVersionModelImpl.COLUMN_BITMASK_ENABLED) {
5778 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
5779 }
5780
5781 else {
5782 if ((dlFileVersionModelImpl.getColumnBitmask() &
5783 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
5784 Object[] args = new Object[] {
5785 dlFileVersionModelImpl.getOriginalUuid()
5786 };
5787
5788 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
5789 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
5790 args);
5791
5792 args = new Object[] { dlFileVersionModelImpl.getUuid() };
5793
5794 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
5795 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
5796 args);
5797 }
5798
5799 if ((dlFileVersionModelImpl.getColumnBitmask() &
5800 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
5801 Object[] args = new Object[] {
5802 dlFileVersionModelImpl.getOriginalUuid(),
5803 dlFileVersionModelImpl.getOriginalCompanyId()
5804 };
5805
5806 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
5807 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
5808 args);
5809
5810 args = new Object[] {
5811 dlFileVersionModelImpl.getUuid(),
5812 dlFileVersionModelImpl.getCompanyId()
5813 };
5814
5815 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
5816 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
5817 args);
5818 }
5819
5820 if ((dlFileVersionModelImpl.getColumnBitmask() &
5821 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
5822 Object[] args = new Object[] {
5823 dlFileVersionModelImpl.getOriginalCompanyId()
5824 };
5825
5826 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
5827 args);
5828 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
5829 args);
5830
5831 args = new Object[] { dlFileVersionModelImpl.getCompanyId() };
5832
5833 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
5834 args);
5835 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
5836 args);
5837 }
5838
5839 if ((dlFileVersionModelImpl.getColumnBitmask() &
5840 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FILEENTRYID.getColumnBitmask()) != 0) {
5841 Object[] args = new Object[] {
5842 dlFileVersionModelImpl.getOriginalFileEntryId()
5843 };
5844
5845 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_FILEENTRYID,
5846 args);
5847 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FILEENTRYID,
5848 args);
5849
5850 args = new Object[] { dlFileVersionModelImpl.getFileEntryId() };
5851
5852 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_FILEENTRYID,
5853 args);
5854 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FILEENTRYID,
5855 args);
5856 }
5857
5858 if ((dlFileVersionModelImpl.getColumnBitmask() &
5859 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_MIMETYPE.getColumnBitmask()) != 0) {
5860 Object[] args = new Object[] {
5861 dlFileVersionModelImpl.getOriginalMimeType()
5862 };
5863
5864 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_MIMETYPE, args);
5865 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_MIMETYPE,
5866 args);
5867
5868 args = new Object[] { dlFileVersionModelImpl.getMimeType() };
5869
5870 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_MIMETYPE, args);
5871 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_MIMETYPE,
5872 args);
5873 }
5874
5875 if ((dlFileVersionModelImpl.getColumnBitmask() &
5876 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_F_S.getColumnBitmask()) != 0) {
5877 Object[] args = new Object[] {
5878 dlFileVersionModelImpl.getOriginalFileEntryId(),
5879 dlFileVersionModelImpl.getOriginalStatus()
5880 };
5881
5882 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_F_S, args);
5883 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_F_S,
5884 args);
5885
5886 args = new Object[] {
5887 dlFileVersionModelImpl.getFileEntryId(),
5888 dlFileVersionModelImpl.getStatus()
5889 };
5890
5891 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_F_S, args);
5892 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_F_S,
5893 args);
5894 }
5895
5896 if ((dlFileVersionModelImpl.getColumnBitmask() &
5897 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_F_S.getColumnBitmask()) != 0) {
5898 Object[] args = new Object[] {
5899 dlFileVersionModelImpl.getOriginalGroupId(),
5900 dlFileVersionModelImpl.getOriginalFolderId(),
5901 dlFileVersionModelImpl.getOriginalStatus()
5902 };
5903
5904 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_F_S, args);
5905 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_F_S,
5906 args);
5907
5908 args = new Object[] {
5909 dlFileVersionModelImpl.getGroupId(),
5910 dlFileVersionModelImpl.getFolderId(),
5911 dlFileVersionModelImpl.getStatus()
5912 };
5913
5914 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_F_S, args);
5915 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_F_S,
5916 args);
5917 }
5918
5919 if ((dlFileVersionModelImpl.getColumnBitmask() &
5920 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_F_T_V.getColumnBitmask()) != 0) {
5921 Object[] args = new Object[] {
5922 dlFileVersionModelImpl.getOriginalGroupId(),
5923 dlFileVersionModelImpl.getOriginalFolderId(),
5924 dlFileVersionModelImpl.getOriginalTitle(),
5925 dlFileVersionModelImpl.getOriginalVersion()
5926 };
5927
5928 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_F_T_V, args);
5929 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_F_T_V,
5930 args);
5931
5932 args = new Object[] {
5933 dlFileVersionModelImpl.getGroupId(),
5934 dlFileVersionModelImpl.getFolderId(),
5935 dlFileVersionModelImpl.getTitle(),
5936 dlFileVersionModelImpl.getVersion()
5937 };
5938
5939 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_F_T_V, args);
5940 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_F_T_V,
5941 args);
5942 }
5943 }
5944
5945 EntityCacheUtil.putResult(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
5946 DLFileVersionImpl.class, dlFileVersion.getPrimaryKey(),
5947 dlFileVersion, false);
5948
5949 clearUniqueFindersCache(dlFileVersion);
5950 cacheUniqueFindersCache(dlFileVersion);
5951
5952 dlFileVersion.resetOriginalValues();
5953
5954 return dlFileVersion;
5955 }
5956
5957 protected DLFileVersion toUnwrappedModel(DLFileVersion dlFileVersion) {
5958 if (dlFileVersion instanceof DLFileVersionImpl) {
5959 return dlFileVersion;
5960 }
5961
5962 DLFileVersionImpl dlFileVersionImpl = new DLFileVersionImpl();
5963
5964 dlFileVersionImpl.setNew(dlFileVersion.isNew());
5965 dlFileVersionImpl.setPrimaryKey(dlFileVersion.getPrimaryKey());
5966
5967 dlFileVersionImpl.setUuid(dlFileVersion.getUuid());
5968 dlFileVersionImpl.setFileVersionId(dlFileVersion.getFileVersionId());
5969 dlFileVersionImpl.setGroupId(dlFileVersion.getGroupId());
5970 dlFileVersionImpl.setCompanyId(dlFileVersion.getCompanyId());
5971 dlFileVersionImpl.setUserId(dlFileVersion.getUserId());
5972 dlFileVersionImpl.setUserName(dlFileVersion.getUserName());
5973 dlFileVersionImpl.setCreateDate(dlFileVersion.getCreateDate());
5974 dlFileVersionImpl.setModifiedDate(dlFileVersion.getModifiedDate());
5975 dlFileVersionImpl.setRepositoryId(dlFileVersion.getRepositoryId());
5976 dlFileVersionImpl.setFolderId(dlFileVersion.getFolderId());
5977 dlFileVersionImpl.setFileEntryId(dlFileVersion.getFileEntryId());
5978 dlFileVersionImpl.setTreePath(dlFileVersion.getTreePath());
5979 dlFileVersionImpl.setFileName(dlFileVersion.getFileName());
5980 dlFileVersionImpl.setExtension(dlFileVersion.getExtension());
5981 dlFileVersionImpl.setMimeType(dlFileVersion.getMimeType());
5982 dlFileVersionImpl.setTitle(dlFileVersion.getTitle());
5983 dlFileVersionImpl.setDescription(dlFileVersion.getDescription());
5984 dlFileVersionImpl.setChangeLog(dlFileVersion.getChangeLog());
5985 dlFileVersionImpl.setExtraSettings(dlFileVersion.getExtraSettings());
5986 dlFileVersionImpl.setFileEntryTypeId(dlFileVersion.getFileEntryTypeId());
5987 dlFileVersionImpl.setVersion(dlFileVersion.getVersion());
5988 dlFileVersionImpl.setSize(dlFileVersion.getSize());
5989 dlFileVersionImpl.setChecksum(dlFileVersion.getChecksum());
5990 dlFileVersionImpl.setStatus(dlFileVersion.getStatus());
5991 dlFileVersionImpl.setStatusByUserId(dlFileVersion.getStatusByUserId());
5992 dlFileVersionImpl.setStatusByUserName(dlFileVersion.getStatusByUserName());
5993 dlFileVersionImpl.setStatusDate(dlFileVersion.getStatusDate());
5994
5995 return dlFileVersionImpl;
5996 }
5997
5998
6005 @Override
6006 public DLFileVersion findByPrimaryKey(Serializable primaryKey)
6007 throws NoSuchFileVersionException {
6008 DLFileVersion dlFileVersion = fetchByPrimaryKey(primaryKey);
6009
6010 if (dlFileVersion == null) {
6011 if (_log.isWarnEnabled()) {
6012 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
6013 }
6014
6015 throw new NoSuchFileVersionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
6016 primaryKey);
6017 }
6018
6019 return dlFileVersion;
6020 }
6021
6022
6029 @Override
6030 public DLFileVersion findByPrimaryKey(long fileVersionId)
6031 throws NoSuchFileVersionException {
6032 return findByPrimaryKey((Serializable)fileVersionId);
6033 }
6034
6035
6041 @Override
6042 public DLFileVersion fetchByPrimaryKey(Serializable primaryKey) {
6043 DLFileVersion dlFileVersion = (DLFileVersion)EntityCacheUtil.getResult(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
6044 DLFileVersionImpl.class, primaryKey);
6045
6046 if (dlFileVersion == _nullDLFileVersion) {
6047 return null;
6048 }
6049
6050 if (dlFileVersion == null) {
6051 Session session = null;
6052
6053 try {
6054 session = openSession();
6055
6056 dlFileVersion = (DLFileVersion)session.get(DLFileVersionImpl.class,
6057 primaryKey);
6058
6059 if (dlFileVersion != null) {
6060 cacheResult(dlFileVersion);
6061 }
6062 else {
6063 EntityCacheUtil.putResult(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
6064 DLFileVersionImpl.class, primaryKey, _nullDLFileVersion);
6065 }
6066 }
6067 catch (Exception e) {
6068 EntityCacheUtil.removeResult(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
6069 DLFileVersionImpl.class, primaryKey);
6070
6071 throw processException(e);
6072 }
6073 finally {
6074 closeSession(session);
6075 }
6076 }
6077
6078 return dlFileVersion;
6079 }
6080
6081
6087 @Override
6088 public DLFileVersion fetchByPrimaryKey(long fileVersionId) {
6089 return fetchByPrimaryKey((Serializable)fileVersionId);
6090 }
6091
6092 @Override
6093 public Map<Serializable, DLFileVersion> fetchByPrimaryKeys(
6094 Set<Serializable> primaryKeys) {
6095 if (primaryKeys.isEmpty()) {
6096 return Collections.emptyMap();
6097 }
6098
6099 Map<Serializable, DLFileVersion> map = new HashMap<Serializable, DLFileVersion>();
6100
6101 if (primaryKeys.size() == 1) {
6102 Iterator<Serializable> iterator = primaryKeys.iterator();
6103
6104 Serializable primaryKey = iterator.next();
6105
6106 DLFileVersion dlFileVersion = fetchByPrimaryKey(primaryKey);
6107
6108 if (dlFileVersion != null) {
6109 map.put(primaryKey, dlFileVersion);
6110 }
6111
6112 return map;
6113 }
6114
6115 Set<Serializable> uncachedPrimaryKeys = null;
6116
6117 for (Serializable primaryKey : primaryKeys) {
6118 DLFileVersion dlFileVersion = (DLFileVersion)EntityCacheUtil.getResult(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
6119 DLFileVersionImpl.class, primaryKey);
6120
6121 if (dlFileVersion == null) {
6122 if (uncachedPrimaryKeys == null) {
6123 uncachedPrimaryKeys = new HashSet<Serializable>();
6124 }
6125
6126 uncachedPrimaryKeys.add(primaryKey);
6127 }
6128 else {
6129 map.put(primaryKey, dlFileVersion);
6130 }
6131 }
6132
6133 if (uncachedPrimaryKeys == null) {
6134 return map;
6135 }
6136
6137 StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
6138 1);
6139
6140 query.append(_SQL_SELECT_DLFILEVERSION_WHERE_PKS_IN);
6141
6142 for (Serializable primaryKey : uncachedPrimaryKeys) {
6143 query.append(String.valueOf(primaryKey));
6144
6145 query.append(StringPool.COMMA);
6146 }
6147
6148 query.setIndex(query.index() - 1);
6149
6150 query.append(StringPool.CLOSE_PARENTHESIS);
6151
6152 String sql = query.toString();
6153
6154 Session session = null;
6155
6156 try {
6157 session = openSession();
6158
6159 Query q = session.createQuery(sql);
6160
6161 for (DLFileVersion dlFileVersion : (List<DLFileVersion>)q.list()) {
6162 map.put(dlFileVersion.getPrimaryKeyObj(), dlFileVersion);
6163
6164 cacheResult(dlFileVersion);
6165
6166 uncachedPrimaryKeys.remove(dlFileVersion.getPrimaryKeyObj());
6167 }
6168
6169 for (Serializable primaryKey : uncachedPrimaryKeys) {
6170 EntityCacheUtil.putResult(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
6171 DLFileVersionImpl.class, primaryKey, _nullDLFileVersion);
6172 }
6173 }
6174 catch (Exception e) {
6175 throw processException(e);
6176 }
6177 finally {
6178 closeSession(session);
6179 }
6180
6181 return map;
6182 }
6183
6184
6189 @Override
6190 public List<DLFileVersion> findAll() {
6191 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
6192 }
6193
6194
6205 @Override
6206 public List<DLFileVersion> findAll(int start, int end) {
6207 return findAll(start, end, null);
6208 }
6209
6210
6222 @Override
6223 public List<DLFileVersion> findAll(int start, int end,
6224 OrderByComparator<DLFileVersion> orderByComparator) {
6225 boolean pagination = true;
6226 FinderPath finderPath = null;
6227 Object[] finderArgs = null;
6228
6229 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6230 (orderByComparator == null)) {
6231 pagination = false;
6232 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
6233 finderArgs = FINDER_ARGS_EMPTY;
6234 }
6235 else {
6236 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
6237 finderArgs = new Object[] { start, end, orderByComparator };
6238 }
6239
6240 List<DLFileVersion> list = (List<DLFileVersion>)FinderCacheUtil.getResult(finderPath,
6241 finderArgs, this);
6242
6243 if (list == null) {
6244 StringBundler query = null;
6245 String sql = null;
6246
6247 if (orderByComparator != null) {
6248 query = new StringBundler(2 +
6249 (orderByComparator.getOrderByFields().length * 3));
6250
6251 query.append(_SQL_SELECT_DLFILEVERSION);
6252
6253 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6254 orderByComparator);
6255
6256 sql = query.toString();
6257 }
6258 else {
6259 sql = _SQL_SELECT_DLFILEVERSION;
6260
6261 if (pagination) {
6262 sql = sql.concat(DLFileVersionModelImpl.ORDER_BY_JPQL);
6263 }
6264 }
6265
6266 Session session = null;
6267
6268 try {
6269 session = openSession();
6270
6271 Query q = session.createQuery(sql);
6272
6273 if (!pagination) {
6274 list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
6275 start, end, false);
6276
6277 Collections.sort(list);
6278
6279 list = Collections.unmodifiableList(list);
6280 }
6281 else {
6282 list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
6283 start, end);
6284 }
6285
6286 cacheResult(list);
6287
6288 FinderCacheUtil.putResult(finderPath, finderArgs, list);
6289 }
6290 catch (Exception e) {
6291 FinderCacheUtil.removeResult(finderPath, finderArgs);
6292
6293 throw processException(e);
6294 }
6295 finally {
6296 closeSession(session);
6297 }
6298 }
6299
6300 return list;
6301 }
6302
6303
6307 @Override
6308 public void removeAll() {
6309 for (DLFileVersion dlFileVersion : findAll()) {
6310 remove(dlFileVersion);
6311 }
6312 }
6313
6314
6319 @Override
6320 public int countAll() {
6321 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
6322 FINDER_ARGS_EMPTY, this);
6323
6324 if (count == null) {
6325 Session session = null;
6326
6327 try {
6328 session = openSession();
6329
6330 Query q = session.createQuery(_SQL_COUNT_DLFILEVERSION);
6331
6332 count = (Long)q.uniqueResult();
6333
6334 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
6335 FINDER_ARGS_EMPTY, count);
6336 }
6337 catch (Exception e) {
6338 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
6339 FINDER_ARGS_EMPTY);
6340
6341 throw processException(e);
6342 }
6343 finally {
6344 closeSession(session);
6345 }
6346 }
6347
6348 return count.intValue();
6349 }
6350
6351 @Override
6352 protected Set<String> getBadColumnNames() {
6353 return _badColumnNames;
6354 }
6355
6356
6359 public void afterPropertiesSet() {
6360 }
6361
6362 public void destroy() {
6363 EntityCacheUtil.removeCache(DLFileVersionImpl.class.getName());
6364 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
6365 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
6366 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
6367 }
6368
6369 private static final String _SQL_SELECT_DLFILEVERSION = "SELECT dlFileVersion FROM DLFileVersion dlFileVersion";
6370 private static final String _SQL_SELECT_DLFILEVERSION_WHERE_PKS_IN = "SELECT dlFileVersion FROM DLFileVersion dlFileVersion WHERE fileVersionId IN (";
6371 private static final String _SQL_SELECT_DLFILEVERSION_WHERE = "SELECT dlFileVersion FROM DLFileVersion dlFileVersion WHERE ";
6372 private static final String _SQL_COUNT_DLFILEVERSION = "SELECT COUNT(dlFileVersion) FROM DLFileVersion dlFileVersion";
6373 private static final String _SQL_COUNT_DLFILEVERSION_WHERE = "SELECT COUNT(dlFileVersion) FROM DLFileVersion dlFileVersion WHERE ";
6374 private static final String _ORDER_BY_ENTITY_ALIAS = "dlFileVersion.";
6375 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No DLFileVersion exists with the primary key ";
6376 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No DLFileVersion exists with the key {";
6377 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
6378 private static final Log _log = LogFactoryUtil.getLog(DLFileVersionPersistenceImpl.class);
6379 private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
6380 "uuid", "size"
6381 });
6382 private static final DLFileVersion _nullDLFileVersion = new DLFileVersionImpl() {
6383 @Override
6384 public Object clone() {
6385 return this;
6386 }
6387
6388 @Override
6389 public CacheModel<DLFileVersion> toCacheModel() {
6390 return _nullDLFileVersionCacheModel;
6391 }
6392 };
6393
6394 private static final CacheModel<DLFileVersion> _nullDLFileVersionCacheModel = new CacheModel<DLFileVersion>() {
6395 @Override
6396 public DLFileVersion toEntityModel() {
6397 return _nullDLFileVersion;
6398 }
6399 };
6400 }