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