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.bean.InitializingBean;
27  import com.liferay.portal.kernel.dao.orm.DynamicQuery;
28  import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
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.util.GetterUtil;
34  import com.liferay.portal.kernel.util.ListUtil;
35  import com.liferay.portal.kernel.util.OrderByComparator;
36  import com.liferay.portal.kernel.util.StringPool;
37  import com.liferay.portal.kernel.util.StringUtil;
38  import com.liferay.portal.kernel.util.Validator;
39  import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
40  import com.liferay.portal.model.ModelListener;
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, InitializingBean {
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             session.delete(dlFileEntry);
138 
139             session.flush();
140 
141             return dlFileEntry;
142         }
143         catch (Exception e) {
144             throw processException(e);
145         }
146         finally {
147             closeSession(session);
148 
149             FinderCacheUtil.clearCache(DLFileEntry.class.getName());
150         }
151     }
152 
153     /**
154      * @deprecated Use <code>update(DLFileEntry dlFileEntry, boolean merge)</code>.
155      */
156     public DLFileEntry update(DLFileEntry dlFileEntry)
157         throws SystemException {
158         if (_log.isWarnEnabled()) {
159             _log.warn(
160                 "Using the deprecated update(DLFileEntry dlFileEntry) method. Use update(DLFileEntry dlFileEntry, boolean merge) instead.");
161         }
162 
163         return update(dlFileEntry, false);
164     }
165 
166     /**
167      * Add, update, or merge, the entity. This method also calls the model
168      * listeners to trigger the proper events associated with adding, deleting,
169      * or updating an entity.
170      *
171      * @param        dlFileEntry the entity to add, update, or merge
172      * @param        merge boolean value for whether to merge the entity. The
173      *                default value is false. Setting merge to true is more
174      *                expensive and should only be true when dlFileEntry is
175      *                transient. See LEP-5473 for a detailed discussion of this
176      *                method.
177      * @return        true if the portlet can be displayed via Ajax
178      */
179     public DLFileEntry update(DLFileEntry dlFileEntry, boolean merge)
180         throws SystemException {
181         boolean isNew = dlFileEntry.isNew();
182 
183         if (_listeners.length > 0) {
184             for (ModelListener listener : _listeners) {
185                 if (isNew) {
186                     listener.onBeforeCreate(dlFileEntry);
187                 }
188                 else {
189                     listener.onBeforeUpdate(dlFileEntry);
190                 }
191             }
192         }
193 
194         dlFileEntry = updateImpl(dlFileEntry, merge);
195 
196         if (_listeners.length > 0) {
197             for (ModelListener listener : _listeners) {
198                 if (isNew) {
199                     listener.onAfterCreate(dlFileEntry);
200                 }
201                 else {
202                     listener.onAfterUpdate(dlFileEntry);
203                 }
204             }
205         }
206 
207         return dlFileEntry;
208     }
209 
210     public DLFileEntry updateImpl(
211         com.liferay.portlet.documentlibrary.model.DLFileEntry dlFileEntry,
212         boolean merge) throws SystemException {
213         if (Validator.isNull(dlFileEntry.getUuid())) {
214             String uuid = PortalUUIDUtil.generate();
215 
216             dlFileEntry.setUuid(uuid);
217         }
218 
219         Session session = null;
220 
221         try {
222             session = openSession();
223 
224             if (merge) {
225                 session.merge(dlFileEntry);
226             }
227             else {
228                 if (dlFileEntry.isNew()) {
229                     session.save(dlFileEntry);
230                 }
231             }
232 
233             session.flush();
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 = (List<DLFileEntry>)QueryUtil.list(q,
1539                        getDialect(), start, end);
1540
1541                if (obc == null) {
1542                    Collections.sort(list);
1543                }
1544
1545                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1546                    finderClassName, finderMethodName, finderParams,
1547                    finderArgs, list);
1548
1549                return list;
1550            }
1551            catch (Exception e) {
1552                throw processException(e);
1553            }
1554            finally {
1555                closeSession(session);
1556            }
1557        }
1558        else {
1559            return (List<DLFileEntry>)result;
1560        }
1561    }
1562
1563    public void removeByUuid(String uuid) throws SystemException {
1564        for (DLFileEntry dlFileEntry : findByUuid(uuid)) {
1565            remove(dlFileEntry);
1566        }
1567    }
1568
1569    public void removeByCompanyId(long companyId) throws SystemException {
1570        for (DLFileEntry dlFileEntry : findByCompanyId(companyId)) {
1571            remove(dlFileEntry);
1572        }
1573    }
1574
1575    public void removeByFolderId(long folderId) throws SystemException {
1576        for (DLFileEntry dlFileEntry : findByFolderId(folderId)) {
1577            remove(dlFileEntry);
1578        }
1579    }
1580
1581    public void removeByF_N(long folderId, String name)
1582        throws NoSuchFileEntryException, SystemException {
1583        DLFileEntry dlFileEntry = findByF_N(folderId, name);
1584
1585        remove(dlFileEntry);
1586    }
1587
1588    public void removeByF_T(long folderId, String title)
1589        throws SystemException {
1590        for (DLFileEntry dlFileEntry : findByF_T(folderId, title)) {
1591            remove(dlFileEntry);
1592        }
1593    }
1594
1595    public void removeAll() throws SystemException {
1596        for (DLFileEntry dlFileEntry : findAll()) {
1597            remove(dlFileEntry);
1598        }
1599    }
1600
1601    public int countByUuid(String uuid) throws SystemException {
1602        boolean finderClassNameCacheEnabled = DLFileEntryModelImpl.CACHE_ENABLED;
1603        String finderClassName = DLFileEntry.class.getName();
1604        String finderMethodName = "countByUuid";
1605        String[] finderParams = new String[] { String.class.getName() };
1606        Object[] finderArgs = new Object[] { uuid };
1607
1608        Object result = null;
1609
1610        if (finderClassNameCacheEnabled) {
1611            result = FinderCacheUtil.getResult(finderClassName,
1612                    finderMethodName, finderParams, finderArgs, this);
1613        }
1614
1615        if (result == null) {
1616            Session session = null;
1617
1618            try {
1619                session = openSession();
1620
1621                StringBuilder query = new StringBuilder();
1622
1623                query.append("SELECT COUNT(*) ");
1624                query.append(
1625                    "FROM com.liferay.portlet.documentlibrary.model.DLFileEntry WHERE ");
1626
1627                if (uuid == null) {
1628                    query.append("uuid_ IS NULL");
1629                }
1630                else {
1631                    query.append("uuid_ = ?");
1632                }
1633
1634                query.append(" ");
1635
1636                Query q = session.createQuery(query.toString());
1637
1638                QueryPos qPos = QueryPos.getInstance(q);
1639
1640                if (uuid != null) {
1641                    qPos.add(uuid);
1642                }
1643
1644                Long count = null;
1645
1646                Iterator<Long> itr = q.list().iterator();
1647
1648                if (itr.hasNext()) {
1649                    count = itr.next();
1650                }
1651
1652                if (count == null) {
1653                    count = new Long(0);
1654                }
1655
1656                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1657                    finderClassName, finderMethodName, finderParams,
1658                    finderArgs, count);
1659
1660                return count.intValue();
1661            }
1662            catch (Exception e) {
1663                throw processException(e);
1664            }
1665            finally {
1666                closeSession(session);
1667            }
1668        }
1669        else {
1670            return ((Long)result).intValue();
1671        }
1672    }
1673
1674    public int countByCompanyId(long companyId) throws SystemException {
1675        boolean finderClassNameCacheEnabled = DLFileEntryModelImpl.CACHE_ENABLED;
1676        String finderClassName = DLFileEntry.class.getName();
1677        String finderMethodName = "countByCompanyId";
1678        String[] finderParams = new String[] { Long.class.getName() };
1679        Object[] finderArgs = new Object[] { new Long(companyId) };
1680
1681        Object result = null;
1682
1683        if (finderClassNameCacheEnabled) {
1684            result = FinderCacheUtil.getResult(finderClassName,
1685                    finderMethodName, finderParams, finderArgs, this);
1686        }
1687
1688        if (result == null) {
1689            Session session = null;
1690
1691            try {
1692                session = openSession();
1693
1694                StringBuilder query = new StringBuilder();
1695
1696                query.append("SELECT COUNT(*) ");
1697                query.append(
1698                    "FROM com.liferay.portlet.documentlibrary.model.DLFileEntry WHERE ");
1699
1700                query.append("companyId = ?");
1701
1702                query.append(" ");
1703
1704                Query q = session.createQuery(query.toString());
1705
1706                QueryPos qPos = QueryPos.getInstance(q);
1707
1708                qPos.add(companyId);
1709
1710                Long count = null;
1711
1712                Iterator<Long> itr = q.list().iterator();
1713
1714                if (itr.hasNext()) {
1715                    count = itr.next();
1716                }
1717
1718                if (count == null) {
1719                    count = new Long(0);
1720                }
1721
1722                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1723                    finderClassName, finderMethodName, finderParams,
1724                    finderArgs, count);
1725
1726                return count.intValue();
1727            }
1728            catch (Exception e) {
1729                throw processException(e);
1730            }
1731            finally {
1732                closeSession(session);
1733            }
1734        }
1735        else {
1736            return ((Long)result).intValue();
1737        }
1738    }
1739
1740    public int countByFolderId(long folderId) throws SystemException {
1741        boolean finderClassNameCacheEnabled = DLFileEntryModelImpl.CACHE_ENABLED;
1742        String finderClassName = DLFileEntry.class.getName();
1743        String finderMethodName = "countByFolderId";
1744        String[] finderParams = new String[] { Long.class.getName() };
1745        Object[] finderArgs = new Object[] { new Long(folderId) };
1746
1747        Object result = null;
1748
1749        if (finderClassNameCacheEnabled) {
1750            result = FinderCacheUtil.getResult(finderClassName,
1751                    finderMethodName, finderParams, finderArgs, this);
1752        }
1753
1754        if (result == null) {
1755            Session session = null;
1756
1757            try {
1758                session = openSession();
1759
1760                StringBuilder query = new StringBuilder();
1761
1762                query.append("SELECT COUNT(*) ");
1763                query.append(
1764                    "FROM com.liferay.portlet.documentlibrary.model.DLFileEntry WHERE ");
1765
1766                query.append("folderId = ?");
1767
1768                query.append(" ");
1769
1770                Query q = session.createQuery(query.toString());
1771
1772                QueryPos qPos = QueryPos.getInstance(q);
1773
1774                qPos.add(folderId);
1775
1776                Long count = null;
1777
1778                Iterator<Long> itr = q.list().iterator();
1779
1780                if (itr.hasNext()) {
1781                    count = itr.next();
1782                }
1783
1784                if (count == null) {
1785                    count = new Long(0);
1786                }
1787
1788                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1789                    finderClassName, finderMethodName, finderParams,
1790                    finderArgs, count);
1791
1792                return count.intValue();
1793            }
1794            catch (Exception e) {
1795                throw processException(e);
1796            }
1797            finally {
1798                closeSession(session);
1799            }
1800        }
1801        else {
1802            return ((Long)result).intValue();
1803        }
1804    }
1805
1806    public int countByF_N(long folderId, String name) throws SystemException {
1807        boolean finderClassNameCacheEnabled = DLFileEntryModelImpl.CACHE_ENABLED;
1808        String finderClassName = DLFileEntry.class.getName();
1809        String finderMethodName = "countByF_N";
1810        String[] finderParams = new String[] {
1811                Long.class.getName(), String.class.getName()
1812            };
1813        Object[] finderArgs = new Object[] { new Long(folderId), name };
1814
1815        Object result = null;
1816
1817        if (finderClassNameCacheEnabled) {
1818            result = FinderCacheUtil.getResult(finderClassName,
1819                    finderMethodName, finderParams, finderArgs, this);
1820        }
1821
1822        if (result == null) {
1823            Session session = null;
1824
1825            try {
1826                session = openSession();
1827
1828                StringBuilder query = new StringBuilder();
1829
1830                query.append("SELECT COUNT(*) ");
1831                query.append(
1832                    "FROM com.liferay.portlet.documentlibrary.model.DLFileEntry WHERE ");
1833
1834                query.append("folderId = ?");
1835
1836                query.append(" AND ");
1837
1838                if (name == null) {
1839                    query.append("name IS NULL");
1840                }
1841                else {
1842                    query.append("name = ?");
1843                }
1844
1845                query.append(" ");
1846
1847                Query q = session.createQuery(query.toString());
1848
1849                QueryPos qPos = QueryPos.getInstance(q);
1850
1851                qPos.add(folderId);
1852
1853                if (name != null) {
1854                    qPos.add(name);
1855                }
1856
1857                Long count = null;
1858
1859                Iterator<Long> itr = q.list().iterator();
1860
1861                if (itr.hasNext()) {
1862                    count = itr.next();
1863                }
1864
1865                if (count == null) {
1866                    count = new Long(0);
1867                }
1868
1869                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1870                    finderClassName, finderMethodName, finderParams,
1871                    finderArgs, count);
1872
1873                return count.intValue();
1874            }
1875            catch (Exception e) {
1876                throw processException(e);
1877            }
1878            finally {
1879                closeSession(session);
1880            }
1881        }
1882        else {
1883            return ((Long)result).intValue();
1884        }
1885    }
1886
1887    public int countByF_T(long folderId, String title)
1888        throws SystemException {
1889        boolean finderClassNameCacheEnabled = DLFileEntryModelImpl.CACHE_ENABLED;
1890        String finderClassName = DLFileEntry.class.getName();
1891        String finderMethodName = "countByF_T";
1892        String[] finderParams = new String[] {
1893                Long.class.getName(), String.class.getName()
1894            };
1895        Object[] finderArgs = new Object[] { new Long(folderId), title };
1896
1897        Object result = null;
1898
1899        if (finderClassNameCacheEnabled) {
1900            result = FinderCacheUtil.getResult(finderClassName,
1901                    finderMethodName, finderParams, finderArgs, this);
1902        }
1903
1904        if (result == null) {
1905            Session session = null;
1906
1907            try {
1908                session = openSession();
1909
1910                StringBuilder query = new StringBuilder();
1911
1912                query.append("SELECT COUNT(*) ");
1913                query.append(
1914                    "FROM com.liferay.portlet.documentlibrary.model.DLFileEntry WHERE ");
1915
1916                query.append("folderId = ?");
1917
1918                query.append(" AND ");
1919
1920                if (title == null) {
1921                    query.append("title IS NULL");
1922                }
1923                else {
1924                    query.append("title = ?");
1925                }
1926
1927                query.append(" ");
1928
1929                Query q = session.createQuery(query.toString());
1930
1931                QueryPos qPos = QueryPos.getInstance(q);
1932
1933                qPos.add(folderId);
1934
1935                if (title != null) {
1936                    qPos.add(title);
1937                }
1938
1939                Long count = null;
1940
1941                Iterator<Long> itr = q.list().iterator();
1942
1943                if (itr.hasNext()) {
1944                    count = itr.next();
1945                }
1946
1947                if (count == null) {
1948                    count = new Long(0);
1949                }
1950
1951                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1952                    finderClassName, finderMethodName, finderParams,
1953                    finderArgs, count);
1954
1955                return count.intValue();
1956            }
1957            catch (Exception e) {
1958                throw processException(e);
1959            }
1960            finally {
1961                closeSession(session);
1962            }
1963        }
1964        else {
1965            return ((Long)result).intValue();
1966        }
1967    }
1968
1969    public int countAll() throws SystemException {
1970        boolean finderClassNameCacheEnabled = DLFileEntryModelImpl.CACHE_ENABLED;
1971        String finderClassName = DLFileEntry.class.getName();
1972        String finderMethodName = "countAll";
1973        String[] finderParams = new String[] {  };
1974        Object[] finderArgs = new Object[] {  };
1975
1976        Object result = null;
1977
1978        if (finderClassNameCacheEnabled) {
1979            result = FinderCacheUtil.getResult(finderClassName,
1980                    finderMethodName, finderParams, finderArgs, this);
1981        }
1982
1983        if (result == null) {
1984            Session session = null;
1985
1986            try {
1987                session = openSession();
1988
1989                Query q = session.createQuery(
1990                        "SELECT COUNT(*) FROM com.liferay.portlet.documentlibrary.model.DLFileEntry");
1991
1992                Long count = null;
1993
1994                Iterator<Long> itr = q.list().iterator();
1995
1996                if (itr.hasNext()) {
1997                    count = itr.next();
1998                }
1999
2000                if (count == null) {
2001                    count = new Long(0);
2002                }
2003
2004                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2005                    finderClassName, finderMethodName, finderParams,
2006                    finderArgs, count);
2007
2008                return count.intValue();
2009            }
2010            catch (Exception e) {
2011                throw processException(e);
2012            }
2013            finally {
2014                closeSession(session);
2015            }
2016        }
2017        else {
2018            return ((Long)result).intValue();
2019        }
2020    }
2021
2022    public void registerListener(ModelListener listener) {
2023        List<ModelListener> listeners = ListUtil.fromArray(_listeners);
2024
2025        listeners.add(listener);
2026
2027        _listeners = listeners.toArray(new ModelListener[listeners.size()]);
2028    }
2029
2030    public void unregisterListener(ModelListener listener) {
2031        List<ModelListener> listeners = ListUtil.fromArray(_listeners);
2032
2033        listeners.remove(listener);
2034
2035        _listeners = listeners.toArray(new ModelListener[listeners.size()]);
2036    }
2037
2038    public void afterPropertiesSet() {
2039        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2040                    com.liferay.portal.util.PropsUtil.get(
2041                        "value.object.listener.com.liferay.portlet.documentlibrary.model.DLFileEntry")));
2042
2043        if (listenerClassNames.length > 0) {
2044            try {
2045                List<ModelListener> listeners = new ArrayList<ModelListener>();
2046
2047                for (String listenerClassName : listenerClassNames) {
2048                    listeners.add((ModelListener)Class.forName(
2049                            listenerClassName).newInstance());
2050                }
2051
2052                _listeners = listeners.toArray(new ModelListener[listeners.size()]);
2053            }
2054            catch (Exception e) {
2055                _log.error(e);
2056            }
2057        }
2058    }
2059
2060    private static Log _log = LogFactory.getLog(DLFileEntryPersistenceImpl.class);
2061    private ModelListener[] _listeners = new ModelListener[0];
2062}