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.BatchSessionUtil;
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 {
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             if (BatchSessionUtil.isEnabled()) {
133                 Object staleObject = session.get(JournalArticleImageImpl.class,
134                         journalArticleImage.getPrimaryKeyObj());
135 
136                 if (staleObject != null) {
137                     session.evict(staleObject);
138                 }
139             }
140 
141             session.delete(journalArticleImage);
142 
143             session.flush();
144 
145             return journalArticleImage;
146         }
147         catch (Exception e) {
148             throw processException(e);
149         }
150         finally {
151             closeSession(session);
152 
153             FinderCacheUtil.clearCache(JournalArticleImage.class.getName());
154         }
155     }
156 
157     /**
158      * @deprecated Use <code>update(JournalArticleImage journalArticleImage, boolean merge)</code>.
159      */
160     public JournalArticleImage update(JournalArticleImage journalArticleImage)
161         throws SystemException {
162         if (_log.isWarnEnabled()) {
163             _log.warn(
164                 "Using the deprecated update(JournalArticleImage journalArticleImage) method. Use update(JournalArticleImage journalArticleImage, boolean merge) instead.");
165         }
166 
167         return update(journalArticleImage, false);
168     }
169 
170     /**
171      * Add, update, or merge, the entity. This method also calls the model
172      * listeners to trigger the proper events associated with adding, deleting,
173      * or updating an entity.
174      *
175      * @param        journalArticleImage the entity to add, update, or merge
176      * @param        merge boolean value for whether to merge the entity. The
177      *                default value is false. Setting merge to true is more
178      *                expensive and should only be true when journalArticleImage is
179      *                transient. See LEP-5473 for a detailed discussion of this
180      *                method.
181      * @return        true if the portlet can be displayed via Ajax
182      */
183     public JournalArticleImage update(JournalArticleImage journalArticleImage,
184         boolean merge) throws SystemException {
185         boolean isNew = journalArticleImage.isNew();
186 
187         if (_listeners.length > 0) {
188             for (ModelListener listener : _listeners) {
189                 if (isNew) {
190                     listener.onBeforeCreate(journalArticleImage);
191                 }
192                 else {
193                     listener.onBeforeUpdate(journalArticleImage);
194                 }
195             }
196         }
197 
198         journalArticleImage = updateImpl(journalArticleImage, merge);
199 
200         if (_listeners.length > 0) {
201             for (ModelListener listener : _listeners) {
202                 if (isNew) {
203                     listener.onAfterCreate(journalArticleImage);
204                 }
205                 else {
206                     listener.onAfterUpdate(journalArticleImage);
207                 }
208             }
209         }
210 
211         return journalArticleImage;
212     }
213 
214     public JournalArticleImage updateImpl(
215         com.liferay.portlet.journal.model.JournalArticleImage journalArticleImage,
216         boolean merge) throws SystemException {
217         Session session = null;
218 
219         try {
220             session = openSession();
221 
222             BatchSessionUtil.update(session, journalArticleImage, merge);
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 = null;
1291
1292                if (obc == null) {
1293                    list = (List<JournalArticleImage>)QueryUtil.list(q,
1294                            getDialect(), start, end, false);
1295
1296                    Collections.sort(list);
1297                }
1298                else {
1299                    list = (List<JournalArticleImage>)QueryUtil.list(q,
1300                            getDialect(), start, end);
1301                }
1302
1303                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1304                    finderClassName, finderMethodName, finderParams,
1305                    finderArgs, list);
1306
1307                return list;
1308            }
1309            catch (Exception e) {
1310                throw processException(e);
1311            }
1312            finally {
1313                closeSession(session);
1314            }
1315        }
1316        else {
1317            return (List<JournalArticleImage>)result;
1318        }
1319    }
1320
1321    public void removeByGroupId(long groupId) throws SystemException {
1322        for (JournalArticleImage journalArticleImage : findByGroupId(groupId)) {
1323            remove(journalArticleImage);
1324        }
1325    }
1326
1327    public void removeByTempImage(boolean tempImage) throws SystemException {
1328        for (JournalArticleImage journalArticleImage : findByTempImage(
1329                tempImage)) {
1330            remove(journalArticleImage);
1331        }
1332    }
1333
1334    public void removeByG_A_V(long groupId, String articleId, double version)
1335        throws SystemException {
1336        for (JournalArticleImage journalArticleImage : findByG_A_V(groupId,
1337                articleId, version)) {
1338            remove(journalArticleImage);
1339        }
1340    }
1341
1342    public void removeByG_A_V_E_L(long groupId, String articleId,
1343        double version, String elName, String languageId)
1344        throws NoSuchArticleImageException, SystemException {
1345        JournalArticleImage journalArticleImage = findByG_A_V_E_L(groupId,
1346                articleId, version, elName, languageId);
1347
1348        remove(journalArticleImage);
1349    }
1350
1351    public void removeAll() throws SystemException {
1352        for (JournalArticleImage journalArticleImage : findAll()) {
1353            remove(journalArticleImage);
1354        }
1355    }
1356
1357    public int countByGroupId(long groupId) throws SystemException {
1358        boolean finderClassNameCacheEnabled = JournalArticleImageModelImpl.CACHE_ENABLED;
1359        String finderClassName = JournalArticleImage.class.getName();
1360        String finderMethodName = "countByGroupId";
1361        String[] finderParams = new String[] { Long.class.getName() };
1362        Object[] finderArgs = new Object[] { new Long(groupId) };
1363
1364        Object result = null;
1365
1366        if (finderClassNameCacheEnabled) {
1367            result = FinderCacheUtil.getResult(finderClassName,
1368                    finderMethodName, finderParams, finderArgs, this);
1369        }
1370
1371        if (result == null) {
1372            Session session = null;
1373
1374            try {
1375                session = openSession();
1376
1377                StringBuilder query = new StringBuilder();
1378
1379                query.append("SELECT COUNT(*) ");
1380                query.append(
1381                    "FROM com.liferay.portlet.journal.model.JournalArticleImage WHERE ");
1382
1383                query.append("groupId = ?");
1384
1385                query.append(" ");
1386
1387                Query q = session.createQuery(query.toString());
1388
1389                QueryPos qPos = QueryPos.getInstance(q);
1390
1391                qPos.add(groupId);
1392
1393                Long count = null;
1394
1395                Iterator<Long> itr = q.list().iterator();
1396
1397                if (itr.hasNext()) {
1398                    count = itr.next();
1399                }
1400
1401                if (count == null) {
1402                    count = new Long(0);
1403                }
1404
1405                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1406                    finderClassName, finderMethodName, finderParams,
1407                    finderArgs, count);
1408
1409                return count.intValue();
1410            }
1411            catch (Exception e) {
1412                throw processException(e);
1413            }
1414            finally {
1415                closeSession(session);
1416            }
1417        }
1418        else {
1419            return ((Long)result).intValue();
1420        }
1421    }
1422
1423    public int countByTempImage(boolean tempImage) throws SystemException {
1424        boolean finderClassNameCacheEnabled = JournalArticleImageModelImpl.CACHE_ENABLED;
1425        String finderClassName = JournalArticleImage.class.getName();
1426        String finderMethodName = "countByTempImage";
1427        String[] finderParams = new String[] { Boolean.class.getName() };
1428        Object[] finderArgs = new Object[] { Boolean.valueOf(tempImage) };
1429
1430        Object result = null;
1431
1432        if (finderClassNameCacheEnabled) {
1433            result = FinderCacheUtil.getResult(finderClassName,
1434                    finderMethodName, finderParams, finderArgs, this);
1435        }
1436
1437        if (result == null) {
1438            Session session = null;
1439
1440            try {
1441                session = openSession();
1442
1443                StringBuilder query = new StringBuilder();
1444
1445                query.append("SELECT COUNT(*) ");
1446                query.append(
1447                    "FROM com.liferay.portlet.journal.model.JournalArticleImage WHERE ");
1448
1449                query.append("tempImage = ?");
1450
1451                query.append(" ");
1452
1453                Query q = session.createQuery(query.toString());
1454
1455                QueryPos qPos = QueryPos.getInstance(q);
1456
1457                qPos.add(tempImage);
1458
1459                Long count = null;
1460
1461                Iterator<Long> itr = q.list().iterator();
1462
1463                if (itr.hasNext()) {
1464                    count = itr.next();
1465                }
1466
1467                if (count == null) {
1468                    count = new Long(0);
1469                }
1470
1471                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1472                    finderClassName, finderMethodName, finderParams,
1473                    finderArgs, count);
1474
1475                return count.intValue();
1476            }
1477            catch (Exception e) {
1478                throw processException(e);
1479            }
1480            finally {
1481                closeSession(session);
1482            }
1483        }
1484        else {
1485            return ((Long)result).intValue();
1486        }
1487    }
1488
1489    public int countByG_A_V(long groupId, String articleId, double version)
1490        throws SystemException {
1491        boolean finderClassNameCacheEnabled = JournalArticleImageModelImpl.CACHE_ENABLED;
1492        String finderClassName = JournalArticleImage.class.getName();
1493        String finderMethodName = "countByG_A_V";
1494        String[] finderParams = new String[] {
1495                Long.class.getName(), String.class.getName(),
1496                Double.class.getName()
1497            };
1498        Object[] finderArgs = new Object[] {
1499                new Long(groupId),
1500                
1501                articleId, new Double(version)
1502            };
1503
1504        Object result = null;
1505
1506        if (finderClassNameCacheEnabled) {
1507            result = FinderCacheUtil.getResult(finderClassName,
1508                    finderMethodName, finderParams, finderArgs, this);
1509        }
1510
1511        if (result == null) {
1512            Session session = null;
1513
1514            try {
1515                session = openSession();
1516
1517                StringBuilder query = new StringBuilder();
1518
1519                query.append("SELECT COUNT(*) ");
1520                query.append(
1521                    "FROM com.liferay.portlet.journal.model.JournalArticleImage WHERE ");
1522
1523                query.append("groupId = ?");
1524
1525                query.append(" AND ");
1526
1527                if (articleId == null) {
1528                    query.append("articleId IS NULL");
1529                }
1530                else {
1531                    query.append("articleId = ?");
1532                }
1533
1534                query.append(" AND ");
1535
1536                query.append("version = ?");
1537
1538                query.append(" ");
1539
1540                Query q = session.createQuery(query.toString());
1541
1542                QueryPos qPos = QueryPos.getInstance(q);
1543
1544                qPos.add(groupId);
1545
1546                if (articleId != null) {
1547                    qPos.add(articleId);
1548                }
1549
1550                qPos.add(version);
1551
1552                Long count = null;
1553
1554                Iterator<Long> itr = q.list().iterator();
1555
1556                if (itr.hasNext()) {
1557                    count = itr.next();
1558                }
1559
1560                if (count == null) {
1561                    count = new Long(0);
1562                }
1563
1564                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1565                    finderClassName, finderMethodName, finderParams,
1566                    finderArgs, count);
1567
1568                return count.intValue();
1569            }
1570            catch (Exception e) {
1571                throw processException(e);
1572            }
1573            finally {
1574                closeSession(session);
1575            }
1576        }
1577        else {
1578            return ((Long)result).intValue();
1579        }
1580    }
1581
1582    public int countByG_A_V_E_L(long groupId, String articleId, double version,
1583        String elName, String languageId) throws SystemException {
1584        boolean finderClassNameCacheEnabled = JournalArticleImageModelImpl.CACHE_ENABLED;
1585        String finderClassName = JournalArticleImage.class.getName();
1586        String finderMethodName = "countByG_A_V_E_L";
1587        String[] finderParams = new String[] {
1588                Long.class.getName(), String.class.getName(),
1589                Double.class.getName(), String.class.getName(),
1590                String.class.getName()
1591            };
1592        Object[] finderArgs = new Object[] {
1593                new Long(groupId),
1594                
1595                articleId, new Double(version),
1596                
1597                elName,
1598                
1599                languageId
1600            };
1601
1602        Object result = null;
1603
1604        if (finderClassNameCacheEnabled) {
1605            result = FinderCacheUtil.getResult(finderClassName,
1606                    finderMethodName, finderParams, finderArgs, this);
1607        }
1608
1609        if (result == null) {
1610            Session session = null;
1611
1612            try {
1613                session = openSession();
1614
1615                StringBuilder query = new StringBuilder();
1616
1617                query.append("SELECT COUNT(*) ");
1618                query.append(
1619                    "FROM com.liferay.portlet.journal.model.JournalArticleImage WHERE ");
1620
1621                query.append("groupId = ?");
1622
1623                query.append(" AND ");
1624
1625                if (articleId == null) {
1626                    query.append("articleId IS NULL");
1627                }
1628                else {
1629                    query.append("articleId = ?");
1630                }
1631
1632                query.append(" AND ");
1633
1634                query.append("version = ?");
1635
1636                query.append(" AND ");
1637
1638                if (elName == null) {
1639                    query.append("elName IS NULL");
1640                }
1641                else {
1642                    query.append("elName = ?");
1643                }
1644
1645                query.append(" AND ");
1646
1647                if (languageId == null) {
1648                    query.append("languageId IS NULL");
1649                }
1650                else {
1651                    query.append("languageId = ?");
1652                }
1653
1654                query.append(" ");
1655
1656                Query q = session.createQuery(query.toString());
1657
1658                QueryPos qPos = QueryPos.getInstance(q);
1659
1660                qPos.add(groupId);
1661
1662                if (articleId != null) {
1663                    qPos.add(articleId);
1664                }
1665
1666                qPos.add(version);
1667
1668                if (elName != null) {
1669                    qPos.add(elName);
1670                }
1671
1672                if (languageId != null) {
1673                    qPos.add(languageId);
1674                }
1675
1676                Long count = null;
1677
1678                Iterator<Long> itr = q.list().iterator();
1679
1680                if (itr.hasNext()) {
1681                    count = itr.next();
1682                }
1683
1684                if (count == null) {
1685                    count = new Long(0);
1686                }
1687
1688                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1689                    finderClassName, finderMethodName, finderParams,
1690                    finderArgs, count);
1691
1692                return count.intValue();
1693            }
1694            catch (Exception e) {
1695                throw processException(e);
1696            }
1697            finally {
1698                closeSession(session);
1699            }
1700        }
1701        else {
1702            return ((Long)result).intValue();
1703        }
1704    }
1705
1706    public int countAll() throws SystemException {
1707        boolean finderClassNameCacheEnabled = JournalArticleImageModelImpl.CACHE_ENABLED;
1708        String finderClassName = JournalArticleImage.class.getName();
1709        String finderMethodName = "countAll";
1710        String[] finderParams = new String[] {  };
1711        Object[] finderArgs = new Object[] {  };
1712
1713        Object result = null;
1714
1715        if (finderClassNameCacheEnabled) {
1716            result = FinderCacheUtil.getResult(finderClassName,
1717                    finderMethodName, finderParams, finderArgs, this);
1718        }
1719
1720        if (result == null) {
1721            Session session = null;
1722
1723            try {
1724                session = openSession();
1725
1726                Query q = session.createQuery(
1727                        "SELECT COUNT(*) FROM com.liferay.portlet.journal.model.JournalArticleImage");
1728
1729                Long count = null;
1730
1731                Iterator<Long> itr = q.list().iterator();
1732
1733                if (itr.hasNext()) {
1734                    count = itr.next();
1735                }
1736
1737                if (count == null) {
1738                    count = new Long(0);
1739                }
1740
1741                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1742                    finderClassName, finderMethodName, finderParams,
1743                    finderArgs, count);
1744
1745                return count.intValue();
1746            }
1747            catch (Exception e) {
1748                throw processException(e);
1749            }
1750            finally {
1751                closeSession(session);
1752            }
1753        }
1754        else {
1755            return ((Long)result).intValue();
1756        }
1757    }
1758
1759    public void registerListener(ModelListener listener) {
1760        List<ModelListener> listeners = ListUtil.fromArray(_listeners);
1761
1762        listeners.add(listener);
1763
1764        _listeners = listeners.toArray(new ModelListener[listeners.size()]);
1765    }
1766
1767    public void unregisterListener(ModelListener listener) {
1768        List<ModelListener> listeners = ListUtil.fromArray(_listeners);
1769
1770        listeners.remove(listener);
1771
1772        _listeners = listeners.toArray(new ModelListener[listeners.size()]);
1773    }
1774
1775    public void afterPropertiesSet() {
1776        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1777                    com.liferay.portal.util.PropsUtil.get(
1778                        "value.object.listener.com.liferay.portlet.journal.model.JournalArticleImage")));
1779
1780        if (listenerClassNames.length > 0) {
1781            try {
1782                List<ModelListener> listeners = new ArrayList<ModelListener>();
1783
1784                for (String listenerClassName : listenerClassNames) {
1785                    listeners.add((ModelListener)Class.forName(
1786                            listenerClassName).newInstance());
1787                }
1788
1789                _listeners = listeners.toArray(new ModelListener[listeners.size()]);
1790            }
1791            catch (Exception e) {
1792                _log.error(e);
1793            }
1794        }
1795    }
1796
1797    private static Log _log = LogFactory.getLog(JournalArticleImagePersistenceImpl.class);
1798    private ModelListener[] _listeners = new ModelListener[0];
1799}