001
014
015 package com.liferay.portlet.documentlibrary.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.kernel.annotation.BeanReference;
019 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderPath;
023 import com.liferay.portal.kernel.dao.orm.Query;
024 import com.liferay.portal.kernel.dao.orm.QueryPos;
025 import com.liferay.portal.kernel.dao.orm.QueryUtil;
026 import com.liferay.portal.kernel.dao.orm.Session;
027 import com.liferay.portal.kernel.exception.SystemException;
028 import com.liferay.portal.kernel.log.Log;
029 import com.liferay.portal.kernel.log.LogFactoryUtil;
030 import com.liferay.portal.kernel.util.GetterUtil;
031 import com.liferay.portal.kernel.util.InstanceFactory;
032 import com.liferay.portal.kernel.util.OrderByComparator;
033 import com.liferay.portal.kernel.util.StringBundler;
034 import com.liferay.portal.kernel.util.StringPool;
035 import com.liferay.portal.kernel.util.StringUtil;
036 import com.liferay.portal.kernel.util.Validator;
037 import com.liferay.portal.model.ModelListener;
038 import com.liferay.portal.service.persistence.BatchSessionUtil;
039 import com.liferay.portal.service.persistence.ResourcePersistence;
040 import com.liferay.portal.service.persistence.UserPersistence;
041 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
042
043 import com.liferay.portlet.asset.service.persistence.AssetEntryPersistence;
044 import com.liferay.portlet.documentlibrary.NoSuchFileVersionException;
045 import com.liferay.portlet.documentlibrary.model.DLFileVersion;
046 import com.liferay.portlet.documentlibrary.model.impl.DLFileVersionImpl;
047 import com.liferay.portlet.documentlibrary.model.impl.DLFileVersionModelImpl;
048
049 import java.io.Serializable;
050
051 import java.util.ArrayList;
052 import java.util.Collections;
053 import java.util.List;
054
055
071 public class DLFileVersionPersistenceImpl extends BasePersistenceImpl<DLFileVersion>
072 implements DLFileVersionPersistence {
073 public static final String FINDER_CLASS_NAME_ENTITY = DLFileVersionImpl.class.getName();
074 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
075 ".List";
076 public static final FinderPath FINDER_PATH_FIND_BY_G_F_N = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
077 DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
078 FINDER_CLASS_NAME_LIST, "findByG_F_N",
079 new String[] {
080 Long.class.getName(), Long.class.getName(),
081 String.class.getName(),
082
083 "java.lang.Integer", "java.lang.Integer",
084 "com.liferay.portal.kernel.util.OrderByComparator"
085 });
086 public static final FinderPath FINDER_PATH_COUNT_BY_G_F_N = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
087 DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
088 FINDER_CLASS_NAME_LIST, "countByG_F_N",
089 new String[] {
090 Long.class.getName(), Long.class.getName(),
091 String.class.getName()
092 });
093 public static final FinderPath FINDER_PATH_FETCH_BY_G_F_N_V = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
094 DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
095 FINDER_CLASS_NAME_ENTITY, "fetchByG_F_N_V",
096 new String[] {
097 Long.class.getName(), Long.class.getName(),
098 String.class.getName(), String.class.getName()
099 });
100 public static final FinderPath FINDER_PATH_COUNT_BY_G_F_N_V = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
101 DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
102 FINDER_CLASS_NAME_LIST, "countByG_F_N_V",
103 new String[] {
104 Long.class.getName(), Long.class.getName(),
105 String.class.getName(), String.class.getName()
106 });
107 public static final FinderPath FINDER_PATH_FIND_BY_G_F_N_S = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
108 DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
109 FINDER_CLASS_NAME_LIST, "findByG_F_N_S",
110 new String[] {
111 Long.class.getName(), Long.class.getName(),
112 String.class.getName(), Integer.class.getName(),
113
114 "java.lang.Integer", "java.lang.Integer",
115 "com.liferay.portal.kernel.util.OrderByComparator"
116 });
117 public static final FinderPath FINDER_PATH_COUNT_BY_G_F_N_S = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
118 DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
119 FINDER_CLASS_NAME_LIST, "countByG_F_N_S",
120 new String[] {
121 Long.class.getName(), Long.class.getName(),
122 String.class.getName(), Integer.class.getName()
123 });
124 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
125 DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
126 FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
127 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
128 DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
129 FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
130
131
136 public void cacheResult(DLFileVersion dlFileVersion) {
137 EntityCacheUtil.putResult(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
138 DLFileVersionImpl.class, dlFileVersion.getPrimaryKey(),
139 dlFileVersion);
140
141 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_F_N_V,
142 new Object[] {
143 new Long(dlFileVersion.getGroupId()),
144 new Long(dlFileVersion.getFolderId()),
145
146 dlFileVersion.getName(),
147
148 dlFileVersion.getVersion()
149 }, dlFileVersion);
150 }
151
152
157 public void cacheResult(List<DLFileVersion> dlFileVersions) {
158 for (DLFileVersion dlFileVersion : dlFileVersions) {
159 if (EntityCacheUtil.getResult(
160 DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
161 DLFileVersionImpl.class, dlFileVersion.getPrimaryKey(),
162 this) == null) {
163 cacheResult(dlFileVersion);
164 }
165 }
166 }
167
168
175 public void clearCache() {
176 CacheRegistryUtil.clear(DLFileVersionImpl.class.getName());
177 EntityCacheUtil.clearCache(DLFileVersionImpl.class.getName());
178 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
179 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
180 }
181
182
189 public void clearCache(DLFileVersion dlFileVersion) {
190 EntityCacheUtil.removeResult(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
191 DLFileVersionImpl.class, dlFileVersion.getPrimaryKey());
192
193 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_F_N_V,
194 new Object[] {
195 new Long(dlFileVersion.getGroupId()),
196 new Long(dlFileVersion.getFolderId()),
197
198 dlFileVersion.getName(),
199
200 dlFileVersion.getVersion()
201 });
202 }
203
204
210 public DLFileVersion create(long fileVersionId) {
211 DLFileVersion dlFileVersion = new DLFileVersionImpl();
212
213 dlFileVersion.setNew(true);
214 dlFileVersion.setPrimaryKey(fileVersionId);
215
216 return dlFileVersion;
217 }
218
219
227 public DLFileVersion remove(Serializable primaryKey)
228 throws NoSuchModelException, SystemException {
229 return remove(((Long)primaryKey).longValue());
230 }
231
232
240 public DLFileVersion remove(long fileVersionId)
241 throws NoSuchFileVersionException, SystemException {
242 Session session = null;
243
244 try {
245 session = openSession();
246
247 DLFileVersion dlFileVersion = (DLFileVersion)session.get(DLFileVersionImpl.class,
248 new Long(fileVersionId));
249
250 if (dlFileVersion == null) {
251 if (_log.isWarnEnabled()) {
252 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + fileVersionId);
253 }
254
255 throw new NoSuchFileVersionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
256 fileVersionId);
257 }
258
259 return remove(dlFileVersion);
260 }
261 catch (NoSuchFileVersionException nsee) {
262 throw nsee;
263 }
264 catch (Exception e) {
265 throw processException(e);
266 }
267 finally {
268 closeSession(session);
269 }
270 }
271
272 protected DLFileVersion removeImpl(DLFileVersion dlFileVersion)
273 throws SystemException {
274 dlFileVersion = toUnwrappedModel(dlFileVersion);
275
276 Session session = null;
277
278 try {
279 session = openSession();
280
281 if (dlFileVersion.isCachedModel() || BatchSessionUtil.isEnabled()) {
282 Object staleObject = session.get(DLFileVersionImpl.class,
283 dlFileVersion.getPrimaryKeyObj());
284
285 if (staleObject != null) {
286 session.evict(staleObject);
287 }
288 }
289
290 session.delete(dlFileVersion);
291
292 session.flush();
293 }
294 catch (Exception e) {
295 throw processException(e);
296 }
297 finally {
298 closeSession(session);
299 }
300
301 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
302
303 DLFileVersionModelImpl dlFileVersionModelImpl = (DLFileVersionModelImpl)dlFileVersion;
304
305 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_F_N_V,
306 new Object[] {
307 new Long(dlFileVersionModelImpl.getOriginalGroupId()),
308 new Long(dlFileVersionModelImpl.getOriginalFolderId()),
309
310 dlFileVersionModelImpl.getOriginalName(),
311
312 dlFileVersionModelImpl.getOriginalVersion()
313 });
314
315 EntityCacheUtil.removeResult(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
316 DLFileVersionImpl.class, dlFileVersion.getPrimaryKey());
317
318 return dlFileVersion;
319 }
320
321 public DLFileVersion updateImpl(
322 com.liferay.portlet.documentlibrary.model.DLFileVersion dlFileVersion,
323 boolean merge) throws SystemException {
324 dlFileVersion = toUnwrappedModel(dlFileVersion);
325
326 boolean isNew = dlFileVersion.isNew();
327
328 DLFileVersionModelImpl dlFileVersionModelImpl = (DLFileVersionModelImpl)dlFileVersion;
329
330 Session session = null;
331
332 try {
333 session = openSession();
334
335 BatchSessionUtil.update(session, dlFileVersion, merge);
336
337 dlFileVersion.setNew(false);
338 }
339 catch (Exception e) {
340 throw processException(e);
341 }
342 finally {
343 closeSession(session);
344 }
345
346 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
347
348 EntityCacheUtil.putResult(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
349 DLFileVersionImpl.class, dlFileVersion.getPrimaryKey(),
350 dlFileVersion);
351
352 if (!isNew &&
353 ((dlFileVersion.getGroupId() != dlFileVersionModelImpl.getOriginalGroupId()) ||
354 (dlFileVersion.getFolderId() != dlFileVersionModelImpl.getOriginalFolderId()) ||
355 !Validator.equals(dlFileVersion.getName(),
356 dlFileVersionModelImpl.getOriginalName()) ||
357 !Validator.equals(dlFileVersion.getVersion(),
358 dlFileVersionModelImpl.getOriginalVersion()))) {
359 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_F_N_V,
360 new Object[] {
361 new Long(dlFileVersionModelImpl.getOriginalGroupId()),
362 new Long(dlFileVersionModelImpl.getOriginalFolderId()),
363
364 dlFileVersionModelImpl.getOriginalName(),
365
366 dlFileVersionModelImpl.getOriginalVersion()
367 });
368 }
369
370 if (isNew ||
371 ((dlFileVersion.getGroupId() != dlFileVersionModelImpl.getOriginalGroupId()) ||
372 (dlFileVersion.getFolderId() != dlFileVersionModelImpl.getOriginalFolderId()) ||
373 !Validator.equals(dlFileVersion.getName(),
374 dlFileVersionModelImpl.getOriginalName()) ||
375 !Validator.equals(dlFileVersion.getVersion(),
376 dlFileVersionModelImpl.getOriginalVersion()))) {
377 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_F_N_V,
378 new Object[] {
379 new Long(dlFileVersion.getGroupId()),
380 new Long(dlFileVersion.getFolderId()),
381
382 dlFileVersion.getName(),
383
384 dlFileVersion.getVersion()
385 }, dlFileVersion);
386 }
387
388 return dlFileVersion;
389 }
390
391 protected DLFileVersion toUnwrappedModel(DLFileVersion dlFileVersion) {
392 if (dlFileVersion instanceof DLFileVersionImpl) {
393 return dlFileVersion;
394 }
395
396 DLFileVersionImpl dlFileVersionImpl = new DLFileVersionImpl();
397
398 dlFileVersionImpl.setNew(dlFileVersion.isNew());
399 dlFileVersionImpl.setPrimaryKey(dlFileVersion.getPrimaryKey());
400
401 dlFileVersionImpl.setFileVersionId(dlFileVersion.getFileVersionId());
402 dlFileVersionImpl.setGroupId(dlFileVersion.getGroupId());
403 dlFileVersionImpl.setCompanyId(dlFileVersion.getCompanyId());
404 dlFileVersionImpl.setUserId(dlFileVersion.getUserId());
405 dlFileVersionImpl.setUserName(dlFileVersion.getUserName());
406 dlFileVersionImpl.setCreateDate(dlFileVersion.getCreateDate());
407 dlFileVersionImpl.setFolderId(dlFileVersion.getFolderId());
408 dlFileVersionImpl.setName(dlFileVersion.getName());
409 dlFileVersionImpl.setExtension(dlFileVersion.getExtension());
410 dlFileVersionImpl.setTitle(dlFileVersion.getTitle());
411 dlFileVersionImpl.setDescription(dlFileVersion.getDescription());
412 dlFileVersionImpl.setChangeLog(dlFileVersion.getChangeLog());
413 dlFileVersionImpl.setExtraSettings(dlFileVersion.getExtraSettings());
414 dlFileVersionImpl.setVersion(dlFileVersion.getVersion());
415 dlFileVersionImpl.setSize(dlFileVersion.getSize());
416 dlFileVersionImpl.setStatus(dlFileVersion.getStatus());
417 dlFileVersionImpl.setStatusByUserId(dlFileVersion.getStatusByUserId());
418 dlFileVersionImpl.setStatusByUserName(dlFileVersion.getStatusByUserName());
419 dlFileVersionImpl.setStatusDate(dlFileVersion.getStatusDate());
420
421 return dlFileVersionImpl;
422 }
423
424
432 public DLFileVersion findByPrimaryKey(Serializable primaryKey)
433 throws NoSuchModelException, SystemException {
434 return findByPrimaryKey(((Long)primaryKey).longValue());
435 }
436
437
445 public DLFileVersion findByPrimaryKey(long fileVersionId)
446 throws NoSuchFileVersionException, SystemException {
447 DLFileVersion dlFileVersion = fetchByPrimaryKey(fileVersionId);
448
449 if (dlFileVersion == null) {
450 if (_log.isWarnEnabled()) {
451 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + fileVersionId);
452 }
453
454 throw new NoSuchFileVersionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
455 fileVersionId);
456 }
457
458 return dlFileVersion;
459 }
460
461
468 public DLFileVersion fetchByPrimaryKey(Serializable primaryKey)
469 throws SystemException {
470 return fetchByPrimaryKey(((Long)primaryKey).longValue());
471 }
472
473
480 public DLFileVersion fetchByPrimaryKey(long fileVersionId)
481 throws SystemException {
482 DLFileVersion dlFileVersion = (DLFileVersion)EntityCacheUtil.getResult(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
483 DLFileVersionImpl.class, fileVersionId, this);
484
485 if (dlFileVersion == null) {
486 Session session = null;
487
488 try {
489 session = openSession();
490
491 dlFileVersion = (DLFileVersion)session.get(DLFileVersionImpl.class,
492 new Long(fileVersionId));
493 }
494 catch (Exception e) {
495 throw processException(e);
496 }
497 finally {
498 if (dlFileVersion != null) {
499 cacheResult(dlFileVersion);
500 }
501
502 closeSession(session);
503 }
504 }
505
506 return dlFileVersion;
507 }
508
509
518 public List<DLFileVersion> findByG_F_N(long groupId, long folderId,
519 String name) throws SystemException {
520 return findByG_F_N(groupId, folderId, name, QueryUtil.ALL_POS,
521 QueryUtil.ALL_POS, null);
522 }
523
524
539 public List<DLFileVersion> findByG_F_N(long groupId, long folderId,
540 String name, int start, int end) throws SystemException {
541 return findByG_F_N(groupId, folderId, name, start, end, null);
542 }
543
544
560 public List<DLFileVersion> findByG_F_N(long groupId, long folderId,
561 String name, int start, int end, OrderByComparator orderByComparator)
562 throws SystemException {
563 Object[] finderArgs = new Object[] {
564 groupId, folderId, name,
565
566 String.valueOf(start), String.valueOf(end),
567 String.valueOf(orderByComparator)
568 };
569
570 List<DLFileVersion> list = (List<DLFileVersion>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_F_N,
571 finderArgs, this);
572
573 if (list == null) {
574 Session session = null;
575
576 try {
577 session = openSession();
578
579 StringBundler query = null;
580
581 if (orderByComparator != null) {
582 query = new StringBundler(5 +
583 (orderByComparator.getOrderByFields().length * 3));
584 }
585 else {
586 query = new StringBundler(5);
587 }
588
589 query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
590
591 query.append(_FINDER_COLUMN_G_F_N_GROUPID_2);
592
593 query.append(_FINDER_COLUMN_G_F_N_FOLDERID_2);
594
595 if (name == null) {
596 query.append(_FINDER_COLUMN_G_F_N_NAME_1);
597 }
598 else {
599 if (name.equals(StringPool.BLANK)) {
600 query.append(_FINDER_COLUMN_G_F_N_NAME_3);
601 }
602 else {
603 query.append(_FINDER_COLUMN_G_F_N_NAME_2);
604 }
605 }
606
607 if (orderByComparator != null) {
608 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
609 orderByComparator);
610 }
611
612 else {
613 query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
614 }
615
616 String sql = query.toString();
617
618 Query q = session.createQuery(sql);
619
620 QueryPos qPos = QueryPos.getInstance(q);
621
622 qPos.add(groupId);
623
624 qPos.add(folderId);
625
626 if (name != null) {
627 qPos.add(name);
628 }
629
630 list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
631 start, end);
632 }
633 catch (Exception e) {
634 throw processException(e);
635 }
636 finally {
637 if (list == null) {
638 list = new ArrayList<DLFileVersion>();
639 }
640
641 cacheResult(list);
642
643 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_F_N,
644 finderArgs, list);
645
646 closeSession(session);
647 }
648 }
649
650 return list;
651 }
652
653
668 public DLFileVersion findByG_F_N_First(long groupId, long folderId,
669 String name, OrderByComparator orderByComparator)
670 throws NoSuchFileVersionException, SystemException {
671 List<DLFileVersion> list = findByG_F_N(groupId, folderId, name, 0, 1,
672 orderByComparator);
673
674 if (list.isEmpty()) {
675 StringBundler msg = new StringBundler(8);
676
677 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
678
679 msg.append("groupId=");
680 msg.append(groupId);
681
682 msg.append(", folderId=");
683 msg.append(folderId);
684
685 msg.append(", name=");
686 msg.append(name);
687
688 msg.append(StringPool.CLOSE_CURLY_BRACE);
689
690 throw new NoSuchFileVersionException(msg.toString());
691 }
692 else {
693 return list.get(0);
694 }
695 }
696
697
712 public DLFileVersion findByG_F_N_Last(long groupId, long folderId,
713 String name, OrderByComparator orderByComparator)
714 throws NoSuchFileVersionException, SystemException {
715 int count = countByG_F_N(groupId, folderId, name);
716
717 List<DLFileVersion> list = findByG_F_N(groupId, folderId, name,
718 count - 1, count, orderByComparator);
719
720 if (list.isEmpty()) {
721 StringBundler msg = new StringBundler(8);
722
723 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
724
725 msg.append("groupId=");
726 msg.append(groupId);
727
728 msg.append(", folderId=");
729 msg.append(folderId);
730
731 msg.append(", name=");
732 msg.append(name);
733
734 msg.append(StringPool.CLOSE_CURLY_BRACE);
735
736 throw new NoSuchFileVersionException(msg.toString());
737 }
738 else {
739 return list.get(0);
740 }
741 }
742
743
759 public DLFileVersion[] findByG_F_N_PrevAndNext(long fileVersionId,
760 long groupId, long folderId, String name,
761 OrderByComparator orderByComparator)
762 throws NoSuchFileVersionException, SystemException {
763 DLFileVersion dlFileVersion = findByPrimaryKey(fileVersionId);
764
765 Session session = null;
766
767 try {
768 session = openSession();
769
770 DLFileVersion[] array = new DLFileVersionImpl[3];
771
772 array[0] = getByG_F_N_PrevAndNext(session, dlFileVersion, groupId,
773 folderId, name, orderByComparator, true);
774
775 array[1] = dlFileVersion;
776
777 array[2] = getByG_F_N_PrevAndNext(session, dlFileVersion, groupId,
778 folderId, name, orderByComparator, false);
779
780 return array;
781 }
782 catch (Exception e) {
783 throw processException(e);
784 }
785 finally {
786 closeSession(session);
787 }
788 }
789
790 protected DLFileVersion getByG_F_N_PrevAndNext(Session session,
791 DLFileVersion dlFileVersion, long groupId, long folderId, String name,
792 OrderByComparator orderByComparator, boolean previous) {
793 StringBundler query = null;
794
795 if (orderByComparator != null) {
796 query = new StringBundler(6 +
797 (orderByComparator.getOrderByFields().length * 6));
798 }
799 else {
800 query = new StringBundler(3);
801 }
802
803 query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
804
805 query.append(_FINDER_COLUMN_G_F_N_GROUPID_2);
806
807 query.append(_FINDER_COLUMN_G_F_N_FOLDERID_2);
808
809 if (name == null) {
810 query.append(_FINDER_COLUMN_G_F_N_NAME_1);
811 }
812 else {
813 if (name.equals(StringPool.BLANK)) {
814 query.append(_FINDER_COLUMN_G_F_N_NAME_3);
815 }
816 else {
817 query.append(_FINDER_COLUMN_G_F_N_NAME_2);
818 }
819 }
820
821 if (orderByComparator != null) {
822 String[] orderByFields = orderByComparator.getOrderByFields();
823
824 if (orderByFields.length > 0) {
825 query.append(WHERE_AND);
826 }
827
828 for (int i = 0; i < orderByFields.length; i++) {
829 query.append(_ORDER_BY_ENTITY_ALIAS);
830 query.append(orderByFields[i]);
831
832 if ((i + 1) < orderByFields.length) {
833 if (orderByComparator.isAscending() ^ previous) {
834 query.append(WHERE_GREATER_THAN_HAS_NEXT);
835 }
836 else {
837 query.append(WHERE_LESSER_THAN_HAS_NEXT);
838 }
839 }
840 else {
841 if (orderByComparator.isAscending() ^ previous) {
842 query.append(WHERE_GREATER_THAN);
843 }
844 else {
845 query.append(WHERE_LESSER_THAN);
846 }
847 }
848 }
849
850 query.append(ORDER_BY_CLAUSE);
851
852 for (int i = 0; i < orderByFields.length; i++) {
853 query.append(_ORDER_BY_ENTITY_ALIAS);
854 query.append(orderByFields[i]);
855
856 if ((i + 1) < orderByFields.length) {
857 if (orderByComparator.isAscending() ^ previous) {
858 query.append(ORDER_BY_ASC_HAS_NEXT);
859 }
860 else {
861 query.append(ORDER_BY_DESC_HAS_NEXT);
862 }
863 }
864 else {
865 if (orderByComparator.isAscending() ^ previous) {
866 query.append(ORDER_BY_ASC);
867 }
868 else {
869 query.append(ORDER_BY_DESC);
870 }
871 }
872 }
873 }
874
875 else {
876 query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
877 }
878
879 String sql = query.toString();
880
881 Query q = session.createQuery(sql);
882
883 q.setFirstResult(0);
884 q.setMaxResults(2);
885
886 QueryPos qPos = QueryPos.getInstance(q);
887
888 qPos.add(groupId);
889
890 qPos.add(folderId);
891
892 if (name != null) {
893 qPos.add(name);
894 }
895
896 if (orderByComparator != null) {
897 Object[] values = orderByComparator.getOrderByValues(dlFileVersion);
898
899 for (Object value : values) {
900 qPos.add(value);
901 }
902 }
903
904 List<DLFileVersion> list = q.list();
905
906 if (list.size() == 2) {
907 return list.get(1);
908 }
909 else {
910 return null;
911 }
912 }
913
914
925 public DLFileVersion findByG_F_N_V(long groupId, long folderId,
926 String name, String version)
927 throws NoSuchFileVersionException, SystemException {
928 DLFileVersion dlFileVersion = fetchByG_F_N_V(groupId, folderId, name,
929 version);
930
931 if (dlFileVersion == null) {
932 StringBundler msg = new StringBundler(10);
933
934 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
935
936 msg.append("groupId=");
937 msg.append(groupId);
938
939 msg.append(", folderId=");
940 msg.append(folderId);
941
942 msg.append(", name=");
943 msg.append(name);
944
945 msg.append(", version=");
946 msg.append(version);
947
948 msg.append(StringPool.CLOSE_CURLY_BRACE);
949
950 if (_log.isWarnEnabled()) {
951 _log.warn(msg.toString());
952 }
953
954 throw new NoSuchFileVersionException(msg.toString());
955 }
956
957 return dlFileVersion;
958 }
959
960
970 public DLFileVersion fetchByG_F_N_V(long groupId, long folderId,
971 String name, String version) throws SystemException {
972 return fetchByG_F_N_V(groupId, folderId, name, version, true);
973 }
974
975
985 public DLFileVersion fetchByG_F_N_V(long groupId, long folderId,
986 String name, String version, boolean retrieveFromCache)
987 throws SystemException {
988 Object[] finderArgs = new Object[] { groupId, folderId, name, version };
989
990 Object result = null;
991
992 if (retrieveFromCache) {
993 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_F_N_V,
994 finderArgs, this);
995 }
996
997 if (result == null) {
998 Session session = null;
999
1000 try {
1001 session = openSession();
1002
1003 StringBundler query = new StringBundler(6);
1004
1005 query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
1006
1007 query.append(_FINDER_COLUMN_G_F_N_V_GROUPID_2);
1008
1009 query.append(_FINDER_COLUMN_G_F_N_V_FOLDERID_2);
1010
1011 if (name == null) {
1012 query.append(_FINDER_COLUMN_G_F_N_V_NAME_1);
1013 }
1014 else {
1015 if (name.equals(StringPool.BLANK)) {
1016 query.append(_FINDER_COLUMN_G_F_N_V_NAME_3);
1017 }
1018 else {
1019 query.append(_FINDER_COLUMN_G_F_N_V_NAME_2);
1020 }
1021 }
1022
1023 if (version == null) {
1024 query.append(_FINDER_COLUMN_G_F_N_V_VERSION_1);
1025 }
1026 else {
1027 if (version.equals(StringPool.BLANK)) {
1028 query.append(_FINDER_COLUMN_G_F_N_V_VERSION_3);
1029 }
1030 else {
1031 query.append(_FINDER_COLUMN_G_F_N_V_VERSION_2);
1032 }
1033 }
1034
1035 query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
1036
1037 String sql = query.toString();
1038
1039 Query q = session.createQuery(sql);
1040
1041 QueryPos qPos = QueryPos.getInstance(q);
1042
1043 qPos.add(groupId);
1044
1045 qPos.add(folderId);
1046
1047 if (name != null) {
1048 qPos.add(name);
1049 }
1050
1051 if (version != null) {
1052 qPos.add(version);
1053 }
1054
1055 List<DLFileVersion> list = q.list();
1056
1057 result = list;
1058
1059 DLFileVersion dlFileVersion = null;
1060
1061 if (list.isEmpty()) {
1062 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_F_N_V,
1063 finderArgs, list);
1064 }
1065 else {
1066 dlFileVersion = list.get(0);
1067
1068 cacheResult(dlFileVersion);
1069
1070 if ((dlFileVersion.getGroupId() != groupId) ||
1071 (dlFileVersion.getFolderId() != folderId) ||
1072 (dlFileVersion.getName() == null) ||
1073 !dlFileVersion.getName().equals(name) ||
1074 (dlFileVersion.getVersion() == null) ||
1075 !dlFileVersion.getVersion().equals(version)) {
1076 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_F_N_V,
1077 finderArgs, dlFileVersion);
1078 }
1079 }
1080
1081 return dlFileVersion;
1082 }
1083 catch (Exception e) {
1084 throw processException(e);
1085 }
1086 finally {
1087 if (result == null) {
1088 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_F_N_V,
1089 finderArgs, new ArrayList<DLFileVersion>());
1090 }
1091
1092 closeSession(session);
1093 }
1094 }
1095 else {
1096 if (result instanceof List<?>) {
1097 return null;
1098 }
1099 else {
1100 return (DLFileVersion)result;
1101 }
1102 }
1103 }
1104
1105
1115 public List<DLFileVersion> findByG_F_N_S(long groupId, long folderId,
1116 String name, int status) throws SystemException {
1117 return findByG_F_N_S(groupId, folderId, name, status,
1118 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1119 }
1120
1121
1137 public List<DLFileVersion> findByG_F_N_S(long groupId, long folderId,
1138 String name, int status, int start, int end) throws SystemException {
1139 return findByG_F_N_S(groupId, folderId, name, status, start, end, null);
1140 }
1141
1142
1159 public List<DLFileVersion> findByG_F_N_S(long groupId, long folderId,
1160 String name, int status, int start, int end,
1161 OrderByComparator orderByComparator) throws SystemException {
1162 Object[] finderArgs = new Object[] {
1163 groupId, folderId, name, status,
1164
1165 String.valueOf(start), String.valueOf(end),
1166 String.valueOf(orderByComparator)
1167 };
1168
1169 List<DLFileVersion> list = (List<DLFileVersion>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_F_N_S,
1170 finderArgs, this);
1171
1172 if (list == null) {
1173 Session session = null;
1174
1175 try {
1176 session = openSession();
1177
1178 StringBundler query = null;
1179
1180 if (orderByComparator != null) {
1181 query = new StringBundler(6 +
1182 (orderByComparator.getOrderByFields().length * 3));
1183 }
1184 else {
1185 query = new StringBundler(6);
1186 }
1187
1188 query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
1189
1190 query.append(_FINDER_COLUMN_G_F_N_S_GROUPID_2);
1191
1192 query.append(_FINDER_COLUMN_G_F_N_S_FOLDERID_2);
1193
1194 if (name == null) {
1195 query.append(_FINDER_COLUMN_G_F_N_S_NAME_1);
1196 }
1197 else {
1198 if (name.equals(StringPool.BLANK)) {
1199 query.append(_FINDER_COLUMN_G_F_N_S_NAME_3);
1200 }
1201 else {
1202 query.append(_FINDER_COLUMN_G_F_N_S_NAME_2);
1203 }
1204 }
1205
1206 query.append(_FINDER_COLUMN_G_F_N_S_STATUS_2);
1207
1208 if (orderByComparator != null) {
1209 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1210 orderByComparator);
1211 }
1212
1213 else {
1214 query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
1215 }
1216
1217 String sql = query.toString();
1218
1219 Query q = session.createQuery(sql);
1220
1221 QueryPos qPos = QueryPos.getInstance(q);
1222
1223 qPos.add(groupId);
1224
1225 qPos.add(folderId);
1226
1227 if (name != null) {
1228 qPos.add(name);
1229 }
1230
1231 qPos.add(status);
1232
1233 list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
1234 start, end);
1235 }
1236 catch (Exception e) {
1237 throw processException(e);
1238 }
1239 finally {
1240 if (list == null) {
1241 list = new ArrayList<DLFileVersion>();
1242 }
1243
1244 cacheResult(list);
1245
1246 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_F_N_S,
1247 finderArgs, list);
1248
1249 closeSession(session);
1250 }
1251 }
1252
1253 return list;
1254 }
1255
1256
1272 public DLFileVersion findByG_F_N_S_First(long groupId, long folderId,
1273 String name, int status, OrderByComparator orderByComparator)
1274 throws NoSuchFileVersionException, SystemException {
1275 List<DLFileVersion> list = findByG_F_N_S(groupId, folderId, name,
1276 status, 0, 1, orderByComparator);
1277
1278 if (list.isEmpty()) {
1279 StringBundler msg = new StringBundler(10);
1280
1281 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1282
1283 msg.append("groupId=");
1284 msg.append(groupId);
1285
1286 msg.append(", folderId=");
1287 msg.append(folderId);
1288
1289 msg.append(", name=");
1290 msg.append(name);
1291
1292 msg.append(", status=");
1293 msg.append(status);
1294
1295 msg.append(StringPool.CLOSE_CURLY_BRACE);
1296
1297 throw new NoSuchFileVersionException(msg.toString());
1298 }
1299 else {
1300 return list.get(0);
1301 }
1302 }
1303
1304
1320 public DLFileVersion findByG_F_N_S_Last(long groupId, long folderId,
1321 String name, int status, OrderByComparator orderByComparator)
1322 throws NoSuchFileVersionException, SystemException {
1323 int count = countByG_F_N_S(groupId, folderId, name, status);
1324
1325 List<DLFileVersion> list = findByG_F_N_S(groupId, folderId, name,
1326 status, count - 1, count, orderByComparator);
1327
1328 if (list.isEmpty()) {
1329 StringBundler msg = new StringBundler(10);
1330
1331 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1332
1333 msg.append("groupId=");
1334 msg.append(groupId);
1335
1336 msg.append(", folderId=");
1337 msg.append(folderId);
1338
1339 msg.append(", name=");
1340 msg.append(name);
1341
1342 msg.append(", status=");
1343 msg.append(status);
1344
1345 msg.append(StringPool.CLOSE_CURLY_BRACE);
1346
1347 throw new NoSuchFileVersionException(msg.toString());
1348 }
1349 else {
1350 return list.get(0);
1351 }
1352 }
1353
1354
1371 public DLFileVersion[] findByG_F_N_S_PrevAndNext(long fileVersionId,
1372 long groupId, long folderId, String name, int status,
1373 OrderByComparator orderByComparator)
1374 throws NoSuchFileVersionException, SystemException {
1375 DLFileVersion dlFileVersion = findByPrimaryKey(fileVersionId);
1376
1377 Session session = null;
1378
1379 try {
1380 session = openSession();
1381
1382 DLFileVersion[] array = new DLFileVersionImpl[3];
1383
1384 array[0] = getByG_F_N_S_PrevAndNext(session, dlFileVersion,
1385 groupId, folderId, name, status, orderByComparator, true);
1386
1387 array[1] = dlFileVersion;
1388
1389 array[2] = getByG_F_N_S_PrevAndNext(session, dlFileVersion,
1390 groupId, folderId, name, status, orderByComparator, false);
1391
1392 return array;
1393 }
1394 catch (Exception e) {
1395 throw processException(e);
1396 }
1397 finally {
1398 closeSession(session);
1399 }
1400 }
1401
1402 protected DLFileVersion getByG_F_N_S_PrevAndNext(Session session,
1403 DLFileVersion dlFileVersion, long groupId, long folderId, String name,
1404 int status, OrderByComparator orderByComparator, boolean previous) {
1405 StringBundler query = null;
1406
1407 if (orderByComparator != null) {
1408 query = new StringBundler(6 +
1409 (orderByComparator.getOrderByFields().length * 6));
1410 }
1411 else {
1412 query = new StringBundler(3);
1413 }
1414
1415 query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
1416
1417 query.append(_FINDER_COLUMN_G_F_N_S_GROUPID_2);
1418
1419 query.append(_FINDER_COLUMN_G_F_N_S_FOLDERID_2);
1420
1421 if (name == null) {
1422 query.append(_FINDER_COLUMN_G_F_N_S_NAME_1);
1423 }
1424 else {
1425 if (name.equals(StringPool.BLANK)) {
1426 query.append(_FINDER_COLUMN_G_F_N_S_NAME_3);
1427 }
1428 else {
1429 query.append(_FINDER_COLUMN_G_F_N_S_NAME_2);
1430 }
1431 }
1432
1433 query.append(_FINDER_COLUMN_G_F_N_S_STATUS_2);
1434
1435 if (orderByComparator != null) {
1436 String[] orderByFields = orderByComparator.getOrderByFields();
1437
1438 if (orderByFields.length > 0) {
1439 query.append(WHERE_AND);
1440 }
1441
1442 for (int i = 0; i < orderByFields.length; i++) {
1443 query.append(_ORDER_BY_ENTITY_ALIAS);
1444 query.append(orderByFields[i]);
1445
1446 if ((i + 1) < orderByFields.length) {
1447 if (orderByComparator.isAscending() ^ previous) {
1448 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1449 }
1450 else {
1451 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1452 }
1453 }
1454 else {
1455 if (orderByComparator.isAscending() ^ previous) {
1456 query.append(WHERE_GREATER_THAN);
1457 }
1458 else {
1459 query.append(WHERE_LESSER_THAN);
1460 }
1461 }
1462 }
1463
1464 query.append(ORDER_BY_CLAUSE);
1465
1466 for (int i = 0; i < orderByFields.length; i++) {
1467 query.append(_ORDER_BY_ENTITY_ALIAS);
1468 query.append(orderByFields[i]);
1469
1470 if ((i + 1) < orderByFields.length) {
1471 if (orderByComparator.isAscending() ^ previous) {
1472 query.append(ORDER_BY_ASC_HAS_NEXT);
1473 }
1474 else {
1475 query.append(ORDER_BY_DESC_HAS_NEXT);
1476 }
1477 }
1478 else {
1479 if (orderByComparator.isAscending() ^ previous) {
1480 query.append(ORDER_BY_ASC);
1481 }
1482 else {
1483 query.append(ORDER_BY_DESC);
1484 }
1485 }
1486 }
1487 }
1488
1489 else {
1490 query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
1491 }
1492
1493 String sql = query.toString();
1494
1495 Query q = session.createQuery(sql);
1496
1497 q.setFirstResult(0);
1498 q.setMaxResults(2);
1499
1500 QueryPos qPos = QueryPos.getInstance(q);
1501
1502 qPos.add(groupId);
1503
1504 qPos.add(folderId);
1505
1506 if (name != null) {
1507 qPos.add(name);
1508 }
1509
1510 qPos.add(status);
1511
1512 if (orderByComparator != null) {
1513 Object[] values = orderByComparator.getOrderByValues(dlFileVersion);
1514
1515 for (Object value : values) {
1516 qPos.add(value);
1517 }
1518 }
1519
1520 List<DLFileVersion> list = q.list();
1521
1522 if (list.size() == 2) {
1523 return list.get(1);
1524 }
1525 else {
1526 return null;
1527 }
1528 }
1529
1530
1536 public List<DLFileVersion> findAll() throws SystemException {
1537 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1538 }
1539
1540
1552 public List<DLFileVersion> findAll(int start, int end)
1553 throws SystemException {
1554 return findAll(start, end, null);
1555 }
1556
1557
1570 public List<DLFileVersion> findAll(int start, int end,
1571 OrderByComparator orderByComparator) throws SystemException {
1572 Object[] finderArgs = new Object[] {
1573 String.valueOf(start), String.valueOf(end),
1574 String.valueOf(orderByComparator)
1575 };
1576
1577 List<DLFileVersion> list = (List<DLFileVersion>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1578 finderArgs, this);
1579
1580 if (list == null) {
1581 Session session = null;
1582
1583 try {
1584 session = openSession();
1585
1586 StringBundler query = null;
1587 String sql = null;
1588
1589 if (orderByComparator != null) {
1590 query = new StringBundler(2 +
1591 (orderByComparator.getOrderByFields().length * 3));
1592
1593 query.append(_SQL_SELECT_DLFILEVERSION);
1594
1595 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1596 orderByComparator);
1597
1598 sql = query.toString();
1599 }
1600 else {
1601 sql = _SQL_SELECT_DLFILEVERSION.concat(DLFileVersionModelImpl.ORDER_BY_JPQL);
1602 }
1603
1604 Query q = session.createQuery(sql);
1605
1606 if (orderByComparator == null) {
1607 list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
1608 start, end, false);
1609
1610 Collections.sort(list);
1611 }
1612 else {
1613 list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
1614 start, end);
1615 }
1616 }
1617 catch (Exception e) {
1618 throw processException(e);
1619 }
1620 finally {
1621 if (list == null) {
1622 list = new ArrayList<DLFileVersion>();
1623 }
1624
1625 cacheResult(list);
1626
1627 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1628
1629 closeSession(session);
1630 }
1631 }
1632
1633 return list;
1634 }
1635
1636
1644 public void removeByG_F_N(long groupId, long folderId, String name)
1645 throws SystemException {
1646 for (DLFileVersion dlFileVersion : findByG_F_N(groupId, folderId, name)) {
1647 remove(dlFileVersion);
1648 }
1649 }
1650
1651
1660 public void removeByG_F_N_V(long groupId, long folderId, String name,
1661 String version) throws NoSuchFileVersionException, SystemException {
1662 DLFileVersion dlFileVersion = findByG_F_N_V(groupId, folderId, name,
1663 version);
1664
1665 remove(dlFileVersion);
1666 }
1667
1668
1677 public void removeByG_F_N_S(long groupId, long folderId, String name,
1678 int status) throws SystemException {
1679 for (DLFileVersion dlFileVersion : findByG_F_N_S(groupId, folderId,
1680 name, status)) {
1681 remove(dlFileVersion);
1682 }
1683 }
1684
1685
1690 public void removeAll() throws SystemException {
1691 for (DLFileVersion dlFileVersion : findAll()) {
1692 remove(dlFileVersion);
1693 }
1694 }
1695
1696
1705 public int countByG_F_N(long groupId, long folderId, String name)
1706 throws SystemException {
1707 Object[] finderArgs = new Object[] { groupId, folderId, name };
1708
1709 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_F_N,
1710 finderArgs, this);
1711
1712 if (count == null) {
1713 Session session = null;
1714
1715 try {
1716 session = openSession();
1717
1718 StringBundler query = new StringBundler(4);
1719
1720 query.append(_SQL_COUNT_DLFILEVERSION_WHERE);
1721
1722 query.append(_FINDER_COLUMN_G_F_N_GROUPID_2);
1723
1724 query.append(_FINDER_COLUMN_G_F_N_FOLDERID_2);
1725
1726 if (name == null) {
1727 query.append(_FINDER_COLUMN_G_F_N_NAME_1);
1728 }
1729 else {
1730 if (name.equals(StringPool.BLANK)) {
1731 query.append(_FINDER_COLUMN_G_F_N_NAME_3);
1732 }
1733 else {
1734 query.append(_FINDER_COLUMN_G_F_N_NAME_2);
1735 }
1736 }
1737
1738 String sql = query.toString();
1739
1740 Query q = session.createQuery(sql);
1741
1742 QueryPos qPos = QueryPos.getInstance(q);
1743
1744 qPos.add(groupId);
1745
1746 qPos.add(folderId);
1747
1748 if (name != null) {
1749 qPos.add(name);
1750 }
1751
1752 count = (Long)q.uniqueResult();
1753 }
1754 catch (Exception e) {
1755 throw processException(e);
1756 }
1757 finally {
1758 if (count == null) {
1759 count = Long.valueOf(0);
1760 }
1761
1762 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_F_N,
1763 finderArgs, count);
1764
1765 closeSession(session);
1766 }
1767 }
1768
1769 return count.intValue();
1770 }
1771
1772
1782 public int countByG_F_N_V(long groupId, long folderId, String name,
1783 String version) throws SystemException {
1784 Object[] finderArgs = new Object[] { groupId, folderId, name, version };
1785
1786 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_F_N_V,
1787 finderArgs, this);
1788
1789 if (count == null) {
1790 Session session = null;
1791
1792 try {
1793 session = openSession();
1794
1795 StringBundler query = new StringBundler(5);
1796
1797 query.append(_SQL_COUNT_DLFILEVERSION_WHERE);
1798
1799 query.append(_FINDER_COLUMN_G_F_N_V_GROUPID_2);
1800
1801 query.append(_FINDER_COLUMN_G_F_N_V_FOLDERID_2);
1802
1803 if (name == null) {
1804 query.append(_FINDER_COLUMN_G_F_N_V_NAME_1);
1805 }
1806 else {
1807 if (name.equals(StringPool.BLANK)) {
1808 query.append(_FINDER_COLUMN_G_F_N_V_NAME_3);
1809 }
1810 else {
1811 query.append(_FINDER_COLUMN_G_F_N_V_NAME_2);
1812 }
1813 }
1814
1815 if (version == null) {
1816 query.append(_FINDER_COLUMN_G_F_N_V_VERSION_1);
1817 }
1818 else {
1819 if (version.equals(StringPool.BLANK)) {
1820 query.append(_FINDER_COLUMN_G_F_N_V_VERSION_3);
1821 }
1822 else {
1823 query.append(_FINDER_COLUMN_G_F_N_V_VERSION_2);
1824 }
1825 }
1826
1827 String sql = query.toString();
1828
1829 Query q = session.createQuery(sql);
1830
1831 QueryPos qPos = QueryPos.getInstance(q);
1832
1833 qPos.add(groupId);
1834
1835 qPos.add(folderId);
1836
1837 if (name != null) {
1838 qPos.add(name);
1839 }
1840
1841 if (version != null) {
1842 qPos.add(version);
1843 }
1844
1845 count = (Long)q.uniqueResult();
1846 }
1847 catch (Exception e) {
1848 throw processException(e);
1849 }
1850 finally {
1851 if (count == null) {
1852 count = Long.valueOf(0);
1853 }
1854
1855 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_F_N_V,
1856 finderArgs, count);
1857
1858 closeSession(session);
1859 }
1860 }
1861
1862 return count.intValue();
1863 }
1864
1865
1875 public int countByG_F_N_S(long groupId, long folderId, String name,
1876 int status) throws SystemException {
1877 Object[] finderArgs = new Object[] { groupId, folderId, name, status };
1878
1879 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_F_N_S,
1880 finderArgs, this);
1881
1882 if (count == null) {
1883 Session session = null;
1884
1885 try {
1886 session = openSession();
1887
1888 StringBundler query = new StringBundler(5);
1889
1890 query.append(_SQL_COUNT_DLFILEVERSION_WHERE);
1891
1892 query.append(_FINDER_COLUMN_G_F_N_S_GROUPID_2);
1893
1894 query.append(_FINDER_COLUMN_G_F_N_S_FOLDERID_2);
1895
1896 if (name == null) {
1897 query.append(_FINDER_COLUMN_G_F_N_S_NAME_1);
1898 }
1899 else {
1900 if (name.equals(StringPool.BLANK)) {
1901 query.append(_FINDER_COLUMN_G_F_N_S_NAME_3);
1902 }
1903 else {
1904 query.append(_FINDER_COLUMN_G_F_N_S_NAME_2);
1905 }
1906 }
1907
1908 query.append(_FINDER_COLUMN_G_F_N_S_STATUS_2);
1909
1910 String sql = query.toString();
1911
1912 Query q = session.createQuery(sql);
1913
1914 QueryPos qPos = QueryPos.getInstance(q);
1915
1916 qPos.add(groupId);
1917
1918 qPos.add(folderId);
1919
1920 if (name != null) {
1921 qPos.add(name);
1922 }
1923
1924 qPos.add(status);
1925
1926 count = (Long)q.uniqueResult();
1927 }
1928 catch (Exception e) {
1929 throw processException(e);
1930 }
1931 finally {
1932 if (count == null) {
1933 count = Long.valueOf(0);
1934 }
1935
1936 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_F_N_S,
1937 finderArgs, count);
1938
1939 closeSession(session);
1940 }
1941 }
1942
1943 return count.intValue();
1944 }
1945
1946
1952 public int countAll() throws SystemException {
1953 Object[] finderArgs = new Object[0];
1954
1955 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1956 finderArgs, this);
1957
1958 if (count == null) {
1959 Session session = null;
1960
1961 try {
1962 session = openSession();
1963
1964 Query q = session.createQuery(_SQL_COUNT_DLFILEVERSION);
1965
1966 count = (Long)q.uniqueResult();
1967 }
1968 catch (Exception e) {
1969 throw processException(e);
1970 }
1971 finally {
1972 if (count == null) {
1973 count = Long.valueOf(0);
1974 }
1975
1976 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1977 count);
1978
1979 closeSession(session);
1980 }
1981 }
1982
1983 return count.intValue();
1984 }
1985
1986
1989 public void afterPropertiesSet() {
1990 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1991 com.liferay.portal.util.PropsUtil.get(
1992 "value.object.listener.com.liferay.portlet.documentlibrary.model.DLFileVersion")));
1993
1994 if (listenerClassNames.length > 0) {
1995 try {
1996 List<ModelListener<DLFileVersion>> listenersList = new ArrayList<ModelListener<DLFileVersion>>();
1997
1998 for (String listenerClassName : listenerClassNames) {
1999 listenersList.add((ModelListener<DLFileVersion>)InstanceFactory.newInstance(
2000 listenerClassName));
2001 }
2002
2003 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2004 }
2005 catch (Exception e) {
2006 _log.error(e);
2007 }
2008 }
2009 }
2010
2011 @BeanReference(type = DLFileEntryPersistence.class)
2012 protected DLFileEntryPersistence dlFileEntryPersistence;
2013 @BeanReference(type = DLFileRankPersistence.class)
2014 protected DLFileRankPersistence dlFileRankPersistence;
2015 @BeanReference(type = DLFileShortcutPersistence.class)
2016 protected DLFileShortcutPersistence dlFileShortcutPersistence;
2017 @BeanReference(type = DLFileVersionPersistence.class)
2018 protected DLFileVersionPersistence dlFileVersionPersistence;
2019 @BeanReference(type = DLFolderPersistence.class)
2020 protected DLFolderPersistence dlFolderPersistence;
2021 @BeanReference(type = ResourcePersistence.class)
2022 protected ResourcePersistence resourcePersistence;
2023 @BeanReference(type = UserPersistence.class)
2024 protected UserPersistence userPersistence;
2025 @BeanReference(type = AssetEntryPersistence.class)
2026 protected AssetEntryPersistence assetEntryPersistence;
2027 private static final String _SQL_SELECT_DLFILEVERSION = "SELECT dlFileVersion FROM DLFileVersion dlFileVersion";
2028 private static final String _SQL_SELECT_DLFILEVERSION_WHERE = "SELECT dlFileVersion FROM DLFileVersion dlFileVersion WHERE ";
2029 private static final String _SQL_COUNT_DLFILEVERSION = "SELECT COUNT(dlFileVersion) FROM DLFileVersion dlFileVersion";
2030 private static final String _SQL_COUNT_DLFILEVERSION_WHERE = "SELECT COUNT(dlFileVersion) FROM DLFileVersion dlFileVersion WHERE ";
2031 private static final String _FINDER_COLUMN_G_F_N_GROUPID_2 = "dlFileVersion.groupId = ? AND ";
2032 private static final String _FINDER_COLUMN_G_F_N_FOLDERID_2 = "dlFileVersion.folderId = ? AND ";
2033 private static final String _FINDER_COLUMN_G_F_N_NAME_1 = "dlFileVersion.name IS NULL";
2034 private static final String _FINDER_COLUMN_G_F_N_NAME_2 = "dlFileVersion.name = ?";
2035 private static final String _FINDER_COLUMN_G_F_N_NAME_3 = "(dlFileVersion.name IS NULL OR dlFileVersion.name = ?)";
2036 private static final String _FINDER_COLUMN_G_F_N_V_GROUPID_2 = "dlFileVersion.groupId = ? AND ";
2037 private static final String _FINDER_COLUMN_G_F_N_V_FOLDERID_2 = "dlFileVersion.folderId = ? AND ";
2038 private static final String _FINDER_COLUMN_G_F_N_V_NAME_1 = "dlFileVersion.name IS NULL AND ";
2039 private static final String _FINDER_COLUMN_G_F_N_V_NAME_2 = "dlFileVersion.name = ? AND ";
2040 private static final String _FINDER_COLUMN_G_F_N_V_NAME_3 = "(dlFileVersion.name IS NULL OR dlFileVersion.name = ?) AND ";
2041 private static final String _FINDER_COLUMN_G_F_N_V_VERSION_1 = "dlFileVersion.version IS NULL";
2042 private static final String _FINDER_COLUMN_G_F_N_V_VERSION_2 = "dlFileVersion.version = ?";
2043 private static final String _FINDER_COLUMN_G_F_N_V_VERSION_3 = "(dlFileVersion.version IS NULL OR dlFileVersion.version = ?)";
2044 private static final String _FINDER_COLUMN_G_F_N_S_GROUPID_2 = "dlFileVersion.groupId = ? AND ";
2045 private static final String _FINDER_COLUMN_G_F_N_S_FOLDERID_2 = "dlFileVersion.folderId = ? AND ";
2046 private static final String _FINDER_COLUMN_G_F_N_S_NAME_1 = "dlFileVersion.name IS NULL AND ";
2047 private static final String _FINDER_COLUMN_G_F_N_S_NAME_2 = "dlFileVersion.name = ? AND ";
2048 private static final String _FINDER_COLUMN_G_F_N_S_NAME_3 = "(dlFileVersion.name IS NULL OR dlFileVersion.name = ?) AND ";
2049 private static final String _FINDER_COLUMN_G_F_N_S_STATUS_2 = "dlFileVersion.status = ?";
2050 private static final String _ORDER_BY_ENTITY_ALIAS = "dlFileVersion.";
2051 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No DLFileVersion exists with the primary key ";
2052 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No DLFileVersion exists with the key {";
2053 private static Log _log = LogFactoryUtil.getLog(DLFileVersionPersistenceImpl.class);
2054 }