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