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