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