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