1   /**
2    * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portlet.documentlibrary.service.persistence;
24  
25  import com.liferay.portal.SystemException;
26  import com.liferay.portal.kernel.dao.orm.DynamicQuery;
27  import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
28  import com.liferay.portal.kernel.dao.orm.Query;
29  import com.liferay.portal.kernel.dao.orm.QueryPos;
30  import com.liferay.portal.kernel.dao.orm.QueryUtil;
31  import com.liferay.portal.kernel.dao.orm.Session;
32  import com.liferay.portal.kernel.util.GetterUtil;
33  import com.liferay.portal.kernel.util.ListUtil;
34  import com.liferay.portal.kernel.util.OrderByComparator;
35  import com.liferay.portal.kernel.util.StringPool;
36  import com.liferay.portal.kernel.util.StringUtil;
37  import com.liferay.portal.kernel.util.Validator;
38  import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
39  import com.liferay.portal.model.ModelListener;
40  import com.liferay.portal.service.persistence.BatchSessionUtil;
41  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
42  
43  import com.liferay.portlet.documentlibrary.NoSuchFileEntryException;
44  import com.liferay.portlet.documentlibrary.model.DLFileEntry;
45  import com.liferay.portlet.documentlibrary.model.impl.DLFileEntryImpl;
46  import com.liferay.portlet.documentlibrary.model.impl.DLFileEntryModelImpl;
47  
48  import org.apache.commons.logging.Log;
49  import org.apache.commons.logging.LogFactory;
50  
51  import java.util.ArrayList;
52  import java.util.Collections;
53  import java.util.Iterator;
54  import java.util.List;
55  
56  /**
57   * <a href="DLFileEntryPersistenceImpl.java.html"><b><i>View Source</i></b></a>
58   *
59   * @author Brian Wing Shun Chan
60   *
61   */
62  public class DLFileEntryPersistenceImpl extends BasePersistenceImpl
63      implements DLFileEntryPersistence {
64      public DLFileEntry create(long fileEntryId) {
65          DLFileEntry dlFileEntry = new DLFileEntryImpl();
66  
67          dlFileEntry.setNew(true);
68          dlFileEntry.setPrimaryKey(fileEntryId);
69  
70          String uuid = PortalUUIDUtil.generate();
71  
72          dlFileEntry.setUuid(uuid);
73  
74          return dlFileEntry;
75      }
76  
77      public DLFileEntry remove(long fileEntryId)
78          throws NoSuchFileEntryException, SystemException {
79          Session session = null;
80  
81          try {
82              session = openSession();
83  
84              DLFileEntry dlFileEntry = (DLFileEntry)session.get(DLFileEntryImpl.class,
85                      new Long(fileEntryId));
86  
87              if (dlFileEntry == null) {
88                  if (_log.isWarnEnabled()) {
89                      _log.warn("No DLFileEntry exists with the primary key " +
90                          fileEntryId);
91                  }
92  
93                  throw new NoSuchFileEntryException(
94                      "No DLFileEntry exists with the primary key " +
95                      fileEntryId);
96              }
97  
98              return remove(dlFileEntry);
99          }
100         catch (NoSuchFileEntryException nsee) {
101             throw nsee;
102         }
103         catch (Exception e) {
104             throw processException(e);
105         }
106         finally {
107             closeSession(session);
108         }
109     }
110 
111     public DLFileEntry remove(DLFileEntry dlFileEntry)
112         throws SystemException {
113         if (_listeners.length > 0) {
114             for (ModelListener listener : _listeners) {
115                 listener.onBeforeRemove(dlFileEntry);
116             }
117         }
118 
119         dlFileEntry = removeImpl(dlFileEntry);
120 
121         if (_listeners.length > 0) {
122             for (ModelListener listener : _listeners) {
123                 listener.onAfterRemove(dlFileEntry);
124             }
125         }
126 
127         return dlFileEntry;
128     }
129 
130     protected DLFileEntry removeImpl(DLFileEntry dlFileEntry)
131         throws SystemException {
132         Session session = null;
133 
134         try {
135             session = openSession();
136 
137             if (BatchSessionUtil.isEnabled()) {
138                 Object staleObject = session.get(DLFileEntryImpl.class,
139                         dlFileEntry.getPrimaryKeyObj());
140 
141                 if (staleObject != null) {
142                     session.evict(staleObject);
143                 }
144             }
145 
146             session.delete(dlFileEntry);
147 
148             session.flush();
149 
150             return dlFileEntry;
151         }
152         catch (Exception e) {
153             throw processException(e);
154         }
155         finally {
156             closeSession(session);
157 
158             FinderCacheUtil.clearCache(DLFileEntry.class.getName());
159         }
160     }
161 
162     /**
163      * @deprecated Use <code>update(DLFileEntry dlFileEntry, boolean merge)</code>.
164      */
165     public DLFileEntry update(DLFileEntry dlFileEntry)
166         throws SystemException {
167         if (_log.isWarnEnabled()) {
168             _log.warn(
169                 "Using the deprecated update(DLFileEntry dlFileEntry) method. Use update(DLFileEntry dlFileEntry, boolean merge) instead.");
170         }
171 
172         return update(dlFileEntry, false);
173     }
174 
175     /**
176      * Add, update, or merge, the entity. This method also calls the model
177      * listeners to trigger the proper events associated with adding, deleting,
178      * or updating an entity.
179      *
180      * @param        dlFileEntry the entity to add, update, or merge
181      * @param        merge boolean value for whether to merge the entity. The
182      *                default value is false. Setting merge to true is more
183      *                expensive and should only be true when dlFileEntry is
184      *                transient. See LEP-5473 for a detailed discussion of this
185      *                method.
186      * @return        true if the portlet can be displayed via Ajax
187      */
188     public DLFileEntry update(DLFileEntry dlFileEntry, boolean merge)
189         throws SystemException {
190         boolean isNew = dlFileEntry.isNew();
191 
192         if (_listeners.length > 0) {
193             for (ModelListener listener : _listeners) {
194                 if (isNew) {
195                     listener.onBeforeCreate(dlFileEntry);
196                 }
197                 else {
198                     listener.onBeforeUpdate(dlFileEntry);
199                 }
200             }
201         }
202 
203         dlFileEntry = updateImpl(dlFileEntry, merge);
204 
205         if (_listeners.length > 0) {
206             for (ModelListener listener : _listeners) {
207                 if (isNew) {
208                     listener.onAfterCreate(dlFileEntry);
209                 }
210                 else {
211                     listener.onAfterUpdate(dlFileEntry);
212                 }
213             }
214         }
215 
216         return dlFileEntry;
217     }
218 
219     public DLFileEntry updateImpl(
220         com.liferay.portlet.documentlibrary.model.DLFileEntry dlFileEntry,
221         boolean merge) throws SystemException {
222         if (Validator.isNull(dlFileEntry.getUuid())) {
223             String uuid = PortalUUIDUtil.generate();
224 
225             dlFileEntry.setUuid(uuid);
226         }
227 
228         Session session = null;
229 
230         try {
231             session = openSession();
232 
233             BatchSessionUtil.update(session, dlFileEntry, merge);
234 
235             dlFileEntry.setNew(false);
236 
237             return dlFileEntry;
238         }
239         catch (Exception e) {
240             throw processException(e);
241         }
242         finally {
243             closeSession(session);
244 
245             FinderCacheUtil.clearCache(DLFileEntry.class.getName());
246         }
247     }
248 
249     public DLFileEntry findByPrimaryKey(long fileEntryId)
250         throws NoSuchFileEntryException, SystemException {
251         DLFileEntry dlFileEntry = fetchByPrimaryKey(fileEntryId);
252 
253         if (dlFileEntry == null) {
254             if (_log.isWarnEnabled()) {
255                 _log.warn("No DLFileEntry exists with the primary key " +
256                     fileEntryId);
257             }
258 
259             throw new NoSuchFileEntryException(
260                 "No DLFileEntry exists with the primary key " + fileEntryId);
261         }
262 
263         return dlFileEntry;
264     }
265 
266     public DLFileEntry fetchByPrimaryKey(long fileEntryId)
267         throws SystemException {
268         Session session = null;
269 
270         try {
271             session = openSession();
272 
273             return (DLFileEntry)session.get(DLFileEntryImpl.class,
274                 new Long(fileEntryId));
275         }
276         catch (Exception e) {
277             throw processException(e);
278         }
279         finally {
280             closeSession(session);
281         }
282     }
283 
284     public List<DLFileEntry> findByUuid(String uuid) throws SystemException {
285         boolean finderClassNameCacheEnabled = DLFileEntryModelImpl.CACHE_ENABLED;
286         String finderClassName = DLFileEntry.class.getName();
287         String finderMethodName = "findByUuid";
288         String[] finderParams = new String[] { String.class.getName() };
289         Object[] finderArgs = new Object[] { uuid };
290 
291         Object result = null;
292 
293         if (finderClassNameCacheEnabled) {
294             result = FinderCacheUtil.getResult(finderClassName,
295                     finderMethodName, finderParams, finderArgs, this);
296         }
297 
298         if (result == null) {
299             Session session = null;
300 
301             try {
302                 session = openSession();
303 
304                 StringBuilder query = new StringBuilder();
305 
306                 query.append(
307                     "FROM com.liferay.portlet.documentlibrary.model.DLFileEntry WHERE ");
308 
309                 if (uuid == null) {
310                     query.append("uuid_ IS NULL");
311                 }
312                 else {
313                     query.append("uuid_ = ?");
314                 }
315 
316                 query.append(" ");
317 
318                 query.append("ORDER BY ");
319 
320                 query.append("folderId ASC, ");
321                 query.append("name ASC");
322 
323                 Query q = session.createQuery(query.toString());
324 
325                 QueryPos qPos = QueryPos.getInstance(q);
326 
327                 if (uuid != null) {
328                     qPos.add(uuid);
329                 }
330 
331                 List<DLFileEntry> list = q.list();
332 
333                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
334                     finderClassName, finderMethodName, finderParams,
335                     finderArgs, list);
336 
337                 return list;
338             }
339             catch (Exception e) {
340                 throw processException(e);
341             }
342             finally {
343                 closeSession(session);
344             }
345         }
346         else {
347             return (List<DLFileEntry>)result;
348         }
349     }
350 
351     public List<DLFileEntry> findByUuid(String uuid, int start, int end)
352         throws SystemException {
353         return findByUuid(uuid, start, end, null);
354     }
355 
356     public List<DLFileEntry> findByUuid(String uuid, int start, int end,
357         OrderByComparator obc) throws SystemException {
358         boolean finderClassNameCacheEnabled = DLFileEntryModelImpl.CACHE_ENABLED;
359         String finderClassName = DLFileEntry.class.getName();
360         String finderMethodName = "findByUuid";
361         String[] finderParams = new String[] {
362                 String.class.getName(),
363                 
364                 "java.lang.Integer", "java.lang.Integer",
365                 "com.liferay.portal.kernel.util.OrderByComparator"
366             };
367         Object[] finderArgs = new Object[] {
368                 uuid,
369                 
370                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
371             };
372 
373         Object result = null;
374 
375         if (finderClassNameCacheEnabled) {
376             result = FinderCacheUtil.getResult(finderClassName,
377                     finderMethodName, finderParams, finderArgs, this);
378         }
379 
380         if (result == null) {
381             Session session = null;
382 
383             try {
384                 session = openSession();
385 
386                 StringBuilder query = new StringBuilder();
387 
388                 query.append(
389                     "FROM com.liferay.portlet.documentlibrary.model.DLFileEntry WHERE ");
390 
391                 if (uuid == null) {
392                     query.append("uuid_ IS NULL");
393                 }
394                 else {
395                     query.append("uuid_ = ?");
396                 }
397 
398                 query.append(" ");
399 
400                 if (obc != null) {
401                     query.append("ORDER BY ");
402                     query.append(obc.getOrderBy());
403                 }
404 
405                 else {
406                     query.append("ORDER BY ");
407 
408                     query.append("folderId ASC, ");
409                     query.append("name ASC");
410                 }
411 
412                 Query q = session.createQuery(query.toString());
413 
414                 QueryPos qPos = QueryPos.getInstance(q);
415 
416                 if (uuid != null) {
417                     qPos.add(uuid);
418                 }
419 
420                 List<DLFileEntry> list = (List<DLFileEntry>)QueryUtil.list(q,
421                         getDialect(), start, end);
422 
423                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
424                     finderClassName, finderMethodName, finderParams,
425                     finderArgs, list);
426 
427                 return list;
428             }
429             catch (Exception e) {
430                 throw processException(e);
431             }
432             finally {
433                 closeSession(session);
434             }
435         }
436         else {
437             return (List<DLFileEntry>)result;
438         }
439     }
440 
441     public DLFileEntry findByUuid_First(String uuid, OrderByComparator obc)
442         throws NoSuchFileEntryException, SystemException {
443         List<DLFileEntry> list = findByUuid(uuid, 0, 1, obc);
444 
445         if (list.size() == 0) {
446             StringBuilder msg = new StringBuilder();
447 
448             msg.append("No DLFileEntry exists with the key {");
449 
450             msg.append("uuid=" + uuid);
451 
452             msg.append(StringPool.CLOSE_CURLY_BRACE);
453 
454             throw new NoSuchFileEntryException(msg.toString());
455         }
456         else {
457             return list.get(0);
458         }
459     }
460 
461     public DLFileEntry findByUuid_Last(String uuid, OrderByComparator obc)
462         throws NoSuchFileEntryException, SystemException {
463         int count = countByUuid(uuid);
464 
465         List<DLFileEntry> list = findByUuid(uuid, count - 1, count, obc);
466 
467         if (list.size() == 0) {
468             StringBuilder msg = new StringBuilder();
469 
470             msg.append("No DLFileEntry exists with the key {");
471 
472             msg.append("uuid=" + uuid);
473 
474             msg.append(StringPool.CLOSE_CURLY_BRACE);
475 
476             throw new NoSuchFileEntryException(msg.toString());
477         }
478         else {
479             return list.get(0);
480         }
481     }
482 
483     public DLFileEntry[] findByUuid_PrevAndNext(long fileEntryId, String uuid,
484         OrderByComparator obc) throws NoSuchFileEntryException, SystemException {
485         DLFileEntry dlFileEntry = findByPrimaryKey(fileEntryId);
486 
487         int count = countByUuid(uuid);
488 
489         Session session = null;
490 
491         try {
492             session = openSession();
493 
494             StringBuilder query = new StringBuilder();
495 
496             query.append(
497                 "FROM com.liferay.portlet.documentlibrary.model.DLFileEntry WHERE ");
498 
499             if (uuid == null) {
500                 query.append("uuid_ IS NULL");
501             }
502             else {
503                 query.append("uuid_ = ?");
504             }
505 
506             query.append(" ");
507 
508             if (obc != null) {
509                 query.append("ORDER BY ");
510                 query.append(obc.getOrderBy());
511             }
512 
513             else {
514                 query.append("ORDER BY ");
515 
516                 query.append("folderId ASC, ");
517                 query.append("name ASC");
518             }
519 
520             Query q = session.createQuery(query.toString());
521 
522             QueryPos qPos = QueryPos.getInstance(q);
523 
524             if (uuid != null) {
525                 qPos.add(uuid);
526             }
527 
528             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
529                     dlFileEntry);
530 
531             DLFileEntry[] array = new DLFileEntryImpl[3];
532 
533             array[0] = (DLFileEntry)objArray[0];
534             array[1] = (DLFileEntry)objArray[1];
535             array[2] = (DLFileEntry)objArray[2];
536 
537             return array;
538         }
539         catch (Exception e) {
540             throw processException(e);
541         }
542         finally {
543             closeSession(session);
544         }
545     }
546 
547     public List<DLFileEntry> findByCompanyId(long companyId)
548         throws SystemException {
549         boolean finderClassNameCacheEnabled = DLFileEntryModelImpl.CACHE_ENABLED;
550         String finderClassName = DLFileEntry.class.getName();
551         String finderMethodName = "findByCompanyId";
552         String[] finderParams = new String[] { Long.class.getName() };
553         Object[] finderArgs = new Object[] { new Long(companyId) };
554 
555         Object result = null;
556 
557         if (finderClassNameCacheEnabled) {
558             result = FinderCacheUtil.getResult(finderClassName,
559                     finderMethodName, finderParams, finderArgs, this);
560         }
561 
562         if (result == null) {
563             Session session = null;
564 
565             try {
566                 session = openSession();
567 
568                 StringBuilder query = new StringBuilder();
569 
570                 query.append(
571                     "FROM com.liferay.portlet.documentlibrary.model.DLFileEntry WHERE ");
572 
573                 query.append("companyId = ?");
574 
575                 query.append(" ");
576 
577                 query.append("ORDER BY ");
578 
579                 query.append("folderId ASC, ");
580                 query.append("name ASC");
581 
582                 Query q = session.createQuery(query.toString());
583 
584                 QueryPos qPos = QueryPos.getInstance(q);
585 
586                 qPos.add(companyId);
587 
588                 List<DLFileEntry> list = q.list();
589 
590                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
591                     finderClassName, finderMethodName, finderParams,
592                     finderArgs, list);
593 
594                 return list;
595             }
596             catch (Exception e) {
597                 throw processException(e);
598             }
599             finally {
600                 closeSession(session);
601             }
602         }
603         else {
604             return (List<DLFileEntry>)result;
605         }
606     }
607 
608     public List<DLFileEntry> findByCompanyId(long companyId, int start, int end)
609         throws SystemException {
610         return findByCompanyId(companyId, start, end, null);
611     }
612 
613     public List<DLFileEntry> findByCompanyId(long companyId, int start,
614         int end, OrderByComparator obc) throws SystemException {
615         boolean finderClassNameCacheEnabled = DLFileEntryModelImpl.CACHE_ENABLED;
616         String finderClassName = DLFileEntry.class.getName();
617         String finderMethodName = "findByCompanyId";
618         String[] finderParams = new String[] {
619                 Long.class.getName(),
620                 
621                 "java.lang.Integer", "java.lang.Integer",
622                 "com.liferay.portal.kernel.util.OrderByComparator"
623             };
624         Object[] finderArgs = new Object[] {
625                 new Long(companyId),
626                 
627                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
628             };
629 
630         Object result = null;
631 
632         if (finderClassNameCacheEnabled) {
633             result = FinderCacheUtil.getResult(finderClassName,
634                     finderMethodName, finderParams, finderArgs, this);
635         }
636 
637         if (result == null) {
638             Session session = null;
639 
640             try {
641                 session = openSession();
642 
643                 StringBuilder query = new StringBuilder();
644 
645                 query.append(
646                     "FROM com.liferay.portlet.documentlibrary.model.DLFileEntry WHERE ");
647 
648                 query.append("companyId = ?");
649 
650                 query.append(" ");
651 
652                 if (obc != null) {
653                     query.append("ORDER BY ");
654                     query.append(obc.getOrderBy());
655                 }
656 
657                 else {
658                     query.append("ORDER BY ");
659 
660                     query.append("folderId ASC, ");
661                     query.append("name ASC");
662                 }
663 
664                 Query q = session.createQuery(query.toString());
665 
666                 QueryPos qPos = QueryPos.getInstance(q);
667 
668                 qPos.add(companyId);
669 
670                 List<DLFileEntry> list = (List<DLFileEntry>)QueryUtil.list(q,
671                         getDialect(), start, end);
672 
673                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
674                     finderClassName, finderMethodName, finderParams,
675                     finderArgs, list);
676 
677                 return list;
678             }
679             catch (Exception e) {
680                 throw processException(e);
681             }
682             finally {
683                 closeSession(session);
684             }
685         }
686         else {
687             return (List<DLFileEntry>)result;
688         }
689     }
690 
691     public DLFileEntry findByCompanyId_First(long companyId,
692         OrderByComparator obc) throws NoSuchFileEntryException, SystemException {
693         List<DLFileEntry> list = findByCompanyId(companyId, 0, 1, obc);
694 
695         if (list.size() == 0) {
696             StringBuilder msg = new StringBuilder();
697 
698             msg.append("No DLFileEntry exists with the key {");
699 
700             msg.append("companyId=" + companyId);
701 
702             msg.append(StringPool.CLOSE_CURLY_BRACE);
703 
704             throw new NoSuchFileEntryException(msg.toString());
705         }
706         else {
707             return list.get(0);
708         }
709     }
710 
711     public DLFileEntry findByCompanyId_Last(long companyId,
712         OrderByComparator obc) throws NoSuchFileEntryException, SystemException {
713         int count = countByCompanyId(companyId);
714 
715         List<DLFileEntry> list = findByCompanyId(companyId, count - 1, count,
716                 obc);
717 
718         if (list.size() == 0) {
719             StringBuilder msg = new StringBuilder();
720 
721             msg.append("No DLFileEntry exists with the key {");
722 
723             msg.append("companyId=" + companyId);
724 
725             msg.append(StringPool.CLOSE_CURLY_BRACE);
726 
727             throw new NoSuchFileEntryException(msg.toString());
728         }
729         else {
730             return list.get(0);
731         }
732     }
733 
734     public DLFileEntry[] findByCompanyId_PrevAndNext(long fileEntryId,
735         long companyId, OrderByComparator obc)
736         throws NoSuchFileEntryException, SystemException {
737         DLFileEntry dlFileEntry = findByPrimaryKey(fileEntryId);
738 
739         int count = countByCompanyId(companyId);
740 
741         Session session = null;
742 
743         try {
744             session = openSession();
745 
746             StringBuilder query = new StringBuilder();
747 
748             query.append(
749                 "FROM com.liferay.portlet.documentlibrary.model.DLFileEntry WHERE ");
750 
751             query.append("companyId = ?");
752 
753             query.append(" ");
754 
755             if (obc != null) {
756                 query.append("ORDER BY ");
757                 query.append(obc.getOrderBy());
758             }
759 
760             else {
761                 query.append("ORDER BY ");
762 
763                 query.append("folderId ASC, ");
764                 query.append("name ASC");
765             }
766 
767             Query q = session.createQuery(query.toString());
768 
769             QueryPos qPos = QueryPos.getInstance(q);
770 
771             qPos.add(companyId);
772 
773             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
774                     dlFileEntry);
775 
776             DLFileEntry[] array = new DLFileEntryImpl[3];
777 
778             array[0] = (DLFileEntry)objArray[0];
779             array[1] = (DLFileEntry)objArray[1];
780             array[2] = (DLFileEntry)objArray[2];
781 
782             return array;
783         }
784         catch (Exception e) {
785             throw processException(e);
786         }
787         finally {
788             closeSession(session);
789         }
790     }
791 
792     public List<DLFileEntry> findByFolderId(long folderId)
793         throws SystemException {
794         boolean finderClassNameCacheEnabled = DLFileEntryModelImpl.CACHE_ENABLED;
795         String finderClassName = DLFileEntry.class.getName();
796         String finderMethodName = "findByFolderId";
797         String[] finderParams = new String[] { Long.class.getName() };
798         Object[] finderArgs = new Object[] { new Long(folderId) };
799 
800         Object result = null;
801 
802         if (finderClassNameCacheEnabled) {
803             result = FinderCacheUtil.getResult(finderClassName,
804                     finderMethodName, finderParams, finderArgs, this);
805         }
806 
807         if (result == null) {
808             Session session = null;
809 
810             try {
811                 session = openSession();
812 
813                 StringBuilder query = new StringBuilder();
814 
815                 query.append(
816                     "FROM com.liferay.portlet.documentlibrary.model.DLFileEntry WHERE ");
817 
818                 query.append("folderId = ?");
819 
820                 query.append(" ");
821 
822                 query.append("ORDER BY ");
823 
824                 query.append("folderId ASC, ");
825                 query.append("name ASC");
826 
827                 Query q = session.createQuery(query.toString());
828 
829                 QueryPos qPos = QueryPos.getInstance(q);
830 
831                 qPos.add(folderId);
832 
833                 List<DLFileEntry> list = q.list();
834 
835                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
836                     finderClassName, finderMethodName, finderParams,
837                     finderArgs, list);
838 
839                 return list;
840             }
841             catch (Exception e) {
842                 throw processException(e);
843             }
844             finally {
845                 closeSession(session);
846             }
847         }
848         else {
849             return (List<DLFileEntry>)result;
850         }
851     }
852 
853     public List<DLFileEntry> findByFolderId(long folderId, int start, int end)
854         throws SystemException {
855         return findByFolderId(folderId, start, end, null);
856     }
857 
858     public List<DLFileEntry> findByFolderId(long folderId, int start, int end,
859         OrderByComparator obc) throws SystemException {
860         boolean finderClassNameCacheEnabled = DLFileEntryModelImpl.CACHE_ENABLED;
861         String finderClassName = DLFileEntry.class.getName();
862         String finderMethodName = "findByFolderId";
863         String[] finderParams = new String[] {
864                 Long.class.getName(),
865                 
866                 "java.lang.Integer", "java.lang.Integer",
867                 "com.liferay.portal.kernel.util.OrderByComparator"
868             };
869         Object[] finderArgs = new Object[] {
870                 new Long(folderId),
871                 
872                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
873             };
874 
875         Object result = null;
876 
877         if (finderClassNameCacheEnabled) {
878             result = FinderCacheUtil.getResult(finderClassName,
879                     finderMethodName, finderParams, finderArgs, this);
880         }
881 
882         if (result == null) {
883             Session session = null;
884 
885             try {
886                 session = openSession();
887 
888                 StringBuilder query = new StringBuilder();
889 
890                 query.append(
891                     "FROM com.liferay.portlet.documentlibrary.model.DLFileEntry WHERE ");
892 
893                 query.append("folderId = ?");
894 
895                 query.append(" ");
896 
897                 if (obc != null) {
898                     query.append("ORDER BY ");
899                     query.append(obc.getOrderBy());
900                 }
901 
902                 else {
903                     query.append("ORDER BY ");
904 
905                     query.append("folderId ASC, ");
906                     query.append("name ASC");
907                 }
908 
909                 Query q = session.createQuery(query.toString());
910 
911                 QueryPos qPos = QueryPos.getInstance(q);
912 
913                 qPos.add(folderId);
914 
915                 List<DLFileEntry> list = (List<DLFileEntry>)QueryUtil.list(q,
916                         getDialect(), start, end);
917 
918                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
919                     finderClassName, finderMethodName, finderParams,
920                     finderArgs, list);
921 
922                 return list;
923             }
924             catch (Exception e) {
925                 throw processException(e);
926             }
927             finally {
928                 closeSession(session);
929             }
930         }
931         else {
932             return (List<DLFileEntry>)result;
933         }
934     }
935 
936     public DLFileEntry findByFolderId_First(long folderId, OrderByComparator obc)
937         throws NoSuchFileEntryException, SystemException {
938         List<DLFileEntry> list = findByFolderId(folderId, 0, 1, obc);
939 
940         if (list.size() == 0) {
941             StringBuilder msg = new StringBuilder();
942 
943             msg.append("No DLFileEntry exists with the key {");
944 
945             msg.append("folderId=" + folderId);
946 
947             msg.append(StringPool.CLOSE_CURLY_BRACE);
948 
949             throw new NoSuchFileEntryException(msg.toString());
950         }
951         else {
952             return list.get(0);
953         }
954     }
955 
956     public DLFileEntry findByFolderId_Last(long folderId, OrderByComparator obc)
957         throws NoSuchFileEntryException, SystemException {
958         int count = countByFolderId(folderId);
959 
960         List<DLFileEntry> list = findByFolderId(folderId, count - 1, count, obc);
961 
962         if (list.size() == 0) {
963             StringBuilder msg = new StringBuilder();
964 
965             msg.append("No DLFileEntry exists with the key {");
966 
967             msg.append("folderId=" + folderId);
968 
969             msg.append(StringPool.CLOSE_CURLY_BRACE);
970 
971             throw new NoSuchFileEntryException(msg.toString());
972         }
973         else {
974             return list.get(0);
975         }
976     }
977 
978     public DLFileEntry[] findByFolderId_PrevAndNext(long fileEntryId,
979         long folderId, OrderByComparator obc)
980         throws NoSuchFileEntryException, SystemException {
981         DLFileEntry dlFileEntry = findByPrimaryKey(fileEntryId);
982 
983         int count = countByFolderId(folderId);
984 
985         Session session = null;
986 
987         try {
988             session = openSession();
989 
990             StringBuilder query = new StringBuilder();
991 
992             query.append(
993                 "FROM com.liferay.portlet.documentlibrary.model.DLFileEntry WHERE ");
994 
995             query.append("folderId = ?");
996 
997             query.append(" ");
998 
999             if (obc != null) {
1000                query.append("ORDER BY ");
1001                query.append(obc.getOrderBy());
1002            }
1003
1004            else {
1005                query.append("ORDER BY ");
1006
1007                query.append("folderId ASC, ");
1008                query.append("name ASC");
1009            }
1010
1011            Query q = session.createQuery(query.toString());
1012
1013            QueryPos qPos = QueryPos.getInstance(q);
1014
1015            qPos.add(folderId);
1016
1017            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1018                    dlFileEntry);
1019
1020            DLFileEntry[] array = new DLFileEntryImpl[3];
1021
1022            array[0] = (DLFileEntry)objArray[0];
1023            array[1] = (DLFileEntry)objArray[1];
1024            array[2] = (DLFileEntry)objArray[2];
1025
1026            return array;
1027        }
1028        catch (Exception e) {
1029            throw processException(e);
1030        }
1031        finally {
1032            closeSession(session);
1033        }
1034    }
1035
1036    public DLFileEntry findByF_N(long folderId, String name)
1037        throws NoSuchFileEntryException, SystemException {
1038        DLFileEntry dlFileEntry = fetchByF_N(folderId, name);
1039
1040        if (dlFileEntry == null) {
1041            StringBuilder msg = new StringBuilder();
1042
1043            msg.append("No DLFileEntry exists with the key {");
1044
1045            msg.append("folderId=" + folderId);
1046
1047            msg.append(", ");
1048            msg.append("name=" + name);
1049
1050            msg.append(StringPool.CLOSE_CURLY_BRACE);
1051
1052            if (_log.isWarnEnabled()) {
1053                _log.warn(msg.toString());
1054            }
1055
1056            throw new NoSuchFileEntryException(msg.toString());
1057        }
1058
1059        return dlFileEntry;
1060    }
1061
1062    public DLFileEntry fetchByF_N(long folderId, String name)
1063        throws SystemException {
1064        boolean finderClassNameCacheEnabled = DLFileEntryModelImpl.CACHE_ENABLED;
1065        String finderClassName = DLFileEntry.class.getName();
1066        String finderMethodName = "fetchByF_N";
1067        String[] finderParams = new String[] {
1068                Long.class.getName(), String.class.getName()
1069            };
1070        Object[] finderArgs = new Object[] { new Long(folderId), name };
1071
1072        Object result = null;
1073
1074        if (finderClassNameCacheEnabled) {
1075            result = FinderCacheUtil.getResult(finderClassName,
1076                    finderMethodName, finderParams, finderArgs, this);
1077        }
1078
1079        if (result == null) {
1080            Session session = null;
1081
1082            try {
1083                session = openSession();
1084
1085                StringBuilder query = new StringBuilder();
1086
1087                query.append(
1088                    "FROM com.liferay.portlet.documentlibrary.model.DLFileEntry WHERE ");
1089
1090                query.append("folderId = ?");
1091
1092                query.append(" AND ");
1093
1094                if (name == null) {
1095                    query.append("name IS NULL");
1096                }
1097                else {
1098                    query.append("name = ?");
1099                }
1100
1101                query.append(" ");
1102
1103                query.append("ORDER BY ");
1104
1105                query.append("folderId ASC, ");
1106                query.append("name ASC");
1107
1108                Query q = session.createQuery(query.toString());
1109
1110                QueryPos qPos = QueryPos.getInstance(q);
1111
1112                qPos.add(folderId);
1113
1114                if (name != null) {
1115                    qPos.add(name);
1116                }
1117
1118                List<DLFileEntry> list = q.list();
1119
1120                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1121                    finderClassName, finderMethodName, finderParams,
1122                    finderArgs, list);
1123
1124                if (list.size() == 0) {
1125                    return null;
1126                }
1127                else {
1128                    return list.get(0);
1129                }
1130            }
1131            catch (Exception e) {
1132                throw processException(e);
1133            }
1134            finally {
1135                closeSession(session);
1136            }
1137        }
1138        else {
1139            List<DLFileEntry> list = (List<DLFileEntry>)result;
1140
1141            if (list.size() == 0) {
1142                return null;
1143            }
1144            else {
1145                return list.get(0);
1146            }
1147        }
1148    }
1149
1150    public List<DLFileEntry> findByF_T(long folderId, String title)
1151        throws SystemException {
1152        boolean finderClassNameCacheEnabled = DLFileEntryModelImpl.CACHE_ENABLED;
1153        String finderClassName = DLFileEntry.class.getName();
1154        String finderMethodName = "findByF_T";
1155        String[] finderParams = new String[] {
1156                Long.class.getName(), String.class.getName()
1157            };
1158        Object[] finderArgs = new Object[] { new Long(folderId), title };
1159
1160        Object result = null;
1161
1162        if (finderClassNameCacheEnabled) {
1163            result = FinderCacheUtil.getResult(finderClassName,
1164                    finderMethodName, finderParams, finderArgs, this);
1165        }
1166
1167        if (result == null) {
1168            Session session = null;
1169
1170            try {
1171                session = openSession();
1172
1173                StringBuilder query = new StringBuilder();
1174
1175                query.append(
1176                    "FROM com.liferay.portlet.documentlibrary.model.DLFileEntry WHERE ");
1177
1178                query.append("folderId = ?");
1179
1180                query.append(" AND ");
1181
1182                if (title == null) {
1183                    query.append("title IS NULL");
1184                }
1185                else {
1186                    query.append("title = ?");
1187                }
1188
1189                query.append(" ");
1190
1191                query.append("ORDER BY ");
1192
1193                query.append("folderId ASC, ");
1194                query.append("name ASC");
1195
1196                Query q = session.createQuery(query.toString());
1197
1198                QueryPos qPos = QueryPos.getInstance(q);
1199
1200                qPos.add(folderId);
1201
1202                if (title != null) {
1203                    qPos.add(title);
1204                }
1205
1206                List<DLFileEntry> list = q.list();
1207
1208                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1209                    finderClassName, finderMethodName, finderParams,
1210                    finderArgs, list);
1211
1212                return list;
1213            }
1214            catch (Exception e) {
1215                throw processException(e);
1216            }
1217            finally {
1218                closeSession(session);
1219            }
1220        }
1221        else {
1222            return (List<DLFileEntry>)result;
1223        }
1224    }
1225
1226    public List<DLFileEntry> findByF_T(long folderId, String title, int start,
1227        int end) throws SystemException {
1228        return findByF_T(folderId, title, start, end, null);
1229    }
1230
1231    public List<DLFileEntry> findByF_T(long folderId, String title, int start,
1232        int end, OrderByComparator obc) throws SystemException {
1233        boolean finderClassNameCacheEnabled = DLFileEntryModelImpl.CACHE_ENABLED;
1234        String finderClassName = DLFileEntry.class.getName();
1235        String finderMethodName = "findByF_T";
1236        String[] finderParams = new String[] {
1237                Long.class.getName(), String.class.getName(),
1238                
1239                "java.lang.Integer", "java.lang.Integer",
1240                "com.liferay.portal.kernel.util.OrderByComparator"
1241            };
1242        Object[] finderArgs = new Object[] {
1243                new Long(folderId),
1244                
1245                title,
1246                
1247                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1248            };
1249
1250        Object result = null;
1251
1252        if (finderClassNameCacheEnabled) {
1253            result = FinderCacheUtil.getResult(finderClassName,
1254                    finderMethodName, finderParams, finderArgs, this);
1255        }
1256
1257        if (result == null) {
1258            Session session = null;
1259
1260            try {
1261                session = openSession();
1262
1263                StringBuilder query = new StringBuilder();
1264
1265                query.append(
1266                    "FROM com.liferay.portlet.documentlibrary.model.DLFileEntry WHERE ");
1267
1268                query.append("folderId = ?");
1269
1270                query.append(" AND ");
1271
1272                if (title == null) {
1273                    query.append("title IS NULL");
1274                }
1275                else {
1276                    query.append("title = ?");
1277                }
1278
1279                query.append(" ");
1280
1281                if (obc != null) {
1282                    query.append("ORDER BY ");
1283                    query.append(obc.getOrderBy());
1284                }
1285
1286                else {
1287                    query.append("ORDER BY ");
1288
1289                    query.append("folderId ASC, ");
1290                    query.append("name ASC");
1291                }
1292
1293                Query q = session.createQuery(query.toString());
1294
1295                QueryPos qPos = QueryPos.getInstance(q);
1296
1297                qPos.add(folderId);
1298
1299                if (title != null) {
1300                    qPos.add(title);
1301                }
1302
1303                List<DLFileEntry> list = (List<DLFileEntry>)QueryUtil.list(q,
1304                        getDialect(), start, end);
1305
1306                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1307                    finderClassName, finderMethodName, finderParams,
1308                    finderArgs, list);
1309
1310                return list;
1311            }
1312            catch (Exception e) {
1313                throw processException(e);
1314            }
1315            finally {
1316                closeSession(session);
1317            }
1318        }
1319        else {
1320            return (List<DLFileEntry>)result;
1321        }
1322    }
1323
1324    public DLFileEntry findByF_T_First(long folderId, String title,
1325        OrderByComparator obc) throws NoSuchFileEntryException, SystemException {
1326        List<DLFileEntry> list = findByF_T(folderId, title, 0, 1, obc);
1327
1328        if (list.size() == 0) {
1329            StringBuilder msg = new StringBuilder();
1330
1331            msg.append("No DLFileEntry exists with the key {");
1332
1333            msg.append("folderId=" + folderId);
1334
1335            msg.append(", ");
1336            msg.append("title=" + title);
1337
1338            msg.append(StringPool.CLOSE_CURLY_BRACE);
1339
1340            throw new NoSuchFileEntryException(msg.toString());
1341        }
1342        else {
1343            return list.get(0);
1344        }
1345    }
1346
1347    public DLFileEntry findByF_T_Last(long folderId, String title,
1348        OrderByComparator obc) throws NoSuchFileEntryException, SystemException {
1349        int count = countByF_T(folderId, title);
1350
1351        List<DLFileEntry> list = findByF_T(folderId, title, count - 1, count,
1352                obc);
1353
1354        if (list.size() == 0) {
1355            StringBuilder msg = new StringBuilder();
1356
1357            msg.append("No DLFileEntry exists with the key {");
1358
1359            msg.append("folderId=" + folderId);
1360
1361            msg.append(", ");
1362            msg.append("title=" + title);
1363
1364            msg.append(StringPool.CLOSE_CURLY_BRACE);
1365
1366            throw new NoSuchFileEntryException(msg.toString());
1367        }
1368        else {
1369            return list.get(0);
1370        }
1371    }
1372
1373    public DLFileEntry[] findByF_T_PrevAndNext(long fileEntryId, long folderId,
1374        String title, OrderByComparator obc)
1375        throws NoSuchFileEntryException, SystemException {
1376        DLFileEntry dlFileEntry = findByPrimaryKey(fileEntryId);
1377
1378        int count = countByF_T(folderId, title);
1379
1380        Session session = null;
1381
1382        try {
1383            session = openSession();
1384
1385            StringBuilder query = new StringBuilder();
1386
1387            query.append(
1388                "FROM com.liferay.portlet.documentlibrary.model.DLFileEntry WHERE ");
1389
1390            query.append("folderId = ?");
1391
1392            query.append(" AND ");
1393
1394            if (title == null) {
1395                query.append("title IS NULL");
1396            }
1397            else {
1398                query.append("title = ?");
1399            }
1400
1401            query.append(" ");
1402
1403            if (obc != null) {
1404                query.append("ORDER BY ");
1405                query.append(obc.getOrderBy());
1406            }
1407
1408            else {
1409                query.append("ORDER BY ");
1410
1411                query.append("folderId ASC, ");
1412                query.append("name ASC");
1413            }
1414
1415            Query q = session.createQuery(query.toString());
1416
1417            QueryPos qPos = QueryPos.getInstance(q);
1418
1419            qPos.add(folderId);
1420
1421            if (title != null) {
1422                qPos.add(title);
1423            }
1424
1425            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1426                    dlFileEntry);
1427
1428            DLFileEntry[] array = new DLFileEntryImpl[3];
1429
1430            array[0] = (DLFileEntry)objArray[0];
1431            array[1] = (DLFileEntry)objArray[1];
1432            array[2] = (DLFileEntry)objArray[2];
1433
1434            return array;
1435        }
1436        catch (Exception e) {
1437            throw processException(e);
1438        }
1439        finally {
1440            closeSession(session);
1441        }
1442    }
1443
1444    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
1445        throws SystemException {
1446        Session session = null;
1447
1448        try {
1449            session = openSession();
1450
1451            dynamicQuery.compile(session);
1452
1453            return dynamicQuery.list();
1454        }
1455        catch (Exception e) {
1456            throw processException(e);
1457        }
1458        finally {
1459            closeSession(session);
1460        }
1461    }
1462
1463    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
1464        int start, int end) throws SystemException {
1465        Session session = null;
1466
1467        try {
1468            session = openSession();
1469
1470            dynamicQuery.setLimit(start, end);
1471
1472            dynamicQuery.compile(session);
1473
1474            return dynamicQuery.list();
1475        }
1476        catch (Exception e) {
1477            throw processException(e);
1478        }
1479        finally {
1480            closeSession(session);
1481        }
1482    }
1483
1484    public List<DLFileEntry> findAll() throws SystemException {
1485        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1486    }
1487
1488    public List<DLFileEntry> findAll(int start, int end)
1489        throws SystemException {
1490        return findAll(start, end, null);
1491    }
1492
1493    public List<DLFileEntry> findAll(int start, int end, OrderByComparator obc)
1494        throws SystemException {
1495        boolean finderClassNameCacheEnabled = DLFileEntryModelImpl.CACHE_ENABLED;
1496        String finderClassName = DLFileEntry.class.getName();
1497        String finderMethodName = "findAll";
1498        String[] finderParams = new String[] {
1499                "java.lang.Integer", "java.lang.Integer",
1500                "com.liferay.portal.kernel.util.OrderByComparator"
1501            };
1502        Object[] finderArgs = new Object[] {
1503                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1504            };
1505
1506        Object result = null;
1507
1508        if (finderClassNameCacheEnabled) {
1509            result = FinderCacheUtil.getResult(finderClassName,
1510                    finderMethodName, finderParams, finderArgs, this);
1511        }
1512
1513        if (result == null) {
1514            Session session = null;
1515
1516            try {
1517                session = openSession();
1518
1519                StringBuilder query = new StringBuilder();
1520
1521                query.append(
1522                    "FROM com.liferay.portlet.documentlibrary.model.DLFileEntry ");
1523
1524                if (obc != null) {
1525                    query.append("ORDER BY ");
1526                    query.append(obc.getOrderBy());
1527                }
1528
1529                else {
1530                    query.append("ORDER BY ");
1531
1532                    query.append("folderId ASC, ");
1533                    query.append("name ASC");
1534                }
1535
1536                Query q = session.createQuery(query.toString());
1537
1538                List<DLFileEntry> list = null;
1539
1540                if (obc == null) {
1541                    list = (List<DLFileEntry>)QueryUtil.list(q, getDialect(),
1542                            start, end, false);
1543
1544                    Collections.sort(list);
1545                }
1546                else {
1547                    list = (List<DLFileEntry>)QueryUtil.list(q, getDialect(),
1548                            start, end);
1549                }
1550
1551                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1552                    finderClassName, finderMethodName, finderParams,
1553                    finderArgs, list);
1554
1555                return list;
1556            }
1557            catch (Exception e) {
1558                throw processException(e);
1559            }
1560            finally {
1561                closeSession(session);
1562            }
1563        }
1564        else {
1565            return (List<DLFileEntry>)result;
1566        }
1567    }
1568
1569    public void removeByUuid(String uuid) throws SystemException {
1570        for (DLFileEntry dlFileEntry : findByUuid(uuid)) {
1571            remove(dlFileEntry);
1572        }
1573    }
1574
1575    public void removeByCompanyId(long companyId) throws SystemException {
1576        for (DLFileEntry dlFileEntry : findByCompanyId(companyId)) {
1577            remove(dlFileEntry);
1578        }
1579    }
1580
1581    public void removeByFolderId(long folderId) throws SystemException {
1582        for (DLFileEntry dlFileEntry : findByFolderId(folderId)) {
1583            remove(dlFileEntry);
1584        }
1585    }
1586
1587    public void removeByF_N(long folderId, String name)
1588        throws NoSuchFileEntryException, SystemException {
1589        DLFileEntry dlFileEntry = findByF_N(folderId, name);
1590
1591        remove(dlFileEntry);
1592    }
1593
1594    public void removeByF_T(long folderId, String title)
1595        throws SystemException {
1596        for (DLFileEntry dlFileEntry : findByF_T(folderId, title)) {
1597            remove(dlFileEntry);
1598        }
1599    }
1600
1601    public void removeAll() throws SystemException {
1602        for (DLFileEntry dlFileEntry : findAll()) {
1603            remove(dlFileEntry);
1604        }
1605    }
1606
1607    public int countByUuid(String uuid) throws SystemException {
1608        boolean finderClassNameCacheEnabled = DLFileEntryModelImpl.CACHE_ENABLED;
1609        String finderClassName = DLFileEntry.class.getName();
1610        String finderMethodName = "countByUuid";
1611        String[] finderParams = new String[] { String.class.getName() };
1612        Object[] finderArgs = new Object[] { uuid };
1613
1614        Object result = null;
1615
1616        if (finderClassNameCacheEnabled) {
1617            result = FinderCacheUtil.getResult(finderClassName,
1618                    finderMethodName, finderParams, finderArgs, this);
1619        }
1620
1621        if (result == null) {
1622            Session session = null;
1623
1624            try {
1625                session = openSession();
1626
1627                StringBuilder query = new StringBuilder();
1628
1629                query.append("SELECT COUNT(*) ");
1630                query.append(
1631                    "FROM com.liferay.portlet.documentlibrary.model.DLFileEntry WHERE ");
1632
1633                if (uuid == null) {
1634                    query.append("uuid_ IS NULL");
1635                }
1636                else {
1637                    query.append("uuid_ = ?");
1638                }
1639
1640                query.append(" ");
1641
1642                Query q = session.createQuery(query.toString());
1643
1644                QueryPos qPos = QueryPos.getInstance(q);
1645
1646                if (uuid != null) {
1647                    qPos.add(uuid);
1648                }
1649
1650                Long count = null;
1651
1652                Iterator<Long> itr = q.list().iterator();
1653
1654                if (itr.hasNext()) {
1655                    count = itr.next();
1656                }
1657
1658                if (count == null) {
1659                    count = new Long(0);
1660                }
1661
1662                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1663                    finderClassName, finderMethodName, finderParams,
1664                    finderArgs, count);
1665
1666                return count.intValue();
1667            }
1668            catch (Exception e) {
1669                throw processException(e);
1670            }
1671            finally {
1672                closeSession(session);
1673            }
1674        }
1675        else {
1676            return ((Long)result).intValue();
1677        }
1678    }
1679
1680    public int countByCompanyId(long companyId) throws SystemException {
1681        boolean finderClassNameCacheEnabled = DLFileEntryModelImpl.CACHE_ENABLED;
1682        String finderClassName = DLFileEntry.class.getName();
1683        String finderMethodName = "countByCompanyId";
1684        String[] finderParams = new String[] { Long.class.getName() };
1685        Object[] finderArgs = new Object[] { new Long(companyId) };
1686
1687        Object result = null;
1688
1689        if (finderClassNameCacheEnabled) {
1690            result = FinderCacheUtil.getResult(finderClassName,
1691                    finderMethodName, finderParams, finderArgs, this);
1692        }
1693
1694        if (result == null) {
1695            Session session = null;
1696
1697            try {
1698                session = openSession();
1699
1700                StringBuilder query = new StringBuilder();
1701
1702                query.append("SELECT COUNT(*) ");
1703                query.append(
1704                    "FROM com.liferay.portlet.documentlibrary.model.DLFileEntry WHERE ");
1705
1706                query.append("companyId = ?");
1707
1708                query.append(" ");
1709
1710                Query q = session.createQuery(query.toString());
1711
1712                QueryPos qPos = QueryPos.getInstance(q);
1713
1714                qPos.add(companyId);
1715
1716                Long count = null;
1717
1718                Iterator<Long> itr = q.list().iterator();
1719
1720                if (itr.hasNext()) {
1721                    count = itr.next();
1722                }
1723
1724                if (count == null) {
1725                    count = new Long(0);
1726                }
1727
1728                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1729                    finderClassName, finderMethodName, finderParams,
1730                    finderArgs, count);
1731
1732                return count.intValue();
1733            }
1734            catch (Exception e) {
1735                throw processException(e);
1736            }
1737            finally {
1738                closeSession(session);
1739            }
1740        }
1741        else {
1742            return ((Long)result).intValue();
1743        }
1744    }
1745
1746    public int countByFolderId(long folderId) throws SystemException {
1747        boolean finderClassNameCacheEnabled = DLFileEntryModelImpl.CACHE_ENABLED;
1748        String finderClassName = DLFileEntry.class.getName();
1749        String finderMethodName = "countByFolderId";
1750        String[] finderParams = new String[] { Long.class.getName() };
1751        Object[] finderArgs = new Object[] { new Long(folderId) };
1752
1753        Object result = null;
1754
1755        if (finderClassNameCacheEnabled) {
1756            result = FinderCacheUtil.getResult(finderClassName,
1757                    finderMethodName, finderParams, finderArgs, this);
1758        }
1759
1760        if (result == null) {
1761            Session session = null;
1762
1763            try {
1764                session = openSession();
1765
1766                StringBuilder query = new StringBuilder();
1767
1768                query.append("SELECT COUNT(*) ");
1769                query.append(
1770                    "FROM com.liferay.portlet.documentlibrary.model.DLFileEntry WHERE ");
1771
1772                query.append("folderId = ?");
1773
1774                query.append(" ");
1775
1776                Query q = session.createQuery(query.toString());
1777
1778                QueryPos qPos = QueryPos.getInstance(q);
1779
1780                qPos.add(folderId);
1781
1782                Long count = null;
1783
1784                Iterator<Long> itr = q.list().iterator();
1785
1786                if (itr.hasNext()) {
1787                    count = itr.next();
1788                }
1789
1790                if (count == null) {
1791                    count = new Long(0);
1792                }
1793
1794                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1795                    finderClassName, finderMethodName, finderParams,
1796                    finderArgs, count);
1797
1798                return count.intValue();
1799            }
1800            catch (Exception e) {
1801                throw processException(e);
1802            }
1803            finally {
1804                closeSession(session);
1805            }
1806        }
1807        else {
1808            return ((Long)result).intValue();
1809        }
1810    }
1811
1812    public int countByF_N(long folderId, String name) throws SystemException {
1813        boolean finderClassNameCacheEnabled = DLFileEntryModelImpl.CACHE_ENABLED;
1814        String finderClassName = DLFileEntry.class.getName();
1815        String finderMethodName = "countByF_N";
1816        String[] finderParams = new String[] {
1817                Long.class.getName(), String.class.getName()
1818            };
1819        Object[] finderArgs = new Object[] { new Long(folderId), name };
1820
1821        Object result = null;
1822
1823        if (finderClassNameCacheEnabled) {
1824            result = FinderCacheUtil.getResult(finderClassName,
1825                    finderMethodName, finderParams, finderArgs, this);
1826        }
1827
1828        if (result == null) {
1829            Session session = null;
1830
1831            try {
1832                session = openSession();
1833
1834                StringBuilder query = new StringBuilder();
1835
1836                query.append("SELECT COUNT(*) ");
1837                query.append(
1838                    "FROM com.liferay.portlet.documentlibrary.model.DLFileEntry WHERE ");
1839
1840                query.append("folderId = ?");
1841
1842                query.append(" AND ");
1843
1844                if (name == null) {
1845                    query.append("name IS NULL");
1846                }
1847                else {
1848                    query.append("name = ?");
1849                }
1850
1851                query.append(" ");
1852
1853                Query q = session.createQuery(query.toString());
1854
1855                QueryPos qPos = QueryPos.getInstance(q);
1856
1857                qPos.add(folderId);
1858
1859                if (name != null) {
1860                    qPos.add(name);
1861                }
1862
1863                Long count = null;
1864
1865                Iterator<Long> itr = q.list().iterator();
1866
1867                if (itr.hasNext()) {
1868                    count = itr.next();
1869                }
1870
1871                if (count == null) {
1872                    count = new Long(0);
1873                }
1874
1875                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1876                    finderClassName, finderMethodName, finderParams,
1877                    finderArgs, count);
1878
1879                return count.intValue();
1880            }
1881            catch (Exception e) {
1882                throw processException(e);
1883            }
1884            finally {
1885                closeSession(session);
1886            }
1887        }
1888        else {
1889            return ((Long)result).intValue();
1890        }
1891    }
1892
1893    public int countByF_T(long folderId, String title)
1894        throws SystemException {
1895        boolean finderClassNameCacheEnabled = DLFileEntryModelImpl.CACHE_ENABLED;
1896        String finderClassName = DLFileEntry.class.getName();
1897        String finderMethodName = "countByF_T";
1898        String[] finderParams = new String[] {
1899                Long.class.getName(), String.class.getName()
1900            };
1901        Object[] finderArgs = new Object[] { new Long(folderId), title };
1902
1903        Object result = null;
1904
1905        if (finderClassNameCacheEnabled) {
1906            result = FinderCacheUtil.getResult(finderClassName,
1907                    finderMethodName, finderParams, finderArgs, this);
1908        }
1909
1910        if (result == null) {
1911            Session session = null;
1912
1913            try {
1914                session = openSession();
1915
1916                StringBuilder query = new StringBuilder();
1917
1918                query.append("SELECT COUNT(*) ");
1919                query.append(
1920                    "FROM com.liferay.portlet.documentlibrary.model.DLFileEntry WHERE ");
1921
1922                query.append("folderId = ?");
1923
1924                query.append(" AND ");
1925
1926                if (title == null) {
1927                    query.append("title IS NULL");
1928                }
1929                else {
1930                    query.append("title = ?");
1931                }
1932
1933                query.append(" ");
1934
1935                Query q = session.createQuery(query.toString());
1936
1937                QueryPos qPos = QueryPos.getInstance(q);
1938
1939                qPos.add(folderId);
1940
1941                if (title != null) {
1942                    qPos.add(title);
1943                }
1944
1945                Long count = null;
1946
1947                Iterator<Long> itr = q.list().iterator();
1948
1949                if (itr.hasNext()) {
1950                    count = itr.next();
1951                }
1952
1953                if (count == null) {
1954                    count = new Long(0);
1955                }
1956
1957                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1958                    finderClassName, finderMethodName, finderParams,
1959                    finderArgs, count);
1960
1961                return count.intValue();
1962            }
1963            catch (Exception e) {
1964                throw processException(e);
1965            }
1966            finally {
1967                closeSession(session);
1968            }
1969        }
1970        else {
1971            return ((Long)result).intValue();
1972        }
1973    }
1974
1975    public int countAll() throws SystemException {
1976        boolean finderClassNameCacheEnabled = DLFileEntryModelImpl.CACHE_ENABLED;
1977        String finderClassName = DLFileEntry.class.getName();
1978        String finderMethodName = "countAll";
1979        String[] finderParams = new String[] {  };
1980        Object[] finderArgs = new Object[] {  };
1981
1982        Object result = null;
1983
1984        if (finderClassNameCacheEnabled) {
1985            result = FinderCacheUtil.getResult(finderClassName,
1986                    finderMethodName, finderParams, finderArgs, this);
1987        }
1988
1989        if (result == null) {
1990            Session session = null;
1991
1992            try {
1993                session = openSession();
1994
1995                Query q = session.createQuery(
1996                        "SELECT COUNT(*) FROM com.liferay.portlet.documentlibrary.model.DLFileEntry");
1997
1998                Long count = null;
1999
2000                Iterator<Long> itr = q.list().iterator();
2001
2002                if (itr.hasNext()) {
2003                    count = itr.next();
2004                }
2005
2006                if (count == null) {
2007                    count = new Long(0);
2008                }
2009
2010                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2011                    finderClassName, finderMethodName, finderParams,
2012                    finderArgs, count);
2013
2014                return count.intValue();
2015            }
2016            catch (Exception e) {
2017                throw processException(e);
2018            }
2019            finally {
2020                closeSession(session);
2021            }
2022        }
2023        else {
2024            return ((Long)result).intValue();
2025        }
2026    }
2027
2028    public void registerListener(ModelListener listener) {
2029        List<ModelListener> listeners = ListUtil.fromArray(_listeners);
2030
2031        listeners.add(listener);
2032
2033        _listeners = listeners.toArray(new ModelListener[listeners.size()]);
2034    }
2035
2036    public void unregisterListener(ModelListener listener) {
2037        List<ModelListener> listeners = ListUtil.fromArray(_listeners);
2038
2039        listeners.remove(listener);
2040
2041        _listeners = listeners.toArray(new ModelListener[listeners.size()]);
2042    }
2043
2044    public void afterPropertiesSet() {
2045        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2046                    com.liferay.portal.util.PropsUtil.get(
2047                        "value.object.listener.com.liferay.portlet.documentlibrary.model.DLFileEntry")));
2048
2049        if (listenerClassNames.length > 0) {
2050            try {
2051                List<ModelListener> listeners = new ArrayList<ModelListener>();
2052
2053                for (String listenerClassName : listenerClassNames) {
2054                    listeners.add((ModelListener)Class.forName(
2055                            listenerClassName).newInstance());
2056                }
2057
2058                _listeners = listeners.toArray(new ModelListener[listeners.size()]);
2059            }
2060            catch (Exception e) {
2061                _log.error(e);
2062            }
2063        }
2064    }
2065
2066    private static Log _log = LogFactory.getLog(DLFileEntryPersistenceImpl.class);
2067    private ModelListener[] _listeners = new ModelListener[0];
2068}