1
22
23 package com.liferay.portlet.documentlibrary.service.persistence;
24
25 import com.liferay.portal.SystemException;
26 import com.liferay.portal.kernel.dao.DynamicQuery;
27 import com.liferay.portal.kernel.dao.DynamicQueryInitializer;
28 import com.liferay.portal.kernel.util.GetterUtil;
29 import com.liferay.portal.kernel.util.OrderByComparator;
30 import com.liferay.portal.kernel.util.StringMaker;
31 import com.liferay.portal.kernel.util.StringPool;
32 import com.liferay.portal.kernel.util.StringUtil;
33 import com.liferay.portal.kernel.util.Validator;
34 import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
35 import com.liferay.portal.model.ModelListener;
36 import com.liferay.portal.service.persistence.BasePersistence;
37 import com.liferay.portal.spring.hibernate.FinderCache;
38 import com.liferay.portal.spring.hibernate.HibernateUtil;
39 import com.liferay.portal.util.PropsUtil;
40
41 import com.liferay.portlet.documentlibrary.NoSuchFolderException;
42 import com.liferay.portlet.documentlibrary.model.DLFolder;
43 import com.liferay.portlet.documentlibrary.model.impl.DLFolderImpl;
44 import com.liferay.portlet.documentlibrary.model.impl.DLFolderModelImpl;
45
46 import com.liferay.util.dao.hibernate.QueryUtil;
47
48 import org.apache.commons.logging.Log;
49 import org.apache.commons.logging.LogFactory;
50
51 import org.hibernate.Query;
52 import org.hibernate.Session;
53
54 import java.util.ArrayList;
55 import java.util.Collections;
56 import java.util.Iterator;
57 import java.util.List;
58
59
65 public class DLFolderPersistenceImpl extends BasePersistence
66 implements DLFolderPersistence {
67 public DLFolder create(long folderId) {
68 DLFolder dlFolder = new DLFolderImpl();
69
70 dlFolder.setNew(true);
71 dlFolder.setPrimaryKey(folderId);
72
73 String uuid = PortalUUIDUtil.generate();
74
75 dlFolder.setUuid(uuid);
76
77 return dlFolder;
78 }
79
80 public DLFolder remove(long folderId)
81 throws NoSuchFolderException, SystemException {
82 Session session = null;
83
84 try {
85 session = openSession();
86
87 DLFolder dlFolder = (DLFolder)session.get(DLFolderImpl.class,
88 new Long(folderId));
89
90 if (dlFolder == null) {
91 if (_log.isWarnEnabled()) {
92 _log.warn("No DLFolder exists with the primary key " +
93 folderId);
94 }
95
96 throw new NoSuchFolderException(
97 "No DLFolder exists with the primary key " + folderId);
98 }
99
100 return remove(dlFolder);
101 }
102 catch (NoSuchFolderException nsee) {
103 throw nsee;
104 }
105 catch (Exception e) {
106 throw HibernateUtil.processException(e);
107 }
108 finally {
109 closeSession(session);
110 }
111 }
112
113 public DLFolder remove(DLFolder dlFolder) throws SystemException {
114 if (_listeners != null) {
115 for (ModelListener listener : _listeners) {
116 listener.onBeforeRemove(dlFolder);
117 }
118 }
119
120 dlFolder = removeImpl(dlFolder);
121
122 if (_listeners != null) {
123 for (ModelListener listener : _listeners) {
124 listener.onAfterRemove(dlFolder);
125 }
126 }
127
128 return dlFolder;
129 }
130
131 protected DLFolder removeImpl(DLFolder dlFolder) throws SystemException {
132 Session session = null;
133
134 try {
135 session = openSession();
136
137 session.delete(dlFolder);
138
139 session.flush();
140
141 return dlFolder;
142 }
143 catch (Exception e) {
144 throw HibernateUtil.processException(e);
145 }
146 finally {
147 closeSession(session);
148
149 FinderCache.clearCache(DLFolder.class.getName());
150 }
151 }
152
153
156 public DLFolder update(DLFolder dlFolder) throws SystemException {
157 if (_log.isWarnEnabled()) {
158 _log.warn(
159 "Using the deprecated update(DLFolder dlFolder) method. Use update(DLFolder dlFolder, boolean merge) instead.");
160 }
161
162 return update(dlFolder, false);
163 }
164
165
178 public DLFolder update(DLFolder dlFolder, boolean merge)
179 throws SystemException {
180 boolean isNew = dlFolder.isNew();
181
182 if (_listeners != null) {
183 for (ModelListener listener : _listeners) {
184 if (isNew) {
185 listener.onBeforeCreate(dlFolder);
186 }
187 else {
188 listener.onBeforeUpdate(dlFolder);
189 }
190 }
191 }
192
193 dlFolder = updateImpl(dlFolder, merge);
194
195 if (_listeners != null) {
196 for (ModelListener listener : _listeners) {
197 if (isNew) {
198 listener.onAfterCreate(dlFolder);
199 }
200 else {
201 listener.onAfterUpdate(dlFolder);
202 }
203 }
204 }
205
206 return dlFolder;
207 }
208
209 public DLFolder updateImpl(
210 com.liferay.portlet.documentlibrary.model.DLFolder dlFolder,
211 boolean merge) throws SystemException {
212 if (Validator.isNull(dlFolder.getUuid())) {
213 String uuid = PortalUUIDUtil.generate();
214
215 dlFolder.setUuid(uuid);
216 }
217
218 Session session = null;
219
220 try {
221 session = openSession();
222
223 if (merge) {
224 session.merge(dlFolder);
225 }
226 else {
227 if (dlFolder.isNew()) {
228 session.save(dlFolder);
229 }
230 }
231
232 session.flush();
233
234 dlFolder.setNew(false);
235
236 return dlFolder;
237 }
238 catch (Exception e) {
239 throw HibernateUtil.processException(e);
240 }
241 finally {
242 closeSession(session);
243
244 FinderCache.clearCache(DLFolder.class.getName());
245 }
246 }
247
248 public DLFolder findByPrimaryKey(long folderId)
249 throws NoSuchFolderException, SystemException {
250 DLFolder dlFolder = fetchByPrimaryKey(folderId);
251
252 if (dlFolder == null) {
253 if (_log.isWarnEnabled()) {
254 _log.warn("No DLFolder exists with the primary key " +
255 folderId);
256 }
257
258 throw new NoSuchFolderException(
259 "No DLFolder exists with the primary key " + folderId);
260 }
261
262 return dlFolder;
263 }
264
265 public DLFolder fetchByPrimaryKey(long folderId) throws SystemException {
266 Session session = null;
267
268 try {
269 session = openSession();
270
271 return (DLFolder)session.get(DLFolderImpl.class, new Long(folderId));
272 }
273 catch (Exception e) {
274 throw HibernateUtil.processException(e);
275 }
276 finally {
277 closeSession(session);
278 }
279 }
280
281 public List<DLFolder> findByUuid(String uuid) throws SystemException {
282 boolean finderClassNameCacheEnabled = DLFolderModelImpl.CACHE_ENABLED;
283 String finderClassName = DLFolder.class.getName();
284 String finderMethodName = "findByUuid";
285 String[] finderParams = new String[] { String.class.getName() };
286 Object[] finderArgs = new Object[] { uuid };
287
288 Object result = null;
289
290 if (finderClassNameCacheEnabled) {
291 result = FinderCache.getResult(finderClassName, finderMethodName,
292 finderParams, finderArgs, getSessionFactory());
293 }
294
295 if (result == null) {
296 Session session = null;
297
298 try {
299 session = openSession();
300
301 StringMaker query = new StringMaker();
302
303 query.append(
304 "FROM com.liferay.portlet.documentlibrary.model.DLFolder WHERE ");
305
306 if (uuid == null) {
307 query.append("uuid_ IS NULL");
308 }
309 else {
310 query.append("uuid_ = ?");
311 }
312
313 query.append(" ");
314
315 query.append("ORDER BY ");
316
317 query.append("parentFolderId ASC, ");
318 query.append("name ASC");
319
320 Query q = session.createQuery(query.toString());
321
322 int queryPos = 0;
323
324 if (uuid != null) {
325 q.setString(queryPos++, uuid);
326 }
327
328 List<DLFolder> list = q.list();
329
330 FinderCache.putResult(finderClassNameCacheEnabled,
331 finderClassName, finderMethodName, finderParams,
332 finderArgs, list);
333
334 return list;
335 }
336 catch (Exception e) {
337 throw HibernateUtil.processException(e);
338 }
339 finally {
340 closeSession(session);
341 }
342 }
343 else {
344 return (List<DLFolder>)result;
345 }
346 }
347
348 public List<DLFolder> findByUuid(String uuid, int begin, int end)
349 throws SystemException {
350 return findByUuid(uuid, begin, end, null);
351 }
352
353 public List<DLFolder> findByUuid(String uuid, int begin, int end,
354 OrderByComparator obc) throws SystemException {
355 boolean finderClassNameCacheEnabled = DLFolderModelImpl.CACHE_ENABLED;
356 String finderClassName = DLFolder.class.getName();
357 String finderMethodName = "findByUuid";
358 String[] finderParams = new String[] {
359 String.class.getName(),
360
361 "java.lang.Integer", "java.lang.Integer",
362 "com.liferay.portal.kernel.util.OrderByComparator"
363 };
364 Object[] finderArgs = new Object[] {
365 uuid,
366
367 String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
368 };
369
370 Object result = null;
371
372 if (finderClassNameCacheEnabled) {
373 result = FinderCache.getResult(finderClassName, finderMethodName,
374 finderParams, finderArgs, getSessionFactory());
375 }
376
377 if (result == null) {
378 Session session = null;
379
380 try {
381 session = openSession();
382
383 StringMaker query = new StringMaker();
384
385 query.append(
386 "FROM com.liferay.portlet.documentlibrary.model.DLFolder WHERE ");
387
388 if (uuid == null) {
389 query.append("uuid_ IS NULL");
390 }
391 else {
392 query.append("uuid_ = ?");
393 }
394
395 query.append(" ");
396
397 if (obc != null) {
398 query.append("ORDER BY ");
399 query.append(obc.getOrderBy());
400 }
401
402 else {
403 query.append("ORDER BY ");
404
405 query.append("parentFolderId ASC, ");
406 query.append("name ASC");
407 }
408
409 Query q = session.createQuery(query.toString());
410
411 int queryPos = 0;
412
413 if (uuid != null) {
414 q.setString(queryPos++, uuid);
415 }
416
417 List<DLFolder> list = (List<DLFolder>)QueryUtil.list(q,
418 getDialect(), begin, end);
419
420 FinderCache.putResult(finderClassNameCacheEnabled,
421 finderClassName, finderMethodName, finderParams,
422 finderArgs, list);
423
424 return list;
425 }
426 catch (Exception e) {
427 throw HibernateUtil.processException(e);
428 }
429 finally {
430 closeSession(session);
431 }
432 }
433 else {
434 return (List<DLFolder>)result;
435 }
436 }
437
438 public DLFolder findByUuid_First(String uuid, OrderByComparator obc)
439 throws NoSuchFolderException, SystemException {
440 List<DLFolder> list = findByUuid(uuid, 0, 1, obc);
441
442 if (list.size() == 0) {
443 StringMaker msg = new StringMaker();
444
445 msg.append("No DLFolder exists with the key {");
446
447 msg.append("uuid=" + uuid);
448
449 msg.append(StringPool.CLOSE_CURLY_BRACE);
450
451 throw new NoSuchFolderException(msg.toString());
452 }
453 else {
454 return list.get(0);
455 }
456 }
457
458 public DLFolder findByUuid_Last(String uuid, OrderByComparator obc)
459 throws NoSuchFolderException, SystemException {
460 int count = countByUuid(uuid);
461
462 List<DLFolder> list = findByUuid(uuid, count - 1, count, obc);
463
464 if (list.size() == 0) {
465 StringMaker msg = new StringMaker();
466
467 msg.append("No DLFolder exists with the key {");
468
469 msg.append("uuid=" + uuid);
470
471 msg.append(StringPool.CLOSE_CURLY_BRACE);
472
473 throw new NoSuchFolderException(msg.toString());
474 }
475 else {
476 return list.get(0);
477 }
478 }
479
480 public DLFolder[] findByUuid_PrevAndNext(long folderId, String uuid,
481 OrderByComparator obc) throws NoSuchFolderException, SystemException {
482 DLFolder dlFolder = findByPrimaryKey(folderId);
483
484 int count = countByUuid(uuid);
485
486 Session session = null;
487
488 try {
489 session = openSession();
490
491 StringMaker query = new StringMaker();
492
493 query.append(
494 "FROM com.liferay.portlet.documentlibrary.model.DLFolder WHERE ");
495
496 if (uuid == null) {
497 query.append("uuid_ IS NULL");
498 }
499 else {
500 query.append("uuid_ = ?");
501 }
502
503 query.append(" ");
504
505 if (obc != null) {
506 query.append("ORDER BY ");
507 query.append(obc.getOrderBy());
508 }
509
510 else {
511 query.append("ORDER BY ");
512
513 query.append("parentFolderId ASC, ");
514 query.append("name ASC");
515 }
516
517 Query q = session.createQuery(query.toString());
518
519 int queryPos = 0;
520
521 if (uuid != null) {
522 q.setString(queryPos++, uuid);
523 }
524
525 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, dlFolder);
526
527 DLFolder[] array = new DLFolderImpl[3];
528
529 array[0] = (DLFolder)objArray[0];
530 array[1] = (DLFolder)objArray[1];
531 array[2] = (DLFolder)objArray[2];
532
533 return array;
534 }
535 catch (Exception e) {
536 throw HibernateUtil.processException(e);
537 }
538 finally {
539 closeSession(session);
540 }
541 }
542
543 public DLFolder findByUUID_G(String uuid, long groupId)
544 throws NoSuchFolderException, SystemException {
545 DLFolder dlFolder = fetchByUUID_G(uuid, groupId);
546
547 if (dlFolder == null) {
548 StringMaker msg = new StringMaker();
549
550 msg.append("No DLFolder exists with the key {");
551
552 msg.append("uuid=" + uuid);
553
554 msg.append(", ");
555 msg.append("groupId=" + groupId);
556
557 msg.append(StringPool.CLOSE_CURLY_BRACE);
558
559 if (_log.isWarnEnabled()) {
560 _log.warn(msg.toString());
561 }
562
563 throw new NoSuchFolderException(msg.toString());
564 }
565
566 return dlFolder;
567 }
568
569 public DLFolder fetchByUUID_G(String uuid, long groupId)
570 throws SystemException {
571 boolean finderClassNameCacheEnabled = DLFolderModelImpl.CACHE_ENABLED;
572 String finderClassName = DLFolder.class.getName();
573 String finderMethodName = "fetchByUUID_G";
574 String[] finderParams = new String[] {
575 String.class.getName(), Long.class.getName()
576 };
577 Object[] finderArgs = new Object[] { uuid, new Long(groupId) };
578
579 Object result = null;
580
581 if (finderClassNameCacheEnabled) {
582 result = FinderCache.getResult(finderClassName, finderMethodName,
583 finderParams, finderArgs, getSessionFactory());
584 }
585
586 if (result == null) {
587 Session session = null;
588
589 try {
590 session = openSession();
591
592 StringMaker query = new StringMaker();
593
594 query.append(
595 "FROM com.liferay.portlet.documentlibrary.model.DLFolder WHERE ");
596
597 if (uuid == null) {
598 query.append("uuid_ IS NULL");
599 }
600 else {
601 query.append("uuid_ = ?");
602 }
603
604 query.append(" AND ");
605
606 query.append("groupId = ?");
607
608 query.append(" ");
609
610 query.append("ORDER BY ");
611
612 query.append("parentFolderId ASC, ");
613 query.append("name ASC");
614
615 Query q = session.createQuery(query.toString());
616
617 int queryPos = 0;
618
619 if (uuid != null) {
620 q.setString(queryPos++, uuid);
621 }
622
623 q.setLong(queryPos++, groupId);
624
625 List<DLFolder> list = q.list();
626
627 FinderCache.putResult(finderClassNameCacheEnabled,
628 finderClassName, finderMethodName, finderParams,
629 finderArgs, list);
630
631 if (list.size() == 0) {
632 return null;
633 }
634 else {
635 return list.get(0);
636 }
637 }
638 catch (Exception e) {
639 throw HibernateUtil.processException(e);
640 }
641 finally {
642 closeSession(session);
643 }
644 }
645 else {
646 List<DLFolder> list = (List<DLFolder>)result;
647
648 if (list.size() == 0) {
649 return null;
650 }
651 else {
652 return list.get(0);
653 }
654 }
655 }
656
657 public List<DLFolder> findByGroupId(long groupId) throws SystemException {
658 boolean finderClassNameCacheEnabled = DLFolderModelImpl.CACHE_ENABLED;
659 String finderClassName = DLFolder.class.getName();
660 String finderMethodName = "findByGroupId";
661 String[] finderParams = new String[] { Long.class.getName() };
662 Object[] finderArgs = new Object[] { new Long(groupId) };
663
664 Object result = null;
665
666 if (finderClassNameCacheEnabled) {
667 result = FinderCache.getResult(finderClassName, finderMethodName,
668 finderParams, finderArgs, getSessionFactory());
669 }
670
671 if (result == null) {
672 Session session = null;
673
674 try {
675 session = openSession();
676
677 StringMaker query = new StringMaker();
678
679 query.append(
680 "FROM com.liferay.portlet.documentlibrary.model.DLFolder WHERE ");
681
682 query.append("groupId = ?");
683
684 query.append(" ");
685
686 query.append("ORDER BY ");
687
688 query.append("parentFolderId ASC, ");
689 query.append("name ASC");
690
691 Query q = session.createQuery(query.toString());
692
693 int queryPos = 0;
694
695 q.setLong(queryPos++, groupId);
696
697 List<DLFolder> list = q.list();
698
699 FinderCache.putResult(finderClassNameCacheEnabled,
700 finderClassName, finderMethodName, finderParams,
701 finderArgs, list);
702
703 return list;
704 }
705 catch (Exception e) {
706 throw HibernateUtil.processException(e);
707 }
708 finally {
709 closeSession(session);
710 }
711 }
712 else {
713 return (List<DLFolder>)result;
714 }
715 }
716
717 public List<DLFolder> findByGroupId(long groupId, int begin, int end)
718 throws SystemException {
719 return findByGroupId(groupId, begin, end, null);
720 }
721
722 public List<DLFolder> findByGroupId(long groupId, int begin, int end,
723 OrderByComparator obc) throws SystemException {
724 boolean finderClassNameCacheEnabled = DLFolderModelImpl.CACHE_ENABLED;
725 String finderClassName = DLFolder.class.getName();
726 String finderMethodName = "findByGroupId";
727 String[] finderParams = new String[] {
728 Long.class.getName(),
729
730 "java.lang.Integer", "java.lang.Integer",
731 "com.liferay.portal.kernel.util.OrderByComparator"
732 };
733 Object[] finderArgs = new Object[] {
734 new Long(groupId),
735
736 String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
737 };
738
739 Object result = null;
740
741 if (finderClassNameCacheEnabled) {
742 result = FinderCache.getResult(finderClassName, finderMethodName,
743 finderParams, finderArgs, getSessionFactory());
744 }
745
746 if (result == null) {
747 Session session = null;
748
749 try {
750 session = openSession();
751
752 StringMaker query = new StringMaker();
753
754 query.append(
755 "FROM com.liferay.portlet.documentlibrary.model.DLFolder WHERE ");
756
757 query.append("groupId = ?");
758
759 query.append(" ");
760
761 if (obc != null) {
762 query.append("ORDER BY ");
763 query.append(obc.getOrderBy());
764 }
765
766 else {
767 query.append("ORDER BY ");
768
769 query.append("parentFolderId ASC, ");
770 query.append("name ASC");
771 }
772
773 Query q = session.createQuery(query.toString());
774
775 int queryPos = 0;
776
777 q.setLong(queryPos++, groupId);
778
779 List<DLFolder> list = (List<DLFolder>)QueryUtil.list(q,
780 getDialect(), begin, end);
781
782 FinderCache.putResult(finderClassNameCacheEnabled,
783 finderClassName, finderMethodName, finderParams,
784 finderArgs, list);
785
786 return list;
787 }
788 catch (Exception e) {
789 throw HibernateUtil.processException(e);
790 }
791 finally {
792 closeSession(session);
793 }
794 }
795 else {
796 return (List<DLFolder>)result;
797 }
798 }
799
800 public DLFolder findByGroupId_First(long groupId, OrderByComparator obc)
801 throws NoSuchFolderException, SystemException {
802 List<DLFolder> list = findByGroupId(groupId, 0, 1, obc);
803
804 if (list.size() == 0) {
805 StringMaker msg = new StringMaker();
806
807 msg.append("No DLFolder exists with the key {");
808
809 msg.append("groupId=" + groupId);
810
811 msg.append(StringPool.CLOSE_CURLY_BRACE);
812
813 throw new NoSuchFolderException(msg.toString());
814 }
815 else {
816 return list.get(0);
817 }
818 }
819
820 public DLFolder findByGroupId_Last(long groupId, OrderByComparator obc)
821 throws NoSuchFolderException, SystemException {
822 int count = countByGroupId(groupId);
823
824 List<DLFolder> list = findByGroupId(groupId, count - 1, count, obc);
825
826 if (list.size() == 0) {
827 StringMaker msg = new StringMaker();
828
829 msg.append("No DLFolder exists with the key {");
830
831 msg.append("groupId=" + groupId);
832
833 msg.append(StringPool.CLOSE_CURLY_BRACE);
834
835 throw new NoSuchFolderException(msg.toString());
836 }
837 else {
838 return list.get(0);
839 }
840 }
841
842 public DLFolder[] findByGroupId_PrevAndNext(long folderId, long groupId,
843 OrderByComparator obc) throws NoSuchFolderException, SystemException {
844 DLFolder dlFolder = findByPrimaryKey(folderId);
845
846 int count = countByGroupId(groupId);
847
848 Session session = null;
849
850 try {
851 session = openSession();
852
853 StringMaker query = new StringMaker();
854
855 query.append(
856 "FROM com.liferay.portlet.documentlibrary.model.DLFolder WHERE ");
857
858 query.append("groupId = ?");
859
860 query.append(" ");
861
862 if (obc != null) {
863 query.append("ORDER BY ");
864 query.append(obc.getOrderBy());
865 }
866
867 else {
868 query.append("ORDER BY ");
869
870 query.append("parentFolderId ASC, ");
871 query.append("name ASC");
872 }
873
874 Query q = session.createQuery(query.toString());
875
876 int queryPos = 0;
877
878 q.setLong(queryPos++, groupId);
879
880 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, dlFolder);
881
882 DLFolder[] array = new DLFolderImpl[3];
883
884 array[0] = (DLFolder)objArray[0];
885 array[1] = (DLFolder)objArray[1];
886 array[2] = (DLFolder)objArray[2];
887
888 return array;
889 }
890 catch (Exception e) {
891 throw HibernateUtil.processException(e);
892 }
893 finally {
894 closeSession(session);
895 }
896 }
897
898 public List<DLFolder> findByCompanyId(long companyId)
899 throws SystemException {
900 boolean finderClassNameCacheEnabled = DLFolderModelImpl.CACHE_ENABLED;
901 String finderClassName = DLFolder.class.getName();
902 String finderMethodName = "findByCompanyId";
903 String[] finderParams = new String[] { Long.class.getName() };
904 Object[] finderArgs = new Object[] { new Long(companyId) };
905
906 Object result = null;
907
908 if (finderClassNameCacheEnabled) {
909 result = FinderCache.getResult(finderClassName, finderMethodName,
910 finderParams, finderArgs, getSessionFactory());
911 }
912
913 if (result == null) {
914 Session session = null;
915
916 try {
917 session = openSession();
918
919 StringMaker query = new StringMaker();
920
921 query.append(
922 "FROM com.liferay.portlet.documentlibrary.model.DLFolder WHERE ");
923
924 query.append("companyId = ?");
925
926 query.append(" ");
927
928 query.append("ORDER BY ");
929
930 query.append("parentFolderId ASC, ");
931 query.append("name ASC");
932
933 Query q = session.createQuery(query.toString());
934
935 int queryPos = 0;
936
937 q.setLong(queryPos++, companyId);
938
939 List<DLFolder> list = q.list();
940
941 FinderCache.putResult(finderClassNameCacheEnabled,
942 finderClassName, finderMethodName, finderParams,
943 finderArgs, list);
944
945 return list;
946 }
947 catch (Exception e) {
948 throw HibernateUtil.processException(e);
949 }
950 finally {
951 closeSession(session);
952 }
953 }
954 else {
955 return (List<DLFolder>)result;
956 }
957 }
958
959 public List<DLFolder> findByCompanyId(long companyId, int begin, int end)
960 throws SystemException {
961 return findByCompanyId(companyId, begin, end, null);
962 }
963
964 public List<DLFolder> findByCompanyId(long companyId, int begin, int end,
965 OrderByComparator obc) throws SystemException {
966 boolean finderClassNameCacheEnabled = DLFolderModelImpl.CACHE_ENABLED;
967 String finderClassName = DLFolder.class.getName();
968 String finderMethodName = "findByCompanyId";
969 String[] finderParams = new String[] {
970 Long.class.getName(),
971
972 "java.lang.Integer", "java.lang.Integer",
973 "com.liferay.portal.kernel.util.OrderByComparator"
974 };
975 Object[] finderArgs = new Object[] {
976 new Long(companyId),
977
978 String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
979 };
980
981 Object result = null;
982
983 if (finderClassNameCacheEnabled) {
984 result = FinderCache.getResult(finderClassName, finderMethodName,
985 finderParams, finderArgs, getSessionFactory());
986 }
987
988 if (result == null) {
989 Session session = null;
990
991 try {
992 session = openSession();
993
994 StringMaker query = new StringMaker();
995
996 query.append(
997 "FROM com.liferay.portlet.documentlibrary.model.DLFolder WHERE ");
998
999 query.append("companyId = ?");
1000
1001 query.append(" ");
1002
1003 if (obc != null) {
1004 query.append("ORDER BY ");
1005 query.append(obc.getOrderBy());
1006 }
1007
1008 else {
1009 query.append("ORDER BY ");
1010
1011 query.append("parentFolderId ASC, ");
1012 query.append("name ASC");
1013 }
1014
1015 Query q = session.createQuery(query.toString());
1016
1017 int queryPos = 0;
1018
1019 q.setLong(queryPos++, companyId);
1020
1021 List<DLFolder> list = (List<DLFolder>)QueryUtil.list(q,
1022 getDialect(), begin, end);
1023
1024 FinderCache.putResult(finderClassNameCacheEnabled,
1025 finderClassName, finderMethodName, finderParams,
1026 finderArgs, list);
1027
1028 return list;
1029 }
1030 catch (Exception e) {
1031 throw HibernateUtil.processException(e);
1032 }
1033 finally {
1034 closeSession(session);
1035 }
1036 }
1037 else {
1038 return (List<DLFolder>)result;
1039 }
1040 }
1041
1042 public DLFolder findByCompanyId_First(long companyId, OrderByComparator obc)
1043 throws NoSuchFolderException, SystemException {
1044 List<DLFolder> list = findByCompanyId(companyId, 0, 1, obc);
1045
1046 if (list.size() == 0) {
1047 StringMaker msg = new StringMaker();
1048
1049 msg.append("No DLFolder exists with the key {");
1050
1051 msg.append("companyId=" + companyId);
1052
1053 msg.append(StringPool.CLOSE_CURLY_BRACE);
1054
1055 throw new NoSuchFolderException(msg.toString());
1056 }
1057 else {
1058 return list.get(0);
1059 }
1060 }
1061
1062 public DLFolder findByCompanyId_Last(long companyId, OrderByComparator obc)
1063 throws NoSuchFolderException, SystemException {
1064 int count = countByCompanyId(companyId);
1065
1066 List<DLFolder> list = findByCompanyId(companyId, count - 1, count, obc);
1067
1068 if (list.size() == 0) {
1069 StringMaker msg = new StringMaker();
1070
1071 msg.append("No DLFolder exists with the key {");
1072
1073 msg.append("companyId=" + companyId);
1074
1075 msg.append(StringPool.CLOSE_CURLY_BRACE);
1076
1077 throw new NoSuchFolderException(msg.toString());
1078 }
1079 else {
1080 return list.get(0);
1081 }
1082 }
1083
1084 public DLFolder[] findByCompanyId_PrevAndNext(long folderId,
1085 long companyId, OrderByComparator obc)
1086 throws NoSuchFolderException, SystemException {
1087 DLFolder dlFolder = findByPrimaryKey(folderId);
1088
1089 int count = countByCompanyId(companyId);
1090
1091 Session session = null;
1092
1093 try {
1094 session = openSession();
1095
1096 StringMaker query = new StringMaker();
1097
1098 query.append(
1099 "FROM com.liferay.portlet.documentlibrary.model.DLFolder WHERE ");
1100
1101 query.append("companyId = ?");
1102
1103 query.append(" ");
1104
1105 if (obc != null) {
1106 query.append("ORDER BY ");
1107 query.append(obc.getOrderBy());
1108 }
1109
1110 else {
1111 query.append("ORDER BY ");
1112
1113 query.append("parentFolderId ASC, ");
1114 query.append("name ASC");
1115 }
1116
1117 Query q = session.createQuery(query.toString());
1118
1119 int queryPos = 0;
1120
1121 q.setLong(queryPos++, companyId);
1122
1123 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, dlFolder);
1124
1125 DLFolder[] array = new DLFolderImpl[3];
1126
1127 array[0] = (DLFolder)objArray[0];
1128 array[1] = (DLFolder)objArray[1];
1129 array[2] = (DLFolder)objArray[2];
1130
1131 return array;
1132 }
1133 catch (Exception e) {
1134 throw HibernateUtil.processException(e);
1135 }
1136 finally {
1137 closeSession(session);
1138 }
1139 }
1140
1141 public List<DLFolder> findByG_P(long groupId, long parentFolderId)
1142 throws SystemException {
1143 boolean finderClassNameCacheEnabled = DLFolderModelImpl.CACHE_ENABLED;
1144 String finderClassName = DLFolder.class.getName();
1145 String finderMethodName = "findByG_P";
1146 String[] finderParams = new String[] {
1147 Long.class.getName(), Long.class.getName()
1148 };
1149 Object[] finderArgs = new Object[] {
1150 new Long(groupId), new Long(parentFolderId)
1151 };
1152
1153 Object result = null;
1154
1155 if (finderClassNameCacheEnabled) {
1156 result = FinderCache.getResult(finderClassName, finderMethodName,
1157 finderParams, finderArgs, getSessionFactory());
1158 }
1159
1160 if (result == null) {
1161 Session session = null;
1162
1163 try {
1164 session = openSession();
1165
1166 StringMaker query = new StringMaker();
1167
1168 query.append(
1169 "FROM com.liferay.portlet.documentlibrary.model.DLFolder WHERE ");
1170
1171 query.append("groupId = ?");
1172
1173 query.append(" AND ");
1174
1175 query.append("parentFolderId = ?");
1176
1177 query.append(" ");
1178
1179 query.append("ORDER BY ");
1180
1181 query.append("parentFolderId ASC, ");
1182 query.append("name ASC");
1183
1184 Query q = session.createQuery(query.toString());
1185
1186 int queryPos = 0;
1187
1188 q.setLong(queryPos++, groupId);
1189
1190 q.setLong(queryPos++, parentFolderId);
1191
1192 List<DLFolder> list = q.list();
1193
1194 FinderCache.putResult(finderClassNameCacheEnabled,
1195 finderClassName, finderMethodName, finderParams,
1196 finderArgs, list);
1197
1198 return list;
1199 }
1200 catch (Exception e) {
1201 throw HibernateUtil.processException(e);
1202 }
1203 finally {
1204 closeSession(session);
1205 }
1206 }
1207 else {
1208 return (List<DLFolder>)result;
1209 }
1210 }
1211
1212 public List<DLFolder> findByG_P(long groupId, long parentFolderId,
1213 int begin, int end) throws SystemException {
1214 return findByG_P(groupId, parentFolderId, begin, end, null);
1215 }
1216
1217 public List<DLFolder> findByG_P(long groupId, long parentFolderId,
1218 int begin, int end, OrderByComparator obc) throws SystemException {
1219 boolean finderClassNameCacheEnabled = DLFolderModelImpl.CACHE_ENABLED;
1220 String finderClassName = DLFolder.class.getName();
1221 String finderMethodName = "findByG_P";
1222 String[] finderParams = new String[] {
1223 Long.class.getName(), Long.class.getName(),
1224
1225 "java.lang.Integer", "java.lang.Integer",
1226 "com.liferay.portal.kernel.util.OrderByComparator"
1227 };
1228 Object[] finderArgs = new Object[] {
1229 new Long(groupId), new Long(parentFolderId),
1230
1231 String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
1232 };
1233
1234 Object result = null;
1235
1236 if (finderClassNameCacheEnabled) {
1237 result = FinderCache.getResult(finderClassName, finderMethodName,
1238 finderParams, finderArgs, getSessionFactory());
1239 }
1240
1241 if (result == null) {
1242 Session session = null;
1243
1244 try {
1245 session = openSession();
1246
1247 StringMaker query = new StringMaker();
1248
1249 query.append(
1250 "FROM com.liferay.portlet.documentlibrary.model.DLFolder WHERE ");
1251
1252 query.append("groupId = ?");
1253
1254 query.append(" AND ");
1255
1256 query.append("parentFolderId = ?");
1257
1258 query.append(" ");
1259
1260 if (obc != null) {
1261 query.append("ORDER BY ");
1262 query.append(obc.getOrderBy());
1263 }
1264
1265 else {
1266 query.append("ORDER BY ");
1267
1268 query.append("parentFolderId ASC, ");
1269 query.append("name ASC");
1270 }
1271
1272 Query q = session.createQuery(query.toString());
1273
1274 int queryPos = 0;
1275
1276 q.setLong(queryPos++, groupId);
1277
1278 q.setLong(queryPos++, parentFolderId);
1279
1280 List<DLFolder> list = (List<DLFolder>)QueryUtil.list(q,
1281 getDialect(), begin, end);
1282
1283 FinderCache.putResult(finderClassNameCacheEnabled,
1284 finderClassName, finderMethodName, finderParams,
1285 finderArgs, list);
1286
1287 return list;
1288 }
1289 catch (Exception e) {
1290 throw HibernateUtil.processException(e);
1291 }
1292 finally {
1293 closeSession(session);
1294 }
1295 }
1296 else {
1297 return (List<DLFolder>)result;
1298 }
1299 }
1300
1301 public DLFolder findByG_P_First(long groupId, long parentFolderId,
1302 OrderByComparator obc) throws NoSuchFolderException, SystemException {
1303 List<DLFolder> list = findByG_P(groupId, parentFolderId, 0, 1, obc);
1304
1305 if (list.size() == 0) {
1306 StringMaker msg = new StringMaker();
1307
1308 msg.append("No DLFolder exists with the key {");
1309
1310 msg.append("groupId=" + groupId);
1311
1312 msg.append(", ");
1313 msg.append("parentFolderId=" + parentFolderId);
1314
1315 msg.append(StringPool.CLOSE_CURLY_BRACE);
1316
1317 throw new NoSuchFolderException(msg.toString());
1318 }
1319 else {
1320 return list.get(0);
1321 }
1322 }
1323
1324 public DLFolder findByG_P_Last(long groupId, long parentFolderId,
1325 OrderByComparator obc) throws NoSuchFolderException, SystemException {
1326 int count = countByG_P(groupId, parentFolderId);
1327
1328 List<DLFolder> list = findByG_P(groupId, parentFolderId, count - 1,
1329 count, obc);
1330
1331 if (list.size() == 0) {
1332 StringMaker msg = new StringMaker();
1333
1334 msg.append("No DLFolder exists with the key {");
1335
1336 msg.append("groupId=" + groupId);
1337
1338 msg.append(", ");
1339 msg.append("parentFolderId=" + parentFolderId);
1340
1341 msg.append(StringPool.CLOSE_CURLY_BRACE);
1342
1343 throw new NoSuchFolderException(msg.toString());
1344 }
1345 else {
1346 return list.get(0);
1347 }
1348 }
1349
1350 public DLFolder[] findByG_P_PrevAndNext(long folderId, long groupId,
1351 long parentFolderId, OrderByComparator obc)
1352 throws NoSuchFolderException, SystemException {
1353 DLFolder dlFolder = findByPrimaryKey(folderId);
1354
1355 int count = countByG_P(groupId, parentFolderId);
1356
1357 Session session = null;
1358
1359 try {
1360 session = openSession();
1361
1362 StringMaker query = new StringMaker();
1363
1364 query.append(
1365 "FROM com.liferay.portlet.documentlibrary.model.DLFolder WHERE ");
1366
1367 query.append("groupId = ?");
1368
1369 query.append(" AND ");
1370
1371 query.append("parentFolderId = ?");
1372
1373 query.append(" ");
1374
1375 if (obc != null) {
1376 query.append("ORDER BY ");
1377 query.append(obc.getOrderBy());
1378 }
1379
1380 else {
1381 query.append("ORDER BY ");
1382
1383 query.append("parentFolderId ASC, ");
1384 query.append("name ASC");
1385 }
1386
1387 Query q = session.createQuery(query.toString());
1388
1389 int queryPos = 0;
1390
1391 q.setLong(queryPos++, groupId);
1392
1393 q.setLong(queryPos++, parentFolderId);
1394
1395 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, dlFolder);
1396
1397 DLFolder[] array = new DLFolderImpl[3];
1398
1399 array[0] = (DLFolder)objArray[0];
1400 array[1] = (DLFolder)objArray[1];
1401 array[2] = (DLFolder)objArray[2];
1402
1403 return array;
1404 }
1405 catch (Exception e) {
1406 throw HibernateUtil.processException(e);
1407 }
1408 finally {
1409 closeSession(session);
1410 }
1411 }
1412
1413 public List<DLFolder> findByP_N(long parentFolderId, String name)
1414 throws SystemException {
1415 boolean finderClassNameCacheEnabled = DLFolderModelImpl.CACHE_ENABLED;
1416 String finderClassName = DLFolder.class.getName();
1417 String finderMethodName = "findByP_N";
1418 String[] finderParams = new String[] {
1419 Long.class.getName(), String.class.getName()
1420 };
1421 Object[] finderArgs = new Object[] { new Long(parentFolderId), name };
1422
1423 Object result = null;
1424
1425 if (finderClassNameCacheEnabled) {
1426 result = FinderCache.getResult(finderClassName, finderMethodName,
1427 finderParams, finderArgs, getSessionFactory());
1428 }
1429
1430 if (result == null) {
1431 Session session = null;
1432
1433 try {
1434 session = openSession();
1435
1436 StringMaker query = new StringMaker();
1437
1438 query.append(
1439 "FROM com.liferay.portlet.documentlibrary.model.DLFolder WHERE ");
1440
1441 query.append("parentFolderId = ?");
1442
1443 query.append(" AND ");
1444
1445 if (name == null) {
1446 query.append("name IS NULL");
1447 }
1448 else {
1449 query.append("name = ?");
1450 }
1451
1452 query.append(" ");
1453
1454 query.append("ORDER BY ");
1455
1456 query.append("parentFolderId ASC, ");
1457 query.append("name ASC");
1458
1459 Query q = session.createQuery(query.toString());
1460
1461 int queryPos = 0;
1462
1463 q.setLong(queryPos++, parentFolderId);
1464
1465 if (name != null) {
1466 q.setString(queryPos++, name);
1467 }
1468
1469 List<DLFolder> list = q.list();
1470
1471 FinderCache.putResult(finderClassNameCacheEnabled,
1472 finderClassName, finderMethodName, finderParams,
1473 finderArgs, list);
1474
1475 return list;
1476 }
1477 catch (Exception e) {
1478 throw HibernateUtil.processException(e);
1479 }
1480 finally {
1481 closeSession(session);
1482 }
1483 }
1484 else {
1485 return (List<DLFolder>)result;
1486 }
1487 }
1488
1489 public List<DLFolder> findByP_N(long parentFolderId, String name,
1490 int begin, int end) throws SystemException {
1491 return findByP_N(parentFolderId, name, begin, end, null);
1492 }
1493
1494 public List<DLFolder> findByP_N(long parentFolderId, String name,
1495 int begin, int end, OrderByComparator obc) throws SystemException {
1496 boolean finderClassNameCacheEnabled = DLFolderModelImpl.CACHE_ENABLED;
1497 String finderClassName = DLFolder.class.getName();
1498 String finderMethodName = "findByP_N";
1499 String[] finderParams = new String[] {
1500 Long.class.getName(), String.class.getName(),
1501
1502 "java.lang.Integer", "java.lang.Integer",
1503 "com.liferay.portal.kernel.util.OrderByComparator"
1504 };
1505 Object[] finderArgs = new Object[] {
1506 new Long(parentFolderId),
1507
1508 name,
1509
1510 String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
1511 };
1512
1513 Object result = null;
1514
1515 if (finderClassNameCacheEnabled) {
1516 result = FinderCache.getResult(finderClassName, finderMethodName,
1517 finderParams, finderArgs, getSessionFactory());
1518 }
1519
1520 if (result == null) {
1521 Session session = null;
1522
1523 try {
1524 session = openSession();
1525
1526 StringMaker query = new StringMaker();
1527
1528 query.append(
1529 "FROM com.liferay.portlet.documentlibrary.model.DLFolder WHERE ");
1530
1531 query.append("parentFolderId = ?");
1532
1533 query.append(" AND ");
1534
1535 if (name == null) {
1536 query.append("name IS NULL");
1537 }
1538 else {
1539 query.append("name = ?");
1540 }
1541
1542 query.append(" ");
1543
1544 if (obc != null) {
1545 query.append("ORDER BY ");
1546 query.append(obc.getOrderBy());
1547 }
1548
1549 else {
1550 query.append("ORDER BY ");
1551
1552 query.append("parentFolderId ASC, ");
1553 query.append("name ASC");
1554 }
1555
1556 Query q = session.createQuery(query.toString());
1557
1558 int queryPos = 0;
1559
1560 q.setLong(queryPos++, parentFolderId);
1561
1562 if (name != null) {
1563 q.setString(queryPos++, name);
1564 }
1565
1566 List<DLFolder> list = (List<DLFolder>)QueryUtil.list(q,
1567 getDialect(), begin, end);
1568
1569 FinderCache.putResult(finderClassNameCacheEnabled,
1570 finderClassName, finderMethodName, finderParams,
1571 finderArgs, list);
1572
1573 return list;
1574 }
1575 catch (Exception e) {
1576 throw HibernateUtil.processException(e);
1577 }
1578 finally {
1579 closeSession(session);
1580 }
1581 }
1582 else {
1583 return (List<DLFolder>)result;
1584 }
1585 }
1586
1587 public DLFolder findByP_N_First(long parentFolderId, String name,
1588 OrderByComparator obc) throws NoSuchFolderException, SystemException {
1589 List<DLFolder> list = findByP_N(parentFolderId, name, 0, 1, obc);
1590
1591 if (list.size() == 0) {
1592 StringMaker msg = new StringMaker();
1593
1594 msg.append("No DLFolder exists with the key {");
1595
1596 msg.append("parentFolderId=" + parentFolderId);
1597
1598 msg.append(", ");
1599 msg.append("name=" + name);
1600
1601 msg.append(StringPool.CLOSE_CURLY_BRACE);
1602
1603 throw new NoSuchFolderException(msg.toString());
1604 }
1605 else {
1606 return list.get(0);
1607 }
1608 }
1609
1610 public DLFolder findByP_N_Last(long parentFolderId, String name,
1611 OrderByComparator obc) throws NoSuchFolderException, SystemException {
1612 int count = countByP_N(parentFolderId, name);
1613
1614 List<DLFolder> list = findByP_N(parentFolderId, name, count - 1, count,
1615 obc);
1616
1617 if (list.size() == 0) {
1618 StringMaker msg = new StringMaker();
1619
1620 msg.append("No DLFolder exists with the key {");
1621
1622 msg.append("parentFolderId=" + parentFolderId);
1623
1624 msg.append(", ");
1625 msg.append("name=" + name);
1626
1627 msg.append(StringPool.CLOSE_CURLY_BRACE);
1628
1629 throw new NoSuchFolderException(msg.toString());
1630 }
1631 else {
1632 return list.get(0);
1633 }
1634 }
1635
1636 public DLFolder[] findByP_N_PrevAndNext(long folderId, long parentFolderId,
1637 String name, OrderByComparator obc)
1638 throws NoSuchFolderException, SystemException {
1639 DLFolder dlFolder = findByPrimaryKey(folderId);
1640
1641 int count = countByP_N(parentFolderId, name);
1642
1643 Session session = null;
1644
1645 try {
1646 session = openSession();
1647
1648 StringMaker query = new StringMaker();
1649
1650 query.append(
1651 "FROM com.liferay.portlet.documentlibrary.model.DLFolder WHERE ");
1652
1653 query.append("parentFolderId = ?");
1654
1655 query.append(" AND ");
1656
1657 if (name == null) {
1658 query.append("name IS NULL");
1659 }
1660 else {
1661 query.append("name = ?");
1662 }
1663
1664 query.append(" ");
1665
1666 if (obc != null) {
1667 query.append("ORDER BY ");
1668 query.append(obc.getOrderBy());
1669 }
1670
1671 else {
1672 query.append("ORDER BY ");
1673
1674 query.append("parentFolderId ASC, ");
1675 query.append("name ASC");
1676 }
1677
1678 Query q = session.createQuery(query.toString());
1679
1680 int queryPos = 0;
1681
1682 q.setLong(queryPos++, parentFolderId);
1683
1684 if (name != null) {
1685 q.setString(queryPos++, name);
1686 }
1687
1688 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, dlFolder);
1689
1690 DLFolder[] array = new DLFolderImpl[3];
1691
1692 array[0] = (DLFolder)objArray[0];
1693 array[1] = (DLFolder)objArray[1];
1694 array[2] = (DLFolder)objArray[2];
1695
1696 return array;
1697 }
1698 catch (Exception e) {
1699 throw HibernateUtil.processException(e);
1700 }
1701 finally {
1702 closeSession(session);
1703 }
1704 }
1705
1706 public DLFolder findByG_P_N(long groupId, long parentFolderId, String name)
1707 throws NoSuchFolderException, SystemException {
1708 DLFolder dlFolder = fetchByG_P_N(groupId, parentFolderId, name);
1709
1710 if (dlFolder == null) {
1711 StringMaker msg = new StringMaker();
1712
1713 msg.append("No DLFolder exists with the key {");
1714
1715 msg.append("groupId=" + groupId);
1716
1717 msg.append(", ");
1718 msg.append("parentFolderId=" + parentFolderId);
1719
1720 msg.append(", ");
1721 msg.append("name=" + name);
1722
1723 msg.append(StringPool.CLOSE_CURLY_BRACE);
1724
1725 if (_log.isWarnEnabled()) {
1726 _log.warn(msg.toString());
1727 }
1728
1729 throw new NoSuchFolderException(msg.toString());
1730 }
1731
1732 return dlFolder;
1733 }
1734
1735 public DLFolder fetchByG_P_N(long groupId, long parentFolderId, String name)
1736 throws SystemException {
1737 boolean finderClassNameCacheEnabled = DLFolderModelImpl.CACHE_ENABLED;
1738 String finderClassName = DLFolder.class.getName();
1739 String finderMethodName = "fetchByG_P_N";
1740 String[] finderParams = new String[] {
1741 Long.class.getName(), Long.class.getName(),
1742 String.class.getName()
1743 };
1744 Object[] finderArgs = new Object[] {
1745 new Long(groupId), new Long(parentFolderId),
1746
1747 name
1748 };
1749
1750 Object result = null;
1751
1752 if (finderClassNameCacheEnabled) {
1753 result = FinderCache.getResult(finderClassName, finderMethodName,
1754 finderParams, finderArgs, getSessionFactory());
1755 }
1756
1757 if (result == null) {
1758 Session session = null;
1759
1760 try {
1761 session = openSession();
1762
1763 StringMaker query = new StringMaker();
1764
1765 query.append(
1766 "FROM com.liferay.portlet.documentlibrary.model.DLFolder WHERE ");
1767
1768 query.append("groupId = ?");
1769
1770 query.append(" AND ");
1771
1772 query.append("parentFolderId = ?");
1773
1774 query.append(" AND ");
1775
1776 if (name == null) {
1777 query.append("name IS NULL");
1778 }
1779 else {
1780 query.append("name = ?");
1781 }
1782
1783 query.append(" ");
1784
1785 query.append("ORDER BY ");
1786
1787 query.append("parentFolderId ASC, ");
1788 query.append("name ASC");
1789
1790 Query q = session.createQuery(query.toString());
1791
1792 int queryPos = 0;
1793
1794 q.setLong(queryPos++, groupId);
1795
1796 q.setLong(queryPos++, parentFolderId);
1797
1798 if (name != null) {
1799 q.setString(queryPos++, name);
1800 }
1801
1802 List<DLFolder> list = q.list();
1803
1804 FinderCache.putResult(finderClassNameCacheEnabled,
1805 finderClassName, finderMethodName, finderParams,
1806 finderArgs, list);
1807
1808 if (list.size() == 0) {
1809 return null;
1810 }
1811 else {
1812 return list.get(0);
1813 }
1814 }
1815 catch (Exception e) {
1816 throw HibernateUtil.processException(e);
1817 }
1818 finally {
1819 closeSession(session);
1820 }
1821 }
1822 else {
1823 List<DLFolder> list = (List<DLFolder>)result;
1824
1825 if (list.size() == 0) {
1826 return null;
1827 }
1828 else {
1829 return list.get(0);
1830 }
1831 }
1832 }
1833
1834 public List<DLFolder> findWithDynamicQuery(
1835 DynamicQueryInitializer queryInitializer) throws SystemException {
1836 Session session = null;
1837
1838 try {
1839 session = openSession();
1840
1841 DynamicQuery query = queryInitializer.initialize(session);
1842
1843 return query.list();
1844 }
1845 catch (Exception e) {
1846 throw HibernateUtil.processException(e);
1847 }
1848 finally {
1849 closeSession(session);
1850 }
1851 }
1852
1853 public List<DLFolder> findWithDynamicQuery(
1854 DynamicQueryInitializer queryInitializer, int begin, int end)
1855 throws SystemException {
1856 Session session = null;
1857
1858 try {
1859 session = openSession();
1860
1861 DynamicQuery query = queryInitializer.initialize(session);
1862
1863 query.setLimit(begin, end);
1864
1865 return query.list();
1866 }
1867 catch (Exception e) {
1868 throw HibernateUtil.processException(e);
1869 }
1870 finally {
1871 closeSession(session);
1872 }
1873 }
1874
1875 public List<DLFolder> findAll() throws SystemException {
1876 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1877 }
1878
1879 public List<DLFolder> findAll(int begin, int end) throws SystemException {
1880 return findAll(begin, end, null);
1881 }
1882
1883 public List<DLFolder> findAll(int begin, int end, OrderByComparator obc)
1884 throws SystemException {
1885 boolean finderClassNameCacheEnabled = DLFolderModelImpl.CACHE_ENABLED;
1886 String finderClassName = DLFolder.class.getName();
1887 String finderMethodName = "findAll";
1888 String[] finderParams = new String[] {
1889 "java.lang.Integer", "java.lang.Integer",
1890 "com.liferay.portal.kernel.util.OrderByComparator"
1891 };
1892 Object[] finderArgs = new Object[] {
1893 String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
1894 };
1895
1896 Object result = null;
1897
1898 if (finderClassNameCacheEnabled) {
1899 result = FinderCache.getResult(finderClassName, finderMethodName,
1900 finderParams, finderArgs, getSessionFactory());
1901 }
1902
1903 if (result == null) {
1904 Session session = null;
1905
1906 try {
1907 session = openSession();
1908
1909 StringMaker query = new StringMaker();
1910
1911 query.append(
1912 "FROM com.liferay.portlet.documentlibrary.model.DLFolder ");
1913
1914 if (obc != null) {
1915 query.append("ORDER BY ");
1916 query.append(obc.getOrderBy());
1917 }
1918
1919 else {
1920 query.append("ORDER BY ");
1921
1922 query.append("parentFolderId ASC, ");
1923 query.append("name ASC");
1924 }
1925
1926 Query q = session.createQuery(query.toString());
1927
1928 List<DLFolder> list = (List<DLFolder>)QueryUtil.list(q,
1929 getDialect(), begin, end);
1930
1931 if (obc == null) {
1932 Collections.sort(list);
1933 }
1934
1935 FinderCache.putResult(finderClassNameCacheEnabled,
1936 finderClassName, finderMethodName, finderParams,
1937 finderArgs, list);
1938
1939 return list;
1940 }
1941 catch (Exception e) {
1942 throw HibernateUtil.processException(e);
1943 }
1944 finally {
1945 closeSession(session);
1946 }
1947 }
1948 else {
1949 return (List<DLFolder>)result;
1950 }
1951 }
1952
1953 public void removeByUuid(String uuid) throws SystemException {
1954 for (DLFolder dlFolder : findByUuid(uuid)) {
1955 remove(dlFolder);
1956 }
1957 }
1958
1959 public void removeByUUID_G(String uuid, long groupId)
1960 throws NoSuchFolderException, SystemException {
1961 DLFolder dlFolder = findByUUID_G(uuid, groupId);
1962
1963 remove(dlFolder);
1964 }
1965
1966 public void removeByGroupId(long groupId) throws SystemException {
1967 for (DLFolder dlFolder : findByGroupId(groupId)) {
1968 remove(dlFolder);
1969 }
1970 }
1971
1972 public void removeByCompanyId(long companyId) throws SystemException {
1973 for (DLFolder dlFolder : findByCompanyId(companyId)) {
1974 remove(dlFolder);
1975 }
1976 }
1977
1978 public void removeByG_P(long groupId, long parentFolderId)
1979 throws SystemException {
1980 for (DLFolder dlFolder : findByG_P(groupId, parentFolderId)) {
1981 remove(dlFolder);
1982 }
1983 }
1984
1985 public void removeByP_N(long parentFolderId, String name)
1986 throws SystemException {
1987 for (DLFolder dlFolder : findByP_N(parentFolderId, name)) {
1988 remove(dlFolder);
1989 }
1990 }
1991
1992 public void removeByG_P_N(long groupId, long parentFolderId, String name)
1993 throws NoSuchFolderException, SystemException {
1994 DLFolder dlFolder = findByG_P_N(groupId, parentFolderId, name);
1995
1996 remove(dlFolder);
1997 }
1998
1999 public void removeAll() throws SystemException {
2000 for (DLFolder dlFolder : findAll()) {
2001 remove(dlFolder);
2002 }
2003 }
2004
2005 public int countByUuid(String uuid) throws SystemException {
2006 boolean finderClassNameCacheEnabled = DLFolderModelImpl.CACHE_ENABLED;
2007 String finderClassName = DLFolder.class.getName();
2008 String finderMethodName = "countByUuid";
2009 String[] finderParams = new String[] { String.class.getName() };
2010 Object[] finderArgs = new Object[] { uuid };
2011
2012 Object result = null;
2013
2014 if (finderClassNameCacheEnabled) {
2015 result = FinderCache.getResult(finderClassName, finderMethodName,
2016 finderParams, finderArgs, getSessionFactory());
2017 }
2018
2019 if (result == null) {
2020 Session session = null;
2021
2022 try {
2023 session = openSession();
2024
2025 StringMaker query = new StringMaker();
2026
2027 query.append("SELECT COUNT(*) ");
2028 query.append(
2029 "FROM com.liferay.portlet.documentlibrary.model.DLFolder WHERE ");
2030
2031 if (uuid == null) {
2032 query.append("uuid_ IS NULL");
2033 }
2034 else {
2035 query.append("uuid_ = ?");
2036 }
2037
2038 query.append(" ");
2039
2040 Query q = session.createQuery(query.toString());
2041
2042 int queryPos = 0;
2043
2044 if (uuid != null) {
2045 q.setString(queryPos++, uuid);
2046 }
2047
2048 Long count = null;
2049
2050 Iterator<Long> itr = q.list().iterator();
2051
2052 if (itr.hasNext()) {
2053 count = itr.next();
2054 }
2055
2056 if (count == null) {
2057 count = new Long(0);
2058 }
2059
2060 FinderCache.putResult(finderClassNameCacheEnabled,
2061 finderClassName, finderMethodName, finderParams,
2062 finderArgs, count);
2063
2064 return count.intValue();
2065 }
2066 catch (Exception e) {
2067 throw HibernateUtil.processException(e);
2068 }
2069 finally {
2070 closeSession(session);
2071 }
2072 }
2073 else {
2074 return ((Long)result).intValue();
2075 }
2076 }
2077
2078 public int countByUUID_G(String uuid, long groupId)
2079 throws SystemException {
2080 boolean finderClassNameCacheEnabled = DLFolderModelImpl.CACHE_ENABLED;
2081 String finderClassName = DLFolder.class.getName();
2082 String finderMethodName = "countByUUID_G";
2083 String[] finderParams = new String[] {
2084 String.class.getName(), Long.class.getName()
2085 };
2086 Object[] finderArgs = new Object[] { uuid, new Long(groupId) };
2087
2088 Object result = null;
2089
2090 if (finderClassNameCacheEnabled) {
2091 result = FinderCache.getResult(finderClassName, finderMethodName,
2092 finderParams, finderArgs, getSessionFactory());
2093 }
2094
2095 if (result == null) {
2096 Session session = null;
2097
2098 try {
2099 session = openSession();
2100
2101 StringMaker query = new StringMaker();
2102
2103 query.append("SELECT COUNT(*) ");
2104 query.append(
2105 "FROM com.liferay.portlet.documentlibrary.model.DLFolder WHERE ");
2106
2107 if (uuid == null) {
2108 query.append("uuid_ IS NULL");
2109 }
2110 else {
2111 query.append("uuid_ = ?");
2112 }
2113
2114 query.append(" AND ");
2115
2116 query.append("groupId = ?");
2117
2118 query.append(" ");
2119
2120 Query q = session.createQuery(query.toString());
2121
2122 int queryPos = 0;
2123
2124 if (uuid != null) {
2125 q.setString(queryPos++, uuid);
2126 }
2127
2128 q.setLong(queryPos++, groupId);
2129
2130 Long count = null;
2131
2132 Iterator<Long> itr = q.list().iterator();
2133
2134 if (itr.hasNext()) {
2135 count = itr.next();
2136 }
2137
2138 if (count == null) {
2139 count = new Long(0);
2140 }
2141
2142 FinderCache.putResult(finderClassNameCacheEnabled,
2143 finderClassName, finderMethodName, finderParams,
2144 finderArgs, count);
2145
2146 return count.intValue();
2147 }
2148 catch (Exception e) {
2149 throw HibernateUtil.processException(e);
2150 }
2151 finally {
2152 closeSession(session);
2153 }
2154 }
2155 else {
2156 return ((Long)result).intValue();
2157 }
2158 }
2159
2160 public int countByGroupId(long groupId) throws SystemException {
2161 boolean finderClassNameCacheEnabled = DLFolderModelImpl.CACHE_ENABLED;
2162 String finderClassName = DLFolder.class.getName();
2163 String finderMethodName = "countByGroupId";
2164 String[] finderParams = new String[] { Long.class.getName() };
2165 Object[] finderArgs = new Object[] { new Long(groupId) };
2166
2167 Object result = null;
2168
2169 if (finderClassNameCacheEnabled) {
2170 result = FinderCache.getResult(finderClassName, finderMethodName,
2171 finderParams, finderArgs, getSessionFactory());
2172 }
2173
2174 if (result == null) {
2175 Session session = null;
2176
2177 try {
2178 session = openSession();
2179
2180 StringMaker query = new StringMaker();
2181
2182 query.append("SELECT COUNT(*) ");
2183 query.append(
2184 "FROM com.liferay.portlet.documentlibrary.model.DLFolder WHERE ");
2185
2186 query.append("groupId = ?");
2187
2188 query.append(" ");
2189
2190 Query q = session.createQuery(query.toString());
2191
2192 int queryPos = 0;
2193
2194 q.setLong(queryPos++, groupId);
2195
2196 Long count = null;
2197
2198 Iterator<Long> itr = q.list().iterator();
2199
2200 if (itr.hasNext()) {
2201 count = itr.next();
2202 }
2203
2204 if (count == null) {
2205 count = new Long(0);
2206 }
2207
2208 FinderCache.putResult(finderClassNameCacheEnabled,
2209 finderClassName, finderMethodName, finderParams,
2210 finderArgs, count);
2211
2212 return count.intValue();
2213 }
2214 catch (Exception e) {
2215 throw HibernateUtil.processException(e);
2216 }
2217 finally {
2218 closeSession(session);
2219 }
2220 }
2221 else {
2222 return ((Long)result).intValue();
2223 }
2224 }
2225
2226 public int countByCompanyId(long companyId) throws SystemException {
2227 boolean finderClassNameCacheEnabled = DLFolderModelImpl.CACHE_ENABLED;
2228 String finderClassName = DLFolder.class.getName();
2229 String finderMethodName = "countByCompanyId";
2230 String[] finderParams = new String[] { Long.class.getName() };
2231 Object[] finderArgs = new Object[] { new Long(companyId) };
2232
2233 Object result = null;
2234
2235 if (finderClassNameCacheEnabled) {
2236 result = FinderCache.getResult(finderClassName, finderMethodName,
2237 finderParams, finderArgs, getSessionFactory());
2238 }
2239
2240 if (result == null) {
2241 Session session = null;
2242
2243 try {
2244 session = openSession();
2245
2246 StringMaker query = new StringMaker();
2247
2248 query.append("SELECT COUNT(*) ");
2249 query.append(
2250 "FROM com.liferay.portlet.documentlibrary.model.DLFolder WHERE ");
2251
2252 query.append("companyId = ?");
2253
2254 query.append(" ");
2255
2256 Query q = session.createQuery(query.toString());
2257
2258 int queryPos = 0;
2259
2260 q.setLong(queryPos++, companyId);
2261
2262 Long count = null;
2263
2264 Iterator<Long> itr = q.list().iterator();
2265
2266 if (itr.hasNext()) {
2267 count = itr.next();
2268 }
2269
2270 if (count == null) {
2271 count = new Long(0);
2272 }
2273
2274 FinderCache.putResult(finderClassNameCacheEnabled,
2275 finderClassName, finderMethodName, finderParams,
2276 finderArgs, count);
2277
2278 return count.intValue();
2279 }
2280 catch (Exception e) {
2281 throw HibernateUtil.processException(e);
2282 }
2283 finally {
2284 closeSession(session);
2285 }
2286 }
2287 else {
2288 return ((Long)result).intValue();
2289 }
2290 }
2291
2292 public int countByG_P(long groupId, long parentFolderId)
2293 throws SystemException {
2294 boolean finderClassNameCacheEnabled = DLFolderModelImpl.CACHE_ENABLED;
2295 String finderClassName = DLFolder.class.getName();
2296 String finderMethodName = "countByG_P";
2297 String[] finderParams = new String[] {
2298 Long.class.getName(), Long.class.getName()
2299 };
2300 Object[] finderArgs = new Object[] {
2301 new Long(groupId), new Long(parentFolderId)
2302 };
2303
2304 Object result = null;
2305
2306 if (finderClassNameCacheEnabled) {
2307 result = FinderCache.getResult(finderClassName, finderMethodName,
2308 finderParams, finderArgs, getSessionFactory());
2309 }
2310
2311 if (result == null) {
2312 Session session = null;
2313
2314 try {
2315 session = openSession();
2316
2317 StringMaker query = new StringMaker();
2318
2319 query.append("SELECT COUNT(*) ");
2320 query.append(
2321 "FROM com.liferay.portlet.documentlibrary.model.DLFolder WHERE ");
2322
2323 query.append("groupId = ?");
2324
2325 query.append(" AND ");
2326
2327 query.append("parentFolderId = ?");
2328
2329 query.append(" ");
2330
2331 Query q = session.createQuery(query.toString());
2332
2333 int queryPos = 0;
2334
2335 q.setLong(queryPos++, groupId);
2336
2337 q.setLong(queryPos++, parentFolderId);
2338
2339 Long count = null;
2340
2341 Iterator<Long> itr = q.list().iterator();
2342
2343 if (itr.hasNext()) {
2344 count = itr.next();
2345 }
2346
2347 if (count == null) {
2348 count = new Long(0);
2349 }
2350
2351 FinderCache.putResult(finderClassNameCacheEnabled,
2352 finderClassName, finderMethodName, finderParams,
2353 finderArgs, count);
2354
2355 return count.intValue();
2356 }
2357 catch (Exception e) {
2358 throw HibernateUtil.processException(e);
2359 }
2360 finally {
2361 closeSession(session);
2362 }
2363 }
2364 else {
2365 return ((Long)result).intValue();
2366 }
2367 }
2368
2369 public int countByP_N(long parentFolderId, String name)
2370 throws SystemException {
2371 boolean finderClassNameCacheEnabled = DLFolderModelImpl.CACHE_ENABLED;
2372 String finderClassName = DLFolder.class.getName();
2373 String finderMethodName = "countByP_N";
2374 String[] finderParams = new String[] {
2375 Long.class.getName(), String.class.getName()
2376 };
2377 Object[] finderArgs = new Object[] { new Long(parentFolderId), name };
2378
2379 Object result = null;
2380
2381 if (finderClassNameCacheEnabled) {
2382 result = FinderCache.getResult(finderClassName, finderMethodName,
2383 finderParams, finderArgs, getSessionFactory());
2384 }
2385
2386 if (result == null) {
2387 Session session = null;
2388
2389 try {
2390 session = openSession();
2391
2392 StringMaker query = new StringMaker();
2393
2394 query.append("SELECT COUNT(*) ");
2395 query.append(
2396 "FROM com.liferay.portlet.documentlibrary.model.DLFolder WHERE ");
2397
2398 query.append("parentFolderId = ?");
2399
2400 query.append(" AND ");
2401
2402 if (name == null) {
2403 query.append("name IS NULL");
2404 }
2405 else {
2406 query.append("name = ?");
2407 }
2408
2409 query.append(" ");
2410
2411 Query q = session.createQuery(query.toString());
2412
2413 int queryPos = 0;
2414
2415 q.setLong(queryPos++, parentFolderId);
2416
2417 if (name != null) {
2418 q.setString(queryPos++, name);
2419 }
2420
2421 Long count = null;
2422
2423 Iterator<Long> itr = q.list().iterator();
2424
2425 if (itr.hasNext()) {
2426 count = itr.next();
2427 }
2428
2429 if (count == null) {
2430 count = new Long(0);
2431 }
2432
2433 FinderCache.putResult(finderClassNameCacheEnabled,
2434 finderClassName, finderMethodName, finderParams,
2435 finderArgs, count);
2436
2437 return count.intValue();
2438 }
2439 catch (Exception e) {
2440 throw HibernateUtil.processException(e);
2441 }
2442 finally {
2443 closeSession(session);
2444 }
2445 }
2446 else {
2447 return ((Long)result).intValue();
2448 }
2449 }
2450
2451 public int countByG_P_N(long groupId, long parentFolderId, String name)
2452 throws SystemException {
2453 boolean finderClassNameCacheEnabled = DLFolderModelImpl.CACHE_ENABLED;
2454 String finderClassName = DLFolder.class.getName();
2455 String finderMethodName = "countByG_P_N";
2456 String[] finderParams = new String[] {
2457 Long.class.getName(), Long.class.getName(),
2458 String.class.getName()
2459 };
2460 Object[] finderArgs = new Object[] {
2461 new Long(groupId), new Long(parentFolderId),
2462
2463 name
2464 };
2465
2466 Object result = null;
2467
2468 if (finderClassNameCacheEnabled) {
2469 result = FinderCache.getResult(finderClassName, finderMethodName,
2470 finderParams, finderArgs, getSessionFactory());
2471 }
2472
2473 if (result == null) {
2474 Session session = null;
2475
2476 try {
2477 session = openSession();
2478
2479 StringMaker query = new StringMaker();
2480
2481 query.append("SELECT COUNT(*) ");
2482 query.append(
2483 "FROM com.liferay.portlet.documentlibrary.model.DLFolder WHERE ");
2484
2485 query.append("groupId = ?");
2486
2487 query.append(" AND ");
2488
2489 query.append("parentFolderId = ?");
2490
2491 query.append(" AND ");
2492
2493 if (name == null) {
2494 query.append("name IS NULL");
2495 }
2496 else {
2497 query.append("name = ?");
2498 }
2499
2500 query.append(" ");
2501
2502 Query q = session.createQuery(query.toString());
2503
2504 int queryPos = 0;
2505
2506 q.setLong(queryPos++, groupId);
2507
2508 q.setLong(queryPos++, parentFolderId);
2509
2510 if (name != null) {
2511 q.setString(queryPos++, name);
2512 }
2513
2514 Long count = null;
2515
2516 Iterator<Long> itr = q.list().iterator();
2517
2518 if (itr.hasNext()) {
2519 count = itr.next();
2520 }
2521
2522 if (count == null) {
2523 count = new Long(0);
2524 }
2525
2526 FinderCache.putResult(finderClassNameCacheEnabled,
2527 finderClassName, finderMethodName, finderParams,
2528 finderArgs, count);
2529
2530 return count.intValue();
2531 }
2532 catch (Exception e) {
2533 throw HibernateUtil.processException(e);
2534 }
2535 finally {
2536 closeSession(session);
2537 }
2538 }
2539 else {
2540 return ((Long)result).intValue();
2541 }
2542 }
2543
2544 public int countAll() throws SystemException {
2545 boolean finderClassNameCacheEnabled = DLFolderModelImpl.CACHE_ENABLED;
2546 String finderClassName = DLFolder.class.getName();
2547 String finderMethodName = "countAll";
2548 String[] finderParams = new String[] { };
2549 Object[] finderArgs = new Object[] { };
2550
2551 Object result = null;
2552
2553 if (finderClassNameCacheEnabled) {
2554 result = FinderCache.getResult(finderClassName, finderMethodName,
2555 finderParams, finderArgs, getSessionFactory());
2556 }
2557
2558 if (result == null) {
2559 Session session = null;
2560
2561 try {
2562 session = openSession();
2563
2564 Query q = session.createQuery(
2565 "SELECT COUNT(*) FROM com.liferay.portlet.documentlibrary.model.DLFolder");
2566
2567 Long count = null;
2568
2569 Iterator<Long> itr = q.list().iterator();
2570
2571 if (itr.hasNext()) {
2572 count = itr.next();
2573 }
2574
2575 if (count == null) {
2576 count = new Long(0);
2577 }
2578
2579 FinderCache.putResult(finderClassNameCacheEnabled,
2580 finderClassName, finderMethodName, finderParams,
2581 finderArgs, count);
2582
2583 return count.intValue();
2584 }
2585 catch (Exception e) {
2586 throw HibernateUtil.processException(e);
2587 }
2588 finally {
2589 closeSession(session);
2590 }
2591 }
2592 else {
2593 return ((Long)result).intValue();
2594 }
2595 }
2596
2597 protected void initDao() {
2598 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2599 PropsUtil.get(
2600 "value.object.listener.com.liferay.portlet.documentlibrary.model.DLFolder")));
2601
2602 if (listenerClassNames.length > 0) {
2603 try {
2604 List<ModelListener> listeners = new ArrayList<ModelListener>();
2605
2606 for (String listenerClassName : listenerClassNames) {
2607 listeners.add((ModelListener)Class.forName(
2608 listenerClassName).newInstance());
2609 }
2610
2611 _listeners = listeners.toArray(new ModelListener[listeners.size()]);
2612 }
2613 catch (Exception e) {
2614 _log.error(e);
2615 }
2616 }
2617 }
2618
2619 private static Log _log = LogFactory.getLog(DLFolderPersistenceImpl.class);
2620 private ModelListener[] _listeners;
2621}