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