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