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