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