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