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