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