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