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