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