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