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.journal.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.StringUtil;
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.journal.NoSuchArticleImageException;
40  import com.liferay.portlet.journal.model.JournalArticleImage;
41  import com.liferay.portlet.journal.model.impl.JournalArticleImageImpl;
42  import com.liferay.portlet.journal.model.impl.JournalArticleImageModelImpl;
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.ArrayList;
53  import java.util.Collections;
54  import java.util.Iterator;
55  import java.util.List;
56  
57  /**
58   * <a href="JournalArticleImagePersistenceImpl.java.html"><b><i>View Source</i></b></a>
59   *
60   * @author Brian Wing Shun Chan
61   *
62   */
63  public class JournalArticleImagePersistenceImpl extends BasePersistence
64      implements JournalArticleImagePersistence {
65      public JournalArticleImage create(long articleImageId) {
66          JournalArticleImage journalArticleImage = new JournalArticleImageImpl();
67  
68          journalArticleImage.setNew(true);
69          journalArticleImage.setPrimaryKey(articleImageId);
70  
71          return journalArticleImage;
72      }
73  
74      public JournalArticleImage remove(long articleImageId)
75          throws NoSuchArticleImageException, SystemException {
76          Session session = null;
77  
78          try {
79              session = openSession();
80  
81              JournalArticleImage journalArticleImage = (JournalArticleImage)session.get(JournalArticleImageImpl.class,
82                      new Long(articleImageId));
83  
84              if (journalArticleImage == null) {
85                  if (_log.isWarnEnabled()) {
86                      _log.warn(
87                          "No JournalArticleImage exists with the primary key " +
88                          articleImageId);
89                  }
90  
91                  throw new NoSuchArticleImageException(
92                      "No JournalArticleImage exists with the primary key " +
93                      articleImageId);
94              }
95  
96              return remove(journalArticleImage);
97          }
98          catch (NoSuchArticleImageException nsee) {
99              throw nsee;
100         }
101         catch (Exception e) {
102             throw HibernateUtil.processException(e);
103         }
104         finally {
105             closeSession(session);
106         }
107     }
108 
109     public JournalArticleImage remove(JournalArticleImage journalArticleImage)
110         throws SystemException {
111         if (_listeners != null) {
112             for (ModelListener listener : _listeners) {
113                 listener.onBeforeRemove(journalArticleImage);
114             }
115         }
116 
117         journalArticleImage = removeImpl(journalArticleImage);
118 
119         if (_listeners != null) {
120             for (ModelListener listener : _listeners) {
121                 listener.onAfterRemove(journalArticleImage);
122             }
123         }
124 
125         return journalArticleImage;
126     }
127 
128     protected JournalArticleImage removeImpl(
129         JournalArticleImage journalArticleImage) throws SystemException {
130         Session session = null;
131 
132         try {
133             session = openSession();
134 
135             session.delete(journalArticleImage);
136 
137             session.flush();
138 
139             return journalArticleImage;
140         }
141         catch (Exception e) {
142             throw HibernateUtil.processException(e);
143         }
144         finally {
145             closeSession(session);
146 
147             FinderCache.clearCache(JournalArticleImage.class.getName());
148         }
149     }
150 
151     /**
152      * @deprecated Use <code>update(JournalArticleImage journalArticleImage, boolean merge)</code>.
153      */
154     public JournalArticleImage update(JournalArticleImage journalArticleImage)
155         throws SystemException {
156         if (_log.isWarnEnabled()) {
157             _log.warn(
158                 "Using the deprecated update(JournalArticleImage journalArticleImage) method. Use update(JournalArticleImage journalArticleImage, boolean merge) instead.");
159         }
160 
161         return update(journalArticleImage, 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        journalArticleImage 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 journalArticleImage 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 JournalArticleImage update(JournalArticleImage journalArticleImage,
178         boolean merge) throws SystemException {
179         boolean isNew = journalArticleImage.isNew();
180 
181         if (_listeners != null) {
182             for (ModelListener listener : _listeners) {
183                 if (isNew) {
184                     listener.onBeforeCreate(journalArticleImage);
185                 }
186                 else {
187                     listener.onBeforeUpdate(journalArticleImage);
188                 }
189             }
190         }
191 
192         journalArticleImage = updateImpl(journalArticleImage, merge);
193 
194         if (_listeners != null) {
195             for (ModelListener listener : _listeners) {
196                 if (isNew) {
197                     listener.onAfterCreate(journalArticleImage);
198                 }
199                 else {
200                     listener.onAfterUpdate(journalArticleImage);
201                 }
202             }
203         }
204 
205         return journalArticleImage;
206     }
207 
208     public JournalArticleImage updateImpl(
209         com.liferay.portlet.journal.model.JournalArticleImage journalArticleImage,
210         boolean merge) throws SystemException {
211         Session session = null;
212 
213         try {
214             session = openSession();
215 
216             if (merge) {
217                 session.merge(journalArticleImage);
218             }
219             else {
220                 if (journalArticleImage.isNew()) {
221                     session.save(journalArticleImage);
222                 }
223             }
224 
225             session.flush();
226 
227             journalArticleImage.setNew(false);
228 
229             return journalArticleImage;
230         }
231         catch (Exception e) {
232             throw HibernateUtil.processException(e);
233         }
234         finally {
235             closeSession(session);
236 
237             FinderCache.clearCache(JournalArticleImage.class.getName());
238         }
239     }
240 
241     public JournalArticleImage findByPrimaryKey(long articleImageId)
242         throws NoSuchArticleImageException, SystemException {
243         JournalArticleImage journalArticleImage = fetchByPrimaryKey(articleImageId);
244 
245         if (journalArticleImage == null) {
246             if (_log.isWarnEnabled()) {
247                 _log.warn("No JournalArticleImage exists with the primary key " +
248                     articleImageId);
249             }
250 
251             throw new NoSuchArticleImageException(
252                 "No JournalArticleImage exists with the primary key " +
253                 articleImageId);
254         }
255 
256         return journalArticleImage;
257     }
258 
259     public JournalArticleImage fetchByPrimaryKey(long articleImageId)
260         throws SystemException {
261         Session session = null;
262 
263         try {
264             session = openSession();
265 
266             return (JournalArticleImage)session.get(JournalArticleImageImpl.class,
267                 new Long(articleImageId));
268         }
269         catch (Exception e) {
270             throw HibernateUtil.processException(e);
271         }
272         finally {
273             closeSession(session);
274         }
275     }
276 
277     public List<JournalArticleImage> findByGroupId(long groupId)
278         throws SystemException {
279         boolean finderClassNameCacheEnabled = JournalArticleImageModelImpl.CACHE_ENABLED;
280         String finderClassName = JournalArticleImage.class.getName();
281         String finderMethodName = "findByGroupId";
282         String[] finderParams = new String[] { Long.class.getName() };
283         Object[] finderArgs = new Object[] { new Long(groupId) };
284 
285         Object result = null;
286 
287         if (finderClassNameCacheEnabled) {
288             result = FinderCache.getResult(finderClassName, finderMethodName,
289                     finderParams, finderArgs, getSessionFactory());
290         }
291 
292         if (result == null) {
293             Session session = null;
294 
295             try {
296                 session = openSession();
297 
298                 StringMaker query = new StringMaker();
299 
300                 query.append(
301                     "FROM com.liferay.portlet.journal.model.JournalArticleImage WHERE ");
302 
303                 query.append("groupId = ?");
304 
305                 query.append(" ");
306 
307                 Query q = session.createQuery(query.toString());
308 
309                 int queryPos = 0;
310 
311                 q.setLong(queryPos++, groupId);
312 
313                 List<JournalArticleImage> list = q.list();
314 
315                 FinderCache.putResult(finderClassNameCacheEnabled,
316                     finderClassName, finderMethodName, finderParams,
317                     finderArgs, list);
318 
319                 return list;
320             }
321             catch (Exception e) {
322                 throw HibernateUtil.processException(e);
323             }
324             finally {
325                 closeSession(session);
326             }
327         }
328         else {
329             return (List<JournalArticleImage>)result;
330         }
331     }
332 
333     public List<JournalArticleImage> findByGroupId(long groupId, int begin,
334         int end) throws SystemException {
335         return findByGroupId(groupId, begin, end, null);
336     }
337 
338     public List<JournalArticleImage> findByGroupId(long groupId, int begin,
339         int end, OrderByComparator obc) throws SystemException {
340         boolean finderClassNameCacheEnabled = JournalArticleImageModelImpl.CACHE_ENABLED;
341         String finderClassName = JournalArticleImage.class.getName();
342         String finderMethodName = "findByGroupId";
343         String[] finderParams = new String[] {
344                 Long.class.getName(),
345                 
346                 "java.lang.Integer", "java.lang.Integer",
347                 "com.liferay.portal.kernel.util.OrderByComparator"
348             };
349         Object[] finderArgs = new Object[] {
350                 new Long(groupId),
351                 
352                 String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
353             };
354 
355         Object result = null;
356 
357         if (finderClassNameCacheEnabled) {
358             result = FinderCache.getResult(finderClassName, finderMethodName,
359                     finderParams, finderArgs, getSessionFactory());
360         }
361 
362         if (result == null) {
363             Session session = null;
364 
365             try {
366                 session = openSession();
367 
368                 StringMaker query = new StringMaker();
369 
370                 query.append(
371                     "FROM com.liferay.portlet.journal.model.JournalArticleImage WHERE ");
372 
373                 query.append("groupId = ?");
374 
375                 query.append(" ");
376 
377                 if (obc != null) {
378                     query.append("ORDER BY ");
379                     query.append(obc.getOrderBy());
380                 }
381 
382                 Query q = session.createQuery(query.toString());
383 
384                 int queryPos = 0;
385 
386                 q.setLong(queryPos++, groupId);
387 
388                 List<JournalArticleImage> list = (List<JournalArticleImage>)QueryUtil.list(q,
389                         getDialect(), begin, end);
390 
391                 FinderCache.putResult(finderClassNameCacheEnabled,
392                     finderClassName, finderMethodName, finderParams,
393                     finderArgs, list);
394 
395                 return list;
396             }
397             catch (Exception e) {
398                 throw HibernateUtil.processException(e);
399             }
400             finally {
401                 closeSession(session);
402             }
403         }
404         else {
405             return (List<JournalArticleImage>)result;
406         }
407     }
408 
409     public JournalArticleImage findByGroupId_First(long groupId,
410         OrderByComparator obc)
411         throws NoSuchArticleImageException, SystemException {
412         List<JournalArticleImage> list = findByGroupId(groupId, 0, 1, obc);
413 
414         if (list.size() == 0) {
415             StringMaker msg = new StringMaker();
416 
417             msg.append("No JournalArticleImage exists with the key {");
418 
419             msg.append("groupId=" + groupId);
420 
421             msg.append(StringPool.CLOSE_CURLY_BRACE);
422 
423             throw new NoSuchArticleImageException(msg.toString());
424         }
425         else {
426             return list.get(0);
427         }
428     }
429 
430     public JournalArticleImage findByGroupId_Last(long groupId,
431         OrderByComparator obc)
432         throws NoSuchArticleImageException, SystemException {
433         int count = countByGroupId(groupId);
434 
435         List<JournalArticleImage> list = findByGroupId(groupId, count - 1,
436                 count, obc);
437 
438         if (list.size() == 0) {
439             StringMaker msg = new StringMaker();
440 
441             msg.append("No JournalArticleImage exists with the key {");
442 
443             msg.append("groupId=" + groupId);
444 
445             msg.append(StringPool.CLOSE_CURLY_BRACE);
446 
447             throw new NoSuchArticleImageException(msg.toString());
448         }
449         else {
450             return list.get(0);
451         }
452     }
453 
454     public JournalArticleImage[] findByGroupId_PrevAndNext(
455         long articleImageId, long groupId, OrderByComparator obc)
456         throws NoSuchArticleImageException, SystemException {
457         JournalArticleImage journalArticleImage = findByPrimaryKey(articleImageId);
458 
459         int count = countByGroupId(groupId);
460 
461         Session session = null;
462 
463         try {
464             session = openSession();
465 
466             StringMaker query = new StringMaker();
467 
468             query.append(
469                 "FROM com.liferay.portlet.journal.model.JournalArticleImage WHERE ");
470 
471             query.append("groupId = ?");
472 
473             query.append(" ");
474 
475             if (obc != null) {
476                 query.append("ORDER BY ");
477                 query.append(obc.getOrderBy());
478             }
479 
480             Query q = session.createQuery(query.toString());
481 
482             int queryPos = 0;
483 
484             q.setLong(queryPos++, groupId);
485 
486             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
487                     journalArticleImage);
488 
489             JournalArticleImage[] array = new JournalArticleImageImpl[3];
490 
491             array[0] = (JournalArticleImage)objArray[0];
492             array[1] = (JournalArticleImage)objArray[1];
493             array[2] = (JournalArticleImage)objArray[2];
494 
495             return array;
496         }
497         catch (Exception e) {
498             throw HibernateUtil.processException(e);
499         }
500         finally {
501             closeSession(session);
502         }
503     }
504 
505     public List<JournalArticleImage> findByTempImage(boolean tempImage)
506         throws SystemException {
507         boolean finderClassNameCacheEnabled = JournalArticleImageModelImpl.CACHE_ENABLED;
508         String finderClassName = JournalArticleImage.class.getName();
509         String finderMethodName = "findByTempImage";
510         String[] finderParams = new String[] { Boolean.class.getName() };
511         Object[] finderArgs = new Object[] { Boolean.valueOf(tempImage) };
512 
513         Object result = null;
514 
515         if (finderClassNameCacheEnabled) {
516             result = FinderCache.getResult(finderClassName, finderMethodName,
517                     finderParams, finderArgs, getSessionFactory());
518         }
519 
520         if (result == null) {
521             Session session = null;
522 
523             try {
524                 session = openSession();
525 
526                 StringMaker query = new StringMaker();
527 
528                 query.append(
529                     "FROM com.liferay.portlet.journal.model.JournalArticleImage WHERE ");
530 
531                 query.append("tempImage = ?");
532 
533                 query.append(" ");
534 
535                 Query q = session.createQuery(query.toString());
536 
537                 int queryPos = 0;
538 
539                 q.setBoolean(queryPos++, tempImage);
540 
541                 List<JournalArticleImage> list = q.list();
542 
543                 FinderCache.putResult(finderClassNameCacheEnabled,
544                     finderClassName, finderMethodName, finderParams,
545                     finderArgs, list);
546 
547                 return list;
548             }
549             catch (Exception e) {
550                 throw HibernateUtil.processException(e);
551             }
552             finally {
553                 closeSession(session);
554             }
555         }
556         else {
557             return (List<JournalArticleImage>)result;
558         }
559     }
560 
561     public List<JournalArticleImage> findByTempImage(boolean tempImage,
562         int begin, int end) throws SystemException {
563         return findByTempImage(tempImage, begin, end, null);
564     }
565 
566     public List<JournalArticleImage> findByTempImage(boolean tempImage,
567         int begin, int end, OrderByComparator obc) throws SystemException {
568         boolean finderClassNameCacheEnabled = JournalArticleImageModelImpl.CACHE_ENABLED;
569         String finderClassName = JournalArticleImage.class.getName();
570         String finderMethodName = "findByTempImage";
571         String[] finderParams = new String[] {
572                 Boolean.class.getName(),
573                 
574                 "java.lang.Integer", "java.lang.Integer",
575                 "com.liferay.portal.kernel.util.OrderByComparator"
576             };
577         Object[] finderArgs = new Object[] {
578                 Boolean.valueOf(tempImage),
579                 
580                 String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
581             };
582 
583         Object result = null;
584 
585         if (finderClassNameCacheEnabled) {
586             result = FinderCache.getResult(finderClassName, finderMethodName,
587                     finderParams, finderArgs, getSessionFactory());
588         }
589 
590         if (result == null) {
591             Session session = null;
592 
593             try {
594                 session = openSession();
595 
596                 StringMaker query = new StringMaker();
597 
598                 query.append(
599                     "FROM com.liferay.portlet.journal.model.JournalArticleImage WHERE ");
600 
601                 query.append("tempImage = ?");
602 
603                 query.append(" ");
604 
605                 if (obc != null) {
606                     query.append("ORDER BY ");
607                     query.append(obc.getOrderBy());
608                 }
609 
610                 Query q = session.createQuery(query.toString());
611 
612                 int queryPos = 0;
613 
614                 q.setBoolean(queryPos++, tempImage);
615 
616                 List<JournalArticleImage> list = (List<JournalArticleImage>)QueryUtil.list(q,
617                         getDialect(), begin, end);
618 
619                 FinderCache.putResult(finderClassNameCacheEnabled,
620                     finderClassName, finderMethodName, finderParams,
621                     finderArgs, list);
622 
623                 return list;
624             }
625             catch (Exception e) {
626                 throw HibernateUtil.processException(e);
627             }
628             finally {
629                 closeSession(session);
630             }
631         }
632         else {
633             return (List<JournalArticleImage>)result;
634         }
635     }
636 
637     public JournalArticleImage findByTempImage_First(boolean tempImage,
638         OrderByComparator obc)
639         throws NoSuchArticleImageException, SystemException {
640         List<JournalArticleImage> list = findByTempImage(tempImage, 0, 1, obc);
641 
642         if (list.size() == 0) {
643             StringMaker msg = new StringMaker();
644 
645             msg.append("No JournalArticleImage exists with the key {");
646 
647             msg.append("tempImage=" + tempImage);
648 
649             msg.append(StringPool.CLOSE_CURLY_BRACE);
650 
651             throw new NoSuchArticleImageException(msg.toString());
652         }
653         else {
654             return list.get(0);
655         }
656     }
657 
658     public JournalArticleImage findByTempImage_Last(boolean tempImage,
659         OrderByComparator obc)
660         throws NoSuchArticleImageException, SystemException {
661         int count = countByTempImage(tempImage);
662 
663         List<JournalArticleImage> list = findByTempImage(tempImage, count - 1,
664                 count, obc);
665 
666         if (list.size() == 0) {
667             StringMaker msg = new StringMaker();
668 
669             msg.append("No JournalArticleImage exists with the key {");
670 
671             msg.append("tempImage=" + tempImage);
672 
673             msg.append(StringPool.CLOSE_CURLY_BRACE);
674 
675             throw new NoSuchArticleImageException(msg.toString());
676         }
677         else {
678             return list.get(0);
679         }
680     }
681 
682     public JournalArticleImage[] findByTempImage_PrevAndNext(
683         long articleImageId, boolean tempImage, OrderByComparator obc)
684         throws NoSuchArticleImageException, SystemException {
685         JournalArticleImage journalArticleImage = findByPrimaryKey(articleImageId);
686 
687         int count = countByTempImage(tempImage);
688 
689         Session session = null;
690 
691         try {
692             session = openSession();
693 
694             StringMaker query = new StringMaker();
695 
696             query.append(
697                 "FROM com.liferay.portlet.journal.model.JournalArticleImage WHERE ");
698 
699             query.append("tempImage = ?");
700 
701             query.append(" ");
702 
703             if (obc != null) {
704                 query.append("ORDER BY ");
705                 query.append(obc.getOrderBy());
706             }
707 
708             Query q = session.createQuery(query.toString());
709 
710             int queryPos = 0;
711 
712             q.setBoolean(queryPos++, tempImage);
713 
714             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
715                     journalArticleImage);
716 
717             JournalArticleImage[] array = new JournalArticleImageImpl[3];
718 
719             array[0] = (JournalArticleImage)objArray[0];
720             array[1] = (JournalArticleImage)objArray[1];
721             array[2] = (JournalArticleImage)objArray[2];
722 
723             return array;
724         }
725         catch (Exception e) {
726             throw HibernateUtil.processException(e);
727         }
728         finally {
729             closeSession(session);
730         }
731     }
732 
733     public List<JournalArticleImage> findByG_A_V(long groupId,
734         String articleId, double version) throws SystemException {
735         boolean finderClassNameCacheEnabled = JournalArticleImageModelImpl.CACHE_ENABLED;
736         String finderClassName = JournalArticleImage.class.getName();
737         String finderMethodName = "findByG_A_V";
738         String[] finderParams = new String[] {
739                 Long.class.getName(), String.class.getName(),
740                 Double.class.getName()
741             };
742         Object[] finderArgs = new Object[] {
743                 new Long(groupId),
744                 
745                 articleId, new Double(version)
746             };
747 
748         Object result = null;
749 
750         if (finderClassNameCacheEnabled) {
751             result = FinderCache.getResult(finderClassName, finderMethodName,
752                     finderParams, finderArgs, getSessionFactory());
753         }
754 
755         if (result == null) {
756             Session session = null;
757 
758             try {
759                 session = openSession();
760 
761                 StringMaker query = new StringMaker();
762 
763                 query.append(
764                     "FROM com.liferay.portlet.journal.model.JournalArticleImage WHERE ");
765 
766                 query.append("groupId = ?");
767 
768                 query.append(" AND ");
769 
770                 if (articleId == null) {
771                     query.append("articleId IS NULL");
772                 }
773                 else {
774                     query.append("articleId = ?");
775                 }
776 
777                 query.append(" AND ");
778 
779                 query.append("version = ?");
780 
781                 query.append(" ");
782 
783                 Query q = session.createQuery(query.toString());
784 
785                 int queryPos = 0;
786 
787                 q.setLong(queryPos++, groupId);
788 
789                 if (articleId != null) {
790                     q.setString(queryPos++, articleId);
791                 }
792 
793                 q.setDouble(queryPos++, version);
794 
795                 List<JournalArticleImage> list = q.list();
796 
797                 FinderCache.putResult(finderClassNameCacheEnabled,
798                     finderClassName, finderMethodName, finderParams,
799                     finderArgs, list);
800 
801                 return list;
802             }
803             catch (Exception e) {
804                 throw HibernateUtil.processException(e);
805             }
806             finally {
807                 closeSession(session);
808             }
809         }
810         else {
811             return (List<JournalArticleImage>)result;
812         }
813     }
814 
815     public List<JournalArticleImage> findByG_A_V(long groupId,
816         String articleId, double version, int begin, int end)
817         throws SystemException {
818         return findByG_A_V(groupId, articleId, version, begin, end, null);
819     }
820 
821     public List<JournalArticleImage> findByG_A_V(long groupId,
822         String articleId, double version, int begin, int end,
823         OrderByComparator obc) throws SystemException {
824         boolean finderClassNameCacheEnabled = JournalArticleImageModelImpl.CACHE_ENABLED;
825         String finderClassName = JournalArticleImage.class.getName();
826         String finderMethodName = "findByG_A_V";
827         String[] finderParams = new String[] {
828                 Long.class.getName(), String.class.getName(),
829                 Double.class.getName(),
830                 
831                 "java.lang.Integer", "java.lang.Integer",
832                 "com.liferay.portal.kernel.util.OrderByComparator"
833             };
834         Object[] finderArgs = new Object[] {
835                 new Long(groupId),
836                 
837                 articleId, new Double(version),
838                 
839                 String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
840             };
841 
842         Object result = null;
843 
844         if (finderClassNameCacheEnabled) {
845             result = FinderCache.getResult(finderClassName, finderMethodName,
846                     finderParams, finderArgs, getSessionFactory());
847         }
848 
849         if (result == null) {
850             Session session = null;
851 
852             try {
853                 session = openSession();
854 
855                 StringMaker query = new StringMaker();
856 
857                 query.append(
858                     "FROM com.liferay.portlet.journal.model.JournalArticleImage WHERE ");
859 
860                 query.append("groupId = ?");
861 
862                 query.append(" AND ");
863 
864                 if (articleId == null) {
865                     query.append("articleId IS NULL");
866                 }
867                 else {
868                     query.append("articleId = ?");
869                 }
870 
871                 query.append(" AND ");
872 
873                 query.append("version = ?");
874 
875                 query.append(" ");
876 
877                 if (obc != null) {
878                     query.append("ORDER BY ");
879                     query.append(obc.getOrderBy());
880                 }
881 
882                 Query q = session.createQuery(query.toString());
883 
884                 int queryPos = 0;
885 
886                 q.setLong(queryPos++, groupId);
887 
888                 if (articleId != null) {
889                     q.setString(queryPos++, articleId);
890                 }
891 
892                 q.setDouble(queryPos++, version);
893 
894                 List<JournalArticleImage> list = (List<JournalArticleImage>)QueryUtil.list(q,
895                         getDialect(), begin, end);
896 
897                 FinderCache.putResult(finderClassNameCacheEnabled,
898                     finderClassName, finderMethodName, finderParams,
899                     finderArgs, list);
900 
901                 return list;
902             }
903             catch (Exception e) {
904                 throw HibernateUtil.processException(e);
905             }
906             finally {
907                 closeSession(session);
908             }
909         }
910         else {
911             return (List<JournalArticleImage>)result;
912         }
913     }
914 
915     public JournalArticleImage findByG_A_V_First(long groupId,
916         String articleId, double version, OrderByComparator obc)
917         throws NoSuchArticleImageException, SystemException {
918         List<JournalArticleImage> list = findByG_A_V(groupId, articleId,
919                 version, 0, 1, obc);
920 
921         if (list.size() == 0) {
922             StringMaker msg = new StringMaker();
923 
924             msg.append("No JournalArticleImage exists with the key {");
925 
926             msg.append("groupId=" + groupId);
927 
928             msg.append(", ");
929             msg.append("articleId=" + articleId);
930 
931             msg.append(", ");
932             msg.append("version=" + version);
933 
934             msg.append(StringPool.CLOSE_CURLY_BRACE);
935 
936             throw new NoSuchArticleImageException(msg.toString());
937         }
938         else {
939             return list.get(0);
940         }
941     }
942 
943     public JournalArticleImage findByG_A_V_Last(long groupId, String articleId,
944         double version, OrderByComparator obc)
945         throws NoSuchArticleImageException, SystemException {
946         int count = countByG_A_V(groupId, articleId, version);
947 
948         List<JournalArticleImage> list = findByG_A_V(groupId, articleId,
949                 version, count - 1, count, obc);
950 
951         if (list.size() == 0) {
952             StringMaker msg = new StringMaker();
953 
954             msg.append("No JournalArticleImage exists with the key {");
955 
956             msg.append("groupId=" + groupId);
957 
958             msg.append(", ");
959             msg.append("articleId=" + articleId);
960 
961             msg.append(", ");
962             msg.append("version=" + version);
963 
964             msg.append(StringPool.CLOSE_CURLY_BRACE);
965 
966             throw new NoSuchArticleImageException(msg.toString());
967         }
968         else {
969             return list.get(0);
970         }
971     }
972 
973     public JournalArticleImage[] findByG_A_V_PrevAndNext(long articleImageId,
974         long groupId, String articleId, double version, OrderByComparator obc)
975         throws NoSuchArticleImageException, SystemException {
976         JournalArticleImage journalArticleImage = findByPrimaryKey(articleImageId);
977 
978         int count = countByG_A_V(groupId, articleId, version);
979 
980         Session session = null;
981 
982         try {
983             session = openSession();
984 
985             StringMaker query = new StringMaker();
986 
987             query.append(
988                 "FROM com.liferay.portlet.journal.model.JournalArticleImage WHERE ");
989 
990             query.append("groupId = ?");
991 
992             query.append(" AND ");
993 
994             if (articleId == null) {
995                 query.append("articleId IS NULL");
996             }
997             else {
998                 query.append("articleId = ?");
999             }
1000
1001            query.append(" AND ");
1002
1003            query.append("version = ?");
1004
1005            query.append(" ");
1006
1007            if (obc != null) {
1008                query.append("ORDER BY ");
1009                query.append(obc.getOrderBy());
1010            }
1011
1012            Query q = session.createQuery(query.toString());
1013
1014            int queryPos = 0;
1015
1016            q.setLong(queryPos++, groupId);
1017
1018            if (articleId != null) {
1019                q.setString(queryPos++, articleId);
1020            }
1021
1022            q.setDouble(queryPos++, version);
1023
1024            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1025                    journalArticleImage);
1026
1027            JournalArticleImage[] array = new JournalArticleImageImpl[3];
1028
1029            array[0] = (JournalArticleImage)objArray[0];
1030            array[1] = (JournalArticleImage)objArray[1];
1031            array[2] = (JournalArticleImage)objArray[2];
1032
1033            return array;
1034        }
1035        catch (Exception e) {
1036            throw HibernateUtil.processException(e);
1037        }
1038        finally {
1039            closeSession(session);
1040        }
1041    }
1042
1043    public JournalArticleImage findByG_A_V_E_L(long groupId, String articleId,
1044        double version, String elName, String languageId)
1045        throws NoSuchArticleImageException, SystemException {
1046        JournalArticleImage journalArticleImage = fetchByG_A_V_E_L(groupId,
1047                articleId, version, elName, languageId);
1048
1049        if (journalArticleImage == null) {
1050            StringMaker msg = new StringMaker();
1051
1052            msg.append("No JournalArticleImage exists with the key {");
1053
1054            msg.append("groupId=" + groupId);
1055
1056            msg.append(", ");
1057            msg.append("articleId=" + articleId);
1058
1059            msg.append(", ");
1060            msg.append("version=" + version);
1061
1062            msg.append(", ");
1063            msg.append("elName=" + elName);
1064
1065            msg.append(", ");
1066            msg.append("languageId=" + languageId);
1067
1068            msg.append(StringPool.CLOSE_CURLY_BRACE);
1069
1070            if (_log.isWarnEnabled()) {
1071                _log.warn(msg.toString());
1072            }
1073
1074            throw new NoSuchArticleImageException(msg.toString());
1075        }
1076
1077        return journalArticleImage;
1078    }
1079
1080    public JournalArticleImage fetchByG_A_V_E_L(long groupId, String articleId,
1081        double version, String elName, String languageId)
1082        throws SystemException {
1083        boolean finderClassNameCacheEnabled = JournalArticleImageModelImpl.CACHE_ENABLED;
1084        String finderClassName = JournalArticleImage.class.getName();
1085        String finderMethodName = "fetchByG_A_V_E_L";
1086        String[] finderParams = new String[] {
1087                Long.class.getName(), String.class.getName(),
1088                Double.class.getName(), String.class.getName(),
1089                String.class.getName()
1090            };
1091        Object[] finderArgs = new Object[] {
1092                new Long(groupId),
1093                
1094                articleId, new Double(version),
1095                
1096                elName,
1097                
1098                languageId
1099            };
1100
1101        Object result = null;
1102
1103        if (finderClassNameCacheEnabled) {
1104            result = FinderCache.getResult(finderClassName, finderMethodName,
1105                    finderParams, finderArgs, getSessionFactory());
1106        }
1107
1108        if (result == null) {
1109            Session session = null;
1110
1111            try {
1112                session = openSession();
1113
1114                StringMaker query = new StringMaker();
1115
1116                query.append(
1117                    "FROM com.liferay.portlet.journal.model.JournalArticleImage WHERE ");
1118
1119                query.append("groupId = ?");
1120
1121                query.append(" AND ");
1122
1123                if (articleId == null) {
1124                    query.append("articleId IS NULL");
1125                }
1126                else {
1127                    query.append("articleId = ?");
1128                }
1129
1130                query.append(" AND ");
1131
1132                query.append("version = ?");
1133
1134                query.append(" AND ");
1135
1136                if (elName == null) {
1137                    query.append("elName IS NULL");
1138                }
1139                else {
1140                    query.append("elName = ?");
1141                }
1142
1143                query.append(" AND ");
1144
1145                if (languageId == null) {
1146                    query.append("languageId IS NULL");
1147                }
1148                else {
1149                    query.append("languageId = ?");
1150                }
1151
1152                query.append(" ");
1153
1154                Query q = session.createQuery(query.toString());
1155
1156                int queryPos = 0;
1157
1158                q.setLong(queryPos++, groupId);
1159
1160                if (articleId != null) {
1161                    q.setString(queryPos++, articleId);
1162                }
1163
1164                q.setDouble(queryPos++, version);
1165
1166                if (elName != null) {
1167                    q.setString(queryPos++, elName);
1168                }
1169
1170                if (languageId != null) {
1171                    q.setString(queryPos++, languageId);
1172                }
1173
1174                List<JournalArticleImage> list = q.list();
1175
1176                FinderCache.putResult(finderClassNameCacheEnabled,
1177                    finderClassName, finderMethodName, finderParams,
1178                    finderArgs, list);
1179
1180                if (list.size() == 0) {
1181                    return null;
1182                }
1183                else {
1184                    return list.get(0);
1185                }
1186            }
1187            catch (Exception e) {
1188                throw HibernateUtil.processException(e);
1189            }
1190            finally {
1191                closeSession(session);
1192            }
1193        }
1194        else {
1195            List<JournalArticleImage> list = (List<JournalArticleImage>)result;
1196
1197            if (list.size() == 0) {
1198                return null;
1199            }
1200            else {
1201                return list.get(0);
1202            }
1203        }
1204    }
1205
1206    public List<JournalArticleImage> findWithDynamicQuery(
1207        DynamicQueryInitializer queryInitializer) throws SystemException {
1208        Session session = null;
1209
1210        try {
1211            session = openSession();
1212
1213            DynamicQuery query = queryInitializer.initialize(session);
1214
1215            return query.list();
1216        }
1217        catch (Exception e) {
1218            throw HibernateUtil.processException(e);
1219        }
1220        finally {
1221            closeSession(session);
1222        }
1223    }
1224
1225    public List<JournalArticleImage> findWithDynamicQuery(
1226        DynamicQueryInitializer queryInitializer, int begin, int end)
1227        throws SystemException {
1228        Session session = null;
1229
1230        try {
1231            session = openSession();
1232
1233            DynamicQuery query = queryInitializer.initialize(session);
1234
1235            query.setLimit(begin, end);
1236
1237            return query.list();
1238        }
1239        catch (Exception e) {
1240            throw HibernateUtil.processException(e);
1241        }
1242        finally {
1243            closeSession(session);
1244        }
1245    }
1246
1247    public List<JournalArticleImage> findAll() throws SystemException {
1248        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1249    }
1250
1251    public List<JournalArticleImage> findAll(int begin, int end)
1252        throws SystemException {
1253        return findAll(begin, end, null);
1254    }
1255
1256    public List<JournalArticleImage> findAll(int begin, int end,
1257        OrderByComparator obc) throws SystemException {
1258        boolean finderClassNameCacheEnabled = JournalArticleImageModelImpl.CACHE_ENABLED;
1259        String finderClassName = JournalArticleImage.class.getName();
1260        String finderMethodName = "findAll";
1261        String[] finderParams = new String[] {
1262                "java.lang.Integer", "java.lang.Integer",
1263                "com.liferay.portal.kernel.util.OrderByComparator"
1264            };
1265        Object[] finderArgs = new Object[] {
1266                String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
1267            };
1268
1269        Object result = null;
1270
1271        if (finderClassNameCacheEnabled) {
1272            result = FinderCache.getResult(finderClassName, finderMethodName,
1273                    finderParams, finderArgs, getSessionFactory());
1274        }
1275
1276        if (result == null) {
1277            Session session = null;
1278
1279            try {
1280                session = openSession();
1281
1282                StringMaker query = new StringMaker();
1283
1284                query.append(
1285                    "FROM com.liferay.portlet.journal.model.JournalArticleImage ");
1286
1287                if (obc != null) {
1288                    query.append("ORDER BY ");
1289                    query.append(obc.getOrderBy());
1290                }
1291
1292                Query q = session.createQuery(query.toString());
1293
1294                List<JournalArticleImage> list = (List<JournalArticleImage>)QueryUtil.list(q,
1295                        getDialect(), begin, end);
1296
1297                if (obc == null) {
1298                    Collections.sort(list);
1299                }
1300
1301                FinderCache.putResult(finderClassNameCacheEnabled,
1302                    finderClassName, finderMethodName, finderParams,
1303                    finderArgs, list);
1304
1305                return list;
1306            }
1307            catch (Exception e) {
1308                throw HibernateUtil.processException(e);
1309            }
1310            finally {
1311                closeSession(session);
1312            }
1313        }
1314        else {
1315            return (List<JournalArticleImage>)result;
1316        }
1317    }
1318
1319    public void removeByGroupId(long groupId) throws SystemException {
1320        for (JournalArticleImage journalArticleImage : findByGroupId(groupId)) {
1321            remove(journalArticleImage);
1322        }
1323    }
1324
1325    public void removeByTempImage(boolean tempImage) throws SystemException {
1326        for (JournalArticleImage journalArticleImage : findByTempImage(
1327                tempImage)) {
1328            remove(journalArticleImage);
1329        }
1330    }
1331
1332    public void removeByG_A_V(long groupId, String articleId, double version)
1333        throws SystemException {
1334        for (JournalArticleImage journalArticleImage : findByG_A_V(groupId,
1335                articleId, version)) {
1336            remove(journalArticleImage);
1337        }
1338    }
1339
1340    public void removeByG_A_V_E_L(long groupId, String articleId,
1341        double version, String elName, String languageId)
1342        throws NoSuchArticleImageException, SystemException {
1343        JournalArticleImage journalArticleImage = findByG_A_V_E_L(groupId,
1344                articleId, version, elName, languageId);
1345
1346        remove(journalArticleImage);
1347    }
1348
1349    public void removeAll() throws SystemException {
1350        for (JournalArticleImage journalArticleImage : findAll()) {
1351            remove(journalArticleImage);
1352        }
1353    }
1354
1355    public int countByGroupId(long groupId) throws SystemException {
1356        boolean finderClassNameCacheEnabled = JournalArticleImageModelImpl.CACHE_ENABLED;
1357        String finderClassName = JournalArticleImage.class.getName();
1358        String finderMethodName = "countByGroupId";
1359        String[] finderParams = new String[] { Long.class.getName() };
1360        Object[] finderArgs = new Object[] { new Long(groupId) };
1361
1362        Object result = null;
1363
1364        if (finderClassNameCacheEnabled) {
1365            result = FinderCache.getResult(finderClassName, finderMethodName,
1366                    finderParams, finderArgs, getSessionFactory());
1367        }
1368
1369        if (result == null) {
1370            Session session = null;
1371
1372            try {
1373                session = openSession();
1374
1375                StringMaker query = new StringMaker();
1376
1377                query.append("SELECT COUNT(*) ");
1378                query.append(
1379                    "FROM com.liferay.portlet.journal.model.JournalArticleImage WHERE ");
1380
1381                query.append("groupId = ?");
1382
1383                query.append(" ");
1384
1385                Query q = session.createQuery(query.toString());
1386
1387                int queryPos = 0;
1388
1389                q.setLong(queryPos++, groupId);
1390
1391                Long count = null;
1392
1393                Iterator<Long> itr = q.list().iterator();
1394
1395                if (itr.hasNext()) {
1396                    count = itr.next();
1397                }
1398
1399                if (count == null) {
1400                    count = new Long(0);
1401                }
1402
1403                FinderCache.putResult(finderClassNameCacheEnabled,
1404                    finderClassName, finderMethodName, finderParams,
1405                    finderArgs, count);
1406
1407                return count.intValue();
1408            }
1409            catch (Exception e) {
1410                throw HibernateUtil.processException(e);
1411            }
1412            finally {
1413                closeSession(session);
1414            }
1415        }
1416        else {
1417            return ((Long)result).intValue();
1418        }
1419    }
1420
1421    public int countByTempImage(boolean tempImage) throws SystemException {
1422        boolean finderClassNameCacheEnabled = JournalArticleImageModelImpl.CACHE_ENABLED;
1423        String finderClassName = JournalArticleImage.class.getName();
1424        String finderMethodName = "countByTempImage";
1425        String[] finderParams = new String[] { Boolean.class.getName() };
1426        Object[] finderArgs = new Object[] { Boolean.valueOf(tempImage) };
1427
1428        Object result = null;
1429
1430        if (finderClassNameCacheEnabled) {
1431            result = FinderCache.getResult(finderClassName, finderMethodName,
1432                    finderParams, finderArgs, getSessionFactory());
1433        }
1434
1435        if (result == null) {
1436            Session session = null;
1437
1438            try {
1439                session = openSession();
1440
1441                StringMaker query = new StringMaker();
1442
1443                query.append("SELECT COUNT(*) ");
1444                query.append(
1445                    "FROM com.liferay.portlet.journal.model.JournalArticleImage WHERE ");
1446
1447                query.append("tempImage = ?");
1448
1449                query.append(" ");
1450
1451                Query q = session.createQuery(query.toString());
1452
1453                int queryPos = 0;
1454
1455                q.setBoolean(queryPos++, tempImage);
1456
1457                Long count = null;
1458
1459                Iterator<Long> itr = q.list().iterator();
1460
1461                if (itr.hasNext()) {
1462                    count = itr.next();
1463                }
1464
1465                if (count == null) {
1466                    count = new Long(0);
1467                }
1468
1469                FinderCache.putResult(finderClassNameCacheEnabled,
1470                    finderClassName, finderMethodName, finderParams,
1471                    finderArgs, count);
1472
1473                return count.intValue();
1474            }
1475            catch (Exception e) {
1476                throw HibernateUtil.processException(e);
1477            }
1478            finally {
1479                closeSession(session);
1480            }
1481        }
1482        else {
1483            return ((Long)result).intValue();
1484        }
1485    }
1486
1487    public int countByG_A_V(long groupId, String articleId, double version)
1488        throws SystemException {
1489        boolean finderClassNameCacheEnabled = JournalArticleImageModelImpl.CACHE_ENABLED;
1490        String finderClassName = JournalArticleImage.class.getName();
1491        String finderMethodName = "countByG_A_V";
1492        String[] finderParams = new String[] {
1493                Long.class.getName(), String.class.getName(),
1494                Double.class.getName()
1495            };
1496        Object[] finderArgs = new Object[] {
1497                new Long(groupId),
1498                
1499                articleId, new Double(version)
1500            };
1501
1502        Object result = null;
1503
1504        if (finderClassNameCacheEnabled) {
1505            result = FinderCache.getResult(finderClassName, finderMethodName,
1506                    finderParams, finderArgs, getSessionFactory());
1507        }
1508
1509        if (result == null) {
1510            Session session = null;
1511
1512            try {
1513                session = openSession();
1514
1515                StringMaker query = new StringMaker();
1516
1517                query.append("SELECT COUNT(*) ");
1518                query.append(
1519                    "FROM com.liferay.portlet.journal.model.JournalArticleImage WHERE ");
1520
1521                query.append("groupId = ?");
1522
1523                query.append(" AND ");
1524
1525                if (articleId == null) {
1526                    query.append("articleId IS NULL");
1527                }
1528                else {
1529                    query.append("articleId = ?");
1530                }
1531
1532                query.append(" AND ");
1533
1534                query.append("version = ?");
1535
1536                query.append(" ");
1537
1538                Query q = session.createQuery(query.toString());
1539
1540                int queryPos = 0;
1541
1542                q.setLong(queryPos++, groupId);
1543
1544                if (articleId != null) {
1545                    q.setString(queryPos++, articleId);
1546                }
1547
1548                q.setDouble(queryPos++, version);
1549
1550                Long count = null;
1551
1552                Iterator<Long> itr = q.list().iterator();
1553
1554                if (itr.hasNext()) {
1555                    count = itr.next();
1556                }
1557
1558                if (count == null) {
1559                    count = new Long(0);
1560                }
1561
1562                FinderCache.putResult(finderClassNameCacheEnabled,
1563                    finderClassName, finderMethodName, finderParams,
1564                    finderArgs, count);
1565
1566                return count.intValue();
1567            }
1568            catch (Exception e) {
1569                throw HibernateUtil.processException(e);
1570            }
1571            finally {
1572                closeSession(session);
1573            }
1574        }
1575        else {
1576            return ((Long)result).intValue();
1577        }
1578    }
1579
1580    public int countByG_A_V_E_L(long groupId, String articleId, double version,
1581        String elName, String languageId) throws SystemException {
1582        boolean finderClassNameCacheEnabled = JournalArticleImageModelImpl.CACHE_ENABLED;
1583        String finderClassName = JournalArticleImage.class.getName();
1584        String finderMethodName = "countByG_A_V_E_L";
1585        String[] finderParams = new String[] {
1586                Long.class.getName(), String.class.getName(),
1587                Double.class.getName(), String.class.getName(),
1588                String.class.getName()
1589            };
1590        Object[] finderArgs = new Object[] {
1591                new Long(groupId),
1592                
1593                articleId, new Double(version),
1594                
1595                elName,
1596                
1597                languageId
1598            };
1599
1600        Object result = null;
1601
1602        if (finderClassNameCacheEnabled) {
1603            result = FinderCache.getResult(finderClassName, finderMethodName,
1604                    finderParams, finderArgs, getSessionFactory());
1605        }
1606
1607        if (result == null) {
1608            Session session = null;
1609
1610            try {
1611                session = openSession();
1612
1613                StringMaker query = new StringMaker();
1614
1615                query.append("SELECT COUNT(*) ");
1616                query.append(
1617                    "FROM com.liferay.portlet.journal.model.JournalArticleImage WHERE ");
1618
1619                query.append("groupId = ?");
1620
1621                query.append(" AND ");
1622
1623                if (articleId == null) {
1624                    query.append("articleId IS NULL");
1625                }
1626                else {
1627                    query.append("articleId = ?");
1628                }
1629
1630                query.append(" AND ");
1631
1632                query.append("version = ?");
1633
1634                query.append(" AND ");
1635
1636                if (elName == null) {
1637                    query.append("elName IS NULL");
1638                }
1639                else {
1640                    query.append("elName = ?");
1641                }
1642
1643                query.append(" AND ");
1644
1645                if (languageId == null) {
1646                    query.append("languageId IS NULL");
1647                }
1648                else {
1649                    query.append("languageId = ?");
1650                }
1651
1652                query.append(" ");
1653
1654                Query q = session.createQuery(query.toString());
1655
1656                int queryPos = 0;
1657
1658                q.setLong(queryPos++, groupId);
1659
1660                if (articleId != null) {
1661                    q.setString(queryPos++, articleId);
1662                }
1663
1664                q.setDouble(queryPos++, version);
1665
1666                if (elName != null) {
1667                    q.setString(queryPos++, elName);
1668                }
1669
1670                if (languageId != null) {
1671                    q.setString(queryPos++, languageId);
1672                }
1673
1674                Long count = null;
1675
1676                Iterator<Long> itr = q.list().iterator();
1677
1678                if (itr.hasNext()) {
1679                    count = itr.next();
1680                }
1681
1682                if (count == null) {
1683                    count = new Long(0);
1684                }
1685
1686                FinderCache.putResult(finderClassNameCacheEnabled,
1687                    finderClassName, finderMethodName, finderParams,
1688                    finderArgs, count);
1689
1690                return count.intValue();
1691            }
1692            catch (Exception e) {
1693                throw HibernateUtil.processException(e);
1694            }
1695            finally {
1696                closeSession(session);
1697            }
1698        }
1699        else {
1700            return ((Long)result).intValue();
1701        }
1702    }
1703
1704    public int countAll() throws SystemException {
1705        boolean finderClassNameCacheEnabled = JournalArticleImageModelImpl.CACHE_ENABLED;
1706        String finderClassName = JournalArticleImage.class.getName();
1707        String finderMethodName = "countAll";
1708        String[] finderParams = new String[] {  };
1709        Object[] finderArgs = new Object[] {  };
1710
1711        Object result = null;
1712
1713        if (finderClassNameCacheEnabled) {
1714            result = FinderCache.getResult(finderClassName, finderMethodName,
1715                    finderParams, finderArgs, getSessionFactory());
1716        }
1717
1718        if (result == null) {
1719            Session session = null;
1720
1721            try {
1722                session = openSession();
1723
1724                Query q = session.createQuery(
1725                        "SELECT COUNT(*) FROM com.liferay.portlet.journal.model.JournalArticleImage");
1726
1727                Long count = null;
1728
1729                Iterator<Long> itr = q.list().iterator();
1730
1731                if (itr.hasNext()) {
1732                    count = itr.next();
1733                }
1734
1735                if (count == null) {
1736                    count = new Long(0);
1737                }
1738
1739                FinderCache.putResult(finderClassNameCacheEnabled,
1740                    finderClassName, finderMethodName, finderParams,
1741                    finderArgs, count);
1742
1743                return count.intValue();
1744            }
1745            catch (Exception e) {
1746                throw HibernateUtil.processException(e);
1747            }
1748            finally {
1749                closeSession(session);
1750            }
1751        }
1752        else {
1753            return ((Long)result).intValue();
1754        }
1755    }
1756
1757    protected void initDao() {
1758        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1759                    PropsUtil.get(
1760                        "value.object.listener.com.liferay.portlet.journal.model.JournalArticleImage")));
1761
1762        if (listenerClassNames.length > 0) {
1763            try {
1764                List<ModelListener> listeners = new ArrayList<ModelListener>();
1765
1766                for (String listenerClassName : listenerClassNames) {
1767                    listeners.add((ModelListener)Class.forName(
1768                            listenerClassName).newInstance());
1769                }
1770
1771                _listeners = listeners.toArray(new ModelListener[listeners.size()]);
1772            }
1773            catch (Exception e) {
1774                _log.error(e);
1775            }
1776        }
1777    }
1778
1779    private static Log _log = LogFactory.getLog(JournalArticleImagePersistenceImpl.class);
1780    private ModelListener[] _listeners;
1781}