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