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.imagegallery.service.persistence;
24  
25  import com.liferay.portal.SystemException;
26  import com.liferay.portal.kernel.dao.DynamicQuery;
27  import com.liferay.portal.kernel.dao.DynamicQueryInitializer;
28  import com.liferay.portal.kernel.util.GetterUtil;
29  import com.liferay.portal.kernel.util.OrderByComparator;
30  import com.liferay.portal.kernel.util.StringMaker;
31  import com.liferay.portal.kernel.util.StringPool;
32  import com.liferay.portal.kernel.util.StringUtil;
33  import com.liferay.portal.kernel.util.Validator;
34  import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
35  import com.liferay.portal.model.ModelListener;
36  import com.liferay.portal.service.persistence.BasePersistence;
37  import com.liferay.portal.spring.hibernate.FinderCache;
38  import com.liferay.portal.spring.hibernate.HibernateUtil;
39  import com.liferay.portal.util.PropsUtil;
40  
41  import com.liferay.portlet.imagegallery.NoSuchImageException;
42  import com.liferay.portlet.imagegallery.model.IGImage;
43  import com.liferay.portlet.imagegallery.model.impl.IGImageImpl;
44  import com.liferay.portlet.imagegallery.model.impl.IGImageModelImpl;
45  
46  import com.liferay.util.dao.hibernate.QueryUtil;
47  
48  import org.apache.commons.logging.Log;
49  import org.apache.commons.logging.LogFactory;
50  
51  import org.hibernate.Query;
52  import org.hibernate.Session;
53  
54  import java.util.ArrayList;
55  import java.util.Collections;
56  import java.util.Iterator;
57  import java.util.List;
58  
59  /**
60   * <a href="IGImagePersistenceImpl.java.html"><b><i>View Source</i></b></a>
61   *
62   * @author Brian Wing Shun Chan
63   *
64   */
65  public class IGImagePersistenceImpl extends BasePersistence
66      implements IGImagePersistence {
67      public IGImage create(long imageId) {
68          IGImage igImage = new IGImageImpl();
69  
70          igImage.setNew(true);
71          igImage.setPrimaryKey(imageId);
72  
73          String uuid = PortalUUIDUtil.generate();
74  
75          igImage.setUuid(uuid);
76  
77          return igImage;
78      }
79  
80      public IGImage remove(long imageId)
81          throws NoSuchImageException, SystemException {
82          Session session = null;
83  
84          try {
85              session = openSession();
86  
87              IGImage igImage = (IGImage)session.get(IGImageImpl.class,
88                      new Long(imageId));
89  
90              if (igImage == null) {
91                  if (_log.isWarnEnabled()) {
92                      _log.warn("No IGImage exists with the primary key " +
93                          imageId);
94                  }
95  
96                  throw new NoSuchImageException(
97                      "No IGImage exists with the primary key " + imageId);
98              }
99  
100             return remove(igImage);
101         }
102         catch (NoSuchImageException nsee) {
103             throw nsee;
104         }
105         catch (Exception e) {
106             throw HibernateUtil.processException(e);
107         }
108         finally {
109             closeSession(session);
110         }
111     }
112 
113     public IGImage remove(IGImage igImage) throws SystemException {
114         if (_listeners != null) {
115             for (ModelListener listener : _listeners) {
116                 listener.onBeforeRemove(igImage);
117             }
118         }
119 
120         igImage = removeImpl(igImage);
121 
122         if (_listeners != null) {
123             for (ModelListener listener : _listeners) {
124                 listener.onAfterRemove(igImage);
125             }
126         }
127 
128         return igImage;
129     }
130 
131     protected IGImage removeImpl(IGImage igImage) throws SystemException {
132         Session session = null;
133 
134         try {
135             session = openSession();
136 
137             session.delete(igImage);
138 
139             session.flush();
140 
141             return igImage;
142         }
143         catch (Exception e) {
144             throw HibernateUtil.processException(e);
145         }
146         finally {
147             closeSession(session);
148 
149             FinderCache.clearCache(IGImage.class.getName());
150         }
151     }
152 
153     /**
154      * @deprecated Use <code>update(IGImage igImage, boolean merge)</code>.
155      */
156     public IGImage update(IGImage igImage) throws SystemException {
157         if (_log.isWarnEnabled()) {
158             _log.warn(
159                 "Using the deprecated update(IGImage igImage) method. Use update(IGImage igImage, boolean merge) instead.");
160         }
161 
162         return update(igImage, false);
163     }
164 
165     /**
166      * Add, update, or merge, the entity. This method also calls the model
167      * listeners to trigger the proper events associated with adding, deleting,
168      * or updating an entity.
169      *
170      * @param        igImage the entity to add, update, or merge
171      * @param        merge boolean value for whether to merge the entity. The
172      *                default value is false. Setting merge to true is more
173      *                expensive and should only be true when igImage is
174      *                transient. See LEP-5473 for a detailed discussion of this
175      *                method.
176      * @return        true if the portlet can be displayed via Ajax
177      */
178     public IGImage update(IGImage igImage, boolean merge)
179         throws SystemException {
180         boolean isNew = igImage.isNew();
181 
182         if (_listeners != null) {
183             for (ModelListener listener : _listeners) {
184                 if (isNew) {
185                     listener.onBeforeCreate(igImage);
186                 }
187                 else {
188                     listener.onBeforeUpdate(igImage);
189                 }
190             }
191         }
192 
193         igImage = updateImpl(igImage, merge);
194 
195         if (_listeners != null) {
196             for (ModelListener listener : _listeners) {
197                 if (isNew) {
198                     listener.onAfterCreate(igImage);
199                 }
200                 else {
201                     listener.onAfterUpdate(igImage);
202                 }
203             }
204         }
205 
206         return igImage;
207     }
208 
209     public IGImage updateImpl(
210         com.liferay.portlet.imagegallery.model.IGImage igImage, boolean merge)
211         throws SystemException {
212         if (Validator.isNull(igImage.getUuid())) {
213             String uuid = PortalUUIDUtil.generate();
214 
215             igImage.setUuid(uuid);
216         }
217 
218         Session session = null;
219 
220         try {
221             session = openSession();
222 
223             if (merge) {
224                 session.merge(igImage);
225             }
226             else {
227                 if (igImage.isNew()) {
228                     session.save(igImage);
229                 }
230             }
231 
232             session.flush();
233 
234             igImage.setNew(false);
235 
236             return igImage;
237         }
238         catch (Exception e) {
239             throw HibernateUtil.processException(e);
240         }
241         finally {
242             closeSession(session);
243 
244             FinderCache.clearCache(IGImage.class.getName());
245         }
246     }
247 
248     public IGImage findByPrimaryKey(long imageId)
249         throws NoSuchImageException, SystemException {
250         IGImage igImage = fetchByPrimaryKey(imageId);
251 
252         if (igImage == null) {
253             if (_log.isWarnEnabled()) {
254                 _log.warn("No IGImage exists with the primary key " + imageId);
255             }
256 
257             throw new NoSuchImageException(
258                 "No IGImage exists with the primary key " + imageId);
259         }
260 
261         return igImage;
262     }
263 
264     public IGImage fetchByPrimaryKey(long imageId) throws SystemException {
265         Session session = null;
266 
267         try {
268             session = openSession();
269 
270             return (IGImage)session.get(IGImageImpl.class, new Long(imageId));
271         }
272         catch (Exception e) {
273             throw HibernateUtil.processException(e);
274         }
275         finally {
276             closeSession(session);
277         }
278     }
279 
280     public List<IGImage> findByUuid(String uuid) throws SystemException {
281         boolean finderClassNameCacheEnabled = IGImageModelImpl.CACHE_ENABLED;
282         String finderClassName = IGImage.class.getName();
283         String finderMethodName = "findByUuid";
284         String[] finderParams = new String[] { String.class.getName() };
285         Object[] finderArgs = new Object[] { uuid };
286 
287         Object result = null;
288 
289         if (finderClassNameCacheEnabled) {
290             result = FinderCache.getResult(finderClassName, finderMethodName,
291                     finderParams, finderArgs, getSessionFactory());
292         }
293 
294         if (result == null) {
295             Session session = null;
296 
297             try {
298                 session = openSession();
299 
300                 StringMaker query = new StringMaker();
301 
302                 query.append(
303                     "FROM com.liferay.portlet.imagegallery.model.IGImage WHERE ");
304 
305                 if (uuid == null) {
306                     query.append("uuid_ IS NULL");
307                 }
308                 else {
309                     query.append("uuid_ = ?");
310                 }
311 
312                 query.append(" ");
313 
314                 query.append("ORDER BY ");
315 
316                 query.append("imageId ASC");
317 
318                 Query q = session.createQuery(query.toString());
319 
320                 int queryPos = 0;
321 
322                 if (uuid != null) {
323                     q.setString(queryPos++, uuid);
324                 }
325 
326                 List<IGImage> list = q.list();
327 
328                 FinderCache.putResult(finderClassNameCacheEnabled,
329                     finderClassName, finderMethodName, finderParams,
330                     finderArgs, list);
331 
332                 return list;
333             }
334             catch (Exception e) {
335                 throw HibernateUtil.processException(e);
336             }
337             finally {
338                 closeSession(session);
339             }
340         }
341         else {
342             return (List<IGImage>)result;
343         }
344     }
345 
346     public List<IGImage> findByUuid(String uuid, int begin, int end)
347         throws SystemException {
348         return findByUuid(uuid, begin, end, null);
349     }
350 
351     public List<IGImage> findByUuid(String uuid, int begin, int end,
352         OrderByComparator obc) throws SystemException {
353         boolean finderClassNameCacheEnabled = IGImageModelImpl.CACHE_ENABLED;
354         String finderClassName = IGImage.class.getName();
355         String finderMethodName = "findByUuid";
356         String[] finderParams = new String[] {
357                 String.class.getName(),
358                 
359                 "java.lang.Integer", "java.lang.Integer",
360                 "com.liferay.portal.kernel.util.OrderByComparator"
361             };
362         Object[] finderArgs = new Object[] {
363                 uuid,
364                 
365                 String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
366             };
367 
368         Object result = null;
369 
370         if (finderClassNameCacheEnabled) {
371             result = FinderCache.getResult(finderClassName, finderMethodName,
372                     finderParams, finderArgs, getSessionFactory());
373         }
374 
375         if (result == null) {
376             Session session = null;
377 
378             try {
379                 session = openSession();
380 
381                 StringMaker query = new StringMaker();
382 
383                 query.append(
384                     "FROM com.liferay.portlet.imagegallery.model.IGImage WHERE ");
385 
386                 if (uuid == null) {
387                     query.append("uuid_ IS NULL");
388                 }
389                 else {
390                     query.append("uuid_ = ?");
391                 }
392 
393                 query.append(" ");
394 
395                 if (obc != null) {
396                     query.append("ORDER BY ");
397                     query.append(obc.getOrderBy());
398                 }
399 
400                 else {
401                     query.append("ORDER BY ");
402 
403                     query.append("imageId ASC");
404                 }
405 
406                 Query q = session.createQuery(query.toString());
407 
408                 int queryPos = 0;
409 
410                 if (uuid != null) {
411                     q.setString(queryPos++, uuid);
412                 }
413 
414                 List<IGImage> list = (List<IGImage>)QueryUtil.list(q,
415                         getDialect(), begin, end);
416 
417                 FinderCache.putResult(finderClassNameCacheEnabled,
418                     finderClassName, finderMethodName, finderParams,
419                     finderArgs, list);
420 
421                 return list;
422             }
423             catch (Exception e) {
424                 throw HibernateUtil.processException(e);
425             }
426             finally {
427                 closeSession(session);
428             }
429         }
430         else {
431             return (List<IGImage>)result;
432         }
433     }
434 
435     public IGImage findByUuid_First(String uuid, OrderByComparator obc)
436         throws NoSuchImageException, SystemException {
437         List<IGImage> list = findByUuid(uuid, 0, 1, obc);
438 
439         if (list.size() == 0) {
440             StringMaker msg = new StringMaker();
441 
442             msg.append("No IGImage exists with the key {");
443 
444             msg.append("uuid=" + uuid);
445 
446             msg.append(StringPool.CLOSE_CURLY_BRACE);
447 
448             throw new NoSuchImageException(msg.toString());
449         }
450         else {
451             return list.get(0);
452         }
453     }
454 
455     public IGImage findByUuid_Last(String uuid, OrderByComparator obc)
456         throws NoSuchImageException, SystemException {
457         int count = countByUuid(uuid);
458 
459         List<IGImage> list = findByUuid(uuid, count - 1, count, obc);
460 
461         if (list.size() == 0) {
462             StringMaker msg = new StringMaker();
463 
464             msg.append("No IGImage exists with the key {");
465 
466             msg.append("uuid=" + uuid);
467 
468             msg.append(StringPool.CLOSE_CURLY_BRACE);
469 
470             throw new NoSuchImageException(msg.toString());
471         }
472         else {
473             return list.get(0);
474         }
475     }
476 
477     public IGImage[] findByUuid_PrevAndNext(long imageId, String uuid,
478         OrderByComparator obc) throws NoSuchImageException, SystemException {
479         IGImage igImage = findByPrimaryKey(imageId);
480 
481         int count = countByUuid(uuid);
482 
483         Session session = null;
484 
485         try {
486             session = openSession();
487 
488             StringMaker query = new StringMaker();
489 
490             query.append(
491                 "FROM com.liferay.portlet.imagegallery.model.IGImage WHERE ");
492 
493             if (uuid == null) {
494                 query.append("uuid_ IS NULL");
495             }
496             else {
497                 query.append("uuid_ = ?");
498             }
499 
500             query.append(" ");
501 
502             if (obc != null) {
503                 query.append("ORDER BY ");
504                 query.append(obc.getOrderBy());
505             }
506 
507             else {
508                 query.append("ORDER BY ");
509 
510                 query.append("imageId ASC");
511             }
512 
513             Query q = session.createQuery(query.toString());
514 
515             int queryPos = 0;
516 
517             if (uuid != null) {
518                 q.setString(queryPos++, uuid);
519             }
520 
521             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, igImage);
522 
523             IGImage[] array = new IGImageImpl[3];
524 
525             array[0] = (IGImage)objArray[0];
526             array[1] = (IGImage)objArray[1];
527             array[2] = (IGImage)objArray[2];
528 
529             return array;
530         }
531         catch (Exception e) {
532             throw HibernateUtil.processException(e);
533         }
534         finally {
535             closeSession(session);
536         }
537     }
538 
539     public List<IGImage> findByFolderId(long folderId)
540         throws SystemException {
541         boolean finderClassNameCacheEnabled = IGImageModelImpl.CACHE_ENABLED;
542         String finderClassName = IGImage.class.getName();
543         String finderMethodName = "findByFolderId";
544         String[] finderParams = new String[] { Long.class.getName() };
545         Object[] finderArgs = new Object[] { new Long(folderId) };
546 
547         Object result = null;
548 
549         if (finderClassNameCacheEnabled) {
550             result = FinderCache.getResult(finderClassName, finderMethodName,
551                     finderParams, finderArgs, getSessionFactory());
552         }
553 
554         if (result == null) {
555             Session session = null;
556 
557             try {
558                 session = openSession();
559 
560                 StringMaker query = new StringMaker();
561 
562                 query.append(
563                     "FROM com.liferay.portlet.imagegallery.model.IGImage WHERE ");
564 
565                 query.append("folderId = ?");
566 
567                 query.append(" ");
568 
569                 query.append("ORDER BY ");
570 
571                 query.append("imageId ASC");
572 
573                 Query q = session.createQuery(query.toString());
574 
575                 int queryPos = 0;
576 
577                 q.setLong(queryPos++, folderId);
578 
579                 List<IGImage> list = q.list();
580 
581                 FinderCache.putResult(finderClassNameCacheEnabled,
582                     finderClassName, finderMethodName, finderParams,
583                     finderArgs, list);
584 
585                 return list;
586             }
587             catch (Exception e) {
588                 throw HibernateUtil.processException(e);
589             }
590             finally {
591                 closeSession(session);
592             }
593         }
594         else {
595             return (List<IGImage>)result;
596         }
597     }
598 
599     public List<IGImage> findByFolderId(long folderId, int begin, int end)
600         throws SystemException {
601         return findByFolderId(folderId, begin, end, null);
602     }
603 
604     public List<IGImage> findByFolderId(long folderId, int begin, int end,
605         OrderByComparator obc) throws SystemException {
606         boolean finderClassNameCacheEnabled = IGImageModelImpl.CACHE_ENABLED;
607         String finderClassName = IGImage.class.getName();
608         String finderMethodName = "findByFolderId";
609         String[] finderParams = new String[] {
610                 Long.class.getName(),
611                 
612                 "java.lang.Integer", "java.lang.Integer",
613                 "com.liferay.portal.kernel.util.OrderByComparator"
614             };
615         Object[] finderArgs = new Object[] {
616                 new Long(folderId),
617                 
618                 String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
619             };
620 
621         Object result = null;
622 
623         if (finderClassNameCacheEnabled) {
624             result = FinderCache.getResult(finderClassName, finderMethodName,
625                     finderParams, finderArgs, getSessionFactory());
626         }
627 
628         if (result == null) {
629             Session session = null;
630 
631             try {
632                 session = openSession();
633 
634                 StringMaker query = new StringMaker();
635 
636                 query.append(
637                     "FROM com.liferay.portlet.imagegallery.model.IGImage WHERE ");
638 
639                 query.append("folderId = ?");
640 
641                 query.append(" ");
642 
643                 if (obc != null) {
644                     query.append("ORDER BY ");
645                     query.append(obc.getOrderBy());
646                 }
647 
648                 else {
649                     query.append("ORDER BY ");
650 
651                     query.append("imageId ASC");
652                 }
653 
654                 Query q = session.createQuery(query.toString());
655 
656                 int queryPos = 0;
657 
658                 q.setLong(queryPos++, folderId);
659 
660                 List<IGImage> list = (List<IGImage>)QueryUtil.list(q,
661                         getDialect(), begin, end);
662 
663                 FinderCache.putResult(finderClassNameCacheEnabled,
664                     finderClassName, finderMethodName, finderParams,
665                     finderArgs, list);
666 
667                 return list;
668             }
669             catch (Exception e) {
670                 throw HibernateUtil.processException(e);
671             }
672             finally {
673                 closeSession(session);
674             }
675         }
676         else {
677             return (List<IGImage>)result;
678         }
679     }
680 
681     public IGImage findByFolderId_First(long folderId, OrderByComparator obc)
682         throws NoSuchImageException, SystemException {
683         List<IGImage> list = findByFolderId(folderId, 0, 1, obc);
684 
685         if (list.size() == 0) {
686             StringMaker msg = new StringMaker();
687 
688             msg.append("No IGImage exists with the key {");
689 
690             msg.append("folderId=" + folderId);
691 
692             msg.append(StringPool.CLOSE_CURLY_BRACE);
693 
694             throw new NoSuchImageException(msg.toString());
695         }
696         else {
697             return list.get(0);
698         }
699     }
700 
701     public IGImage findByFolderId_Last(long folderId, OrderByComparator obc)
702         throws NoSuchImageException, SystemException {
703         int count = countByFolderId(folderId);
704 
705         List<IGImage> list = findByFolderId(folderId, count - 1, count, obc);
706 
707         if (list.size() == 0) {
708             StringMaker msg = new StringMaker();
709 
710             msg.append("No IGImage exists with the key {");
711 
712             msg.append("folderId=" + folderId);
713 
714             msg.append(StringPool.CLOSE_CURLY_BRACE);
715 
716             throw new NoSuchImageException(msg.toString());
717         }
718         else {
719             return list.get(0);
720         }
721     }
722 
723     public IGImage[] findByFolderId_PrevAndNext(long imageId, long folderId,
724         OrderByComparator obc) throws NoSuchImageException, SystemException {
725         IGImage igImage = findByPrimaryKey(imageId);
726 
727         int count = countByFolderId(folderId);
728 
729         Session session = null;
730 
731         try {
732             session = openSession();
733 
734             StringMaker query = new StringMaker();
735 
736             query.append(
737                 "FROM com.liferay.portlet.imagegallery.model.IGImage WHERE ");
738 
739             query.append("folderId = ?");
740 
741             query.append(" ");
742 
743             if (obc != null) {
744                 query.append("ORDER BY ");
745                 query.append(obc.getOrderBy());
746             }
747 
748             else {
749                 query.append("ORDER BY ");
750 
751                 query.append("imageId ASC");
752             }
753 
754             Query q = session.createQuery(query.toString());
755 
756             int queryPos = 0;
757 
758             q.setLong(queryPos++, folderId);
759 
760             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, igImage);
761 
762             IGImage[] array = new IGImageImpl[3];
763 
764             array[0] = (IGImage)objArray[0];
765             array[1] = (IGImage)objArray[1];
766             array[2] = (IGImage)objArray[2];
767 
768             return array;
769         }
770         catch (Exception e) {
771             throw HibernateUtil.processException(e);
772         }
773         finally {
774             closeSession(session);
775         }
776     }
777 
778     public IGImage findBySmallImageId(long smallImageId)
779         throws NoSuchImageException, SystemException {
780         IGImage igImage = fetchBySmallImageId(smallImageId);
781 
782         if (igImage == null) {
783             StringMaker msg = new StringMaker();
784 
785             msg.append("No IGImage exists with the key {");
786 
787             msg.append("smallImageId=" + smallImageId);
788 
789             msg.append(StringPool.CLOSE_CURLY_BRACE);
790 
791             if (_log.isWarnEnabled()) {
792                 _log.warn(msg.toString());
793             }
794 
795             throw new NoSuchImageException(msg.toString());
796         }
797 
798         return igImage;
799     }
800 
801     public IGImage fetchBySmallImageId(long smallImageId)
802         throws SystemException {
803         boolean finderClassNameCacheEnabled = IGImageModelImpl.CACHE_ENABLED;
804         String finderClassName = IGImage.class.getName();
805         String finderMethodName = "fetchBySmallImageId";
806         String[] finderParams = new String[] { Long.class.getName() };
807         Object[] finderArgs = new Object[] { new Long(smallImageId) };
808 
809         Object result = null;
810 
811         if (finderClassNameCacheEnabled) {
812             result = FinderCache.getResult(finderClassName, finderMethodName,
813                     finderParams, finderArgs, getSessionFactory());
814         }
815 
816         if (result == null) {
817             Session session = null;
818 
819             try {
820                 session = openSession();
821 
822                 StringMaker query = new StringMaker();
823 
824                 query.append(
825                     "FROM com.liferay.portlet.imagegallery.model.IGImage WHERE ");
826 
827                 query.append("smallImageId = ?");
828 
829                 query.append(" ");
830 
831                 query.append("ORDER BY ");
832 
833                 query.append("imageId ASC");
834 
835                 Query q = session.createQuery(query.toString());
836 
837                 int queryPos = 0;
838 
839                 q.setLong(queryPos++, smallImageId);
840 
841                 List<IGImage> list = q.list();
842 
843                 FinderCache.putResult(finderClassNameCacheEnabled,
844                     finderClassName, finderMethodName, finderParams,
845                     finderArgs, list);
846 
847                 if (list.size() == 0) {
848                     return null;
849                 }
850                 else {
851                     return list.get(0);
852                 }
853             }
854             catch (Exception e) {
855                 throw HibernateUtil.processException(e);
856             }
857             finally {
858                 closeSession(session);
859             }
860         }
861         else {
862             List<IGImage> list = (List<IGImage>)result;
863 
864             if (list.size() == 0) {
865                 return null;
866             }
867             else {
868                 return list.get(0);
869             }
870         }
871     }
872 
873     public IGImage findByLargeImageId(long largeImageId)
874         throws NoSuchImageException, SystemException {
875         IGImage igImage = fetchByLargeImageId(largeImageId);
876 
877         if (igImage == null) {
878             StringMaker msg = new StringMaker();
879 
880             msg.append("No IGImage exists with the key {");
881 
882             msg.append("largeImageId=" + largeImageId);
883 
884             msg.append(StringPool.CLOSE_CURLY_BRACE);
885 
886             if (_log.isWarnEnabled()) {
887                 _log.warn(msg.toString());
888             }
889 
890             throw new NoSuchImageException(msg.toString());
891         }
892 
893         return igImage;
894     }
895 
896     public IGImage fetchByLargeImageId(long largeImageId)
897         throws SystemException {
898         boolean finderClassNameCacheEnabled = IGImageModelImpl.CACHE_ENABLED;
899         String finderClassName = IGImage.class.getName();
900         String finderMethodName = "fetchByLargeImageId";
901         String[] finderParams = new String[] { Long.class.getName() };
902         Object[] finderArgs = new Object[] { new Long(largeImageId) };
903 
904         Object result = null;
905 
906         if (finderClassNameCacheEnabled) {
907             result = FinderCache.getResult(finderClassName, finderMethodName,
908                     finderParams, finderArgs, getSessionFactory());
909         }
910 
911         if (result == null) {
912             Session session = null;
913 
914             try {
915                 session = openSession();
916 
917                 StringMaker query = new StringMaker();
918 
919                 query.append(
920                     "FROM com.liferay.portlet.imagegallery.model.IGImage WHERE ");
921 
922                 query.append("largeImageId = ?");
923 
924                 query.append(" ");
925 
926                 query.append("ORDER BY ");
927 
928                 query.append("imageId ASC");
929 
930                 Query q = session.createQuery(query.toString());
931 
932                 int queryPos = 0;
933 
934                 q.setLong(queryPos++, largeImageId);
935 
936                 List<IGImage> list = q.list();
937 
938                 FinderCache.putResult(finderClassNameCacheEnabled,
939                     finderClassName, finderMethodName, finderParams,
940                     finderArgs, list);
941 
942                 if (list.size() == 0) {
943                     return null;
944                 }
945                 else {
946                     return list.get(0);
947                 }
948             }
949             catch (Exception e) {
950                 throw HibernateUtil.processException(e);
951             }
952             finally {
953                 closeSession(session);
954             }
955         }
956         else {
957             List<IGImage> list = (List<IGImage>)result;
958 
959             if (list.size() == 0) {
960                 return null;
961             }
962             else {
963                 return list.get(0);
964             }
965         }
966     }
967 
968     public IGImage findByCustom1ImageId(long custom1ImageId)
969         throws NoSuchImageException, SystemException {
970         IGImage igImage = fetchByCustom1ImageId(custom1ImageId);
971 
972         if (igImage == null) {
973             StringMaker msg = new StringMaker();
974 
975             msg.append("No IGImage exists with the key {");
976 
977             msg.append("custom1ImageId=" + custom1ImageId);
978 
979             msg.append(StringPool.CLOSE_CURLY_BRACE);
980 
981             if (_log.isWarnEnabled()) {
982                 _log.warn(msg.toString());
983             }
984 
985             throw new NoSuchImageException(msg.toString());
986         }
987 
988         return igImage;
989     }
990 
991     public IGImage fetchByCustom1ImageId(long custom1ImageId)
992         throws SystemException {
993         boolean finderClassNameCacheEnabled = IGImageModelImpl.CACHE_ENABLED;
994         String finderClassName = IGImage.class.getName();
995         String finderMethodName = "fetchByCustom1ImageId";
996         String[] finderParams = new String[] { Long.class.getName() };
997         Object[] finderArgs = new Object[] { new Long(custom1ImageId) };
998 
999         Object result = null;
1000
1001        if (finderClassNameCacheEnabled) {
1002            result = FinderCache.getResult(finderClassName, finderMethodName,
1003                    finderParams, finderArgs, getSessionFactory());
1004        }
1005
1006        if (result == null) {
1007            Session session = null;
1008
1009            try {
1010                session = openSession();
1011
1012                StringMaker query = new StringMaker();
1013
1014                query.append(
1015                    "FROM com.liferay.portlet.imagegallery.model.IGImage WHERE ");
1016
1017                query.append("custom1ImageId = ?");
1018
1019                query.append(" ");
1020
1021                query.append("ORDER BY ");
1022
1023                query.append("imageId ASC");
1024
1025                Query q = session.createQuery(query.toString());
1026
1027                int queryPos = 0;
1028
1029                q.setLong(queryPos++, custom1ImageId);
1030
1031                List<IGImage> list = q.list();
1032
1033                FinderCache.putResult(finderClassNameCacheEnabled,
1034                    finderClassName, finderMethodName, finderParams,
1035                    finderArgs, list);
1036
1037                if (list.size() == 0) {
1038                    return null;
1039                }
1040                else {
1041                    return list.get(0);
1042                }
1043            }
1044            catch (Exception e) {
1045                throw HibernateUtil.processException(e);
1046            }
1047            finally {
1048                closeSession(session);
1049            }
1050        }
1051        else {
1052            List<IGImage> list = (List<IGImage>)result;
1053
1054            if (list.size() == 0) {
1055                return null;
1056            }
1057            else {
1058                return list.get(0);
1059            }
1060        }
1061    }
1062
1063    public IGImage findByCustom2ImageId(long custom2ImageId)
1064        throws NoSuchImageException, SystemException {
1065        IGImage igImage = fetchByCustom2ImageId(custom2ImageId);
1066
1067        if (igImage == null) {
1068            StringMaker msg = new StringMaker();
1069
1070            msg.append("No IGImage exists with the key {");
1071
1072            msg.append("custom2ImageId=" + custom2ImageId);
1073
1074            msg.append(StringPool.CLOSE_CURLY_BRACE);
1075
1076            if (_log.isWarnEnabled()) {
1077                _log.warn(msg.toString());
1078            }
1079
1080            throw new NoSuchImageException(msg.toString());
1081        }
1082
1083        return igImage;
1084    }
1085
1086    public IGImage fetchByCustom2ImageId(long custom2ImageId)
1087        throws SystemException {
1088        boolean finderClassNameCacheEnabled = IGImageModelImpl.CACHE_ENABLED;
1089        String finderClassName = IGImage.class.getName();
1090        String finderMethodName = "fetchByCustom2ImageId";
1091        String[] finderParams = new String[] { Long.class.getName() };
1092        Object[] finderArgs = new Object[] { new Long(custom2ImageId) };
1093
1094        Object result = null;
1095
1096        if (finderClassNameCacheEnabled) {
1097            result = FinderCache.getResult(finderClassName, finderMethodName,
1098                    finderParams, finderArgs, getSessionFactory());
1099        }
1100
1101        if (result == null) {
1102            Session session = null;
1103
1104            try {
1105                session = openSession();
1106
1107                StringMaker query = new StringMaker();
1108
1109                query.append(
1110                    "FROM com.liferay.portlet.imagegallery.model.IGImage WHERE ");
1111
1112                query.append("custom2ImageId = ?");
1113
1114                query.append(" ");
1115
1116                query.append("ORDER BY ");
1117
1118                query.append("imageId ASC");
1119
1120                Query q = session.createQuery(query.toString());
1121
1122                int queryPos = 0;
1123
1124                q.setLong(queryPos++, custom2ImageId);
1125
1126                List<IGImage> list = q.list();
1127
1128                FinderCache.putResult(finderClassNameCacheEnabled,
1129                    finderClassName, finderMethodName, finderParams,
1130                    finderArgs, list);
1131
1132                if (list.size() == 0) {
1133                    return null;
1134                }
1135                else {
1136                    return list.get(0);
1137                }
1138            }
1139            catch (Exception e) {
1140                throw HibernateUtil.processException(e);
1141            }
1142            finally {
1143                closeSession(session);
1144            }
1145        }
1146        else {
1147            List<IGImage> list = (List<IGImage>)result;
1148
1149            if (list.size() == 0) {
1150                return null;
1151            }
1152            else {
1153                return list.get(0);
1154            }
1155        }
1156    }
1157
1158    public List<IGImage> findByF_N(long folderId, String name)
1159        throws SystemException {
1160        boolean finderClassNameCacheEnabled = IGImageModelImpl.CACHE_ENABLED;
1161        String finderClassName = IGImage.class.getName();
1162        String finderMethodName = "findByF_N";
1163        String[] finderParams = new String[] {
1164                Long.class.getName(), String.class.getName()
1165            };
1166        Object[] finderArgs = new Object[] { new Long(folderId), name };
1167
1168        Object result = null;
1169
1170        if (finderClassNameCacheEnabled) {
1171            result = FinderCache.getResult(finderClassName, finderMethodName,
1172                    finderParams, finderArgs, getSessionFactory());
1173        }
1174
1175        if (result == null) {
1176            Session session = null;
1177
1178            try {
1179                session = openSession();
1180
1181                StringMaker query = new StringMaker();
1182
1183                query.append(
1184                    "FROM com.liferay.portlet.imagegallery.model.IGImage WHERE ");
1185
1186                query.append("folderId = ?");
1187
1188                query.append(" AND ");
1189
1190                if (name == null) {
1191                    query.append("name IS NULL");
1192                }
1193                else {
1194                    query.append("name = ?");
1195                }
1196
1197                query.append(" ");
1198
1199                query.append("ORDER BY ");
1200
1201                query.append("imageId ASC");
1202
1203                Query q = session.createQuery(query.toString());
1204
1205                int queryPos = 0;
1206
1207                q.setLong(queryPos++, folderId);
1208
1209                if (name != null) {
1210                    q.setString(queryPos++, name);
1211                }
1212
1213                List<IGImage> list = q.list();
1214
1215                FinderCache.putResult(finderClassNameCacheEnabled,
1216                    finderClassName, finderMethodName, finderParams,
1217                    finderArgs, list);
1218
1219                return list;
1220            }
1221            catch (Exception e) {
1222                throw HibernateUtil.processException(e);
1223            }
1224            finally {
1225                closeSession(session);
1226            }
1227        }
1228        else {
1229            return (List<IGImage>)result;
1230        }
1231    }
1232
1233    public List<IGImage> findByF_N(long folderId, String name, int begin,
1234        int end) throws SystemException {
1235        return findByF_N(folderId, name, begin, end, null);
1236    }
1237
1238    public List<IGImage> findByF_N(long folderId, String name, int begin,
1239        int end, OrderByComparator obc) throws SystemException {
1240        boolean finderClassNameCacheEnabled = IGImageModelImpl.CACHE_ENABLED;
1241        String finderClassName = IGImage.class.getName();
1242        String finderMethodName = "findByF_N";
1243        String[] finderParams = new String[] {
1244                Long.class.getName(), String.class.getName(),
1245                
1246                "java.lang.Integer", "java.lang.Integer",
1247                "com.liferay.portal.kernel.util.OrderByComparator"
1248            };
1249        Object[] finderArgs = new Object[] {
1250                new Long(folderId),
1251                
1252                name,
1253                
1254                String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
1255            };
1256
1257        Object result = null;
1258
1259        if (finderClassNameCacheEnabled) {
1260            result = FinderCache.getResult(finderClassName, finderMethodName,
1261                    finderParams, finderArgs, getSessionFactory());
1262        }
1263
1264        if (result == null) {
1265            Session session = null;
1266
1267            try {
1268                session = openSession();
1269
1270                StringMaker query = new StringMaker();
1271
1272                query.append(
1273                    "FROM com.liferay.portlet.imagegallery.model.IGImage WHERE ");
1274
1275                query.append("folderId = ?");
1276
1277                query.append(" AND ");
1278
1279                if (name == null) {
1280                    query.append("name IS NULL");
1281                }
1282                else {
1283                    query.append("name = ?");
1284                }
1285
1286                query.append(" ");
1287
1288                if (obc != null) {
1289                    query.append("ORDER BY ");
1290                    query.append(obc.getOrderBy());
1291                }
1292
1293                else {
1294                    query.append("ORDER BY ");
1295
1296                    query.append("imageId ASC");
1297                }
1298
1299                Query q = session.createQuery(query.toString());
1300
1301                int queryPos = 0;
1302
1303                q.setLong(queryPos++, folderId);
1304
1305                if (name != null) {
1306                    q.setString(queryPos++, name);
1307                }
1308
1309                List<IGImage> list = (List<IGImage>)QueryUtil.list(q,
1310                        getDialect(), begin, end);
1311
1312                FinderCache.putResult(finderClassNameCacheEnabled,
1313                    finderClassName, finderMethodName, finderParams,
1314                    finderArgs, list);
1315
1316                return list;
1317            }
1318            catch (Exception e) {
1319                throw HibernateUtil.processException(e);
1320            }
1321            finally {
1322                closeSession(session);
1323            }
1324        }
1325        else {
1326            return (List<IGImage>)result;
1327        }
1328    }
1329
1330    public IGImage findByF_N_First(long folderId, String name,
1331        OrderByComparator obc) throws NoSuchImageException, SystemException {
1332        List<IGImage> list = findByF_N(folderId, name, 0, 1, obc);
1333
1334        if (list.size() == 0) {
1335            StringMaker msg = new StringMaker();
1336
1337            msg.append("No IGImage exists with the key {");
1338
1339            msg.append("folderId=" + folderId);
1340
1341            msg.append(", ");
1342            msg.append("name=" + name);
1343
1344            msg.append(StringPool.CLOSE_CURLY_BRACE);
1345
1346            throw new NoSuchImageException(msg.toString());
1347        }
1348        else {
1349            return list.get(0);
1350        }
1351    }
1352
1353    public IGImage findByF_N_Last(long folderId, String name,
1354        OrderByComparator obc) throws NoSuchImageException, SystemException {
1355        int count = countByF_N(folderId, name);
1356
1357        List<IGImage> list = findByF_N(folderId, name, count - 1, count, obc);
1358
1359        if (list.size() == 0) {
1360            StringMaker msg = new StringMaker();
1361
1362            msg.append("No IGImage exists with the key {");
1363
1364            msg.append("folderId=" + folderId);
1365
1366            msg.append(", ");
1367            msg.append("name=" + name);
1368
1369            msg.append(StringPool.CLOSE_CURLY_BRACE);
1370
1371            throw new NoSuchImageException(msg.toString());
1372        }
1373        else {
1374            return list.get(0);
1375        }
1376    }
1377
1378    public IGImage[] findByF_N_PrevAndNext(long imageId, long folderId,
1379        String name, OrderByComparator obc)
1380        throws NoSuchImageException, SystemException {
1381        IGImage igImage = findByPrimaryKey(imageId);
1382
1383        int count = countByF_N(folderId, name);
1384
1385        Session session = null;
1386
1387        try {
1388            session = openSession();
1389
1390            StringMaker query = new StringMaker();
1391
1392            query.append(
1393                "FROM com.liferay.portlet.imagegallery.model.IGImage WHERE ");
1394
1395            query.append("folderId = ?");
1396
1397            query.append(" AND ");
1398
1399            if (name == null) {
1400                query.append("name IS NULL");
1401            }
1402            else {
1403                query.append("name = ?");
1404            }
1405
1406            query.append(" ");
1407
1408            if (obc != null) {
1409                query.append("ORDER BY ");
1410                query.append(obc.getOrderBy());
1411            }
1412
1413            else {
1414                query.append("ORDER BY ");
1415
1416                query.append("imageId ASC");
1417            }
1418
1419            Query q = session.createQuery(query.toString());
1420
1421            int queryPos = 0;
1422
1423            q.setLong(queryPos++, folderId);
1424
1425            if (name != null) {
1426                q.setString(queryPos++, name);
1427            }
1428
1429            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, igImage);
1430
1431            IGImage[] array = new IGImageImpl[3];
1432
1433            array[0] = (IGImage)objArray[0];
1434            array[1] = (IGImage)objArray[1];
1435            array[2] = (IGImage)objArray[2];
1436
1437            return array;
1438        }
1439        catch (Exception e) {
1440            throw HibernateUtil.processException(e);
1441        }
1442        finally {
1443            closeSession(session);
1444        }
1445    }
1446
1447    public List<IGImage> findWithDynamicQuery(
1448        DynamicQueryInitializer queryInitializer) throws SystemException {
1449        Session session = null;
1450
1451        try {
1452            session = openSession();
1453
1454            DynamicQuery query = queryInitializer.initialize(session);
1455
1456            return query.list();
1457        }
1458        catch (Exception e) {
1459            throw HibernateUtil.processException(e);
1460        }
1461        finally {
1462            closeSession(session);
1463        }
1464    }
1465
1466    public List<IGImage> findWithDynamicQuery(
1467        DynamicQueryInitializer queryInitializer, int begin, int end)
1468        throws SystemException {
1469        Session session = null;
1470
1471        try {
1472            session = openSession();
1473
1474            DynamicQuery query = queryInitializer.initialize(session);
1475
1476            query.setLimit(begin, end);
1477
1478            return query.list();
1479        }
1480        catch (Exception e) {
1481            throw HibernateUtil.processException(e);
1482        }
1483        finally {
1484            closeSession(session);
1485        }
1486    }
1487
1488    public List<IGImage> findAll() throws SystemException {
1489        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1490    }
1491
1492    public List<IGImage> findAll(int begin, int end) throws SystemException {
1493        return findAll(begin, end, null);
1494    }
1495
1496    public List<IGImage> findAll(int begin, int end, OrderByComparator obc)
1497        throws SystemException {
1498        boolean finderClassNameCacheEnabled = IGImageModelImpl.CACHE_ENABLED;
1499        String finderClassName = IGImage.class.getName();
1500        String finderMethodName = "findAll";
1501        String[] finderParams = new String[] {
1502                "java.lang.Integer", "java.lang.Integer",
1503                "com.liferay.portal.kernel.util.OrderByComparator"
1504            };
1505        Object[] finderArgs = new Object[] {
1506                String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
1507            };
1508
1509        Object result = null;
1510
1511        if (finderClassNameCacheEnabled) {
1512            result = FinderCache.getResult(finderClassName, finderMethodName,
1513                    finderParams, finderArgs, getSessionFactory());
1514        }
1515
1516        if (result == null) {
1517            Session session = null;
1518
1519            try {
1520                session = openSession();
1521
1522                StringMaker query = new StringMaker();
1523
1524                query.append(
1525                    "FROM com.liferay.portlet.imagegallery.model.IGImage ");
1526
1527                if (obc != null) {
1528                    query.append("ORDER BY ");
1529                    query.append(obc.getOrderBy());
1530                }
1531
1532                else {
1533                    query.append("ORDER BY ");
1534
1535                    query.append("imageId ASC");
1536                }
1537
1538                Query q = session.createQuery(query.toString());
1539
1540                List<IGImage> list = (List<IGImage>)QueryUtil.list(q,
1541                        getDialect(), begin, end);
1542
1543                if (obc == null) {
1544                    Collections.sort(list);
1545                }
1546
1547                FinderCache.putResult(finderClassNameCacheEnabled,
1548                    finderClassName, finderMethodName, finderParams,
1549                    finderArgs, list);
1550
1551                return list;
1552            }
1553            catch (Exception e) {
1554                throw HibernateUtil.processException(e);
1555            }
1556            finally {
1557                closeSession(session);
1558            }
1559        }
1560        else {
1561            return (List<IGImage>)result;
1562        }
1563    }
1564
1565    public void removeByUuid(String uuid) throws SystemException {
1566        for (IGImage igImage : findByUuid(uuid)) {
1567            remove(igImage);
1568        }
1569    }
1570
1571    public void removeByFolderId(long folderId) throws SystemException {
1572        for (IGImage igImage : findByFolderId(folderId)) {
1573            remove(igImage);
1574        }
1575    }
1576
1577    public void removeBySmallImageId(long smallImageId)
1578        throws NoSuchImageException, SystemException {
1579        IGImage igImage = findBySmallImageId(smallImageId);
1580
1581        remove(igImage);
1582    }
1583
1584    public void removeByLargeImageId(long largeImageId)
1585        throws NoSuchImageException, SystemException {
1586        IGImage igImage = findByLargeImageId(largeImageId);
1587
1588        remove(igImage);
1589    }
1590
1591    public void removeByCustom1ImageId(long custom1ImageId)
1592        throws NoSuchImageException, SystemException {
1593        IGImage igImage = findByCustom1ImageId(custom1ImageId);
1594
1595        remove(igImage);
1596    }
1597
1598    public void removeByCustom2ImageId(long custom2ImageId)
1599        throws NoSuchImageException, SystemException {
1600        IGImage igImage = findByCustom2ImageId(custom2ImageId);
1601
1602        remove(igImage);
1603    }
1604
1605    public void removeByF_N(long folderId, String name)
1606        throws SystemException {
1607        for (IGImage igImage : findByF_N(folderId, name)) {
1608            remove(igImage);
1609        }
1610    }
1611
1612    public void removeAll() throws SystemException {
1613        for (IGImage igImage : findAll()) {
1614            remove(igImage);
1615        }
1616    }
1617
1618    public int countByUuid(String uuid) throws SystemException {
1619        boolean finderClassNameCacheEnabled = IGImageModelImpl.CACHE_ENABLED;
1620        String finderClassName = IGImage.class.getName();
1621        String finderMethodName = "countByUuid";
1622        String[] finderParams = new String[] { String.class.getName() };
1623        Object[] finderArgs = new Object[] { uuid };
1624
1625        Object result = null;
1626
1627        if (finderClassNameCacheEnabled) {
1628            result = FinderCache.getResult(finderClassName, finderMethodName,
1629                    finderParams, finderArgs, getSessionFactory());
1630        }
1631
1632        if (result == null) {
1633            Session session = null;
1634
1635            try {
1636                session = openSession();
1637
1638                StringMaker query = new StringMaker();
1639
1640                query.append("SELECT COUNT(*) ");
1641                query.append(
1642                    "FROM com.liferay.portlet.imagegallery.model.IGImage WHERE ");
1643
1644                if (uuid == null) {
1645                    query.append("uuid_ IS NULL");
1646                }
1647                else {
1648                    query.append("uuid_ = ?");
1649                }
1650
1651                query.append(" ");
1652
1653                Query q = session.createQuery(query.toString());
1654
1655                int queryPos = 0;
1656
1657                if (uuid != null) {
1658                    q.setString(queryPos++, uuid);
1659                }
1660
1661                Long count = null;
1662
1663                Iterator<Long> itr = q.list().iterator();
1664
1665                if (itr.hasNext()) {
1666                    count = itr.next();
1667                }
1668
1669                if (count == null) {
1670                    count = new Long(0);
1671                }
1672
1673                FinderCache.putResult(finderClassNameCacheEnabled,
1674                    finderClassName, finderMethodName, finderParams,
1675                    finderArgs, count);
1676
1677                return count.intValue();
1678            }
1679            catch (Exception e) {
1680                throw HibernateUtil.processException(e);
1681            }
1682            finally {
1683                closeSession(session);
1684            }
1685        }
1686        else {
1687            return ((Long)result).intValue();
1688        }
1689    }
1690
1691    public int countByFolderId(long folderId) throws SystemException {
1692        boolean finderClassNameCacheEnabled = IGImageModelImpl.CACHE_ENABLED;
1693        String finderClassName = IGImage.class.getName();
1694        String finderMethodName = "countByFolderId";
1695        String[] finderParams = new String[] { Long.class.getName() };
1696        Object[] finderArgs = new Object[] { new Long(folderId) };
1697
1698        Object result = null;
1699
1700        if (finderClassNameCacheEnabled) {
1701            result = FinderCache.getResult(finderClassName, finderMethodName,
1702                    finderParams, finderArgs, getSessionFactory());
1703        }
1704
1705        if (result == null) {
1706            Session session = null;
1707
1708            try {
1709                session = openSession();
1710
1711                StringMaker query = new StringMaker();
1712
1713                query.append("SELECT COUNT(*) ");
1714                query.append(
1715                    "FROM com.liferay.portlet.imagegallery.model.IGImage WHERE ");
1716
1717                query.append("folderId = ?");
1718
1719                query.append(" ");
1720
1721                Query q = session.createQuery(query.toString());
1722
1723                int queryPos = 0;
1724
1725                q.setLong(queryPos++, folderId);
1726
1727                Long count = null;
1728
1729                Iterator<Long> itr = q.list().iterator();
1730
1731                if (itr.hasNext()) {
1732                    count = itr.next();
1733                }
1734
1735                if (count == null) {
1736                    count = new Long(0);
1737                }
1738
1739                FinderCache.putResult(finderClassNameCacheEnabled,
1740                    finderClassName, finderMethodName, finderParams,
1741                    finderArgs, count);
1742
1743                return count.intValue();
1744            }
1745            catch (Exception e) {
1746                throw HibernateUtil.processException(e);
1747            }
1748            finally {
1749                closeSession(session);
1750            }
1751        }
1752        else {
1753            return ((Long)result).intValue();
1754        }
1755    }
1756
1757    public int countBySmallImageId(long smallImageId) throws SystemException {
1758        boolean finderClassNameCacheEnabled = IGImageModelImpl.CACHE_ENABLED;
1759        String finderClassName = IGImage.class.getName();
1760        String finderMethodName = "countBySmallImageId";
1761        String[] finderParams = new String[] { Long.class.getName() };
1762        Object[] finderArgs = new Object[] { new Long(smallImageId) };
1763
1764        Object result = null;
1765
1766        if (finderClassNameCacheEnabled) {
1767            result = FinderCache.getResult(finderClassName, finderMethodName,
1768                    finderParams, finderArgs, getSessionFactory());
1769        }
1770
1771        if (result == null) {
1772            Session session = null;
1773
1774            try {
1775                session = openSession();
1776
1777                StringMaker query = new StringMaker();
1778
1779                query.append("SELECT COUNT(*) ");
1780                query.append(
1781                    "FROM com.liferay.portlet.imagegallery.model.IGImage WHERE ");
1782
1783                query.append("smallImageId = ?");
1784
1785                query.append(" ");
1786
1787                Query q = session.createQuery(query.toString());
1788
1789                int queryPos = 0;
1790
1791                q.setLong(queryPos++, smallImageId);
1792
1793                Long count = null;
1794
1795                Iterator<Long> itr = q.list().iterator();
1796
1797                if (itr.hasNext()) {
1798                    count = itr.next();
1799                }
1800
1801                if (count == null) {
1802                    count = new Long(0);
1803                }
1804
1805                FinderCache.putResult(finderClassNameCacheEnabled,
1806                    finderClassName, finderMethodName, finderParams,
1807                    finderArgs, count);
1808
1809                return count.intValue();
1810            }
1811            catch (Exception e) {
1812                throw HibernateUtil.processException(e);
1813            }
1814            finally {
1815                closeSession(session);
1816            }
1817        }
1818        else {
1819            return ((Long)result).intValue();
1820        }
1821    }
1822
1823    public int countByLargeImageId(long largeImageId) throws SystemException {
1824        boolean finderClassNameCacheEnabled = IGImageModelImpl.CACHE_ENABLED;
1825        String finderClassName = IGImage.class.getName();
1826        String finderMethodName = "countByLargeImageId";
1827        String[] finderParams = new String[] { Long.class.getName() };
1828        Object[] finderArgs = new Object[] { new Long(largeImageId) };
1829
1830        Object result = null;
1831
1832        if (finderClassNameCacheEnabled) {
1833            result = FinderCache.getResult(finderClassName, finderMethodName,
1834                    finderParams, finderArgs, getSessionFactory());
1835        }
1836
1837        if (result == null) {
1838            Session session = null;
1839
1840            try {
1841                session = openSession();
1842
1843                StringMaker query = new StringMaker();
1844
1845                query.append("SELECT COUNT(*) ");
1846                query.append(
1847                    "FROM com.liferay.portlet.imagegallery.model.IGImage WHERE ");
1848
1849                query.append("largeImageId = ?");
1850
1851                query.append(" ");
1852
1853                Query q = session.createQuery(query.toString());
1854
1855                int queryPos = 0;
1856
1857                q.setLong(queryPos++, largeImageId);
1858
1859                Long count = null;
1860
1861                Iterator<Long> itr = q.list().iterator();
1862
1863                if (itr.hasNext()) {
1864                    count = itr.next();
1865                }
1866
1867                if (count == null) {
1868                    count = new Long(0);
1869                }
1870
1871                FinderCache.putResult(finderClassNameCacheEnabled,
1872                    finderClassName, finderMethodName, finderParams,
1873                    finderArgs, count);
1874
1875                return count.intValue();
1876            }
1877            catch (Exception e) {
1878                throw HibernateUtil.processException(e);
1879            }
1880            finally {
1881                closeSession(session);
1882            }
1883        }
1884        else {
1885            return ((Long)result).intValue();
1886        }
1887    }
1888
1889    public int countByCustom1ImageId(long custom1ImageId)
1890        throws SystemException {
1891        boolean finderClassNameCacheEnabled = IGImageModelImpl.CACHE_ENABLED;
1892        String finderClassName = IGImage.class.getName();
1893        String finderMethodName = "countByCustom1ImageId";
1894        String[] finderParams = new String[] { Long.class.getName() };
1895        Object[] finderArgs = new Object[] { new Long(custom1ImageId) };
1896
1897        Object result = null;
1898
1899        if (finderClassNameCacheEnabled) {
1900            result = FinderCache.getResult(finderClassName, finderMethodName,
1901                    finderParams, finderArgs, getSessionFactory());
1902        }
1903
1904        if (result == null) {
1905            Session session = null;
1906
1907            try {
1908                session = openSession();
1909
1910                StringMaker query = new StringMaker();
1911
1912                query.append("SELECT COUNT(*) ");
1913                query.append(
1914                    "FROM com.liferay.portlet.imagegallery.model.IGImage WHERE ");
1915
1916                query.append("custom1ImageId = ?");
1917
1918                query.append(" ");
1919
1920                Query q = session.createQuery(query.toString());
1921
1922                int queryPos = 0;
1923
1924                q.setLong(queryPos++, custom1ImageId);
1925
1926                Long count = null;
1927
1928                Iterator<Long> itr = q.list().iterator();
1929
1930                if (itr.hasNext()) {
1931                    count = itr.next();
1932                }
1933
1934                if (count == null) {
1935                    count = new Long(0);
1936                }
1937
1938                FinderCache.putResult(finderClassNameCacheEnabled,
1939                    finderClassName, finderMethodName, finderParams,
1940                    finderArgs, count);
1941
1942                return count.intValue();
1943            }
1944            catch (Exception e) {
1945                throw HibernateUtil.processException(e);
1946            }
1947            finally {
1948                closeSession(session);
1949            }
1950        }
1951        else {
1952            return ((Long)result).intValue();
1953        }
1954    }
1955
1956    public int countByCustom2ImageId(long custom2ImageId)
1957        throws SystemException {
1958        boolean finderClassNameCacheEnabled = IGImageModelImpl.CACHE_ENABLED;
1959        String finderClassName = IGImage.class.getName();
1960        String finderMethodName = "countByCustom2ImageId";
1961        String[] finderParams = new String[] { Long.class.getName() };
1962        Object[] finderArgs = new Object[] { new Long(custom2ImageId) };
1963
1964        Object result = null;
1965
1966        if (finderClassNameCacheEnabled) {
1967            result = FinderCache.getResult(finderClassName, finderMethodName,
1968                    finderParams, finderArgs, getSessionFactory());
1969        }
1970
1971        if (result == null) {
1972            Session session = null;
1973
1974            try {
1975                session = openSession();
1976
1977                StringMaker query = new StringMaker();
1978
1979                query.append("SELECT COUNT(*) ");
1980                query.append(
1981                    "FROM com.liferay.portlet.imagegallery.model.IGImage WHERE ");
1982
1983                query.append("custom2ImageId = ?");
1984
1985                query.append(" ");
1986
1987                Query q = session.createQuery(query.toString());
1988
1989                int queryPos = 0;
1990
1991                q.setLong(queryPos++, custom2ImageId);
1992
1993                Long count = null;
1994
1995                Iterator<Long> itr = q.list().iterator();
1996
1997                if (itr.hasNext()) {
1998                    count = itr.next();
1999                }
2000
2001                if (count == null) {
2002                    count = new Long(0);
2003                }
2004
2005                FinderCache.putResult(finderClassNameCacheEnabled,
2006                    finderClassName, finderMethodName, finderParams,
2007                    finderArgs, count);
2008
2009                return count.intValue();
2010            }
2011            catch (Exception e) {
2012                throw HibernateUtil.processException(e);
2013            }
2014            finally {
2015                closeSession(session);
2016            }
2017        }
2018        else {
2019            return ((Long)result).intValue();
2020        }
2021    }
2022
2023    public int countByF_N(long folderId, String name) throws SystemException {
2024        boolean finderClassNameCacheEnabled = IGImageModelImpl.CACHE_ENABLED;
2025        String finderClassName = IGImage.class.getName();
2026        String finderMethodName = "countByF_N";
2027        String[] finderParams = new String[] {
2028                Long.class.getName(), String.class.getName()
2029            };
2030        Object[] finderArgs = new Object[] { new Long(folderId), name };
2031
2032        Object result = null;
2033
2034        if (finderClassNameCacheEnabled) {
2035            result = FinderCache.getResult(finderClassName, finderMethodName,
2036                    finderParams, finderArgs, getSessionFactory());
2037        }
2038
2039        if (result == null) {
2040            Session session = null;
2041
2042            try {
2043                session = openSession();
2044
2045                StringMaker query = new StringMaker();
2046
2047                query.append("SELECT COUNT(*) ");
2048                query.append(
2049                    "FROM com.liferay.portlet.imagegallery.model.IGImage WHERE ");
2050
2051                query.append("folderId = ?");
2052
2053                query.append(" AND ");
2054
2055                if (name == null) {
2056                    query.append("name IS NULL");
2057                }
2058                else {
2059                    query.append("name = ?");
2060                }
2061
2062                query.append(" ");
2063
2064                Query q = session.createQuery(query.toString());
2065
2066                int queryPos = 0;
2067
2068                q.setLong(queryPos++, folderId);
2069
2070                if (name != null) {
2071                    q.setString(queryPos++, name);
2072                }
2073
2074                Long count = null;
2075
2076                Iterator<Long> itr = q.list().iterator();
2077
2078                if (itr.hasNext()) {
2079                    count = itr.next();
2080                }
2081
2082                if (count == null) {
2083                    count = new Long(0);
2084                }
2085
2086                FinderCache.putResult(finderClassNameCacheEnabled,
2087                    finderClassName, finderMethodName, finderParams,
2088                    finderArgs, count);
2089
2090                return count.intValue();
2091            }
2092            catch (Exception e) {
2093                throw HibernateUtil.processException(e);
2094            }
2095            finally {
2096                closeSession(session);
2097            }
2098        }
2099        else {
2100            return ((Long)result).intValue();
2101        }
2102    }
2103
2104    public int countAll() throws SystemException {
2105        boolean finderClassNameCacheEnabled = IGImageModelImpl.CACHE_ENABLED;
2106        String finderClassName = IGImage.class.getName();
2107        String finderMethodName = "countAll";
2108        String[] finderParams = new String[] {  };
2109        Object[] finderArgs = new Object[] {  };
2110
2111        Object result = null;
2112
2113        if (finderClassNameCacheEnabled) {
2114            result = FinderCache.getResult(finderClassName, finderMethodName,
2115                    finderParams, finderArgs, getSessionFactory());
2116        }
2117
2118        if (result == null) {
2119            Session session = null;
2120
2121            try {
2122                session = openSession();
2123
2124                Query q = session.createQuery(
2125                        "SELECT COUNT(*) FROM com.liferay.portlet.imagegallery.model.IGImage");
2126
2127                Long count = null;
2128
2129                Iterator<Long> itr = q.list().iterator();
2130
2131                if (itr.hasNext()) {
2132                    count = itr.next();
2133                }
2134
2135                if (count == null) {
2136                    count = new Long(0);
2137                }
2138
2139                FinderCache.putResult(finderClassNameCacheEnabled,
2140                    finderClassName, finderMethodName, finderParams,
2141                    finderArgs, count);
2142
2143                return count.intValue();
2144            }
2145            catch (Exception e) {
2146                throw HibernateUtil.processException(e);
2147            }
2148            finally {
2149                closeSession(session);
2150            }
2151        }
2152        else {
2153            return ((Long)result).intValue();
2154        }
2155    }
2156
2157    protected void initDao() {
2158        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2159                    PropsUtil.get(
2160                        "value.object.listener.com.liferay.portlet.imagegallery.model.IGImage")));
2161
2162        if (listenerClassNames.length > 0) {
2163            try {
2164                List<ModelListener> listeners = new ArrayList<ModelListener>();
2165
2166                for (String listenerClassName : listenerClassNames) {
2167                    listeners.add((ModelListener)Class.forName(
2168                            listenerClassName).newInstance());
2169                }
2170
2171                _listeners = listeners.toArray(new ModelListener[listeners.size()]);
2172            }
2173            catch (Exception e) {
2174                _log.error(e);
2175            }
2176        }
2177    }
2178
2179    private static Log _log = LogFactory.getLog(IGImagePersistenceImpl.class);
2180    private ModelListener[] _listeners;
2181}