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                 (!Validator.equals(dlFileEntry.getUuid(),
417                     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                 (!Validator.equals(dlFileEntry.getUuid(),
428                     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                 !Validator.equals(dlFileEntry.getName(),
439                     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                 !Validator.equals(dlFileEntry.getName(),
451                     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                     "SELECT dlFileEntry FROM DLFileEntry dlFileEntry WHERE ");
525 
526                 if (uuid == null) {
527                     query.append("dlFileEntry.uuid IS NULL");
528                 }
529                 else {
530                     query.append("dlFileEntry.uuid = ?");
531                 }
532 
533                 query.append(" ");
534 
535                 query.append("ORDER BY ");
536 
537                 query.append("dlFileEntry.folderId ASC, ");
538                 query.append("dlFileEntry.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                     "SELECT dlFileEntry FROM DLFileEntry dlFileEntry WHERE ");
596 
597                 if (uuid == null) {
598                     query.append("dlFileEntry.uuid IS NULL");
599                 }
600                 else {
601                     query.append("dlFileEntry.uuid = ?");
602                 }
603 
604                 query.append(" ");
605 
606                 if (obc != null) {
607                     query.append("ORDER BY ");
608 
609                     String[] orderByFields = obc.getOrderByFields();
610 
611                     for (int i = 0; i < orderByFields.length; i++) {
612                         query.append("dlFileEntry.");
613                         query.append(orderByFields[i]);
614 
615                         if (obc.isAscending()) {
616                             query.append(" ASC");
617                         }
618                         else {
619                             query.append(" DESC");
620                         }
621 
622                         if ((i + 1) < orderByFields.length) {
623                             query.append(", ");
624                         }
625                     }
626                 }
627 
628                 else {
629                     query.append("ORDER BY ");
630 
631                     query.append("dlFileEntry.folderId ASC, ");
632                     query.append("dlFileEntry.name ASC");
633                 }
634 
635                 Query q = session.createQuery(query.toString());
636 
637                 QueryPos qPos = QueryPos.getInstance(q);
638 
639                 if (uuid != null) {
640                     qPos.add(uuid);
641                 }
642 
643                 list = (List<DLFileEntry>)QueryUtil.list(q, getDialect(),
644                         start, end);
645             }
646             catch (Exception e) {
647                 throw processException(e);
648             }
649             finally {
650                 if (list == null) {
651                     list = new ArrayList<DLFileEntry>();
652                 }
653 
654                 cacheResult(list);
655 
656                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_UUID,
657                     finderArgs, list);
658 
659                 closeSession(session);
660             }
661         }
662 
663         return list;
664     }
665 
666     public DLFileEntry findByUuid_First(String uuid, OrderByComparator obc)
667         throws NoSuchFileEntryException, SystemException {
668         List<DLFileEntry> list = findByUuid(uuid, 0, 1, obc);
669 
670         if (list.isEmpty()) {
671             StringBuilder msg = new StringBuilder();
672 
673             msg.append("No DLFileEntry exists with the key {");
674 
675             msg.append("uuid=" + uuid);
676 
677             msg.append(StringPool.CLOSE_CURLY_BRACE);
678 
679             throw new NoSuchFileEntryException(msg.toString());
680         }
681         else {
682             return list.get(0);
683         }
684     }
685 
686     public DLFileEntry findByUuid_Last(String uuid, OrderByComparator obc)
687         throws NoSuchFileEntryException, SystemException {
688         int count = countByUuid(uuid);
689 
690         List<DLFileEntry> list = findByUuid(uuid, count - 1, count, obc);
691 
692         if (list.isEmpty()) {
693             StringBuilder msg = new StringBuilder();
694 
695             msg.append("No DLFileEntry exists with the key {");
696 
697             msg.append("uuid=" + uuid);
698 
699             msg.append(StringPool.CLOSE_CURLY_BRACE);
700 
701             throw new NoSuchFileEntryException(msg.toString());
702         }
703         else {
704             return list.get(0);
705         }
706     }
707 
708     public DLFileEntry[] findByUuid_PrevAndNext(long fileEntryId, String uuid,
709         OrderByComparator obc) throws NoSuchFileEntryException, SystemException {
710         DLFileEntry dlFileEntry = findByPrimaryKey(fileEntryId);
711 
712         int count = countByUuid(uuid);
713 
714         Session session = null;
715 
716         try {
717             session = openSession();
718 
719             StringBuilder query = new StringBuilder();
720 
721             query.append(
722                 "SELECT dlFileEntry FROM DLFileEntry dlFileEntry WHERE ");
723 
724             if (uuid == null) {
725                 query.append("dlFileEntry.uuid IS NULL");
726             }
727             else {
728                 query.append("dlFileEntry.uuid = ?");
729             }
730 
731             query.append(" ");
732 
733             if (obc != null) {
734                 query.append("ORDER BY ");
735 
736                 String[] orderByFields = obc.getOrderByFields();
737 
738                 for (int i = 0; i < orderByFields.length; i++) {
739                     query.append("dlFileEntry.");
740                     query.append(orderByFields[i]);
741 
742                     if (obc.isAscending()) {
743                         query.append(" ASC");
744                     }
745                     else {
746                         query.append(" DESC");
747                     }
748 
749                     if ((i + 1) < orderByFields.length) {
750                         query.append(", ");
751                     }
752                 }
753             }
754 
755             else {
756                 query.append("ORDER BY ");
757 
758                 query.append("dlFileEntry.folderId ASC, ");
759                 query.append("dlFileEntry.name ASC");
760             }
761 
762             Query q = session.createQuery(query.toString());
763 
764             QueryPos qPos = QueryPos.getInstance(q);
765 
766             if (uuid != null) {
767                 qPos.add(uuid);
768             }
769 
770             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
771                     dlFileEntry);
772 
773             DLFileEntry[] array = new DLFileEntryImpl[3];
774 
775             array[0] = (DLFileEntry)objArray[0];
776             array[1] = (DLFileEntry)objArray[1];
777             array[2] = (DLFileEntry)objArray[2];
778 
779             return array;
780         }
781         catch (Exception e) {
782             throw processException(e);
783         }
784         finally {
785             closeSession(session);
786         }
787     }
788 
789     public DLFileEntry findByUUID_G(String uuid, long groupId)
790         throws NoSuchFileEntryException, SystemException {
791         DLFileEntry dlFileEntry = fetchByUUID_G(uuid, groupId);
792 
793         if (dlFileEntry == null) {
794             StringBuilder msg = new StringBuilder();
795 
796             msg.append("No DLFileEntry exists with the key {");
797 
798             msg.append("uuid=" + uuid);
799 
800             msg.append(", ");
801             msg.append("groupId=" + groupId);
802 
803             msg.append(StringPool.CLOSE_CURLY_BRACE);
804 
805             if (_log.isWarnEnabled()) {
806                 _log.warn(msg.toString());
807             }
808 
809             throw new NoSuchFileEntryException(msg.toString());
810         }
811 
812         return dlFileEntry;
813     }
814 
815     public DLFileEntry fetchByUUID_G(String uuid, long groupId)
816         throws SystemException {
817         return fetchByUUID_G(uuid, groupId, true);
818     }
819 
820     public DLFileEntry fetchByUUID_G(String uuid, long groupId,
821         boolean retrieveFromCache) throws SystemException {
822         Object[] finderArgs = new Object[] { uuid, new Long(groupId) };
823 
824         Object result = null;
825 
826         if (retrieveFromCache) {
827             result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
828                     finderArgs, this);
829         }
830 
831         if (result == null) {
832             Session session = null;
833 
834             try {
835                 session = openSession();
836 
837                 StringBuilder query = new StringBuilder();
838 
839                 query.append(
840                     "SELECT dlFileEntry FROM DLFileEntry dlFileEntry WHERE ");
841 
842                 if (uuid == null) {
843                     query.append("dlFileEntry.uuid IS NULL");
844                 }
845                 else {
846                     query.append("dlFileEntry.uuid = ?");
847                 }
848 
849                 query.append(" AND ");
850 
851                 query.append("dlFileEntry.groupId = ?");
852 
853                 query.append(" ");
854 
855                 query.append("ORDER BY ");
856 
857                 query.append("dlFileEntry.folderId ASC, ");
858                 query.append("dlFileEntry.name ASC");
859 
860                 Query q = session.createQuery(query.toString());
861 
862                 QueryPos qPos = QueryPos.getInstance(q);
863 
864                 if (uuid != null) {
865                     qPos.add(uuid);
866                 }
867 
868                 qPos.add(groupId);
869 
870                 List<DLFileEntry> list = q.list();
871 
872                 result = list;
873 
874                 DLFileEntry dlFileEntry = null;
875 
876                 if (list.isEmpty()) {
877                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
878                         finderArgs, list);
879                 }
880                 else {
881                     dlFileEntry = list.get(0);
882 
883                     cacheResult(dlFileEntry);
884 
885                     if ((dlFileEntry.getUuid() == null) ||
886                             !dlFileEntry.getUuid().equals(uuid) ||
887                             (dlFileEntry.getGroupId() != groupId)) {
888                         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
889                             finderArgs, dlFileEntry);
890                     }
891                 }
892 
893                 return dlFileEntry;
894             }
895             catch (Exception e) {
896                 throw processException(e);
897             }
898             finally {
899                 if (result == null) {
900                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
901                         finderArgs, new ArrayList<DLFileEntry>());
902                 }
903 
904                 closeSession(session);
905             }
906         }
907         else {
908             if (result instanceof List) {
909                 return null;
910             }
911             else {
912                 return (DLFileEntry)result;
913             }
914         }
915     }
916 
917     public List<DLFileEntry> findByGroupId(long groupId)
918         throws SystemException {
919         Object[] finderArgs = new Object[] { new Long(groupId) };
920 
921         List<DLFileEntry> list = (List<DLFileEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
922                 finderArgs, this);
923 
924         if (list == null) {
925             Session session = null;
926 
927             try {
928                 session = openSession();
929 
930                 StringBuilder query = new StringBuilder();
931 
932                 query.append(
933                     "SELECT dlFileEntry FROM DLFileEntry dlFileEntry WHERE ");
934 
935                 query.append("dlFileEntry.groupId = ?");
936 
937                 query.append(" ");
938 
939                 query.append("ORDER BY ");
940 
941                 query.append("dlFileEntry.folderId ASC, ");
942                 query.append("dlFileEntry.name ASC");
943 
944                 Query q = session.createQuery(query.toString());
945 
946                 QueryPos qPos = QueryPos.getInstance(q);
947 
948                 qPos.add(groupId);
949 
950                 list = q.list();
951             }
952             catch (Exception e) {
953                 throw processException(e);
954             }
955             finally {
956                 if (list == null) {
957                     list = new ArrayList<DLFileEntry>();
958                 }
959 
960                 cacheResult(list);
961 
962                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
963                     finderArgs, list);
964 
965                 closeSession(session);
966             }
967         }
968 
969         return list;
970     }
971 
972     public List<DLFileEntry> findByGroupId(long groupId, int start, int end)
973         throws SystemException {
974         return findByGroupId(groupId, start, end, null);
975     }
976 
977     public List<DLFileEntry> findByGroupId(long groupId, int start, int end,
978         OrderByComparator obc) throws SystemException {
979         Object[] finderArgs = new Object[] {
980                 new Long(groupId),
981                 
982                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
983             };
984 
985         List<DLFileEntry> list = (List<DLFileEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_GROUPID,
986                 finderArgs, this);
987 
988         if (list == null) {
989             Session session = null;
990 
991             try {
992                 session = openSession();
993 
994                 StringBuilder query = new StringBuilder();
995 
996                 query.append(
997                     "SELECT dlFileEntry FROM DLFileEntry dlFileEntry WHERE ");
998 
999                 query.append("dlFileEntry.groupId = ?");
1000
1001                query.append(" ");
1002
1003                if (obc != null) {
1004                    query.append("ORDER BY ");
1005
1006                    String[] orderByFields = obc.getOrderByFields();
1007
1008                    for (int i = 0; i < orderByFields.length; i++) {
1009                        query.append("dlFileEntry.");
1010                        query.append(orderByFields[i]);
1011
1012                        if (obc.isAscending()) {
1013                            query.append(" ASC");
1014                        }
1015                        else {
1016                            query.append(" DESC");
1017                        }
1018
1019                        if ((i + 1) < orderByFields.length) {
1020                            query.append(", ");
1021                        }
1022                    }
1023                }
1024
1025                else {
1026                    query.append("ORDER BY ");
1027
1028                    query.append("dlFileEntry.folderId ASC, ");
1029                    query.append("dlFileEntry.name ASC");
1030                }
1031
1032                Query q = session.createQuery(query.toString());
1033
1034                QueryPos qPos = QueryPos.getInstance(q);
1035
1036                qPos.add(groupId);
1037
1038                list = (List<DLFileEntry>)QueryUtil.list(q, getDialect(),
1039                        start, end);
1040            }
1041            catch (Exception e) {
1042                throw processException(e);
1043            }
1044            finally {
1045                if (list == null) {
1046                    list = new ArrayList<DLFileEntry>();
1047                }
1048
1049                cacheResult(list);
1050
1051                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_GROUPID,
1052                    finderArgs, list);
1053
1054                closeSession(session);
1055            }
1056        }
1057
1058        return list;
1059    }
1060
1061    public DLFileEntry findByGroupId_First(long groupId, OrderByComparator obc)
1062        throws NoSuchFileEntryException, SystemException {
1063        List<DLFileEntry> list = findByGroupId(groupId, 0, 1, obc);
1064
1065        if (list.isEmpty()) {
1066            StringBuilder msg = new StringBuilder();
1067
1068            msg.append("No DLFileEntry exists with the key {");
1069
1070            msg.append("groupId=" + groupId);
1071
1072            msg.append(StringPool.CLOSE_CURLY_BRACE);
1073
1074            throw new NoSuchFileEntryException(msg.toString());
1075        }
1076        else {
1077            return list.get(0);
1078        }
1079    }
1080
1081    public DLFileEntry findByGroupId_Last(long groupId, OrderByComparator obc)
1082        throws NoSuchFileEntryException, SystemException {
1083        int count = countByGroupId(groupId);
1084
1085        List<DLFileEntry> list = findByGroupId(groupId, count - 1, count, obc);
1086
1087        if (list.isEmpty()) {
1088            StringBuilder msg = new StringBuilder();
1089
1090            msg.append("No DLFileEntry exists with the key {");
1091
1092            msg.append("groupId=" + groupId);
1093
1094            msg.append(StringPool.CLOSE_CURLY_BRACE);
1095
1096            throw new NoSuchFileEntryException(msg.toString());
1097        }
1098        else {
1099            return list.get(0);
1100        }
1101    }
1102
1103    public DLFileEntry[] findByGroupId_PrevAndNext(long fileEntryId,
1104        long groupId, OrderByComparator obc)
1105        throws NoSuchFileEntryException, SystemException {
1106        DLFileEntry dlFileEntry = findByPrimaryKey(fileEntryId);
1107
1108        int count = countByGroupId(groupId);
1109
1110        Session session = null;
1111
1112        try {
1113            session = openSession();
1114
1115            StringBuilder query = new StringBuilder();
1116
1117            query.append(
1118                "SELECT dlFileEntry FROM DLFileEntry dlFileEntry WHERE ");
1119
1120            query.append("dlFileEntry.groupId = ?");
1121
1122            query.append(" ");
1123
1124            if (obc != null) {
1125                query.append("ORDER BY ");
1126
1127                String[] orderByFields = obc.getOrderByFields();
1128
1129                for (int i = 0; i < orderByFields.length; i++) {
1130                    query.append("dlFileEntry.");
1131                    query.append(orderByFields[i]);
1132
1133                    if (obc.isAscending()) {
1134                        query.append(" ASC");
1135                    }
1136                    else {
1137                        query.append(" DESC");
1138                    }
1139
1140                    if ((i + 1) < orderByFields.length) {
1141                        query.append(", ");
1142                    }
1143                }
1144            }
1145
1146            else {
1147                query.append("ORDER BY ");
1148
1149                query.append("dlFileEntry.folderId ASC, ");
1150                query.append("dlFileEntry.name ASC");
1151            }
1152
1153            Query q = session.createQuery(query.toString());
1154
1155            QueryPos qPos = QueryPos.getInstance(q);
1156
1157            qPos.add(groupId);
1158
1159            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1160                    dlFileEntry);
1161
1162            DLFileEntry[] array = new DLFileEntryImpl[3];
1163
1164            array[0] = (DLFileEntry)objArray[0];
1165            array[1] = (DLFileEntry)objArray[1];
1166            array[2] = (DLFileEntry)objArray[2];
1167
1168            return array;
1169        }
1170        catch (Exception e) {
1171            throw processException(e);
1172        }
1173        finally {
1174            closeSession(session);
1175        }
1176    }
1177
1178    public List<DLFileEntry> findByCompanyId(long companyId)
1179        throws SystemException {
1180        Object[] finderArgs = new Object[] { new Long(companyId) };
1181
1182        List<DLFileEntry> list = (List<DLFileEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_COMPANYID,
1183                finderArgs, this);
1184
1185        if (list == null) {
1186            Session session = null;
1187
1188            try {
1189                session = openSession();
1190
1191                StringBuilder query = new StringBuilder();
1192
1193                query.append(
1194                    "SELECT dlFileEntry FROM DLFileEntry dlFileEntry WHERE ");
1195
1196                query.append("dlFileEntry.companyId = ?");
1197
1198                query.append(" ");
1199
1200                query.append("ORDER BY ");
1201
1202                query.append("dlFileEntry.folderId ASC, ");
1203                query.append("dlFileEntry.name ASC");
1204
1205                Query q = session.createQuery(query.toString());
1206
1207                QueryPos qPos = QueryPos.getInstance(q);
1208
1209                qPos.add(companyId);
1210
1211                list = q.list();
1212            }
1213            catch (Exception e) {
1214                throw processException(e);
1215            }
1216            finally {
1217                if (list == null) {
1218                    list = new ArrayList<DLFileEntry>();
1219                }
1220
1221                cacheResult(list);
1222
1223                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_COMPANYID,
1224                    finderArgs, list);
1225
1226                closeSession(session);
1227            }
1228        }
1229
1230        return list;
1231    }
1232
1233    public List<DLFileEntry> findByCompanyId(long companyId, int start, int end)
1234        throws SystemException {
1235        return findByCompanyId(companyId, start, end, null);
1236    }
1237
1238    public List<DLFileEntry> findByCompanyId(long companyId, int start,
1239        int end, OrderByComparator obc) throws SystemException {
1240        Object[] finderArgs = new Object[] {
1241                new Long(companyId),
1242                
1243                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1244            };
1245
1246        List<DLFileEntry> list = (List<DLFileEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_COMPANYID,
1247                finderArgs, this);
1248
1249        if (list == null) {
1250            Session session = null;
1251
1252            try {
1253                session = openSession();
1254
1255                StringBuilder query = new StringBuilder();
1256
1257                query.append(
1258                    "SELECT dlFileEntry FROM DLFileEntry dlFileEntry WHERE ");
1259
1260                query.append("dlFileEntry.companyId = ?");
1261
1262                query.append(" ");
1263
1264                if (obc != null) {
1265                    query.append("ORDER BY ");
1266
1267                    String[] orderByFields = obc.getOrderByFields();
1268
1269                    for (int i = 0; i < orderByFields.length; i++) {
1270                        query.append("dlFileEntry.");
1271                        query.append(orderByFields[i]);
1272
1273                        if (obc.isAscending()) {
1274                            query.append(" ASC");
1275                        }
1276                        else {
1277                            query.append(" DESC");
1278                        }
1279
1280                        if ((i + 1) < orderByFields.length) {
1281                            query.append(", ");
1282                        }
1283                    }
1284                }
1285
1286                else {
1287                    query.append("ORDER BY ");
1288
1289                    query.append("dlFileEntry.folderId ASC, ");
1290                    query.append("dlFileEntry.name ASC");
1291                }
1292
1293                Query q = session.createQuery(query.toString());
1294
1295                QueryPos qPos = QueryPos.getInstance(q);
1296
1297                qPos.add(companyId);
1298
1299                list = (List<DLFileEntry>)QueryUtil.list(q, getDialect(),
1300                        start, end);
1301            }
1302            catch (Exception e) {
1303                throw processException(e);
1304            }
1305            finally {
1306                if (list == null) {
1307                    list = new ArrayList<DLFileEntry>();
1308                }
1309
1310                cacheResult(list);
1311
1312                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_COMPANYID,
1313                    finderArgs, list);
1314
1315                closeSession(session);
1316            }
1317        }
1318
1319        return list;
1320    }
1321
1322    public DLFileEntry findByCompanyId_First(long companyId,
1323        OrderByComparator obc) throws NoSuchFileEntryException, SystemException {
1324        List<DLFileEntry> list = findByCompanyId(companyId, 0, 1, obc);
1325
1326        if (list.isEmpty()) {
1327            StringBuilder msg = new StringBuilder();
1328
1329            msg.append("No DLFileEntry exists with the key {");
1330
1331            msg.append("companyId=" + companyId);
1332
1333            msg.append(StringPool.CLOSE_CURLY_BRACE);
1334
1335            throw new NoSuchFileEntryException(msg.toString());
1336        }
1337        else {
1338            return list.get(0);
1339        }
1340    }
1341
1342    public DLFileEntry findByCompanyId_Last(long companyId,
1343        OrderByComparator obc) throws NoSuchFileEntryException, SystemException {
1344        int count = countByCompanyId(companyId);
1345
1346        List<DLFileEntry> list = findByCompanyId(companyId, count - 1, count,
1347                obc);
1348
1349        if (list.isEmpty()) {
1350            StringBuilder msg = new StringBuilder();
1351
1352            msg.append("No DLFileEntry exists with the key {");
1353
1354            msg.append("companyId=" + companyId);
1355
1356            msg.append(StringPool.CLOSE_CURLY_BRACE);
1357
1358            throw new NoSuchFileEntryException(msg.toString());
1359        }
1360        else {
1361            return list.get(0);
1362        }
1363    }
1364
1365    public DLFileEntry[] findByCompanyId_PrevAndNext(long fileEntryId,
1366        long companyId, OrderByComparator obc)
1367        throws NoSuchFileEntryException, SystemException {
1368        DLFileEntry dlFileEntry = findByPrimaryKey(fileEntryId);
1369
1370        int count = countByCompanyId(companyId);
1371
1372        Session session = null;
1373
1374        try {
1375            session = openSession();
1376
1377            StringBuilder query = new StringBuilder();
1378
1379            query.append(
1380                "SELECT dlFileEntry FROM DLFileEntry dlFileEntry WHERE ");
1381
1382            query.append("dlFileEntry.companyId = ?");
1383
1384            query.append(" ");
1385
1386            if (obc != null) {
1387                query.append("ORDER BY ");
1388
1389                String[] orderByFields = obc.getOrderByFields();
1390
1391                for (int i = 0; i < orderByFields.length; i++) {
1392                    query.append("dlFileEntry.");
1393                    query.append(orderByFields[i]);
1394
1395                    if (obc.isAscending()) {
1396                        query.append(" ASC");
1397                    }
1398                    else {
1399                        query.append(" DESC");
1400                    }
1401
1402                    if ((i + 1) < orderByFields.length) {
1403                        query.append(", ");
1404                    }
1405                }
1406            }
1407
1408            else {
1409                query.append("ORDER BY ");
1410
1411                query.append("dlFileEntry.folderId ASC, ");
1412                query.append("dlFileEntry.name ASC");
1413            }
1414
1415            Query q = session.createQuery(query.toString());
1416
1417            QueryPos qPos = QueryPos.getInstance(q);
1418
1419            qPos.add(companyId);
1420
1421            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1422                    dlFileEntry);
1423
1424            DLFileEntry[] array = new DLFileEntryImpl[3];
1425
1426            array[0] = (DLFileEntry)objArray[0];
1427            array[1] = (DLFileEntry)objArray[1];
1428            array[2] = (DLFileEntry)objArray[2];
1429
1430            return array;
1431        }
1432        catch (Exception e) {
1433            throw processException(e);
1434        }
1435        finally {
1436            closeSession(session);
1437        }
1438    }
1439
1440    public List<DLFileEntry> findByFolderId(long folderId)
1441        throws SystemException {
1442        Object[] finderArgs = new Object[] { new Long(folderId) };
1443
1444        List<DLFileEntry> list = (List<DLFileEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_FOLDERID,
1445                finderArgs, this);
1446
1447        if (list == null) {
1448            Session session = null;
1449
1450            try {
1451                session = openSession();
1452
1453                StringBuilder query = new StringBuilder();
1454
1455                query.append(
1456                    "SELECT dlFileEntry FROM DLFileEntry dlFileEntry WHERE ");
1457
1458                query.append("dlFileEntry.folderId = ?");
1459
1460                query.append(" ");
1461
1462                query.append("ORDER BY ");
1463
1464                query.append("dlFileEntry.folderId ASC, ");
1465                query.append("dlFileEntry.name ASC");
1466
1467                Query q = session.createQuery(query.toString());
1468
1469                QueryPos qPos = QueryPos.getInstance(q);
1470
1471                qPos.add(folderId);
1472
1473                list = q.list();
1474            }
1475            catch (Exception e) {
1476                throw processException(e);
1477            }
1478            finally {
1479                if (list == null) {
1480                    list = new ArrayList<DLFileEntry>();
1481                }
1482
1483                cacheResult(list);
1484
1485                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_FOLDERID,
1486                    finderArgs, list);
1487
1488                closeSession(session);
1489            }
1490        }
1491
1492        return list;
1493    }
1494
1495    public List<DLFileEntry> findByFolderId(long folderId, int start, int end)
1496        throws SystemException {
1497        return findByFolderId(folderId, start, end, null);
1498    }
1499
1500    public List<DLFileEntry> findByFolderId(long folderId, int start, int end,
1501        OrderByComparator obc) throws SystemException {
1502        Object[] finderArgs = new Object[] {
1503                new Long(folderId),
1504                
1505                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1506            };
1507
1508        List<DLFileEntry> list = (List<DLFileEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_FOLDERID,
1509                finderArgs, this);
1510
1511        if (list == null) {
1512            Session session = null;
1513
1514            try {
1515                session = openSession();
1516
1517                StringBuilder query = new StringBuilder();
1518
1519                query.append(
1520                    "SELECT dlFileEntry FROM DLFileEntry dlFileEntry WHERE ");
1521
1522                query.append("dlFileEntry.folderId = ?");
1523
1524                query.append(" ");
1525
1526                if (obc != null) {
1527                    query.append("ORDER BY ");
1528
1529                    String[] orderByFields = obc.getOrderByFields();
1530
1531                    for (int i = 0; i < orderByFields.length; i++) {
1532                        query.append("dlFileEntry.");
1533                        query.append(orderByFields[i]);
1534
1535                        if (obc.isAscending()) {
1536                            query.append(" ASC");
1537                        }
1538                        else {
1539                            query.append(" DESC");
1540                        }
1541
1542                        if ((i + 1) < orderByFields.length) {
1543                            query.append(", ");
1544                        }
1545                    }
1546                }
1547
1548                else {
1549                    query.append("ORDER BY ");
1550
1551                    query.append("dlFileEntry.folderId ASC, ");
1552                    query.append("dlFileEntry.name ASC");
1553                }
1554
1555                Query q = session.createQuery(query.toString());
1556
1557                QueryPos qPos = QueryPos.getInstance(q);
1558
1559                qPos.add(folderId);
1560
1561                list = (List<DLFileEntry>)QueryUtil.list(q, getDialect(),
1562                        start, end);
1563            }
1564            catch (Exception e) {
1565                throw processException(e);
1566            }
1567            finally {
1568                if (list == null) {
1569                    list = new ArrayList<DLFileEntry>();
1570                }
1571
1572                cacheResult(list);
1573
1574                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_FOLDERID,
1575                    finderArgs, list);
1576
1577                closeSession(session);
1578            }
1579        }
1580
1581        return list;
1582    }
1583
1584    public DLFileEntry findByFolderId_First(long folderId, OrderByComparator obc)
1585        throws NoSuchFileEntryException, SystemException {
1586        List<DLFileEntry> list = findByFolderId(folderId, 0, 1, obc);
1587
1588        if (list.isEmpty()) {
1589            StringBuilder msg = new StringBuilder();
1590
1591            msg.append("No DLFileEntry exists with the key {");
1592
1593            msg.append("folderId=" + folderId);
1594
1595            msg.append(StringPool.CLOSE_CURLY_BRACE);
1596
1597            throw new NoSuchFileEntryException(msg.toString());
1598        }
1599        else {
1600            return list.get(0);
1601        }
1602    }
1603
1604    public DLFileEntry findByFolderId_Last(long folderId, OrderByComparator obc)
1605        throws NoSuchFileEntryException, SystemException {
1606        int count = countByFolderId(folderId);
1607
1608        List<DLFileEntry> list = findByFolderId(folderId, count - 1, count, obc);
1609
1610        if (list.isEmpty()) {
1611            StringBuilder msg = new StringBuilder();
1612
1613            msg.append("No DLFileEntry exists with the key {");
1614
1615            msg.append("folderId=" + folderId);
1616
1617            msg.append(StringPool.CLOSE_CURLY_BRACE);
1618
1619            throw new NoSuchFileEntryException(msg.toString());
1620        }
1621        else {
1622            return list.get(0);
1623        }
1624    }
1625
1626    public DLFileEntry[] findByFolderId_PrevAndNext(long fileEntryId,
1627        long folderId, OrderByComparator obc)
1628        throws NoSuchFileEntryException, SystemException {
1629        DLFileEntry dlFileEntry = findByPrimaryKey(fileEntryId);
1630
1631        int count = countByFolderId(folderId);
1632
1633        Session session = null;
1634
1635        try {
1636            session = openSession();
1637
1638            StringBuilder query = new StringBuilder();
1639
1640            query.append(
1641                "SELECT dlFileEntry FROM DLFileEntry dlFileEntry WHERE ");
1642
1643            query.append("dlFileEntry.folderId = ?");
1644
1645            query.append(" ");
1646
1647            if (obc != null) {
1648                query.append("ORDER BY ");
1649
1650                String[] orderByFields = obc.getOrderByFields();
1651
1652                for (int i = 0; i < orderByFields.length; i++) {
1653                    query.append("dlFileEntry.");
1654                    query.append(orderByFields[i]);
1655
1656                    if (obc.isAscending()) {
1657                        query.append(" ASC");
1658                    }
1659                    else {
1660                        query.append(" DESC");
1661                    }
1662
1663                    if ((i + 1) < orderByFields.length) {
1664                        query.append(", ");
1665                    }
1666                }
1667            }
1668
1669            else {
1670                query.append("ORDER BY ");
1671
1672                query.append("dlFileEntry.folderId ASC, ");
1673                query.append("dlFileEntry.name ASC");
1674            }
1675
1676            Query q = session.createQuery(query.toString());
1677
1678            QueryPos qPos = QueryPos.getInstance(q);
1679
1680            qPos.add(folderId);
1681
1682            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1683                    dlFileEntry);
1684
1685            DLFileEntry[] array = new DLFileEntryImpl[3];
1686
1687            array[0] = (DLFileEntry)objArray[0];
1688            array[1] = (DLFileEntry)objArray[1];
1689            array[2] = (DLFileEntry)objArray[2];
1690
1691            return array;
1692        }
1693        catch (Exception e) {
1694            throw processException(e);
1695        }
1696        finally {
1697            closeSession(session);
1698        }
1699    }
1700
1701    public List<DLFileEntry> findByG_U(long groupId, long userId)
1702        throws SystemException {
1703        Object[] finderArgs = new Object[] { new Long(groupId), new Long(userId) };
1704
1705        List<DLFileEntry> list = (List<DLFileEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_U,
1706                finderArgs, this);
1707
1708        if (list == null) {
1709            Session session = null;
1710
1711            try {
1712                session = openSession();
1713
1714                StringBuilder query = new StringBuilder();
1715
1716                query.append(
1717                    "SELECT dlFileEntry FROM DLFileEntry dlFileEntry WHERE ");
1718
1719                query.append("dlFileEntry.groupId = ?");
1720
1721                query.append(" AND ");
1722
1723                query.append("dlFileEntry.userId = ?");
1724
1725                query.append(" ");
1726
1727                query.append("ORDER BY ");
1728
1729                query.append("dlFileEntry.folderId ASC, ");
1730                query.append("dlFileEntry.name ASC");
1731
1732                Query q = session.createQuery(query.toString());
1733
1734                QueryPos qPos = QueryPos.getInstance(q);
1735
1736                qPos.add(groupId);
1737
1738                qPos.add(userId);
1739
1740                list = q.list();
1741            }
1742            catch (Exception e) {
1743                throw processException(e);
1744            }
1745            finally {
1746                if (list == null) {
1747                    list = new ArrayList<DLFileEntry>();
1748                }
1749
1750                cacheResult(list);
1751
1752                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_U, finderArgs,
1753                    list);
1754
1755                closeSession(session);
1756            }
1757        }
1758
1759        return list;
1760    }
1761
1762    public List<DLFileEntry> findByG_U(long groupId, long userId, int start,
1763        int end) throws SystemException {
1764        return findByG_U(groupId, userId, start, end, null);
1765    }
1766
1767    public List<DLFileEntry> findByG_U(long groupId, long userId, int start,
1768        int end, OrderByComparator obc) throws SystemException {
1769        Object[] finderArgs = new Object[] {
1770                new Long(groupId), new Long(userId),
1771                
1772                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1773            };
1774
1775        List<DLFileEntry> list = (List<DLFileEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_G_U,
1776                finderArgs, this);
1777
1778        if (list == null) {
1779            Session session = null;
1780
1781            try {
1782                session = openSession();
1783
1784                StringBuilder query = new StringBuilder();
1785
1786                query.append(
1787                    "SELECT dlFileEntry FROM DLFileEntry dlFileEntry WHERE ");
1788
1789                query.append("dlFileEntry.groupId = ?");
1790
1791                query.append(" AND ");
1792
1793                query.append("dlFileEntry.userId = ?");
1794
1795                query.append(" ");
1796
1797                if (obc != null) {
1798                    query.append("ORDER BY ");
1799
1800                    String[] orderByFields = obc.getOrderByFields();
1801
1802                    for (int i = 0; i < orderByFields.length; i++) {
1803                        query.append("dlFileEntry.");
1804                        query.append(orderByFields[i]);
1805
1806                        if (obc.isAscending()) {
1807                            query.append(" ASC");
1808                        }
1809                        else {
1810                            query.append(" DESC");
1811                        }
1812
1813                        if ((i + 1) < orderByFields.length) {
1814                            query.append(", ");
1815                        }
1816                    }
1817                }
1818
1819                else {
1820                    query.append("ORDER BY ");
1821
1822                    query.append("dlFileEntry.folderId ASC, ");
1823                    query.append("dlFileEntry.name ASC");
1824                }
1825
1826                Query q = session.createQuery(query.toString());
1827
1828                QueryPos qPos = QueryPos.getInstance(q);
1829
1830                qPos.add(groupId);
1831
1832                qPos.add(userId);
1833
1834                list = (List<DLFileEntry>)QueryUtil.list(q, getDialect(),
1835                        start, end);
1836            }
1837            catch (Exception e) {
1838                throw processException(e);
1839            }
1840            finally {
1841                if (list == null) {
1842                    list = new ArrayList<DLFileEntry>();
1843                }
1844
1845                cacheResult(list);
1846
1847                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_G_U,
1848                    finderArgs, list);
1849
1850                closeSession(session);
1851            }
1852        }
1853
1854        return list;
1855    }
1856
1857    public DLFileEntry findByG_U_First(long groupId, long userId,
1858        OrderByComparator obc) throws NoSuchFileEntryException, SystemException {
1859        List<DLFileEntry> list = findByG_U(groupId, userId, 0, 1, obc);
1860
1861        if (list.isEmpty()) {
1862            StringBuilder msg = new StringBuilder();
1863
1864            msg.append("No DLFileEntry exists with the key {");
1865
1866            msg.append("groupId=" + groupId);
1867
1868            msg.append(", ");
1869            msg.append("userId=" + userId);
1870
1871            msg.append(StringPool.CLOSE_CURLY_BRACE);
1872
1873            throw new NoSuchFileEntryException(msg.toString());
1874        }
1875        else {
1876            return list.get(0);
1877        }
1878    }
1879
1880    public DLFileEntry findByG_U_Last(long groupId, long userId,
1881        OrderByComparator obc) throws NoSuchFileEntryException, SystemException {
1882        int count = countByG_U(groupId, userId);
1883
1884        List<DLFileEntry> list = findByG_U(groupId, userId, count - 1, count,
1885                obc);
1886
1887        if (list.isEmpty()) {
1888            StringBuilder msg = new StringBuilder();
1889
1890            msg.append("No DLFileEntry exists with the key {");
1891
1892            msg.append("groupId=" + groupId);
1893
1894            msg.append(", ");
1895            msg.append("userId=" + userId);
1896
1897            msg.append(StringPool.CLOSE_CURLY_BRACE);
1898
1899            throw new NoSuchFileEntryException(msg.toString());
1900        }
1901        else {
1902            return list.get(0);
1903        }
1904    }
1905
1906    public DLFileEntry[] findByG_U_PrevAndNext(long fileEntryId, long groupId,
1907        long userId, OrderByComparator obc)
1908        throws NoSuchFileEntryException, SystemException {
1909        DLFileEntry dlFileEntry = findByPrimaryKey(fileEntryId);
1910
1911        int count = countByG_U(groupId, userId);
1912
1913        Session session = null;
1914
1915        try {
1916            session = openSession();
1917
1918            StringBuilder query = new StringBuilder();
1919
1920            query.append(
1921                "SELECT dlFileEntry FROM DLFileEntry dlFileEntry WHERE ");
1922
1923            query.append("dlFileEntry.groupId = ?");
1924
1925            query.append(" AND ");
1926
1927            query.append("dlFileEntry.userId = ?");
1928
1929            query.append(" ");
1930
1931            if (obc != null) {
1932                query.append("ORDER BY ");
1933
1934                String[] orderByFields = obc.getOrderByFields();
1935
1936                for (int i = 0; i < orderByFields.length; i++) {
1937                    query.append("dlFileEntry.");
1938                    query.append(orderByFields[i]);
1939
1940                    if (obc.isAscending()) {
1941                        query.append(" ASC");
1942                    }
1943                    else {
1944                        query.append(" DESC");
1945                    }
1946
1947                    if ((i + 1) < orderByFields.length) {
1948                        query.append(", ");
1949                    }
1950                }
1951            }
1952
1953            else {
1954                query.append("ORDER BY ");
1955
1956                query.append("dlFileEntry.folderId ASC, ");
1957                query.append("dlFileEntry.name ASC");
1958            }
1959
1960            Query q = session.createQuery(query.toString());
1961
1962            QueryPos qPos = QueryPos.getInstance(q);
1963
1964            qPos.add(groupId);
1965
1966            qPos.add(userId);
1967
1968            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1969                    dlFileEntry);
1970
1971            DLFileEntry[] array = new DLFileEntryImpl[3];
1972
1973            array[0] = (DLFileEntry)objArray[0];
1974            array[1] = (DLFileEntry)objArray[1];
1975            array[2] = (DLFileEntry)objArray[2];
1976
1977            return array;
1978        }
1979        catch (Exception e) {
1980            throw processException(e);
1981        }
1982        finally {
1983            closeSession(session);
1984        }
1985    }
1986
1987    public DLFileEntry findByF_N(long folderId, String name)
1988        throws NoSuchFileEntryException, SystemException {
1989        DLFileEntry dlFileEntry = fetchByF_N(folderId, name);
1990
1991        if (dlFileEntry == null) {
1992            StringBuilder msg = new StringBuilder();
1993
1994            msg.append("No DLFileEntry exists with the key {");
1995
1996            msg.append("folderId=" + folderId);
1997
1998            msg.append(", ");
1999            msg.append("name=" + name);
2000
2001            msg.append(StringPool.CLOSE_CURLY_BRACE);
2002
2003            if (_log.isWarnEnabled()) {
2004                _log.warn(msg.toString());
2005            }
2006
2007            throw new NoSuchFileEntryException(msg.toString());
2008        }
2009
2010        return dlFileEntry;
2011    }
2012
2013    public DLFileEntry fetchByF_N(long folderId, String name)
2014        throws SystemException {
2015        return fetchByF_N(folderId, name, true);
2016    }
2017
2018    public DLFileEntry fetchByF_N(long folderId, String name,
2019        boolean retrieveFromCache) throws SystemException {
2020        Object[] finderArgs = new Object[] { new Long(folderId), name };
2021
2022        Object result = null;
2023
2024        if (retrieveFromCache) {
2025            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_F_N,
2026                    finderArgs, this);
2027        }
2028
2029        if (result == null) {
2030            Session session = null;
2031
2032            try {
2033                session = openSession();
2034
2035                StringBuilder query = new StringBuilder();
2036
2037                query.append(
2038                    "SELECT dlFileEntry FROM DLFileEntry dlFileEntry WHERE ");
2039
2040                query.append("dlFileEntry.folderId = ?");
2041
2042                query.append(" AND ");
2043
2044                if (name == null) {
2045                    query.append("dlFileEntry.name IS NULL");
2046                }
2047                else {
2048                    query.append("dlFileEntry.name = ?");
2049                }
2050
2051                query.append(" ");
2052
2053                query.append("ORDER BY ");
2054
2055                query.append("dlFileEntry.folderId ASC, ");
2056                query.append("dlFileEntry.name ASC");
2057
2058                Query q = session.createQuery(query.toString());
2059
2060                QueryPos qPos = QueryPos.getInstance(q);
2061
2062                qPos.add(folderId);
2063
2064                if (name != null) {
2065                    qPos.add(name);
2066                }
2067
2068                List<DLFileEntry> list = q.list();
2069
2070                result = list;
2071
2072                DLFileEntry dlFileEntry = null;
2073
2074                if (list.isEmpty()) {
2075                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_F_N,
2076                        finderArgs, list);
2077                }
2078                else {
2079                    dlFileEntry = list.get(0);
2080
2081                    cacheResult(dlFileEntry);
2082
2083                    if ((dlFileEntry.getFolderId() != folderId) ||
2084                            (dlFileEntry.getName() == null) ||
2085                            !dlFileEntry.getName().equals(name)) {
2086                        FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_F_N,
2087                            finderArgs, dlFileEntry);
2088                    }
2089                }
2090
2091                return dlFileEntry;
2092            }
2093            catch (Exception e) {
2094                throw processException(e);
2095            }
2096            finally {
2097                if (result == null) {
2098                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_F_N,
2099                        finderArgs, new ArrayList<DLFileEntry>());
2100                }
2101
2102                closeSession(session);
2103            }
2104        }
2105        else {
2106            if (result instanceof List) {
2107                return null;
2108            }
2109            else {
2110                return (DLFileEntry)result;
2111            }
2112        }
2113    }
2114
2115    public List<DLFileEntry> findByF_T(long folderId, String title)
2116        throws SystemException {
2117        Object[] finderArgs = new Object[] { new Long(folderId), title };
2118
2119        List<DLFileEntry> list = (List<DLFileEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_F_T,
2120                finderArgs, this);
2121
2122        if (list == null) {
2123            Session session = null;
2124
2125            try {
2126                session = openSession();
2127
2128                StringBuilder query = new StringBuilder();
2129
2130                query.append(
2131                    "SELECT dlFileEntry FROM DLFileEntry dlFileEntry WHERE ");
2132
2133                query.append("dlFileEntry.folderId = ?");
2134
2135                query.append(" AND ");
2136
2137                if (title == null) {
2138                    query.append("dlFileEntry.title IS NULL");
2139                }
2140                else {
2141                    query.append("dlFileEntry.title = ?");
2142                }
2143
2144                query.append(" ");
2145
2146                query.append("ORDER BY ");
2147
2148                query.append("dlFileEntry.folderId ASC, ");
2149                query.append("dlFileEntry.name ASC");
2150
2151                Query q = session.createQuery(query.toString());
2152
2153                QueryPos qPos = QueryPos.getInstance(q);
2154
2155                qPos.add(folderId);
2156
2157                if (title != null) {
2158                    qPos.add(title);
2159                }
2160
2161                list = q.list();
2162            }
2163            catch (Exception e) {
2164                throw processException(e);
2165            }
2166            finally {
2167                if (list == null) {
2168                    list = new ArrayList<DLFileEntry>();
2169                }
2170
2171                cacheResult(list);
2172
2173                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_F_T, finderArgs,
2174                    list);
2175
2176                closeSession(session);
2177            }
2178        }
2179
2180        return list;
2181    }
2182
2183    public List<DLFileEntry> findByF_T(long folderId, String title, int start,
2184        int end) throws SystemException {
2185        return findByF_T(folderId, title, start, end, null);
2186    }
2187
2188    public List<DLFileEntry> findByF_T(long folderId, String title, int start,
2189        int end, OrderByComparator obc) throws SystemException {
2190        Object[] finderArgs = new Object[] {
2191                new Long(folderId),
2192                
2193                title,
2194                
2195                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
2196            };
2197
2198        List<DLFileEntry> list = (List<DLFileEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_F_T,
2199                finderArgs, this);
2200
2201        if (list == null) {
2202            Session session = null;
2203
2204            try {
2205                session = openSession();
2206
2207                StringBuilder query = new StringBuilder();
2208
2209                query.append(
2210                    "SELECT dlFileEntry FROM DLFileEntry dlFileEntry WHERE ");
2211
2212                query.append("dlFileEntry.folderId = ?");
2213
2214                query.append(" AND ");
2215
2216                if (title == null) {
2217                    query.append("dlFileEntry.title IS NULL");
2218                }
2219                else {
2220                    query.append("dlFileEntry.title = ?");
2221                }
2222
2223                query.append(" ");
2224
2225                if (obc != null) {
2226                    query.append("ORDER BY ");
2227
2228                    String[] orderByFields = obc.getOrderByFields();
2229
2230                    for (int i = 0; i < orderByFields.length; i++) {
2231                        query.append("dlFileEntry.");
2232                        query.append(orderByFields[i]);
2233
2234                        if (obc.isAscending()) {
2235                            query.append(" ASC");
2236                        }
2237                        else {
2238                            query.append(" DESC");
2239                        }
2240
2241                        if ((i + 1) < orderByFields.length) {
2242                            query.append(", ");
2243                        }
2244                    }
2245                }
2246
2247                else {
2248                    query.append("ORDER BY ");
2249
2250                    query.append("dlFileEntry.folderId ASC, ");
2251                    query.append("dlFileEntry.name ASC");
2252                }
2253
2254                Query q = session.createQuery(query.toString());
2255
2256                QueryPos qPos = QueryPos.getInstance(q);
2257
2258                qPos.add(folderId);
2259
2260                if (title != null) {
2261                    qPos.add(title);
2262                }
2263
2264                list = (List<DLFileEntry>)QueryUtil.list(q, getDialect(),
2265                        start, end);
2266            }
2267            catch (Exception e) {
2268                throw processException(e);
2269            }
2270            finally {
2271                if (list == null) {
2272                    list = new ArrayList<DLFileEntry>();
2273                }
2274
2275                cacheResult(list);
2276
2277                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_F_T,
2278                    finderArgs, list);
2279
2280                closeSession(session);
2281            }
2282        }
2283
2284        return list;
2285    }
2286
2287    public DLFileEntry findByF_T_First(long folderId, String title,
2288        OrderByComparator obc) throws NoSuchFileEntryException, SystemException {
2289        List<DLFileEntry> list = findByF_T(folderId, title, 0, 1, obc);
2290
2291        if (list.isEmpty()) {
2292            StringBuilder msg = new StringBuilder();
2293
2294            msg.append("No DLFileEntry exists with the key {");
2295
2296            msg.append("folderId=" + folderId);
2297
2298            msg.append(", ");
2299            msg.append("title=" + title);
2300
2301            msg.append(StringPool.CLOSE_CURLY_BRACE);
2302
2303            throw new NoSuchFileEntryException(msg.toString());
2304        }
2305        else {
2306            return list.get(0);
2307        }
2308    }
2309
2310    public DLFileEntry findByF_T_Last(long folderId, String title,
2311        OrderByComparator obc) throws NoSuchFileEntryException, SystemException {
2312        int count = countByF_T(folderId, title);
2313
2314        List<DLFileEntry> list = findByF_T(folderId, title, count - 1, count,
2315                obc);
2316
2317        if (list.isEmpty()) {
2318            StringBuilder msg = new StringBuilder();
2319
2320            msg.append("No DLFileEntry exists with the key {");
2321
2322            msg.append("folderId=" + folderId);
2323
2324            msg.append(", ");
2325            msg.append("title=" + title);
2326
2327            msg.append(StringPool.CLOSE_CURLY_BRACE);
2328
2329            throw new NoSuchFileEntryException(msg.toString());
2330        }
2331        else {
2332            return list.get(0);
2333        }
2334    }
2335
2336    public DLFileEntry[] findByF_T_PrevAndNext(long fileEntryId, long folderId,
2337        String title, OrderByComparator obc)
2338        throws NoSuchFileEntryException, SystemException {
2339        DLFileEntry dlFileEntry = findByPrimaryKey(fileEntryId);
2340
2341        int count = countByF_T(folderId, title);
2342
2343        Session session = null;
2344
2345        try {
2346            session = openSession();
2347
2348            StringBuilder query = new StringBuilder();
2349
2350            query.append(
2351                "SELECT dlFileEntry FROM DLFileEntry dlFileEntry WHERE ");
2352
2353            query.append("dlFileEntry.folderId = ?");
2354
2355            query.append(" AND ");
2356
2357            if (title == null) {
2358                query.append("dlFileEntry.title IS NULL");
2359            }
2360            else {
2361                query.append("dlFileEntry.title = ?");
2362            }
2363
2364            query.append(" ");
2365
2366            if (obc != null) {
2367                query.append("ORDER BY ");
2368
2369                String[] orderByFields = obc.getOrderByFields();
2370
2371                for (int i = 0; i < orderByFields.length; i++) {
2372                    query.append("dlFileEntry.");
2373                    query.append(orderByFields[i]);
2374
2375                    if (obc.isAscending()) {
2376                        query.append(" ASC");
2377                    }
2378                    else {
2379                        query.append(" DESC");
2380                    }
2381
2382                    if ((i + 1) < orderByFields.length) {
2383                        query.append(", ");
2384                    }
2385                }
2386            }
2387
2388            else {
2389                query.append("ORDER BY ");
2390
2391                query.append("dlFileEntry.folderId ASC, ");
2392                query.append("dlFileEntry.name ASC");
2393            }
2394
2395            Query q = session.createQuery(query.toString());
2396
2397            QueryPos qPos = QueryPos.getInstance(q);
2398
2399            qPos.add(folderId);
2400
2401            if (title != null) {
2402                qPos.add(title);
2403            }
2404
2405            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
2406                    dlFileEntry);
2407
2408            DLFileEntry[] array = new DLFileEntryImpl[3];
2409
2410            array[0] = (DLFileEntry)objArray[0];
2411            array[1] = (DLFileEntry)objArray[1];
2412            array[2] = (DLFileEntry)objArray[2];
2413
2414            return array;
2415        }
2416        catch (Exception e) {
2417            throw processException(e);
2418        }
2419        finally {
2420            closeSession(session);
2421        }
2422    }
2423
2424    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
2425        throws SystemException {
2426        Session session = null;
2427
2428        try {
2429            session = openSession();
2430
2431            dynamicQuery.compile(session);
2432
2433            return dynamicQuery.list();
2434        }
2435        catch (Exception e) {
2436            throw processException(e);
2437        }
2438        finally {
2439            closeSession(session);
2440        }
2441    }
2442
2443    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
2444        int start, int end) throws SystemException {
2445        Session session = null;
2446
2447        try {
2448            session = openSession();
2449
2450            dynamicQuery.setLimit(start, end);
2451
2452            dynamicQuery.compile(session);
2453
2454            return dynamicQuery.list();
2455        }
2456        catch (Exception e) {
2457            throw processException(e);
2458        }
2459        finally {
2460            closeSession(session);
2461        }
2462    }
2463
2464    public List<DLFileEntry> findAll() throws SystemException {
2465        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2466    }
2467
2468    public List<DLFileEntry> findAll(int start, int end)
2469        throws SystemException {
2470        return findAll(start, end, null);
2471    }
2472
2473    public List<DLFileEntry> findAll(int start, int end, OrderByComparator obc)
2474        throws SystemException {
2475        Object[] finderArgs = new Object[] {
2476                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
2477            };
2478
2479        List<DLFileEntry> list = (List<DLFileEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
2480                finderArgs, this);
2481
2482        if (list == null) {
2483            Session session = null;
2484
2485            try {
2486                session = openSession();
2487
2488                StringBuilder query = new StringBuilder();
2489
2490                query.append("SELECT dlFileEntry FROM DLFileEntry dlFileEntry ");
2491
2492                if (obc != null) {
2493                    query.append("ORDER BY ");
2494
2495                    String[] orderByFields = obc.getOrderByFields();
2496
2497                    for (int i = 0; i < orderByFields.length; i++) {
2498                        query.append("dlFileEntry.");
2499                        query.append(orderByFields[i]);
2500
2501                        if (obc.isAscending()) {
2502                            query.append(" ASC");
2503                        }
2504                        else {
2505                            query.append(" DESC");
2506                        }
2507
2508                        if ((i + 1) < orderByFields.length) {
2509                            query.append(", ");
2510                        }
2511                    }
2512                }
2513
2514                else {
2515                    query.append("ORDER BY ");
2516
2517                    query.append("dlFileEntry.folderId ASC, ");
2518                    query.append("dlFileEntry.name ASC");
2519                }
2520
2521                Query q = session.createQuery(query.toString());
2522
2523                if (obc == null) {
2524                    list = (List<DLFileEntry>)QueryUtil.list(q, getDialect(),
2525                            start, end, false);
2526
2527                    Collections.sort(list);
2528                }
2529                else {
2530                    list = (List<DLFileEntry>)QueryUtil.list(q, getDialect(),
2531                            start, end);
2532                }
2533            }
2534            catch (Exception e) {
2535                throw processException(e);
2536            }
2537            finally {
2538                if (list == null) {
2539                    list = new ArrayList<DLFileEntry>();
2540                }
2541
2542                cacheResult(list);
2543
2544                FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
2545
2546                closeSession(session);
2547            }
2548        }
2549
2550        return list;
2551    }
2552
2553    public void removeByUuid(String uuid) throws SystemException {
2554        for (DLFileEntry dlFileEntry : findByUuid(uuid)) {
2555            remove(dlFileEntry);
2556        }
2557    }
2558
2559    public void removeByUUID_G(String uuid, long groupId)
2560        throws NoSuchFileEntryException, SystemException {
2561        DLFileEntry dlFileEntry = findByUUID_G(uuid, groupId);
2562
2563        remove(dlFileEntry);
2564    }
2565
2566    public void removeByGroupId(long groupId) throws SystemException {
2567        for (DLFileEntry dlFileEntry : findByGroupId(groupId)) {
2568            remove(dlFileEntry);
2569        }
2570    }
2571
2572    public void removeByCompanyId(long companyId) throws SystemException {
2573        for (DLFileEntry dlFileEntry : findByCompanyId(companyId)) {
2574            remove(dlFileEntry);
2575        }
2576    }
2577
2578    public void removeByFolderId(long folderId) throws SystemException {
2579        for (DLFileEntry dlFileEntry : findByFolderId(folderId)) {
2580            remove(dlFileEntry);
2581        }
2582    }
2583
2584    public void removeByG_U(long groupId, long userId)
2585        throws SystemException {
2586        for (DLFileEntry dlFileEntry : findByG_U(groupId, userId)) {
2587            remove(dlFileEntry);
2588        }
2589    }
2590
2591    public void removeByF_N(long folderId, String name)
2592        throws NoSuchFileEntryException, SystemException {
2593        DLFileEntry dlFileEntry = findByF_N(folderId, name);
2594
2595        remove(dlFileEntry);
2596    }
2597
2598    public void removeByF_T(long folderId, String title)
2599        throws SystemException {
2600        for (DLFileEntry dlFileEntry : findByF_T(folderId, title)) {
2601            remove(dlFileEntry);
2602        }
2603    }
2604
2605    public void removeAll() throws SystemException {
2606        for (DLFileEntry dlFileEntry : findAll()) {
2607            remove(dlFileEntry);
2608        }
2609    }
2610
2611    public int countByUuid(String uuid) throws SystemException {
2612        Object[] finderArgs = new Object[] { uuid };
2613
2614        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
2615                finderArgs, this);
2616
2617        if (count == null) {
2618            Session session = null;
2619
2620            try {
2621                session = openSession();
2622
2623                StringBuilder query = new StringBuilder();
2624
2625                query.append("SELECT COUNT(dlFileEntry) ");
2626                query.append("FROM DLFileEntry dlFileEntry WHERE ");
2627
2628                if (uuid == null) {
2629                    query.append("dlFileEntry.uuid IS NULL");
2630                }
2631                else {
2632                    query.append("dlFileEntry.uuid = ?");
2633                }
2634
2635                query.append(" ");
2636
2637                Query q = session.createQuery(query.toString());
2638
2639                QueryPos qPos = QueryPos.getInstance(q);
2640
2641                if (uuid != null) {
2642                    qPos.add(uuid);
2643                }
2644
2645                count = (Long)q.uniqueResult();
2646            }
2647            catch (Exception e) {
2648                throw processException(e);
2649            }
2650            finally {
2651                if (count == null) {
2652                    count = Long.valueOf(0);
2653                }
2654
2655                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
2656                    finderArgs, count);
2657
2658                closeSession(session);
2659            }
2660        }
2661
2662        return count.intValue();
2663    }
2664
2665    public int countByUUID_G(String uuid, long groupId)
2666        throws SystemException {
2667        Object[] finderArgs = new Object[] { uuid, new Long(groupId) };
2668
2669        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
2670                finderArgs, this);
2671
2672        if (count == null) {
2673            Session session = null;
2674
2675            try {
2676                session = openSession();
2677
2678                StringBuilder query = new StringBuilder();
2679
2680                query.append("SELECT COUNT(dlFileEntry) ");
2681                query.append("FROM DLFileEntry dlFileEntry WHERE ");
2682
2683                if (uuid == null) {
2684                    query.append("dlFileEntry.uuid IS NULL");
2685                }
2686                else {
2687                    query.append("dlFileEntry.uuid = ?");
2688                }
2689
2690                query.append(" AND ");
2691
2692                query.append("dlFileEntry.groupId = ?");
2693
2694                query.append(" ");
2695
2696                Query q = session.createQuery(query.toString());
2697
2698                QueryPos qPos = QueryPos.getInstance(q);
2699
2700                if (uuid != null) {
2701                    qPos.add(uuid);
2702                }
2703
2704                qPos.add(groupId);
2705
2706                count = (Long)q.uniqueResult();
2707            }
2708            catch (Exception e) {
2709                throw processException(e);
2710            }
2711            finally {
2712                if (count == null) {
2713                    count = Long.valueOf(0);
2714                }
2715
2716                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
2717                    finderArgs, count);
2718
2719                closeSession(session);
2720            }
2721        }
2722
2723        return count.intValue();
2724    }
2725
2726    public int countByGroupId(long groupId) throws SystemException {
2727        Object[] finderArgs = new Object[] { new Long(groupId) };
2728
2729        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
2730                finderArgs, this);
2731
2732        if (count == null) {
2733            Session session = null;
2734
2735            try {
2736                session = openSession();
2737
2738                StringBuilder query = new StringBuilder();
2739
2740                query.append("SELECT COUNT(dlFileEntry) ");
2741                query.append("FROM DLFileEntry dlFileEntry WHERE ");
2742
2743                query.append("dlFileEntry.groupId = ?");
2744
2745                query.append(" ");
2746
2747                Query q = session.createQuery(query.toString());
2748
2749                QueryPos qPos = QueryPos.getInstance(q);
2750
2751                qPos.add(groupId);
2752
2753                count = (Long)q.uniqueResult();
2754            }
2755            catch (Exception e) {
2756                throw processException(e);
2757            }
2758            finally {
2759                if (count == null) {
2760                    count = Long.valueOf(0);
2761                }
2762
2763                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
2764                    finderArgs, count);
2765
2766                closeSession(session);
2767            }
2768        }
2769
2770        return count.intValue();
2771    }
2772
2773    public int countByCompanyId(long companyId) throws SystemException {
2774        Object[] finderArgs = new Object[] { new Long(companyId) };
2775
2776        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
2777                finderArgs, this);
2778
2779        if (count == null) {
2780            Session session = null;
2781
2782            try {
2783                session = openSession();
2784
2785                StringBuilder query = new StringBuilder();
2786
2787                query.append("SELECT COUNT(dlFileEntry) ");
2788                query.append("FROM DLFileEntry dlFileEntry WHERE ");
2789
2790                query.append("dlFileEntry.companyId = ?");
2791
2792                query.append(" ");
2793
2794                Query q = session.createQuery(query.toString());
2795
2796                QueryPos qPos = QueryPos.getInstance(q);
2797
2798                qPos.add(companyId);
2799
2800                count = (Long)q.uniqueResult();
2801            }
2802            catch (Exception e) {
2803                throw processException(e);
2804            }
2805            finally {
2806                if (count == null) {
2807                    count = Long.valueOf(0);
2808                }
2809
2810                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
2811                    finderArgs, count);
2812
2813                closeSession(session);
2814            }
2815        }
2816
2817        return count.intValue();
2818    }
2819
2820    public int countByFolderId(long folderId) throws SystemException {
2821        Object[] finderArgs = new Object[] { new Long(folderId) };
2822
2823        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_FOLDERID,
2824                finderArgs, this);
2825
2826        if (count == null) {
2827            Session session = null;
2828
2829            try {
2830                session = openSession();
2831
2832                StringBuilder query = new StringBuilder();
2833
2834                query.append("SELECT COUNT(dlFileEntry) ");
2835                query.append("FROM DLFileEntry dlFileEntry WHERE ");
2836
2837                query.append("dlFileEntry.folderId = ?");
2838
2839                query.append(" ");
2840
2841                Query q = session.createQuery(query.toString());
2842
2843                QueryPos qPos = QueryPos.getInstance(q);
2844
2845                qPos.add(folderId);
2846
2847                count = (Long)q.uniqueResult();
2848            }
2849            catch (Exception e) {
2850                throw processException(e);
2851            }
2852            finally {
2853                if (count == null) {
2854                    count = Long.valueOf(0);
2855                }
2856
2857                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_FOLDERID,
2858                    finderArgs, count);
2859
2860                closeSession(session);
2861            }
2862        }
2863
2864        return count.intValue();
2865    }
2866
2867    public int countByG_U(long groupId, long userId) throws SystemException {
2868        Object[] finderArgs = new Object[] { new Long(groupId), new Long(userId) };
2869
2870        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_U,
2871                finderArgs, this);
2872
2873        if (count == null) {
2874            Session session = null;
2875
2876            try {
2877                session = openSession();
2878
2879                StringBuilder query = new StringBuilder();
2880
2881                query.append("SELECT COUNT(dlFileEntry) ");
2882                query.append("FROM DLFileEntry dlFileEntry WHERE ");
2883
2884                query.append("dlFileEntry.groupId = ?");
2885
2886                query.append(" AND ");
2887
2888                query.append("dlFileEntry.userId = ?");
2889
2890                query.append(" ");
2891
2892                Query q = session.createQuery(query.toString());
2893
2894                QueryPos qPos = QueryPos.getInstance(q);
2895
2896                qPos.add(groupId);
2897
2898                qPos.add(userId);
2899
2900                count = (Long)q.uniqueResult();
2901            }
2902            catch (Exception e) {
2903                throw processException(e);
2904            }
2905            finally {
2906                if (count == null) {
2907                    count = Long.valueOf(0);
2908                }
2909
2910                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_U, finderArgs,
2911                    count);
2912
2913                closeSession(session);
2914            }
2915        }
2916
2917        return count.intValue();
2918    }
2919
2920    public int countByF_N(long folderId, String name) throws SystemException {
2921        Object[] finderArgs = new Object[] { new Long(folderId), name };
2922
2923        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_F_N,
2924                finderArgs, this);
2925
2926        if (count == null) {
2927            Session session = null;
2928
2929            try {
2930                session = openSession();
2931
2932                StringBuilder query = new StringBuilder();
2933
2934                query.append("SELECT COUNT(dlFileEntry) ");
2935                query.append("FROM DLFileEntry dlFileEntry WHERE ");
2936
2937                query.append("dlFileEntry.folderId = ?");
2938
2939                query.append(" AND ");
2940
2941                if (name == null) {
2942                    query.append("dlFileEntry.name IS NULL");
2943                }
2944                else {
2945                    query.append("dlFileEntry.name = ?");
2946                }
2947
2948                query.append(" ");
2949
2950                Query q = session.createQuery(query.toString());
2951
2952                QueryPos qPos = QueryPos.getInstance(q);
2953
2954                qPos.add(folderId);
2955
2956                if (name != null) {
2957                    qPos.add(name);
2958                }
2959
2960                count = (Long)q.uniqueResult();
2961            }
2962            catch (Exception e) {
2963                throw processException(e);
2964            }
2965            finally {
2966                if (count == null) {
2967                    count = Long.valueOf(0);
2968                }
2969
2970                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_F_N, finderArgs,
2971                    count);
2972
2973                closeSession(session);
2974            }
2975        }
2976
2977        return count.intValue();
2978    }
2979
2980    public int countByF_T(long folderId, String title)
2981        throws SystemException {
2982        Object[] finderArgs = new Object[] { new Long(folderId), title };
2983
2984        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_F_T,
2985                finderArgs, this);
2986
2987        if (count == null) {
2988            Session session = null;
2989
2990            try {
2991                session = openSession();
2992
2993                StringBuilder query = new StringBuilder();
2994
2995                query.append("SELECT COUNT(dlFileEntry) ");
2996                query.append("FROM DLFileEntry dlFileEntry WHERE ");
2997
2998                query.append("dlFileEntry.folderId = ?");
2999
3000                query.append(" AND ");
3001
3002                if (title == null) {
3003                    query.append("dlFileEntry.title IS NULL");
3004                }
3005                else {
3006                    query.append("dlFileEntry.title = ?");
3007                }
3008
3009                query.append(" ");
3010
3011                Query q = session.createQuery(query.toString());
3012
3013                QueryPos qPos = QueryPos.getInstance(q);
3014
3015                qPos.add(folderId);
3016
3017                if (title != null) {
3018                    qPos.add(title);
3019                }
3020
3021                count = (Long)q.uniqueResult();
3022            }
3023            catch (Exception e) {
3024                throw processException(e);
3025            }
3026            finally {
3027                if (count == null) {
3028                    count = Long.valueOf(0);
3029                }
3030
3031                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_F_T, finderArgs,
3032                    count);
3033
3034                closeSession(session);
3035            }
3036        }
3037
3038        return count.intValue();
3039    }
3040
3041    public int countAll() throws SystemException {
3042        Object[] finderArgs = new Object[0];
3043
3044        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
3045                finderArgs, this);
3046
3047        if (count == null) {
3048            Session session = null;
3049
3050            try {
3051                session = openSession();
3052
3053                Query q = session.createQuery(
3054                        "SELECT COUNT(dlFileEntry) FROM DLFileEntry dlFileEntry");
3055
3056                count = (Long)q.uniqueResult();
3057            }
3058            catch (Exception e) {
3059                throw processException(e);
3060            }
3061            finally {
3062                if (count == null) {
3063                    count = Long.valueOf(0);
3064                }
3065
3066                FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
3067                    count);
3068
3069                closeSession(session);
3070            }
3071        }
3072
3073        return count.intValue();
3074    }
3075
3076    public void afterPropertiesSet() {
3077        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
3078                    com.liferay.portal.util.PropsUtil.get(
3079                        "value.object.listener.com.liferay.portlet.documentlibrary.model.DLFileEntry")));
3080
3081        if (listenerClassNames.length > 0) {
3082            try {
3083                List<ModelListener<DLFileEntry>> listenersList = new ArrayList<ModelListener<DLFileEntry>>();
3084
3085                for (String listenerClassName : listenerClassNames) {
3086                    listenersList.add((ModelListener<DLFileEntry>)Class.forName(
3087                            listenerClassName).newInstance());
3088                }
3089
3090                listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
3091            }
3092            catch (Exception e) {
3093                _log.error(e);
3094            }
3095        }
3096    }
3097
3098    @BeanReference(name = "com.liferay.portlet.documentlibrary.service.persistence.DLFileEntryPersistence.impl")
3099    protected com.liferay.portlet.documentlibrary.service.persistence.DLFileEntryPersistence dlFileEntryPersistence;
3100    @BeanReference(name = "com.liferay.portlet.documentlibrary.service.persistence.DLFileRankPersistence.impl")
3101    protected com.liferay.portlet.documentlibrary.service.persistence.DLFileRankPersistence dlFileRankPersistence;
3102    @BeanReference(name = "com.liferay.portlet.documentlibrary.service.persistence.DLFileShortcutPersistence.impl")
3103    protected com.liferay.portlet.documentlibrary.service.persistence.DLFileShortcutPersistence dlFileShortcutPersistence;
3104    @BeanReference(name = "com.liferay.portlet.documentlibrary.service.persistence.DLFileVersionPersistence.impl")
3105    protected com.liferay.portlet.documentlibrary.service.persistence.DLFileVersionPersistence dlFileVersionPersistence;
3106    @BeanReference(name = "com.liferay.portlet.documentlibrary.service.persistence.DLFolderPersistence.impl")
3107    protected com.liferay.portlet.documentlibrary.service.persistence.DLFolderPersistence dlFolderPersistence;
3108    @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence.impl")
3109    protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
3110    @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence.impl")
3111    protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
3112    @BeanReference(name = "com.liferay.portal.service.persistence.WebDAVPropsPersistence.impl")
3113    protected com.liferay.portal.service.persistence.WebDAVPropsPersistence webDAVPropsPersistence;
3114    @BeanReference(name = "com.liferay.portlet.expando.service.persistence.ExpandoValuePersistence.impl")
3115    protected com.liferay.portlet.expando.service.persistence.ExpandoValuePersistence expandoValuePersistence;
3116    @BeanReference(name = "com.liferay.portlet.messageboards.service.persistence.MBDiscussionPersistence.impl")
3117    protected com.liferay.portlet.messageboards.service.persistence.MBDiscussionPersistence mbDiscussionPersistence;
3118    @BeanReference(name = "com.liferay.portlet.messageboards.service.persistence.MBMessagePersistence.impl")
3119    protected com.liferay.portlet.messageboards.service.persistence.MBMessagePersistence mbMessagePersistence;
3120    @BeanReference(name = "com.liferay.portlet.ratings.service.persistence.RatingsEntryPersistence.impl")
3121    protected com.liferay.portlet.ratings.service.persistence.RatingsEntryPersistence ratingsEntryPersistence;
3122    @BeanReference(name = "com.liferay.portlet.ratings.service.persistence.RatingsStatsPersistence.impl")
3123    protected com.liferay.portlet.ratings.service.persistence.RatingsStatsPersistence ratingsStatsPersistence;
3124    @BeanReference(name = "com.liferay.portlet.social.service.persistence.SocialActivityPersistence.impl")
3125    protected com.liferay.portlet.social.service.persistence.SocialActivityPersistence socialActivityPersistence;
3126    @BeanReference(name = "com.liferay.portlet.tags.service.persistence.TagsAssetPersistence.impl")
3127    protected com.liferay.portlet.tags.service.persistence.TagsAssetPersistence tagsAssetPersistence;
3128    @BeanReference(name = "com.liferay.portlet.tags.service.persistence.TagsEntryPersistence.impl")
3129    protected com.liferay.portlet.tags.service.persistence.TagsEntryPersistence tagsEntryPersistence;
3130    private static Log _log = LogFactoryUtil.getLog(DLFileEntryPersistenceImpl.class);
3131}