1   /**
2    * Copyright (c) 2000-2007 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portlet.journal.service.persistence;
24  
25  import com.liferay.portal.SystemException;
26  import com.liferay.portal.kernel.dao.DynamicQuery;
27  import com.liferay.portal.kernel.dao.DynamicQueryInitializer;
28  import com.liferay.portal.kernel.util.OrderByComparator;
29  import com.liferay.portal.kernel.util.StringMaker;
30  import com.liferay.portal.kernel.util.StringPool;
31  import com.liferay.portal.service.persistence.BasePersistence;
32  import com.liferay.portal.spring.hibernate.FinderCache;
33  import com.liferay.portal.spring.hibernate.HibernateUtil;
34  
35  import com.liferay.portlet.journal.NoSuchArticleImageException;
36  import com.liferay.portlet.journal.model.JournalArticleImage;
37  import com.liferay.portlet.journal.model.impl.JournalArticleImageImpl;
38  
39  import com.liferay.util.dao.hibernate.QueryUtil;
40  
41  import org.apache.commons.logging.Log;
42  import org.apache.commons.logging.LogFactory;
43  
44  import org.hibernate.Query;
45  import org.hibernate.Session;
46  
47  import java.util.Collections;
48  import java.util.Iterator;
49  import java.util.List;
50  
51  /**
52   * <a href="JournalArticleImagePersistenceImpl.java.html"><b><i>View Source</i></b></a>
53   *
54   * @author Brian Wing Shun Chan
55   *
56   */
57  public class JournalArticleImagePersistenceImpl extends BasePersistence
58      implements JournalArticleImagePersistence {
59      public JournalArticleImage create(long articleImageId) {
60          JournalArticleImage journalArticleImage = new JournalArticleImageImpl();
61          journalArticleImage.setNew(true);
62          journalArticleImage.setPrimaryKey(articleImageId);
63  
64          return journalArticleImage;
65      }
66  
67      public JournalArticleImage remove(long articleImageId)
68          throws NoSuchArticleImageException, SystemException {
69          Session session = null;
70  
71          try {
72              session = openSession();
73  
74              JournalArticleImage journalArticleImage = (JournalArticleImage)session.get(JournalArticleImageImpl.class,
75                      new Long(articleImageId));
76  
77              if (journalArticleImage == null) {
78                  if (_log.isWarnEnabled()) {
79                      _log.warn(
80                          "No JournalArticleImage exists with the primary key " +
81                          articleImageId);
82                  }
83  
84                  throw new NoSuchArticleImageException(
85                      "No JournalArticleImage exists with the primary key " +
86                      articleImageId);
87              }
88  
89              return remove(journalArticleImage);
90          }
91          catch (NoSuchArticleImageException nsee) {
92              throw nsee;
93          }
94          catch (Exception e) {
95              throw HibernateUtil.processException(e);
96          }
97          finally {
98              closeSession(session);
99          }
100     }
101 
102     public JournalArticleImage remove(JournalArticleImage journalArticleImage)
103         throws SystemException {
104         Session session = null;
105 
106         try {
107             session = openSession();
108             session.delete(journalArticleImage);
109             session.flush();
110 
111             return journalArticleImage;
112         }
113         catch (Exception e) {
114             throw HibernateUtil.processException(e);
115         }
116         finally {
117             closeSession(session);
118             FinderCache.clearCache(JournalArticleImage.class.getName());
119         }
120     }
121 
122     public JournalArticleImage update(
123         com.liferay.portlet.journal.model.JournalArticleImage journalArticleImage)
124         throws SystemException {
125         return update(journalArticleImage, false);
126     }
127 
128     public JournalArticleImage update(
129         com.liferay.portlet.journal.model.JournalArticleImage journalArticleImage,
130         boolean merge) throws SystemException {
131         Session session = null;
132 
133         try {
134             session = openSession();
135 
136             if (merge) {
137                 session.merge(journalArticleImage);
138             }
139             else {
140                 if (journalArticleImage.isNew()) {
141                     session.save(journalArticleImage);
142                 }
143             }
144 
145             session.flush();
146             journalArticleImage.setNew(false);
147 
148             return journalArticleImage;
149         }
150         catch (Exception e) {
151             throw HibernateUtil.processException(e);
152         }
153         finally {
154             closeSession(session);
155             FinderCache.clearCache(JournalArticleImage.class.getName());
156         }
157     }
158 
159     public JournalArticleImage findByPrimaryKey(long articleImageId)
160         throws NoSuchArticleImageException, SystemException {
161         JournalArticleImage journalArticleImage = fetchByPrimaryKey(articleImageId);
162 
163         if (journalArticleImage == null) {
164             if (_log.isWarnEnabled()) {
165                 _log.warn("No JournalArticleImage exists with the primary key " +
166                     articleImageId);
167             }
168 
169             throw new NoSuchArticleImageException(
170                 "No JournalArticleImage exists with the primary key " +
171                 articleImageId);
172         }
173 
174         return journalArticleImage;
175     }
176 
177     public JournalArticleImage fetchByPrimaryKey(long articleImageId)
178         throws SystemException {
179         Session session = null;
180 
181         try {
182             session = openSession();
183 
184             return (JournalArticleImage)session.get(JournalArticleImageImpl.class,
185                 new Long(articleImageId));
186         }
187         catch (Exception e) {
188             throw HibernateUtil.processException(e);
189         }
190         finally {
191             closeSession(session);
192         }
193     }
194 
195     public List findByGroupId(long groupId) throws SystemException {
196         String finderClassName = JournalArticleImage.class.getName();
197         String finderMethodName = "findByGroupId";
198         String[] finderParams = new String[] { Long.class.getName() };
199         Object[] finderArgs = new Object[] { new Long(groupId) };
200         Object result = FinderCache.getResult(finderClassName,
201                 finderMethodName, finderParams, finderArgs, getSessionFactory());
202 
203         if (result == null) {
204             Session session = null;
205 
206             try {
207                 session = openSession();
208 
209                 StringMaker query = new StringMaker();
210                 query.append(
211                     "FROM com.liferay.portlet.journal.model.JournalArticleImage WHERE ");
212                 query.append("groupId = ?");
213                 query.append(" ");
214 
215                 Query q = session.createQuery(query.toString());
216                 int queryPos = 0;
217                 q.setLong(queryPos++, groupId);
218 
219                 List list = q.list();
220                 FinderCache.putResult(finderClassName, finderMethodName,
221                     finderParams, finderArgs, list);
222 
223                 return list;
224             }
225             catch (Exception e) {
226                 throw HibernateUtil.processException(e);
227             }
228             finally {
229                 closeSession(session);
230             }
231         }
232         else {
233             return (List)result;
234         }
235     }
236 
237     public List findByGroupId(long groupId, int begin, int end)
238         throws SystemException {
239         return findByGroupId(groupId, begin, end, null);
240     }
241 
242     public List findByGroupId(long groupId, int begin, int end,
243         OrderByComparator obc) throws SystemException {
244         String finderClassName = JournalArticleImage.class.getName();
245         String finderMethodName = "findByGroupId";
246         String[] finderParams = new String[] {
247                 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
248                 "com.liferay.portal.kernel.util.OrderByComparator"
249             };
250         Object[] finderArgs = new Object[] {
251                 new Long(groupId), String.valueOf(begin), String.valueOf(end),
252                 String.valueOf(obc)
253             };
254         Object result = FinderCache.getResult(finderClassName,
255                 finderMethodName, finderParams, finderArgs, getSessionFactory());
256 
257         if (result == null) {
258             Session session = null;
259 
260             try {
261                 session = openSession();
262 
263                 StringMaker query = new StringMaker();
264                 query.append(
265                     "FROM com.liferay.portlet.journal.model.JournalArticleImage WHERE ");
266                 query.append("groupId = ?");
267                 query.append(" ");
268 
269                 if (obc != null) {
270                     query.append("ORDER BY ");
271                     query.append(obc.getOrderBy());
272                 }
273 
274                 Query q = session.createQuery(query.toString());
275                 int queryPos = 0;
276                 q.setLong(queryPos++, groupId);
277 
278                 List list = QueryUtil.list(q, getDialect(), begin, end);
279                 FinderCache.putResult(finderClassName, finderMethodName,
280                     finderParams, finderArgs, list);
281 
282                 return list;
283             }
284             catch (Exception e) {
285                 throw HibernateUtil.processException(e);
286             }
287             finally {
288                 closeSession(session);
289             }
290         }
291         else {
292             return (List)result;
293         }
294     }
295 
296     public JournalArticleImage findByGroupId_First(long groupId,
297         OrderByComparator obc)
298         throws NoSuchArticleImageException, SystemException {
299         List list = findByGroupId(groupId, 0, 1, obc);
300 
301         if (list.size() == 0) {
302             StringMaker msg = new StringMaker();
303             msg.append("No JournalArticleImage exists with the key ");
304             msg.append(StringPool.OPEN_CURLY_BRACE);
305             msg.append("groupId=");
306             msg.append(groupId);
307             msg.append(StringPool.CLOSE_CURLY_BRACE);
308             throw new NoSuchArticleImageException(msg.toString());
309         }
310         else {
311             return (JournalArticleImage)list.get(0);
312         }
313     }
314 
315     public JournalArticleImage findByGroupId_Last(long groupId,
316         OrderByComparator obc)
317         throws NoSuchArticleImageException, SystemException {
318         int count = countByGroupId(groupId);
319         List list = findByGroupId(groupId, count - 1, count, obc);
320 
321         if (list.size() == 0) {
322             StringMaker msg = new StringMaker();
323             msg.append("No JournalArticleImage exists with the key ");
324             msg.append(StringPool.OPEN_CURLY_BRACE);
325             msg.append("groupId=");
326             msg.append(groupId);
327             msg.append(StringPool.CLOSE_CURLY_BRACE);
328             throw new NoSuchArticleImageException(msg.toString());
329         }
330         else {
331             return (JournalArticleImage)list.get(0);
332         }
333     }
334 
335     public JournalArticleImage[] findByGroupId_PrevAndNext(
336         long articleImageId, long groupId, OrderByComparator obc)
337         throws NoSuchArticleImageException, SystemException {
338         JournalArticleImage journalArticleImage = findByPrimaryKey(articleImageId);
339         int count = countByGroupId(groupId);
340         Session session = null;
341 
342         try {
343             session = openSession();
344 
345             StringMaker query = new StringMaker();
346             query.append(
347                 "FROM com.liferay.portlet.journal.model.JournalArticleImage WHERE ");
348             query.append("groupId = ?");
349             query.append(" ");
350 
351             if (obc != null) {
352                 query.append("ORDER BY ");
353                 query.append(obc.getOrderBy());
354             }
355 
356             Query q = session.createQuery(query.toString());
357             int queryPos = 0;
358             q.setLong(queryPos++, groupId);
359 
360             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
361                     journalArticleImage);
362             JournalArticleImage[] array = new JournalArticleImageImpl[3];
363             array[0] = (JournalArticleImage)objArray[0];
364             array[1] = (JournalArticleImage)objArray[1];
365             array[2] = (JournalArticleImage)objArray[2];
366 
367             return array;
368         }
369         catch (Exception e) {
370             throw HibernateUtil.processException(e);
371         }
372         finally {
373             closeSession(session);
374         }
375     }
376 
377     public List findByTempImage(boolean tempImage) throws SystemException {
378         String finderClassName = JournalArticleImage.class.getName();
379         String finderMethodName = "findByTempImage";
380         String[] finderParams = new String[] { Boolean.class.getName() };
381         Object[] finderArgs = new Object[] { Boolean.valueOf(tempImage) };
382         Object result = FinderCache.getResult(finderClassName,
383                 finderMethodName, finderParams, finderArgs, getSessionFactory());
384 
385         if (result == null) {
386             Session session = null;
387 
388             try {
389                 session = openSession();
390 
391                 StringMaker query = new StringMaker();
392                 query.append(
393                     "FROM com.liferay.portlet.journal.model.JournalArticleImage WHERE ");
394                 query.append("tempImage = ?");
395                 query.append(" ");
396 
397                 Query q = session.createQuery(query.toString());
398                 int queryPos = 0;
399                 q.setBoolean(queryPos++, tempImage);
400 
401                 List list = q.list();
402                 FinderCache.putResult(finderClassName, finderMethodName,
403                     finderParams, finderArgs, list);
404 
405                 return list;
406             }
407             catch (Exception e) {
408                 throw HibernateUtil.processException(e);
409             }
410             finally {
411                 closeSession(session);
412             }
413         }
414         else {
415             return (List)result;
416         }
417     }
418 
419     public List findByTempImage(boolean tempImage, int begin, int end)
420         throws SystemException {
421         return findByTempImage(tempImage, begin, end, null);
422     }
423 
424     public List findByTempImage(boolean tempImage, int begin, int end,
425         OrderByComparator obc) throws SystemException {
426         String finderClassName = JournalArticleImage.class.getName();
427         String finderMethodName = "findByTempImage";
428         String[] finderParams = new String[] {
429                 Boolean.class.getName(), "java.lang.Integer",
430                 "java.lang.Integer",
431                 "com.liferay.portal.kernel.util.OrderByComparator"
432             };
433         Object[] finderArgs = new Object[] {
434                 Boolean.valueOf(tempImage), String.valueOf(begin),
435                 String.valueOf(end), String.valueOf(obc)
436             };
437         Object result = FinderCache.getResult(finderClassName,
438                 finderMethodName, finderParams, finderArgs, getSessionFactory());
439 
440         if (result == null) {
441             Session session = null;
442 
443             try {
444                 session = openSession();
445 
446                 StringMaker query = new StringMaker();
447                 query.append(
448                     "FROM com.liferay.portlet.journal.model.JournalArticleImage WHERE ");
449                 query.append("tempImage = ?");
450                 query.append(" ");
451 
452                 if (obc != null) {
453                     query.append("ORDER BY ");
454                     query.append(obc.getOrderBy());
455                 }
456 
457                 Query q = session.createQuery(query.toString());
458                 int queryPos = 0;
459                 q.setBoolean(queryPos++, tempImage);
460 
461                 List list = QueryUtil.list(q, getDialect(), begin, end);
462                 FinderCache.putResult(finderClassName, finderMethodName,
463                     finderParams, finderArgs, list);
464 
465                 return list;
466             }
467             catch (Exception e) {
468                 throw HibernateUtil.processException(e);
469             }
470             finally {
471                 closeSession(session);
472             }
473         }
474         else {
475             return (List)result;
476         }
477     }
478 
479     public JournalArticleImage findByTempImage_First(boolean tempImage,
480         OrderByComparator obc)
481         throws NoSuchArticleImageException, SystemException {
482         List list = findByTempImage(tempImage, 0, 1, obc);
483 
484         if (list.size() == 0) {
485             StringMaker msg = new StringMaker();
486             msg.append("No JournalArticleImage exists with the key ");
487             msg.append(StringPool.OPEN_CURLY_BRACE);
488             msg.append("tempImage=");
489             msg.append(tempImage);
490             msg.append(StringPool.CLOSE_CURLY_BRACE);
491             throw new NoSuchArticleImageException(msg.toString());
492         }
493         else {
494             return (JournalArticleImage)list.get(0);
495         }
496     }
497 
498     public JournalArticleImage findByTempImage_Last(boolean tempImage,
499         OrderByComparator obc)
500         throws NoSuchArticleImageException, SystemException {
501         int count = countByTempImage(tempImage);
502         List list = findByTempImage(tempImage, count - 1, count, obc);
503 
504         if (list.size() == 0) {
505             StringMaker msg = new StringMaker();
506             msg.append("No JournalArticleImage exists with the key ");
507             msg.append(StringPool.OPEN_CURLY_BRACE);
508             msg.append("tempImage=");
509             msg.append(tempImage);
510             msg.append(StringPool.CLOSE_CURLY_BRACE);
511             throw new NoSuchArticleImageException(msg.toString());
512         }
513         else {
514             return (JournalArticleImage)list.get(0);
515         }
516     }
517 
518     public JournalArticleImage[] findByTempImage_PrevAndNext(
519         long articleImageId, boolean tempImage, OrderByComparator obc)
520         throws NoSuchArticleImageException, SystemException {
521         JournalArticleImage journalArticleImage = findByPrimaryKey(articleImageId);
522         int count = countByTempImage(tempImage);
523         Session session = null;
524 
525         try {
526             session = openSession();
527 
528             StringMaker query = new StringMaker();
529             query.append(
530                 "FROM com.liferay.portlet.journal.model.JournalArticleImage WHERE ");
531             query.append("tempImage = ?");
532             query.append(" ");
533 
534             if (obc != null) {
535                 query.append("ORDER BY ");
536                 query.append(obc.getOrderBy());
537             }
538 
539             Query q = session.createQuery(query.toString());
540             int queryPos = 0;
541             q.setBoolean(queryPos++, tempImage);
542 
543             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
544                     journalArticleImage);
545             JournalArticleImage[] array = new JournalArticleImageImpl[3];
546             array[0] = (JournalArticleImage)objArray[0];
547             array[1] = (JournalArticleImage)objArray[1];
548             array[2] = (JournalArticleImage)objArray[2];
549 
550             return array;
551         }
552         catch (Exception e) {
553             throw HibernateUtil.processException(e);
554         }
555         finally {
556             closeSession(session);
557         }
558     }
559 
560     public List findByG_A_V(long groupId, String articleId, double version)
561         throws SystemException {
562         String finderClassName = JournalArticleImage.class.getName();
563         String finderMethodName = "findByG_A_V";
564         String[] finderParams = new String[] {
565                 Long.class.getName(), String.class.getName(),
566                 Double.class.getName()
567             };
568         Object[] finderArgs = new Object[] {
569                 new Long(groupId), articleId, new Double(version)
570             };
571         Object result = FinderCache.getResult(finderClassName,
572                 finderMethodName, finderParams, finderArgs, getSessionFactory());
573 
574         if (result == null) {
575             Session session = null;
576 
577             try {
578                 session = openSession();
579 
580                 StringMaker query = new StringMaker();
581                 query.append(
582                     "FROM com.liferay.portlet.journal.model.JournalArticleImage WHERE ");
583                 query.append("groupId = ?");
584                 query.append(" AND ");
585 
586                 if (articleId == null) {
587                     query.append("articleId IS NULL");
588                 }
589                 else {
590                     query.append("articleId = ?");
591                 }
592 
593                 query.append(" AND ");
594                 query.append("version = ?");
595                 query.append(" ");
596 
597                 Query q = session.createQuery(query.toString());
598                 int queryPos = 0;
599                 q.setLong(queryPos++, groupId);
600 
601                 if (articleId != null) {
602                     q.setString(queryPos++, articleId);
603                 }
604 
605                 q.setDouble(queryPos++, version);
606 
607                 List list = q.list();
608                 FinderCache.putResult(finderClassName, finderMethodName,
609                     finderParams, finderArgs, list);
610 
611                 return list;
612             }
613             catch (Exception e) {
614                 throw HibernateUtil.processException(e);
615             }
616             finally {
617                 closeSession(session);
618             }
619         }
620         else {
621             return (List)result;
622         }
623     }
624 
625     public List findByG_A_V(long groupId, String articleId, double version,
626         int begin, int end) throws SystemException {
627         return findByG_A_V(groupId, articleId, version, begin, end, null);
628     }
629 
630     public List findByG_A_V(long groupId, String articleId, double version,
631         int begin, int end, OrderByComparator obc) throws SystemException {
632         String finderClassName = JournalArticleImage.class.getName();
633         String finderMethodName = "findByG_A_V";
634         String[] finderParams = new String[] {
635                 Long.class.getName(), String.class.getName(),
636                 Double.class.getName(), "java.lang.Integer", "java.lang.Integer",
637                 "com.liferay.portal.kernel.util.OrderByComparator"
638             };
639         Object[] finderArgs = new Object[] {
640                 new Long(groupId), articleId, new Double(version),
641                 String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
642             };
643         Object result = FinderCache.getResult(finderClassName,
644                 finderMethodName, finderParams, finderArgs, getSessionFactory());
645 
646         if (result == null) {
647             Session session = null;
648 
649             try {
650                 session = openSession();
651 
652                 StringMaker query = new StringMaker();
653                 query.append(
654                     "FROM com.liferay.portlet.journal.model.JournalArticleImage WHERE ");
655                 query.append("groupId = ?");
656                 query.append(" AND ");
657 
658                 if (articleId == null) {
659                     query.append("articleId IS NULL");
660                 }
661                 else {
662                     query.append("articleId = ?");
663                 }
664 
665                 query.append(" AND ");
666                 query.append("version = ?");
667                 query.append(" ");
668 
669                 if (obc != null) {
670                     query.append("ORDER BY ");
671                     query.append(obc.getOrderBy());
672                 }
673 
674                 Query q = session.createQuery(query.toString());
675                 int queryPos = 0;
676                 q.setLong(queryPos++, groupId);
677 
678                 if (articleId != null) {
679                     q.setString(queryPos++, articleId);
680                 }
681 
682                 q.setDouble(queryPos++, version);
683 
684                 List list = QueryUtil.list(q, getDialect(), begin, end);
685                 FinderCache.putResult(finderClassName, finderMethodName,
686                     finderParams, finderArgs, list);
687 
688                 return list;
689             }
690             catch (Exception e) {
691                 throw HibernateUtil.processException(e);
692             }
693             finally {
694                 closeSession(session);
695             }
696         }
697         else {
698             return (List)result;
699         }
700     }
701 
702     public JournalArticleImage findByG_A_V_First(long groupId,
703         String articleId, double version, OrderByComparator obc)
704         throws NoSuchArticleImageException, SystemException {
705         List list = findByG_A_V(groupId, articleId, version, 0, 1, obc);
706 
707         if (list.size() == 0) {
708             StringMaker msg = new StringMaker();
709             msg.append("No JournalArticleImage exists with the key ");
710             msg.append(StringPool.OPEN_CURLY_BRACE);
711             msg.append("groupId=");
712             msg.append(groupId);
713             msg.append(", ");
714             msg.append("articleId=");
715             msg.append(articleId);
716             msg.append(", ");
717             msg.append("version=");
718             msg.append(version);
719             msg.append(StringPool.CLOSE_CURLY_BRACE);
720             throw new NoSuchArticleImageException(msg.toString());
721         }
722         else {
723             return (JournalArticleImage)list.get(0);
724         }
725     }
726 
727     public JournalArticleImage findByG_A_V_Last(long groupId, String articleId,
728         double version, OrderByComparator obc)
729         throws NoSuchArticleImageException, SystemException {
730         int count = countByG_A_V(groupId, articleId, version);
731         List list = findByG_A_V(groupId, articleId, version, count - 1, count,
732                 obc);
733 
734         if (list.size() == 0) {
735             StringMaker msg = new StringMaker();
736             msg.append("No JournalArticleImage exists with the key ");
737             msg.append(StringPool.OPEN_CURLY_BRACE);
738             msg.append("groupId=");
739             msg.append(groupId);
740             msg.append(", ");
741             msg.append("articleId=");
742             msg.append(articleId);
743             msg.append(", ");
744             msg.append("version=");
745             msg.append(version);
746             msg.append(StringPool.CLOSE_CURLY_BRACE);
747             throw new NoSuchArticleImageException(msg.toString());
748         }
749         else {
750             return (JournalArticleImage)list.get(0);
751         }
752     }
753 
754     public JournalArticleImage[] findByG_A_V_PrevAndNext(long articleImageId,
755         long groupId, String articleId, double version, OrderByComparator obc)
756         throws NoSuchArticleImageException, SystemException {
757         JournalArticleImage journalArticleImage = findByPrimaryKey(articleImageId);
758         int count = countByG_A_V(groupId, articleId, version);
759         Session session = null;
760 
761         try {
762             session = openSession();
763 
764             StringMaker query = new StringMaker();
765             query.append(
766                 "FROM com.liferay.portlet.journal.model.JournalArticleImage WHERE ");
767             query.append("groupId = ?");
768             query.append(" AND ");
769 
770             if (articleId == null) {
771                 query.append("articleId IS NULL");
772             }
773             else {
774                 query.append("articleId = ?");
775             }
776 
777             query.append(" AND ");
778             query.append("version = ?");
779             query.append(" ");
780 
781             if (obc != null) {
782                 query.append("ORDER BY ");
783                 query.append(obc.getOrderBy());
784             }
785 
786             Query q = session.createQuery(query.toString());
787             int queryPos = 0;
788             q.setLong(queryPos++, groupId);
789 
790             if (articleId != null) {
791                 q.setString(queryPos++, articleId);
792             }
793 
794             q.setDouble(queryPos++, version);
795 
796             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
797                     journalArticleImage);
798             JournalArticleImage[] array = new JournalArticleImageImpl[3];
799             array[0] = (JournalArticleImage)objArray[0];
800             array[1] = (JournalArticleImage)objArray[1];
801             array[2] = (JournalArticleImage)objArray[2];
802 
803             return array;
804         }
805         catch (Exception e) {
806             throw HibernateUtil.processException(e);
807         }
808         finally {
809             closeSession(session);
810         }
811     }
812 
813     public JournalArticleImage findByG_A_V_E_L(long groupId, String articleId,
814         double version, String elName, String languageId)
815         throws NoSuchArticleImageException, SystemException {
816         JournalArticleImage journalArticleImage = fetchByG_A_V_E_L(groupId,
817                 articleId, version, elName, languageId);
818 
819         if (journalArticleImage == null) {
820             StringMaker msg = new StringMaker();
821             msg.append("No JournalArticleImage exists with the key ");
822             msg.append(StringPool.OPEN_CURLY_BRACE);
823             msg.append("groupId=");
824             msg.append(groupId);
825             msg.append(", ");
826             msg.append("articleId=");
827             msg.append(articleId);
828             msg.append(", ");
829             msg.append("version=");
830             msg.append(version);
831             msg.append(", ");
832             msg.append("elName=");
833             msg.append(elName);
834             msg.append(", ");
835             msg.append("languageId=");
836             msg.append(languageId);
837             msg.append(StringPool.CLOSE_CURLY_BRACE);
838 
839             if (_log.isWarnEnabled()) {
840                 _log.warn(msg.toString());
841             }
842 
843             throw new NoSuchArticleImageException(msg.toString());
844         }
845 
846         return journalArticleImage;
847     }
848 
849     public JournalArticleImage fetchByG_A_V_E_L(long groupId, String articleId,
850         double version, String elName, String languageId)
851         throws SystemException {
852         String finderClassName = JournalArticleImage.class.getName();
853         String finderMethodName = "fetchByG_A_V_E_L";
854         String[] finderParams = new String[] {
855                 Long.class.getName(), String.class.getName(),
856                 Double.class.getName(), String.class.getName(),
857                 String.class.getName()
858             };
859         Object[] finderArgs = new Object[] {
860                 new Long(groupId), articleId, new Double(version), elName,
861                 languageId
862             };
863         Object result = FinderCache.getResult(finderClassName,
864                 finderMethodName, finderParams, finderArgs, getSessionFactory());
865 
866         if (result == null) {
867             Session session = null;
868 
869             try {
870                 session = openSession();
871 
872                 StringMaker query = new StringMaker();
873                 query.append(
874                     "FROM com.liferay.portlet.journal.model.JournalArticleImage WHERE ");
875                 query.append("groupId = ?");
876                 query.append(" AND ");
877 
878                 if (articleId == null) {
879                     query.append("articleId IS NULL");
880                 }
881                 else {
882                     query.append("articleId = ?");
883                 }
884 
885                 query.append(" AND ");
886                 query.append("version = ?");
887                 query.append(" AND ");
888 
889                 if (elName == null) {
890                     query.append("elName IS NULL");
891                 }
892                 else {
893                     query.append("elName = ?");
894                 }
895 
896                 query.append(" AND ");
897 
898                 if (languageId == null) {
899                     query.append("languageId IS NULL");
900                 }
901                 else {
902                     query.append("languageId = ?");
903                 }
904 
905                 query.append(" ");
906 
907                 Query q = session.createQuery(query.toString());
908                 int queryPos = 0;
909                 q.setLong(queryPos++, groupId);
910 
911                 if (articleId != null) {
912                     q.setString(queryPos++, articleId);
913                 }
914 
915                 q.setDouble(queryPos++, version);
916 
917                 if (elName != null) {
918                     q.setString(queryPos++, elName);
919                 }
920 
921                 if (languageId != null) {
922                     q.setString(queryPos++, languageId);
923                 }
924 
925                 List list = q.list();
926                 FinderCache.putResult(finderClassName, finderMethodName,
927                     finderParams, finderArgs, list);
928 
929                 if (list.size() == 0) {
930                     return null;
931                 }
932                 else {
933                     return (JournalArticleImage)list.get(0);
934                 }
935             }
936             catch (Exception e) {
937                 throw HibernateUtil.processException(e);
938             }
939             finally {
940                 closeSession(session);
941             }
942         }
943         else {
944             List list = (List)result;
945 
946             if (list.size() == 0) {
947                 return null;
948             }
949             else {
950                 return (JournalArticleImage)list.get(0);
951             }
952         }
953     }
954 
955     public List findWithDynamicQuery(DynamicQueryInitializer queryInitializer)
956         throws SystemException {
957         Session session = null;
958 
959         try {
960             session = openSession();
961 
962             DynamicQuery query = queryInitializer.initialize(session);
963 
964             return query.list();
965         }
966         catch (Exception e) {
967             throw HibernateUtil.processException(e);
968         }
969         finally {
970             closeSession(session);
971         }
972     }
973 
974     public List findWithDynamicQuery(DynamicQueryInitializer queryInitializer,
975         int begin, int end) throws SystemException {
976         Session session = null;
977 
978         try {
979             session = openSession();
980 
981             DynamicQuery query = queryInitializer.initialize(session);
982             query.setLimit(begin, end);
983 
984             return query.list();
985         }
986         catch (Exception e) {
987             throw HibernateUtil.processException(e);
988         }
989         finally {
990             closeSession(session);
991         }
992     }
993 
994     public List findAll() throws SystemException {
995         return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
996     }
997 
998     public List findAll(int begin, int end) throws SystemException {
999         return findAll(begin, end, null);
1000    }
1001
1002    public List findAll(int begin, int end, OrderByComparator obc)
1003        throws SystemException {
1004        String finderClassName = JournalArticleImage.class.getName();
1005        String finderMethodName = "findAll";
1006        String[] finderParams = new String[] {
1007                "java.lang.Integer", "java.lang.Integer",
1008                "com.liferay.portal.kernel.util.OrderByComparator"
1009            };
1010        Object[] finderArgs = new Object[] {
1011                String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
1012            };
1013        Object result = FinderCache.getResult(finderClassName,
1014                finderMethodName, finderParams, finderArgs, getSessionFactory());
1015
1016        if (result == null) {
1017            Session session = null;
1018
1019            try {
1020                session = openSession();
1021
1022                StringMaker query = new StringMaker();
1023                query.append(
1024                    "FROM com.liferay.portlet.journal.model.JournalArticleImage ");
1025
1026                if (obc != null) {
1027                    query.append("ORDER BY ");
1028                    query.append(obc.getOrderBy());
1029                }
1030
1031                Query q = session.createQuery(query.toString());
1032                List list = QueryUtil.list(q, getDialect(), begin, end);
1033
1034                if (obc == null) {
1035                    Collections.sort(list);
1036                }
1037
1038                FinderCache.putResult(finderClassName, finderMethodName,
1039                    finderParams, finderArgs, list);
1040
1041                return list;
1042            }
1043            catch (Exception e) {
1044                throw HibernateUtil.processException(e);
1045            }
1046            finally {
1047                closeSession(session);
1048            }
1049        }
1050        else {
1051            return (List)result;
1052        }
1053    }
1054
1055    public void removeByGroupId(long groupId) throws SystemException {
1056        Iterator itr = findByGroupId(groupId).iterator();
1057
1058        while (itr.hasNext()) {
1059            JournalArticleImage journalArticleImage = (JournalArticleImage)itr.next();
1060            remove(journalArticleImage);
1061        }
1062    }
1063
1064    public void removeByTempImage(boolean tempImage) throws SystemException {
1065        Iterator itr = findByTempImage(tempImage).iterator();
1066
1067        while (itr.hasNext()) {
1068            JournalArticleImage journalArticleImage = (JournalArticleImage)itr.next();
1069            remove(journalArticleImage);
1070        }
1071    }
1072
1073    public void removeByG_A_V(long groupId, String articleId, double version)
1074        throws SystemException {
1075        Iterator itr = findByG_A_V(groupId, articleId, version).iterator();
1076
1077        while (itr.hasNext()) {
1078            JournalArticleImage journalArticleImage = (JournalArticleImage)itr.next();
1079            remove(journalArticleImage);
1080        }
1081    }
1082
1083    public void removeByG_A_V_E_L(long groupId, String articleId,
1084        double version, String elName, String languageId)
1085        throws NoSuchArticleImageException, SystemException {
1086        JournalArticleImage journalArticleImage = findByG_A_V_E_L(groupId,
1087                articleId, version, elName, languageId);
1088        remove(journalArticleImage);
1089    }
1090
1091    public void removeAll() throws SystemException {
1092        Iterator itr = findAll().iterator();
1093
1094        while (itr.hasNext()) {
1095            remove((JournalArticleImage)itr.next());
1096        }
1097    }
1098
1099    public int countByGroupId(long groupId) throws SystemException {
1100        String finderClassName = JournalArticleImage.class.getName();
1101        String finderMethodName = "countByGroupId";
1102        String[] finderParams = new String[] { Long.class.getName() };
1103        Object[] finderArgs = new Object[] { new Long(groupId) };
1104        Object result = FinderCache.getResult(finderClassName,
1105                finderMethodName, finderParams, finderArgs, getSessionFactory());
1106
1107        if (result == null) {
1108            Session session = null;
1109
1110            try {
1111                session = openSession();
1112
1113                StringMaker query = new StringMaker();
1114                query.append("SELECT COUNT(*) ");
1115                query.append(
1116                    "FROM com.liferay.portlet.journal.model.JournalArticleImage WHERE ");
1117                query.append("groupId = ?");
1118                query.append(" ");
1119
1120                Query q = session.createQuery(query.toString());
1121                int queryPos = 0;
1122                q.setLong(queryPos++, groupId);
1123
1124                Long count = null;
1125                Iterator itr = q.list().iterator();
1126
1127                if (itr.hasNext()) {
1128                    count = (Long)itr.next();
1129                }
1130
1131                if (count == null) {
1132                    count = new Long(0);
1133                }
1134
1135                FinderCache.putResult(finderClassName, finderMethodName,
1136                    finderParams, finderArgs, count);
1137
1138                return count.intValue();
1139            }
1140            catch (Exception e) {
1141                throw HibernateUtil.processException(e);
1142            }
1143            finally {
1144                closeSession(session);
1145            }
1146        }
1147        else {
1148            return ((Long)result).intValue();
1149        }
1150    }
1151
1152    public int countByTempImage(boolean tempImage) throws SystemException {
1153        String finderClassName = JournalArticleImage.class.getName();
1154        String finderMethodName = "countByTempImage";
1155        String[] finderParams = new String[] { Boolean.class.getName() };
1156        Object[] finderArgs = new Object[] { Boolean.valueOf(tempImage) };
1157        Object result = FinderCache.getResult(finderClassName,
1158                finderMethodName, finderParams, finderArgs, getSessionFactory());
1159
1160        if (result == null) {
1161            Session session = null;
1162
1163            try {
1164                session = openSession();
1165
1166                StringMaker query = new StringMaker();
1167                query.append("SELECT COUNT(*) ");
1168                query.append(
1169                    "FROM com.liferay.portlet.journal.model.JournalArticleImage WHERE ");
1170                query.append("tempImage = ?");
1171                query.append(" ");
1172
1173                Query q = session.createQuery(query.toString());
1174                int queryPos = 0;
1175                q.setBoolean(queryPos++, tempImage);
1176
1177                Long count = null;
1178                Iterator itr = q.list().iterator();
1179
1180                if (itr.hasNext()) {
1181                    count = (Long)itr.next();
1182                }
1183
1184                if (count == null) {
1185                    count = new Long(0);
1186                }
1187
1188                FinderCache.putResult(finderClassName, finderMethodName,
1189                    finderParams, finderArgs, count);
1190
1191                return count.intValue();
1192            }
1193            catch (Exception e) {
1194                throw HibernateUtil.processException(e);
1195            }
1196            finally {
1197                closeSession(session);
1198            }
1199        }
1200        else {
1201            return ((Long)result).intValue();
1202        }
1203    }
1204
1205    public int countByG_A_V(long groupId, String articleId, double version)
1206        throws SystemException {
1207        String finderClassName = JournalArticleImage.class.getName();
1208        String finderMethodName = "countByG_A_V";
1209        String[] finderParams = new String[] {
1210                Long.class.getName(), String.class.getName(),
1211                Double.class.getName()
1212            };
1213        Object[] finderArgs = new Object[] {
1214                new Long(groupId), articleId, new Double(version)
1215            };
1216        Object result = FinderCache.getResult(finderClassName,
1217                finderMethodName, finderParams, finderArgs, getSessionFactory());
1218
1219        if (result == null) {
1220            Session session = null;
1221
1222            try {
1223                session = openSession();
1224
1225                StringMaker query = new StringMaker();
1226                query.append("SELECT COUNT(*) ");
1227                query.append(
1228                    "FROM com.liferay.portlet.journal.model.JournalArticleImage WHERE ");
1229                query.append("groupId = ?");
1230                query.append(" AND ");
1231
1232                if (articleId == null) {
1233                    query.append("articleId IS NULL");
1234                }
1235                else {
1236                    query.append("articleId = ?");
1237                }
1238
1239                query.append(" AND ");
1240                query.append("version = ?");
1241                query.append(" ");
1242
1243                Query q = session.createQuery(query.toString());
1244                int queryPos = 0;
1245                q.setLong(queryPos++, groupId);
1246
1247                if (articleId != null) {
1248                    q.setString(queryPos++, articleId);
1249                }
1250
1251                q.setDouble(queryPos++, version);
1252
1253                Long count = null;
1254                Iterator itr = q.list().iterator();
1255
1256                if (itr.hasNext()) {
1257                    count = (Long)itr.next();
1258                }
1259
1260                if (count == null) {
1261                    count = new Long(0);
1262                }
1263
1264                FinderCache.putResult(finderClassName, finderMethodName,
1265                    finderParams, finderArgs, count);
1266
1267                return count.intValue();
1268            }
1269            catch (Exception e) {
1270                throw HibernateUtil.processException(e);
1271            }
1272            finally {
1273                closeSession(session);
1274            }
1275        }
1276        else {
1277            return ((Long)result).intValue();
1278        }
1279    }
1280
1281    public int countByG_A_V_E_L(long groupId, String articleId, double version,
1282        String elName, String languageId) throws SystemException {
1283        String finderClassName = JournalArticleImage.class.getName();
1284        String finderMethodName = "countByG_A_V_E_L";
1285        String[] finderParams = new String[] {
1286                Long.class.getName(), String.class.getName(),
1287                Double.class.getName(), String.class.getName(),
1288                String.class.getName()
1289            };
1290        Object[] finderArgs = new Object[] {
1291                new Long(groupId), articleId, new Double(version), elName,
1292                languageId
1293            };
1294        Object result = FinderCache.getResult(finderClassName,
1295                finderMethodName, finderParams, finderArgs, getSessionFactory());
1296
1297        if (result == null) {
1298            Session session = null;
1299
1300            try {
1301                session = openSession();
1302
1303                StringMaker query = new StringMaker();
1304                query.append("SELECT COUNT(*) ");
1305                query.append(
1306                    "FROM com.liferay.portlet.journal.model.JournalArticleImage WHERE ");
1307                query.append("groupId = ?");
1308                query.append(" AND ");
1309
1310                if (articleId == null) {
1311                    query.append("articleId IS NULL");
1312                }
1313                else {
1314                    query.append("articleId = ?");
1315                }
1316
1317                query.append(" AND ");
1318                query.append("version = ?");
1319                query.append(" AND ");
1320
1321                if (elName == null) {
1322                    query.append("elName IS NULL");
1323                }
1324                else {
1325                    query.append("elName = ?");
1326                }
1327
1328                query.append(" AND ");
1329
1330                if (languageId == null) {
1331                    query.append("languageId IS NULL");
1332                }
1333                else {
1334                    query.append("languageId = ?");
1335                }
1336
1337                query.append(" ");
1338
1339                Query q = session.createQuery(query.toString());
1340                int queryPos = 0;
1341                q.setLong(queryPos++, groupId);
1342
1343                if (articleId != null) {
1344                    q.setString(queryPos++, articleId);
1345                }
1346
1347                q.setDouble(queryPos++, version);
1348
1349                if (elName != null) {
1350                    q.setString(queryPos++, elName);
1351                }
1352
1353                if (languageId != null) {
1354                    q.setString(queryPos++, languageId);
1355                }
1356
1357                Long count = null;
1358                Iterator itr = q.list().iterator();
1359
1360                if (itr.hasNext()) {
1361                    count = (Long)itr.next();
1362                }
1363
1364                if (count == null) {
1365                    count = new Long(0);
1366                }
1367
1368                FinderCache.putResult(finderClassName, finderMethodName,
1369                    finderParams, finderArgs, count);
1370
1371                return count.intValue();
1372            }
1373            catch (Exception e) {
1374                throw HibernateUtil.processException(e);
1375            }
1376            finally {
1377                closeSession(session);
1378            }
1379        }
1380        else {
1381            return ((Long)result).intValue();
1382        }
1383    }
1384
1385    public int countAll() throws SystemException {
1386        String finderClassName = JournalArticleImage.class.getName();
1387        String finderMethodName = "countAll";
1388        String[] finderParams = new String[] {  };
1389        Object[] finderArgs = new Object[] {  };
1390        Object result = FinderCache.getResult(finderClassName,
1391                finderMethodName, finderParams, finderArgs, getSessionFactory());
1392
1393        if (result == null) {
1394            Session session = null;
1395
1396            try {
1397                session = openSession();
1398
1399                StringMaker query = new StringMaker();
1400                query.append("SELECT COUNT(*) ");
1401                query.append(
1402                    "FROM com.liferay.portlet.journal.model.JournalArticleImage");
1403
1404                Query q = session.createQuery(query.toString());
1405                Long count = null;
1406                Iterator itr = q.list().iterator();
1407
1408                if (itr.hasNext()) {
1409                    count = (Long)itr.next();
1410                }
1411
1412                if (count == null) {
1413                    count = new Long(0);
1414                }
1415
1416                FinderCache.putResult(finderClassName, finderMethodName,
1417                    finderParams, finderArgs, count);
1418
1419                return count.intValue();
1420            }
1421            catch (Exception e) {
1422                throw HibernateUtil.processException(e);
1423            }
1424            finally {
1425                closeSession(session);
1426            }
1427        }
1428        else {
1429            return ((Long)result).intValue();
1430        }
1431    }
1432
1433    protected void initDao() {
1434    }
1435
1436    private static Log _log = LogFactory.getLog(JournalArticleImagePersistenceImpl.class);
1437}