1   /**
2    * Copyright (c) 2000-2007 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.DynamicQuery;
27  import com.liferay.portal.kernel.dao.DynamicQueryInitializer;
28  import com.liferay.portal.kernel.util.OrderByComparator;
29  import com.liferay.portal.kernel.util.StringMaker;
30  import com.liferay.portal.kernel.util.StringPool;
31  import com.liferay.portal.service.persistence.BasePersistence;
32  import com.liferay.portal.spring.hibernate.FinderCache;
33  import com.liferay.portal.spring.hibernate.HibernateUtil;
34  
35  import com.liferay.portlet.documentlibrary.NoSuchFileVersionException;
36  import com.liferay.portlet.documentlibrary.model.DLFileVersion;
37  import com.liferay.portlet.documentlibrary.model.impl.DLFileVersionImpl;
38  
39  import com.liferay.util.dao.hibernate.QueryUtil;
40  
41  import org.apache.commons.logging.Log;
42  import org.apache.commons.logging.LogFactory;
43  
44  import org.hibernate.Query;
45  import org.hibernate.Session;
46  
47  import java.util.Collections;
48  import java.util.Iterator;
49  import java.util.List;
50  
51  /**
52   * <a href="DLFileVersionPersistenceImpl.java.html"><b><i>View Source</i></b></a>
53   *
54   * @author Brian Wing Shun Chan
55   *
56   */
57  public class DLFileVersionPersistenceImpl extends BasePersistence
58      implements DLFileVersionPersistence {
59      public DLFileVersion create(long fileVersionId) {
60          DLFileVersion dlFileVersion = new DLFileVersionImpl();
61          dlFileVersion.setNew(true);
62          dlFileVersion.setPrimaryKey(fileVersionId);
63  
64          return dlFileVersion;
65      }
66  
67      public DLFileVersion remove(long fileVersionId)
68          throws NoSuchFileVersionException, SystemException {
69          Session session = null;
70  
71          try {
72              session = openSession();
73  
74              DLFileVersion dlFileVersion = (DLFileVersion)session.get(DLFileVersionImpl.class,
75                      new Long(fileVersionId));
76  
77              if (dlFileVersion == null) {
78                  if (_log.isWarnEnabled()) {
79                      _log.warn("No DLFileVersion exists with the primary key " +
80                          fileVersionId);
81                  }
82  
83                  throw new NoSuchFileVersionException(
84                      "No DLFileVersion exists with the primary key " +
85                      fileVersionId);
86              }
87  
88              return remove(dlFileVersion);
89          }
90          catch (NoSuchFileVersionException nsee) {
91              throw nsee;
92          }
93          catch (Exception e) {
94              throw HibernateUtil.processException(e);
95          }
96          finally {
97              closeSession(session);
98          }
99      }
100 
101     public DLFileVersion remove(DLFileVersion dlFileVersion)
102         throws SystemException {
103         Session session = null;
104 
105         try {
106             session = openSession();
107             session.delete(dlFileVersion);
108             session.flush();
109 
110             return dlFileVersion;
111         }
112         catch (Exception e) {
113             throw HibernateUtil.processException(e);
114         }
115         finally {
116             closeSession(session);
117             FinderCache.clearCache(DLFileVersion.class.getName());
118         }
119     }
120 
121     public DLFileVersion update(
122         com.liferay.portlet.documentlibrary.model.DLFileVersion dlFileVersion)
123         throws SystemException {
124         return update(dlFileVersion, false);
125     }
126 
127     public DLFileVersion update(
128         com.liferay.portlet.documentlibrary.model.DLFileVersion dlFileVersion,
129         boolean merge) throws SystemException {
130         Session session = null;
131 
132         try {
133             session = openSession();
134 
135             if (merge) {
136                 session.merge(dlFileVersion);
137             }
138             else {
139                 if (dlFileVersion.isNew()) {
140                     session.save(dlFileVersion);
141                 }
142             }
143 
144             session.flush();
145             dlFileVersion.setNew(false);
146 
147             return dlFileVersion;
148         }
149         catch (Exception e) {
150             throw HibernateUtil.processException(e);
151         }
152         finally {
153             closeSession(session);
154             FinderCache.clearCache(DLFileVersion.class.getName());
155         }
156     }
157 
158     public DLFileVersion findByPrimaryKey(long fileVersionId)
159         throws NoSuchFileVersionException, SystemException {
160         DLFileVersion dlFileVersion = fetchByPrimaryKey(fileVersionId);
161 
162         if (dlFileVersion == null) {
163             if (_log.isWarnEnabled()) {
164                 _log.warn("No DLFileVersion exists with the primary key " +
165                     fileVersionId);
166             }
167 
168             throw new NoSuchFileVersionException(
169                 "No DLFileVersion exists with the primary key " +
170                 fileVersionId);
171         }
172 
173         return dlFileVersion;
174     }
175 
176     public DLFileVersion fetchByPrimaryKey(long fileVersionId)
177         throws SystemException {
178         Session session = null;
179 
180         try {
181             session = openSession();
182 
183             return (DLFileVersion)session.get(DLFileVersionImpl.class,
184                 new Long(fileVersionId));
185         }
186         catch (Exception e) {
187             throw HibernateUtil.processException(e);
188         }
189         finally {
190             closeSession(session);
191         }
192     }
193 
194     public List findByF_N(long folderId, String name) throws SystemException {
195         String finderClassName = DLFileVersion.class.getName();
196         String finderMethodName = "findByF_N";
197         String[] finderParams = new String[] {
198                 Long.class.getName(), String.class.getName()
199             };
200         Object[] finderArgs = new Object[] { new Long(folderId), name };
201         Object result = FinderCache.getResult(finderClassName,
202                 finderMethodName, finderParams, finderArgs, getSessionFactory());
203 
204         if (result == null) {
205             Session session = null;
206 
207             try {
208                 session = openSession();
209 
210                 StringMaker query = new StringMaker();
211                 query.append(
212                     "FROM com.liferay.portlet.documentlibrary.model.DLFileVersion WHERE ");
213                 query.append("folderId = ?");
214                 query.append(" AND ");
215 
216                 if (name == null) {
217                     query.append("name IS NULL");
218                 }
219                 else {
220                     query.append("name = ?");
221                 }
222 
223                 query.append(" ");
224                 query.append("ORDER BY ");
225                 query.append("folderId DESC").append(", ");
226                 query.append("name DESC").append(", ");
227                 query.append("version DESC");
228 
229                 Query q = session.createQuery(query.toString());
230                 int queryPos = 0;
231                 q.setLong(queryPos++, folderId);
232 
233                 if (name != null) {
234                     q.setString(queryPos++, name);
235                 }
236 
237                 List list = q.list();
238                 FinderCache.putResult(finderClassName, finderMethodName,
239                     finderParams, finderArgs, list);
240 
241                 return list;
242             }
243             catch (Exception e) {
244                 throw HibernateUtil.processException(e);
245             }
246             finally {
247                 closeSession(session);
248             }
249         }
250         else {
251             return (List)result;
252         }
253     }
254 
255     public List findByF_N(long folderId, String name, int begin, int end)
256         throws SystemException {
257         return findByF_N(folderId, name, begin, end, null);
258     }
259 
260     public List findByF_N(long folderId, String name, int begin, int end,
261         OrderByComparator obc) throws SystemException {
262         String finderClassName = DLFileVersion.class.getName();
263         String finderMethodName = "findByF_N";
264         String[] finderParams = new String[] {
265                 Long.class.getName(), String.class.getName(),
266                 "java.lang.Integer", "java.lang.Integer",
267                 "com.liferay.portal.kernel.util.OrderByComparator"
268             };
269         Object[] finderArgs = new Object[] {
270                 new Long(folderId), name, String.valueOf(begin),
271                 String.valueOf(end), String.valueOf(obc)
272             };
273         Object result = FinderCache.getResult(finderClassName,
274                 finderMethodName, finderParams, finderArgs, getSessionFactory());
275 
276         if (result == null) {
277             Session session = null;
278 
279             try {
280                 session = openSession();
281 
282                 StringMaker query = new StringMaker();
283                 query.append(
284                     "FROM com.liferay.portlet.documentlibrary.model.DLFileVersion WHERE ");
285                 query.append("folderId = ?");
286                 query.append(" AND ");
287 
288                 if (name == null) {
289                     query.append("name IS NULL");
290                 }
291                 else {
292                     query.append("name = ?");
293                 }
294 
295                 query.append(" ");
296 
297                 if (obc != null) {
298                     query.append("ORDER BY ");
299                     query.append(obc.getOrderBy());
300                 }
301                 else {
302                     query.append("ORDER BY ");
303                     query.append("folderId DESC").append(", ");
304                     query.append("name DESC").append(", ");
305                     query.append("version DESC");
306                 }
307 
308                 Query q = session.createQuery(query.toString());
309                 int queryPos = 0;
310                 q.setLong(queryPos++, folderId);
311 
312                 if (name != null) {
313                     q.setString(queryPos++, name);
314                 }
315 
316                 List list = QueryUtil.list(q, getDialect(), begin, end);
317                 FinderCache.putResult(finderClassName, finderMethodName,
318                     finderParams, finderArgs, list);
319 
320                 return list;
321             }
322             catch (Exception e) {
323                 throw HibernateUtil.processException(e);
324             }
325             finally {
326                 closeSession(session);
327             }
328         }
329         else {
330             return (List)result;
331         }
332     }
333 
334     public DLFileVersion findByF_N_First(long folderId, String name,
335         OrderByComparator obc)
336         throws NoSuchFileVersionException, SystemException {
337         List list = findByF_N(folderId, name, 0, 1, obc);
338 
339         if (list.size() == 0) {
340             StringMaker msg = new StringMaker();
341             msg.append("No DLFileVersion exists with the key ");
342             msg.append(StringPool.OPEN_CURLY_BRACE);
343             msg.append("folderId=");
344             msg.append(folderId);
345             msg.append(", ");
346             msg.append("name=");
347             msg.append(name);
348             msg.append(StringPool.CLOSE_CURLY_BRACE);
349             throw new NoSuchFileVersionException(msg.toString());
350         }
351         else {
352             return (DLFileVersion)list.get(0);
353         }
354     }
355 
356     public DLFileVersion findByF_N_Last(long folderId, String name,
357         OrderByComparator obc)
358         throws NoSuchFileVersionException, SystemException {
359         int count = countByF_N(folderId, name);
360         List list = findByF_N(folderId, name, count - 1, count, obc);
361 
362         if (list.size() == 0) {
363             StringMaker msg = new StringMaker();
364             msg.append("No DLFileVersion exists with the key ");
365             msg.append(StringPool.OPEN_CURLY_BRACE);
366             msg.append("folderId=");
367             msg.append(folderId);
368             msg.append(", ");
369             msg.append("name=");
370             msg.append(name);
371             msg.append(StringPool.CLOSE_CURLY_BRACE);
372             throw new NoSuchFileVersionException(msg.toString());
373         }
374         else {
375             return (DLFileVersion)list.get(0);
376         }
377     }
378 
379     public DLFileVersion[] findByF_N_PrevAndNext(long fileVersionId,
380         long folderId, String name, OrderByComparator obc)
381         throws NoSuchFileVersionException, SystemException {
382         DLFileVersion dlFileVersion = findByPrimaryKey(fileVersionId);
383         int count = countByF_N(folderId, name);
384         Session session = null;
385 
386         try {
387             session = openSession();
388 
389             StringMaker query = new StringMaker();
390             query.append(
391                 "FROM com.liferay.portlet.documentlibrary.model.DLFileVersion WHERE ");
392             query.append("folderId = ?");
393             query.append(" AND ");
394 
395             if (name == null) {
396                 query.append("name IS NULL");
397             }
398             else {
399                 query.append("name = ?");
400             }
401 
402             query.append(" ");
403 
404             if (obc != null) {
405                 query.append("ORDER BY ");
406                 query.append(obc.getOrderBy());
407             }
408             else {
409                 query.append("ORDER BY ");
410                 query.append("folderId DESC").append(", ");
411                 query.append("name DESC").append(", ");
412                 query.append("version DESC");
413             }
414 
415             Query q = session.createQuery(query.toString());
416             int queryPos = 0;
417             q.setLong(queryPos++, folderId);
418 
419             if (name != null) {
420                 q.setString(queryPos++, name);
421             }
422 
423             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
424                     dlFileVersion);
425             DLFileVersion[] array = new DLFileVersionImpl[3];
426             array[0] = (DLFileVersion)objArray[0];
427             array[1] = (DLFileVersion)objArray[1];
428             array[2] = (DLFileVersion)objArray[2];
429 
430             return array;
431         }
432         catch (Exception e) {
433             throw HibernateUtil.processException(e);
434         }
435         finally {
436             closeSession(session);
437         }
438     }
439 
440     public DLFileVersion findByF_N_V(long folderId, String name, double version)
441         throws NoSuchFileVersionException, SystemException {
442         DLFileVersion dlFileVersion = fetchByF_N_V(folderId, name, version);
443 
444         if (dlFileVersion == null) {
445             StringMaker msg = new StringMaker();
446             msg.append("No DLFileVersion exists with the key ");
447             msg.append(StringPool.OPEN_CURLY_BRACE);
448             msg.append("folderId=");
449             msg.append(folderId);
450             msg.append(", ");
451             msg.append("name=");
452             msg.append(name);
453             msg.append(", ");
454             msg.append("version=");
455             msg.append(version);
456             msg.append(StringPool.CLOSE_CURLY_BRACE);
457 
458             if (_log.isWarnEnabled()) {
459                 _log.warn(msg.toString());
460             }
461 
462             throw new NoSuchFileVersionException(msg.toString());
463         }
464 
465         return dlFileVersion;
466     }
467 
468     public DLFileVersion fetchByF_N_V(long folderId, String name, double version)
469         throws SystemException {
470         String finderClassName = DLFileVersion.class.getName();
471         String finderMethodName = "fetchByF_N_V";
472         String[] finderParams = new String[] {
473                 Long.class.getName(), String.class.getName(),
474                 Double.class.getName()
475             };
476         Object[] finderArgs = new Object[] {
477                 new Long(folderId), name, new Double(version)
478             };
479         Object result = FinderCache.getResult(finderClassName,
480                 finderMethodName, finderParams, finderArgs, getSessionFactory());
481 
482         if (result == null) {
483             Session session = null;
484 
485             try {
486                 session = openSession();
487 
488                 StringMaker query = new StringMaker();
489                 query.append(
490                     "FROM com.liferay.portlet.documentlibrary.model.DLFileVersion WHERE ");
491                 query.append("folderId = ?");
492                 query.append(" AND ");
493 
494                 if (name == null) {
495                     query.append("name IS NULL");
496                 }
497                 else {
498                     query.append("name = ?");
499                 }
500 
501                 query.append(" AND ");
502                 query.append("version = ?");
503                 query.append(" ");
504                 query.append("ORDER BY ");
505                 query.append("folderId DESC").append(", ");
506                 query.append("name DESC").append(", ");
507                 query.append("version DESC");
508 
509                 Query q = session.createQuery(query.toString());
510                 int queryPos = 0;
511                 q.setLong(queryPos++, folderId);
512 
513                 if (name != null) {
514                     q.setString(queryPos++, name);
515                 }
516 
517                 q.setDouble(queryPos++, version);
518 
519                 List list = q.list();
520                 FinderCache.putResult(finderClassName, finderMethodName,
521                     finderParams, finderArgs, list);
522 
523                 if (list.size() == 0) {
524                     return null;
525                 }
526                 else {
527                     return (DLFileVersion)list.get(0);
528                 }
529             }
530             catch (Exception e) {
531                 throw HibernateUtil.processException(e);
532             }
533             finally {
534                 closeSession(session);
535             }
536         }
537         else {
538             List list = (List)result;
539 
540             if (list.size() == 0) {
541                 return null;
542             }
543             else {
544                 return (DLFileVersion)list.get(0);
545             }
546         }
547     }
548 
549     public List findWithDynamicQuery(DynamicQueryInitializer queryInitializer)
550         throws SystemException {
551         Session session = null;
552 
553         try {
554             session = openSession();
555 
556             DynamicQuery query = queryInitializer.initialize(session);
557 
558             return query.list();
559         }
560         catch (Exception e) {
561             throw HibernateUtil.processException(e);
562         }
563         finally {
564             closeSession(session);
565         }
566     }
567 
568     public List findWithDynamicQuery(DynamicQueryInitializer queryInitializer,
569         int begin, int end) throws SystemException {
570         Session session = null;
571 
572         try {
573             session = openSession();
574 
575             DynamicQuery query = queryInitializer.initialize(session);
576             query.setLimit(begin, end);
577 
578             return query.list();
579         }
580         catch (Exception e) {
581             throw HibernateUtil.processException(e);
582         }
583         finally {
584             closeSession(session);
585         }
586     }
587 
588     public List findAll() throws SystemException {
589         return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
590     }
591 
592     public List findAll(int begin, int end) throws SystemException {
593         return findAll(begin, end, null);
594     }
595 
596     public List findAll(int begin, int end, OrderByComparator obc)
597         throws SystemException {
598         String finderClassName = DLFileVersion.class.getName();
599         String finderMethodName = "findAll";
600         String[] finderParams = new String[] {
601                 "java.lang.Integer", "java.lang.Integer",
602                 "com.liferay.portal.kernel.util.OrderByComparator"
603             };
604         Object[] finderArgs = new Object[] {
605                 String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
606             };
607         Object result = FinderCache.getResult(finderClassName,
608                 finderMethodName, finderParams, finderArgs, getSessionFactory());
609 
610         if (result == null) {
611             Session session = null;
612 
613             try {
614                 session = openSession();
615 
616                 StringMaker query = new StringMaker();
617                 query.append(
618                     "FROM com.liferay.portlet.documentlibrary.model.DLFileVersion ");
619 
620                 if (obc != null) {
621                     query.append("ORDER BY ");
622                     query.append(obc.getOrderBy());
623                 }
624                 else {
625                     query.append("ORDER BY ");
626                     query.append("folderId DESC").append(", ");
627                     query.append("name DESC").append(", ");
628                     query.append("version DESC");
629                 }
630 
631                 Query q = session.createQuery(query.toString());
632                 List list = QueryUtil.list(q, getDialect(), begin, end);
633 
634                 if (obc == null) {
635                     Collections.sort(list);
636                 }
637 
638                 FinderCache.putResult(finderClassName, finderMethodName,
639                     finderParams, finderArgs, list);
640 
641                 return list;
642             }
643             catch (Exception e) {
644                 throw HibernateUtil.processException(e);
645             }
646             finally {
647                 closeSession(session);
648             }
649         }
650         else {
651             return (List)result;
652         }
653     }
654 
655     public void removeByF_N(long folderId, String name)
656         throws SystemException {
657         Iterator itr = findByF_N(folderId, name).iterator();
658 
659         while (itr.hasNext()) {
660             DLFileVersion dlFileVersion = (DLFileVersion)itr.next();
661             remove(dlFileVersion);
662         }
663     }
664 
665     public void removeByF_N_V(long folderId, String name, double version)
666         throws NoSuchFileVersionException, SystemException {
667         DLFileVersion dlFileVersion = findByF_N_V(folderId, name, version);
668         remove(dlFileVersion);
669     }
670 
671     public void removeAll() throws SystemException {
672         Iterator itr = findAll().iterator();
673 
674         while (itr.hasNext()) {
675             remove((DLFileVersion)itr.next());
676         }
677     }
678 
679     public int countByF_N(long folderId, String name) throws SystemException {
680         String finderClassName = DLFileVersion.class.getName();
681         String finderMethodName = "countByF_N";
682         String[] finderParams = new String[] {
683                 Long.class.getName(), String.class.getName()
684             };
685         Object[] finderArgs = new Object[] { new Long(folderId), name };
686         Object result = FinderCache.getResult(finderClassName,
687                 finderMethodName, finderParams, finderArgs, getSessionFactory());
688 
689         if (result == null) {
690             Session session = null;
691 
692             try {
693                 session = openSession();
694 
695                 StringMaker query = new StringMaker();
696                 query.append("SELECT COUNT(*) ");
697                 query.append(
698                     "FROM com.liferay.portlet.documentlibrary.model.DLFileVersion WHERE ");
699                 query.append("folderId = ?");
700                 query.append(" AND ");
701 
702                 if (name == null) {
703                     query.append("name IS NULL");
704                 }
705                 else {
706                     query.append("name = ?");
707                 }
708 
709                 query.append(" ");
710 
711                 Query q = session.createQuery(query.toString());
712                 int queryPos = 0;
713                 q.setLong(queryPos++, folderId);
714 
715                 if (name != null) {
716                     q.setString(queryPos++, name);
717                 }
718 
719                 Long count = null;
720                 Iterator itr = q.list().iterator();
721 
722                 if (itr.hasNext()) {
723                     count = (Long)itr.next();
724                 }
725 
726                 if (count == null) {
727                     count = new Long(0);
728                 }
729 
730                 FinderCache.putResult(finderClassName, finderMethodName,
731                     finderParams, finderArgs, count);
732 
733                 return count.intValue();
734             }
735             catch (Exception e) {
736                 throw HibernateUtil.processException(e);
737             }
738             finally {
739                 closeSession(session);
740             }
741         }
742         else {
743             return ((Long)result).intValue();
744         }
745     }
746 
747     public int countByF_N_V(long folderId, String name, double version)
748         throws SystemException {
749         String finderClassName = DLFileVersion.class.getName();
750         String finderMethodName = "countByF_N_V";
751         String[] finderParams = new String[] {
752                 Long.class.getName(), String.class.getName(),
753                 Double.class.getName()
754             };
755         Object[] finderArgs = new Object[] {
756                 new Long(folderId), name, new Double(version)
757             };
758         Object result = FinderCache.getResult(finderClassName,
759                 finderMethodName, finderParams, finderArgs, getSessionFactory());
760 
761         if (result == null) {
762             Session session = null;
763 
764             try {
765                 session = openSession();
766 
767                 StringMaker query = new StringMaker();
768                 query.append("SELECT COUNT(*) ");
769                 query.append(
770                     "FROM com.liferay.portlet.documentlibrary.model.DLFileVersion WHERE ");
771                 query.append("folderId = ?");
772                 query.append(" AND ");
773 
774                 if (name == null) {
775                     query.append("name IS NULL");
776                 }
777                 else {
778                     query.append("name = ?");
779                 }
780 
781                 query.append(" AND ");
782                 query.append("version = ?");
783                 query.append(" ");
784 
785                 Query q = session.createQuery(query.toString());
786                 int queryPos = 0;
787                 q.setLong(queryPos++, folderId);
788 
789                 if (name != null) {
790                     q.setString(queryPos++, name);
791                 }
792 
793                 q.setDouble(queryPos++, version);
794 
795                 Long count = null;
796                 Iterator itr = q.list().iterator();
797 
798                 if (itr.hasNext()) {
799                     count = (Long)itr.next();
800                 }
801 
802                 if (count == null) {
803                     count = new Long(0);
804                 }
805 
806                 FinderCache.putResult(finderClassName, finderMethodName,
807                     finderParams, finderArgs, count);
808 
809                 return count.intValue();
810             }
811             catch (Exception e) {
812                 throw HibernateUtil.processException(e);
813             }
814             finally {
815                 closeSession(session);
816             }
817         }
818         else {
819             return ((Long)result).intValue();
820         }
821     }
822 
823     public int countAll() throws SystemException {
824         String finderClassName = DLFileVersion.class.getName();
825         String finderMethodName = "countAll";
826         String[] finderParams = new String[] {  };
827         Object[] finderArgs = new Object[] {  };
828         Object result = FinderCache.getResult(finderClassName,
829                 finderMethodName, finderParams, finderArgs, getSessionFactory());
830 
831         if (result == null) {
832             Session session = null;
833 
834             try {
835                 session = openSession();
836 
837                 StringMaker query = new StringMaker();
838                 query.append("SELECT COUNT(*) ");
839                 query.append(
840                     "FROM com.liferay.portlet.documentlibrary.model.DLFileVersion");
841 
842                 Query q = session.createQuery(query.toString());
843                 Long count = null;
844                 Iterator itr = q.list().iterator();
845 
846                 if (itr.hasNext()) {
847                     count = (Long)itr.next();
848                 }
849 
850                 if (count == null) {
851                     count = new Long(0);
852                 }
853 
854                 FinderCache.putResult(finderClassName, finderMethodName,
855                     finderParams, finderArgs, count);
856 
857                 return count.intValue();
858             }
859             catch (Exception e) {
860                 throw HibernateUtil.processException(e);
861             }
862             finally {
863                 closeSession(session);
864             }
865         }
866         else {
867             return ((Long)result).intValue();
868         }
869     }
870 
871     protected void initDao() {
872     }
873 
874     private static Log _log = LogFactory.getLog(DLFileVersionPersistenceImpl.class);
875 }