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