1
22
23 package com.liferay.portlet.documentlibrary.service.persistence;
24
25 import com.liferay.portal.SystemException;
26 import com.liferay.portal.kernel.annotation.BeanReference;
27 import com.liferay.portal.kernel.cache.CacheRegistry;
28 import com.liferay.portal.kernel.dao.orm.DynamicQuery;
29 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
30 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
31 import com.liferay.portal.kernel.dao.orm.FinderPath;
32 import com.liferay.portal.kernel.dao.orm.Query;
33 import com.liferay.portal.kernel.dao.orm.QueryPos;
34 import com.liferay.portal.kernel.dao.orm.QueryUtil;
35 import com.liferay.portal.kernel.dao.orm.Session;
36 import com.liferay.portal.kernel.log.Log;
37 import com.liferay.portal.kernel.log.LogFactoryUtil;
38 import com.liferay.portal.kernel.util.GetterUtil;
39 import com.liferay.portal.kernel.util.OrderByComparator;
40 import com.liferay.portal.kernel.util.StringPool;
41 import com.liferay.portal.kernel.util.StringUtil;
42 import com.liferay.portal.kernel.util.Validator;
43 import com.liferay.portal.model.ModelListener;
44 import com.liferay.portal.service.persistence.BatchSessionUtil;
45 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
46
47 import com.liferay.portlet.documentlibrary.NoSuchFileVersionException;
48 import com.liferay.portlet.documentlibrary.model.DLFileVersion;
49 import com.liferay.portlet.documentlibrary.model.impl.DLFileVersionImpl;
50 import com.liferay.portlet.documentlibrary.model.impl.DLFileVersionModelImpl;
51
52 import java.util.ArrayList;
53 import java.util.Collections;
54 import java.util.List;
55
56
69 public class DLFileVersionPersistenceImpl extends BasePersistenceImpl
70 implements DLFileVersionPersistence {
71 public static final String FINDER_CLASS_NAME_ENTITY = DLFileVersionImpl.class.getName();
72 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
73 ".List";
74 public static final FinderPath FINDER_PATH_FIND_BY_F_N = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
75 DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
76 FINDER_CLASS_NAME_LIST, "findByF_N",
77 new String[] { Long.class.getName(), String.class.getName() });
78 public static final FinderPath FINDER_PATH_FIND_BY_OBC_F_N = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
79 DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
80 FINDER_CLASS_NAME_LIST, "findByF_N",
81 new String[] {
82 Long.class.getName(), String.class.getName(),
83
84 "java.lang.Integer", "java.lang.Integer",
85 "com.liferay.portal.kernel.util.OrderByComparator"
86 });
87 public static final FinderPath FINDER_PATH_COUNT_BY_F_N = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
88 DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
89 FINDER_CLASS_NAME_LIST, "countByF_N",
90 new String[] { Long.class.getName(), String.class.getName() });
91 public static final FinderPath FINDER_PATH_FETCH_BY_F_N_V = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
92 DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
93 FINDER_CLASS_NAME_ENTITY, "fetchByF_N_V",
94 new String[] {
95 Long.class.getName(), String.class.getName(),
96 Double.class.getName()
97 });
98 public static final FinderPath FINDER_PATH_COUNT_BY_F_N_V = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
99 DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
100 FINDER_CLASS_NAME_LIST, "countByF_N_V",
101 new String[] {
102 Long.class.getName(), String.class.getName(),
103 Double.class.getName()
104 });
105 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
106 DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
107 FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
108 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
109 DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
110 FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
111
112 public void cacheResult(DLFileVersion dlFileVersion) {
113 EntityCacheUtil.putResult(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
114 DLFileVersionImpl.class, dlFileVersion.getPrimaryKey(),
115 dlFileVersion);
116
117 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_F_N_V,
118 new Object[] {
119 new Long(dlFileVersion.getFolderId()),
120
121 dlFileVersion.getName(), new Double(dlFileVersion.getVersion())
122 }, dlFileVersion);
123 }
124
125 public void cacheResult(List<DLFileVersion> dlFileVersions) {
126 for (DLFileVersion dlFileVersion : dlFileVersions) {
127 if (EntityCacheUtil.getResult(
128 DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
129 DLFileVersionImpl.class, dlFileVersion.getPrimaryKey(),
130 this) == null) {
131 cacheResult(dlFileVersion);
132 }
133 }
134 }
135
136 public void clearCache() {
137 CacheRegistry.clear(DLFileVersionImpl.class.getName());
138 EntityCacheUtil.clearCache(DLFileVersionImpl.class.getName());
139 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
140 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
141 }
142
143 public DLFileVersion create(long fileVersionId) {
144 DLFileVersion dlFileVersion = new DLFileVersionImpl();
145
146 dlFileVersion.setNew(true);
147 dlFileVersion.setPrimaryKey(fileVersionId);
148
149 return dlFileVersion;
150 }
151
152 public DLFileVersion remove(long fileVersionId)
153 throws NoSuchFileVersionException, SystemException {
154 Session session = null;
155
156 try {
157 session = openSession();
158
159 DLFileVersion dlFileVersion = (DLFileVersion)session.get(DLFileVersionImpl.class,
160 new Long(fileVersionId));
161
162 if (dlFileVersion == null) {
163 if (_log.isWarnEnabled()) {
164 _log.warn("No DLFileVersion exists with the primary key " +
165 fileVersionId);
166 }
167
168 throw new NoSuchFileVersionException(
169 "No DLFileVersion exists with the primary key " +
170 fileVersionId);
171 }
172
173 return remove(dlFileVersion);
174 }
175 catch (NoSuchFileVersionException nsee) {
176 throw nsee;
177 }
178 catch (Exception e) {
179 throw processException(e);
180 }
181 finally {
182 closeSession(session);
183 }
184 }
185
186 public DLFileVersion remove(DLFileVersion dlFileVersion)
187 throws SystemException {
188 for (ModelListener<DLFileVersion> listener : listeners) {
189 listener.onBeforeRemove(dlFileVersion);
190 }
191
192 dlFileVersion = removeImpl(dlFileVersion);
193
194 for (ModelListener<DLFileVersion> listener : listeners) {
195 listener.onAfterRemove(dlFileVersion);
196 }
197
198 return dlFileVersion;
199 }
200
201 protected DLFileVersion removeImpl(DLFileVersion dlFileVersion)
202 throws SystemException {
203 dlFileVersion = toUnwrappedModel(dlFileVersion);
204
205 Session session = null;
206
207 try {
208 session = openSession();
209
210 if (dlFileVersion.isCachedModel() || BatchSessionUtil.isEnabled()) {
211 Object staleObject = session.get(DLFileVersionImpl.class,
212 dlFileVersion.getPrimaryKeyObj());
213
214 if (staleObject != null) {
215 session.evict(staleObject);
216 }
217 }
218
219 session.delete(dlFileVersion);
220
221 session.flush();
222 }
223 catch (Exception e) {
224 throw processException(e);
225 }
226 finally {
227 closeSession(session);
228 }
229
230 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
231
232 DLFileVersionModelImpl dlFileVersionModelImpl = (DLFileVersionModelImpl)dlFileVersion;
233
234 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_F_N_V,
235 new Object[] {
236 new Long(dlFileVersionModelImpl.getOriginalFolderId()),
237
238 dlFileVersionModelImpl.getOriginalName(),
239 new Double(dlFileVersionModelImpl.getOriginalVersion())
240 });
241
242 EntityCacheUtil.removeResult(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
243 DLFileVersionImpl.class, dlFileVersion.getPrimaryKey());
244
245 return dlFileVersion;
246 }
247
248
251 public DLFileVersion update(DLFileVersion dlFileVersion)
252 throws SystemException {
253 if (_log.isWarnEnabled()) {
254 _log.warn(
255 "Using the deprecated update(DLFileVersion dlFileVersion) method. Use update(DLFileVersion dlFileVersion, boolean merge) instead.");
256 }
257
258 return update(dlFileVersion, false);
259 }
260
261
273 public DLFileVersion update(DLFileVersion dlFileVersion, boolean merge)
274 throws SystemException {
275 boolean isNew = dlFileVersion.isNew();
276
277 for (ModelListener<DLFileVersion> listener : listeners) {
278 if (isNew) {
279 listener.onBeforeCreate(dlFileVersion);
280 }
281 else {
282 listener.onBeforeUpdate(dlFileVersion);
283 }
284 }
285
286 dlFileVersion = updateImpl(dlFileVersion, merge);
287
288 for (ModelListener<DLFileVersion> listener : listeners) {
289 if (isNew) {
290 listener.onAfterCreate(dlFileVersion);
291 }
292 else {
293 listener.onAfterUpdate(dlFileVersion);
294 }
295 }
296
297 return dlFileVersion;
298 }
299
300 public DLFileVersion updateImpl(
301 com.liferay.portlet.documentlibrary.model.DLFileVersion dlFileVersion,
302 boolean merge) throws SystemException {
303 dlFileVersion = toUnwrappedModel(dlFileVersion);
304
305 boolean isNew = dlFileVersion.isNew();
306
307 DLFileVersionModelImpl dlFileVersionModelImpl = (DLFileVersionModelImpl)dlFileVersion;
308
309 Session session = null;
310
311 try {
312 session = openSession();
313
314 BatchSessionUtil.update(session, dlFileVersion, merge);
315
316 dlFileVersion.setNew(false);
317 }
318 catch (Exception e) {
319 throw processException(e);
320 }
321 finally {
322 closeSession(session);
323 }
324
325 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
326
327 EntityCacheUtil.putResult(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
328 DLFileVersionImpl.class, dlFileVersion.getPrimaryKey(),
329 dlFileVersion);
330
331 if (!isNew &&
332 ((dlFileVersion.getFolderId() != dlFileVersionModelImpl.getOriginalFolderId()) ||
333 !Validator.equals(dlFileVersion.getName(),
334 dlFileVersionModelImpl.getOriginalName()) ||
335 (dlFileVersion.getVersion() != dlFileVersionModelImpl.getOriginalVersion()))) {
336 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_F_N_V,
337 new Object[] {
338 new Long(dlFileVersionModelImpl.getOriginalFolderId()),
339
340 dlFileVersionModelImpl.getOriginalName(),
341 new Double(dlFileVersionModelImpl.getOriginalVersion())
342 });
343 }
344
345 if (isNew ||
346 ((dlFileVersion.getFolderId() != dlFileVersionModelImpl.getOriginalFolderId()) ||
347 !Validator.equals(dlFileVersion.getName(),
348 dlFileVersionModelImpl.getOriginalName()) ||
349 (dlFileVersion.getVersion() != dlFileVersionModelImpl.getOriginalVersion()))) {
350 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_F_N_V,
351 new Object[] {
352 new Long(dlFileVersion.getFolderId()),
353
354 dlFileVersion.getName(), new Double(dlFileVersion.getVersion())
355 }, dlFileVersion);
356 }
357
358 return dlFileVersion;
359 }
360
361 protected DLFileVersion toUnwrappedModel(DLFileVersion dlFileVersion) {
362 if (dlFileVersion instanceof DLFileVersionImpl) {
363 return dlFileVersion;
364 }
365
366 DLFileVersionImpl dlFileVersionImpl = new DLFileVersionImpl();
367
368 dlFileVersionImpl.setNew(dlFileVersion.isNew());
369 dlFileVersionImpl.setPrimaryKey(dlFileVersion.getPrimaryKey());
370
371 dlFileVersionImpl.setFileVersionId(dlFileVersion.getFileVersionId());
372 dlFileVersionImpl.setGroupId(dlFileVersion.getGroupId());
373 dlFileVersionImpl.setCompanyId(dlFileVersion.getCompanyId());
374 dlFileVersionImpl.setUserId(dlFileVersion.getUserId());
375 dlFileVersionImpl.setUserName(dlFileVersion.getUserName());
376 dlFileVersionImpl.setCreateDate(dlFileVersion.getCreateDate());
377 dlFileVersionImpl.setFolderId(dlFileVersion.getFolderId());
378 dlFileVersionImpl.setName(dlFileVersion.getName());
379 dlFileVersionImpl.setVersion(dlFileVersion.getVersion());
380 dlFileVersionImpl.setSize(dlFileVersion.getSize());
381
382 return dlFileVersionImpl;
383 }
384
385 public DLFileVersion findByPrimaryKey(long fileVersionId)
386 throws NoSuchFileVersionException, SystemException {
387 DLFileVersion dlFileVersion = fetchByPrimaryKey(fileVersionId);
388
389 if (dlFileVersion == null) {
390 if (_log.isWarnEnabled()) {
391 _log.warn("No DLFileVersion exists with the primary key " +
392 fileVersionId);
393 }
394
395 throw new NoSuchFileVersionException(
396 "No DLFileVersion exists with the primary key " +
397 fileVersionId);
398 }
399
400 return dlFileVersion;
401 }
402
403 public DLFileVersion fetchByPrimaryKey(long fileVersionId)
404 throws SystemException {
405 DLFileVersion dlFileVersion = (DLFileVersion)EntityCacheUtil.getResult(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
406 DLFileVersionImpl.class, fileVersionId, this);
407
408 if (dlFileVersion == null) {
409 Session session = null;
410
411 try {
412 session = openSession();
413
414 dlFileVersion = (DLFileVersion)session.get(DLFileVersionImpl.class,
415 new Long(fileVersionId));
416 }
417 catch (Exception e) {
418 throw processException(e);
419 }
420 finally {
421 if (dlFileVersion != null) {
422 cacheResult(dlFileVersion);
423 }
424
425 closeSession(session);
426 }
427 }
428
429 return dlFileVersion;
430 }
431
432 public List<DLFileVersion> findByF_N(long folderId, String name)
433 throws SystemException {
434 Object[] finderArgs = new Object[] { new Long(folderId), name };
435
436 List<DLFileVersion> list = (List<DLFileVersion>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_F_N,
437 finderArgs, this);
438
439 if (list == null) {
440 Session session = null;
441
442 try {
443 session = openSession();
444
445 StringBuilder query = new StringBuilder();
446
447 query.append(
448 "SELECT dlFileVersion FROM DLFileVersion dlFileVersion WHERE ");
449
450 query.append("dlFileVersion.folderId = ?");
451
452 query.append(" AND ");
453
454 if (name == null) {
455 query.append("dlFileVersion.name IS NULL");
456 }
457 else {
458 query.append("dlFileVersion.name = ?");
459 }
460
461 query.append(" ");
462
463 query.append("ORDER BY ");
464
465 query.append("dlFileVersion.folderId DESC, ");
466 query.append("dlFileVersion.name DESC, ");
467 query.append("dlFileVersion.version DESC");
468
469 Query q = session.createQuery(query.toString());
470
471 QueryPos qPos = QueryPos.getInstance(q);
472
473 qPos.add(folderId);
474
475 if (name != null) {
476 qPos.add(name);
477 }
478
479 list = q.list();
480 }
481 catch (Exception e) {
482 throw processException(e);
483 }
484 finally {
485 if (list == null) {
486 list = new ArrayList<DLFileVersion>();
487 }
488
489 cacheResult(list);
490
491 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_F_N, finderArgs,
492 list);
493
494 closeSession(session);
495 }
496 }
497
498 return list;
499 }
500
501 public List<DLFileVersion> findByF_N(long folderId, String name, int start,
502 int end) throws SystemException {
503 return findByF_N(folderId, name, start, end, null);
504 }
505
506 public List<DLFileVersion> findByF_N(long folderId, String name, int start,
507 int end, OrderByComparator obc) throws SystemException {
508 Object[] finderArgs = new Object[] {
509 new Long(folderId),
510
511 name,
512
513 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
514 };
515
516 List<DLFileVersion> list = (List<DLFileVersion>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_F_N,
517 finderArgs, this);
518
519 if (list == null) {
520 Session session = null;
521
522 try {
523 session = openSession();
524
525 StringBuilder query = new StringBuilder();
526
527 query.append(
528 "SELECT dlFileVersion FROM DLFileVersion dlFileVersion WHERE ");
529
530 query.append("dlFileVersion.folderId = ?");
531
532 query.append(" AND ");
533
534 if (name == null) {
535 query.append("dlFileVersion.name IS NULL");
536 }
537 else {
538 query.append("dlFileVersion.name = ?");
539 }
540
541 query.append(" ");
542
543 if (obc != null) {
544 query.append("ORDER BY ");
545
546 String[] orderByFields = obc.getOrderByFields();
547
548 for (int i = 0; i < orderByFields.length; i++) {
549 query.append("dlFileVersion.");
550 query.append(orderByFields[i]);
551
552 if (obc.isAscending()) {
553 query.append(" ASC");
554 }
555 else {
556 query.append(" DESC");
557 }
558
559 if ((i + 1) < orderByFields.length) {
560 query.append(", ");
561 }
562 }
563 }
564
565 else {
566 query.append("ORDER BY ");
567
568 query.append("dlFileVersion.folderId DESC, ");
569 query.append("dlFileVersion.name DESC, ");
570 query.append("dlFileVersion.version DESC");
571 }
572
573 Query q = session.createQuery(query.toString());
574
575 QueryPos qPos = QueryPos.getInstance(q);
576
577 qPos.add(folderId);
578
579 if (name != null) {
580 qPos.add(name);
581 }
582
583 list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
584 start, end);
585 }
586 catch (Exception e) {
587 throw processException(e);
588 }
589 finally {
590 if (list == null) {
591 list = new ArrayList<DLFileVersion>();
592 }
593
594 cacheResult(list);
595
596 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_F_N,
597 finderArgs, list);
598
599 closeSession(session);
600 }
601 }
602
603 return list;
604 }
605
606 public DLFileVersion findByF_N_First(long folderId, String name,
607 OrderByComparator obc)
608 throws NoSuchFileVersionException, SystemException {
609 List<DLFileVersion> list = findByF_N(folderId, name, 0, 1, obc);
610
611 if (list.isEmpty()) {
612 StringBuilder msg = new StringBuilder();
613
614 msg.append("No DLFileVersion exists with the key {");
615
616 msg.append("folderId=" + folderId);
617
618 msg.append(", ");
619 msg.append("name=" + name);
620
621 msg.append(StringPool.CLOSE_CURLY_BRACE);
622
623 throw new NoSuchFileVersionException(msg.toString());
624 }
625 else {
626 return list.get(0);
627 }
628 }
629
630 public DLFileVersion findByF_N_Last(long folderId, String name,
631 OrderByComparator obc)
632 throws NoSuchFileVersionException, SystemException {
633 int count = countByF_N(folderId, name);
634
635 List<DLFileVersion> list = findByF_N(folderId, name, count - 1, count,
636 obc);
637
638 if (list.isEmpty()) {
639 StringBuilder msg = new StringBuilder();
640
641 msg.append("No DLFileVersion exists with the key {");
642
643 msg.append("folderId=" + folderId);
644
645 msg.append(", ");
646 msg.append("name=" + name);
647
648 msg.append(StringPool.CLOSE_CURLY_BRACE);
649
650 throw new NoSuchFileVersionException(msg.toString());
651 }
652 else {
653 return list.get(0);
654 }
655 }
656
657 public DLFileVersion[] findByF_N_PrevAndNext(long fileVersionId,
658 long folderId, String name, OrderByComparator obc)
659 throws NoSuchFileVersionException, SystemException {
660 DLFileVersion dlFileVersion = findByPrimaryKey(fileVersionId);
661
662 int count = countByF_N(folderId, name);
663
664 Session session = null;
665
666 try {
667 session = openSession();
668
669 StringBuilder query = new StringBuilder();
670
671 query.append(
672 "SELECT dlFileVersion FROM DLFileVersion dlFileVersion WHERE ");
673
674 query.append("dlFileVersion.folderId = ?");
675
676 query.append(" AND ");
677
678 if (name == null) {
679 query.append("dlFileVersion.name IS NULL");
680 }
681 else {
682 query.append("dlFileVersion.name = ?");
683 }
684
685 query.append(" ");
686
687 if (obc != null) {
688 query.append("ORDER BY ");
689
690 String[] orderByFields = obc.getOrderByFields();
691
692 for (int i = 0; i < orderByFields.length; i++) {
693 query.append("dlFileVersion.");
694 query.append(orderByFields[i]);
695
696 if (obc.isAscending()) {
697 query.append(" ASC");
698 }
699 else {
700 query.append(" DESC");
701 }
702
703 if ((i + 1) < orderByFields.length) {
704 query.append(", ");
705 }
706 }
707 }
708
709 else {
710 query.append("ORDER BY ");
711
712 query.append("dlFileVersion.folderId DESC, ");
713 query.append("dlFileVersion.name DESC, ");
714 query.append("dlFileVersion.version DESC");
715 }
716
717 Query q = session.createQuery(query.toString());
718
719 QueryPos qPos = QueryPos.getInstance(q);
720
721 qPos.add(folderId);
722
723 if (name != null) {
724 qPos.add(name);
725 }
726
727 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
728 dlFileVersion);
729
730 DLFileVersion[] array = new DLFileVersionImpl[3];
731
732 array[0] = (DLFileVersion)objArray[0];
733 array[1] = (DLFileVersion)objArray[1];
734 array[2] = (DLFileVersion)objArray[2];
735
736 return array;
737 }
738 catch (Exception e) {
739 throw processException(e);
740 }
741 finally {
742 closeSession(session);
743 }
744 }
745
746 public DLFileVersion findByF_N_V(long folderId, String name, double version)
747 throws NoSuchFileVersionException, SystemException {
748 DLFileVersion dlFileVersion = fetchByF_N_V(folderId, name, version);
749
750 if (dlFileVersion == null) {
751 StringBuilder msg = new StringBuilder();
752
753 msg.append("No DLFileVersion exists with the key {");
754
755 msg.append("folderId=" + folderId);
756
757 msg.append(", ");
758 msg.append("name=" + name);
759
760 msg.append(", ");
761 msg.append("version=" + version);
762
763 msg.append(StringPool.CLOSE_CURLY_BRACE);
764
765 if (_log.isWarnEnabled()) {
766 _log.warn(msg.toString());
767 }
768
769 throw new NoSuchFileVersionException(msg.toString());
770 }
771
772 return dlFileVersion;
773 }
774
775 public DLFileVersion fetchByF_N_V(long folderId, String name, double version)
776 throws SystemException {
777 return fetchByF_N_V(folderId, name, version, true);
778 }
779
780 public DLFileVersion fetchByF_N_V(long folderId, String name,
781 double version, boolean retrieveFromCache) throws SystemException {
782 Object[] finderArgs = new Object[] {
783 new Long(folderId),
784
785 name, new Double(version)
786 };
787
788 Object result = null;
789
790 if (retrieveFromCache) {
791 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_F_N_V,
792 finderArgs, this);
793 }
794
795 if (result == null) {
796 Session session = null;
797
798 try {
799 session = openSession();
800
801 StringBuilder query = new StringBuilder();
802
803 query.append(
804 "SELECT dlFileVersion FROM DLFileVersion dlFileVersion WHERE ");
805
806 query.append("dlFileVersion.folderId = ?");
807
808 query.append(" AND ");
809
810 if (name == null) {
811 query.append("dlFileVersion.name IS NULL");
812 }
813 else {
814 query.append("dlFileVersion.name = ?");
815 }
816
817 query.append(" AND ");
818
819 query.append("dlFileVersion.version = ?");
820
821 query.append(" ");
822
823 query.append("ORDER BY ");
824
825 query.append("dlFileVersion.folderId DESC, ");
826 query.append("dlFileVersion.name DESC, ");
827 query.append("dlFileVersion.version DESC");
828
829 Query q = session.createQuery(query.toString());
830
831 QueryPos qPos = QueryPos.getInstance(q);
832
833 qPos.add(folderId);
834
835 if (name != null) {
836 qPos.add(name);
837 }
838
839 qPos.add(version);
840
841 List<DLFileVersion> list = q.list();
842
843 result = list;
844
845 DLFileVersion dlFileVersion = null;
846
847 if (list.isEmpty()) {
848 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_F_N_V,
849 finderArgs, list);
850 }
851 else {
852 dlFileVersion = list.get(0);
853
854 cacheResult(dlFileVersion);
855
856 if ((dlFileVersion.getFolderId() != folderId) ||
857 (dlFileVersion.getName() == null) ||
858 !dlFileVersion.getName().equals(name) ||
859 (dlFileVersion.getVersion() != version)) {
860 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_F_N_V,
861 finderArgs, dlFileVersion);
862 }
863 }
864
865 return dlFileVersion;
866 }
867 catch (Exception e) {
868 throw processException(e);
869 }
870 finally {
871 if (result == null) {
872 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_F_N_V,
873 finderArgs, new ArrayList<DLFileVersion>());
874 }
875
876 closeSession(session);
877 }
878 }
879 else {
880 if (result instanceof List<?>) {
881 return null;
882 }
883 else {
884 return (DLFileVersion)result;
885 }
886 }
887 }
888
889 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
890 throws SystemException {
891 Session session = null;
892
893 try {
894 session = openSession();
895
896 dynamicQuery.compile(session);
897
898 return dynamicQuery.list();
899 }
900 catch (Exception e) {
901 throw processException(e);
902 }
903 finally {
904 closeSession(session);
905 }
906 }
907
908 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
909 int start, int end) throws SystemException {
910 Session session = null;
911
912 try {
913 session = openSession();
914
915 dynamicQuery.setLimit(start, end);
916
917 dynamicQuery.compile(session);
918
919 return dynamicQuery.list();
920 }
921 catch (Exception e) {
922 throw processException(e);
923 }
924 finally {
925 closeSession(session);
926 }
927 }
928
929 public List<DLFileVersion> findAll() throws SystemException {
930 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
931 }
932
933 public List<DLFileVersion> findAll(int start, int end)
934 throws SystemException {
935 return findAll(start, end, null);
936 }
937
938 public List<DLFileVersion> findAll(int start, int end, OrderByComparator obc)
939 throws SystemException {
940 Object[] finderArgs = new Object[] {
941 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
942 };
943
944 List<DLFileVersion> list = (List<DLFileVersion>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
945 finderArgs, this);
946
947 if (list == null) {
948 Session session = null;
949
950 try {
951 session = openSession();
952
953 StringBuilder query = new StringBuilder();
954
955 query.append(
956 "SELECT dlFileVersion FROM DLFileVersion dlFileVersion ");
957
958 if (obc != null) {
959 query.append("ORDER BY ");
960
961 String[] orderByFields = obc.getOrderByFields();
962
963 for (int i = 0; i < orderByFields.length; i++) {
964 query.append("dlFileVersion.");
965 query.append(orderByFields[i]);
966
967 if (obc.isAscending()) {
968 query.append(" ASC");
969 }
970 else {
971 query.append(" DESC");
972 }
973
974 if ((i + 1) < orderByFields.length) {
975 query.append(", ");
976 }
977 }
978 }
979
980 else {
981 query.append("ORDER BY ");
982
983 query.append("dlFileVersion.folderId DESC, ");
984 query.append("dlFileVersion.name DESC, ");
985 query.append("dlFileVersion.version DESC");
986 }
987
988 Query q = session.createQuery(query.toString());
989
990 if (obc == null) {
991 list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
992 start, end, false);
993
994 Collections.sort(list);
995 }
996 else {
997 list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
998 start, end);
999 }
1000 }
1001 catch (Exception e) {
1002 throw processException(e);
1003 }
1004 finally {
1005 if (list == null) {
1006 list = new ArrayList<DLFileVersion>();
1007 }
1008
1009 cacheResult(list);
1010
1011 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1012
1013 closeSession(session);
1014 }
1015 }
1016
1017 return list;
1018 }
1019
1020 public void removeByF_N(long folderId, String name)
1021 throws SystemException {
1022 for (DLFileVersion dlFileVersion : findByF_N(folderId, name)) {
1023 remove(dlFileVersion);
1024 }
1025 }
1026
1027 public void removeByF_N_V(long folderId, String name, double version)
1028 throws NoSuchFileVersionException, SystemException {
1029 DLFileVersion dlFileVersion = findByF_N_V(folderId, name, version);
1030
1031 remove(dlFileVersion);
1032 }
1033
1034 public void removeAll() throws SystemException {
1035 for (DLFileVersion dlFileVersion : findAll()) {
1036 remove(dlFileVersion);
1037 }
1038 }
1039
1040 public int countByF_N(long folderId, String name) throws SystemException {
1041 Object[] finderArgs = new Object[] { new Long(folderId), name };
1042
1043 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_F_N,
1044 finderArgs, this);
1045
1046 if (count == null) {
1047 Session session = null;
1048
1049 try {
1050 session = openSession();
1051
1052 StringBuilder query = new StringBuilder();
1053
1054 query.append("SELECT COUNT(dlFileVersion) ");
1055 query.append("FROM DLFileVersion dlFileVersion WHERE ");
1056
1057 query.append("dlFileVersion.folderId = ?");
1058
1059 query.append(" AND ");
1060
1061 if (name == null) {
1062 query.append("dlFileVersion.name IS NULL");
1063 }
1064 else {
1065 query.append("dlFileVersion.name = ?");
1066 }
1067
1068 query.append(" ");
1069
1070 Query q = session.createQuery(query.toString());
1071
1072 QueryPos qPos = QueryPos.getInstance(q);
1073
1074 qPos.add(folderId);
1075
1076 if (name != null) {
1077 qPos.add(name);
1078 }
1079
1080 count = (Long)q.uniqueResult();
1081 }
1082 catch (Exception e) {
1083 throw processException(e);
1084 }
1085 finally {
1086 if (count == null) {
1087 count = Long.valueOf(0);
1088 }
1089
1090 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_F_N, finderArgs,
1091 count);
1092
1093 closeSession(session);
1094 }
1095 }
1096
1097 return count.intValue();
1098 }
1099
1100 public int countByF_N_V(long folderId, String name, double version)
1101 throws SystemException {
1102 Object[] finderArgs = new Object[] {
1103 new Long(folderId),
1104
1105 name, new Double(version)
1106 };
1107
1108 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_F_N_V,
1109 finderArgs, this);
1110
1111 if (count == null) {
1112 Session session = null;
1113
1114 try {
1115 session = openSession();
1116
1117 StringBuilder query = new StringBuilder();
1118
1119 query.append("SELECT COUNT(dlFileVersion) ");
1120 query.append("FROM DLFileVersion dlFileVersion WHERE ");
1121
1122 query.append("dlFileVersion.folderId = ?");
1123
1124 query.append(" AND ");
1125
1126 if (name == null) {
1127 query.append("dlFileVersion.name IS NULL");
1128 }
1129 else {
1130 query.append("dlFileVersion.name = ?");
1131 }
1132
1133 query.append(" AND ");
1134
1135 query.append("dlFileVersion.version = ?");
1136
1137 query.append(" ");
1138
1139 Query q = session.createQuery(query.toString());
1140
1141 QueryPos qPos = QueryPos.getInstance(q);
1142
1143 qPos.add(folderId);
1144
1145 if (name != null) {
1146 qPos.add(name);
1147 }
1148
1149 qPos.add(version);
1150
1151 count = (Long)q.uniqueResult();
1152 }
1153 catch (Exception e) {
1154 throw processException(e);
1155 }
1156 finally {
1157 if (count == null) {
1158 count = Long.valueOf(0);
1159 }
1160
1161 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_F_N_V,
1162 finderArgs, count);
1163
1164 closeSession(session);
1165 }
1166 }
1167
1168 return count.intValue();
1169 }
1170
1171 public int countAll() throws SystemException {
1172 Object[] finderArgs = new Object[0];
1173
1174 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1175 finderArgs, this);
1176
1177 if (count == null) {
1178 Session session = null;
1179
1180 try {
1181 session = openSession();
1182
1183 Query q = session.createQuery(
1184 "SELECT COUNT(dlFileVersion) FROM DLFileVersion dlFileVersion");
1185
1186 count = (Long)q.uniqueResult();
1187 }
1188 catch (Exception e) {
1189 throw processException(e);
1190 }
1191 finally {
1192 if (count == null) {
1193 count = Long.valueOf(0);
1194 }
1195
1196 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1197 count);
1198
1199 closeSession(session);
1200 }
1201 }
1202
1203 return count.intValue();
1204 }
1205
1206 public void afterPropertiesSet() {
1207 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1208 com.liferay.portal.util.PropsUtil.get(
1209 "value.object.listener.com.liferay.portlet.documentlibrary.model.DLFileVersion")));
1210
1211 if (listenerClassNames.length > 0) {
1212 try {
1213 List<ModelListener<DLFileVersion>> listenersList = new ArrayList<ModelListener<DLFileVersion>>();
1214
1215 for (String listenerClassName : listenerClassNames) {
1216 listenersList.add((ModelListener<DLFileVersion>)Class.forName(
1217 listenerClassName).newInstance());
1218 }
1219
1220 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1221 }
1222 catch (Exception e) {
1223 _log.error(e);
1224 }
1225 }
1226 }
1227
1228 @BeanReference(name = "com.liferay.portlet.documentlibrary.service.persistence.DLFileEntryPersistence.impl")
1229 protected com.liferay.portlet.documentlibrary.service.persistence.DLFileEntryPersistence dlFileEntryPersistence;
1230 @BeanReference(name = "com.liferay.portlet.documentlibrary.service.persistence.DLFileRankPersistence.impl")
1231 protected com.liferay.portlet.documentlibrary.service.persistence.DLFileRankPersistence dlFileRankPersistence;
1232 @BeanReference(name = "com.liferay.portlet.documentlibrary.service.persistence.DLFileShortcutPersistence.impl")
1233 protected com.liferay.portlet.documentlibrary.service.persistence.DLFileShortcutPersistence dlFileShortcutPersistence;
1234 @BeanReference(name = "com.liferay.portlet.documentlibrary.service.persistence.DLFileVersionPersistence.impl")
1235 protected com.liferay.portlet.documentlibrary.service.persistence.DLFileVersionPersistence dlFileVersionPersistence;
1236 @BeanReference(name = "com.liferay.portlet.documentlibrary.service.persistence.DLFolderPersistence.impl")
1237 protected com.liferay.portlet.documentlibrary.service.persistence.DLFolderPersistence dlFolderPersistence;
1238 @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence.impl")
1239 protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
1240 @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence.impl")
1241 protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
1242 private static Log _log = LogFactoryUtil.getLog(DLFileVersionPersistenceImpl.class);
1243}