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