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