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