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.cache.CacheRegistry;
28  import com.liferay.portal.kernel.dao.orm.DynamicQuery;
29  import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
30  import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
31  import com.liferay.portal.kernel.dao.orm.FinderPath;
32  import com.liferay.portal.kernel.dao.orm.Query;
33  import com.liferay.portal.kernel.dao.orm.QueryPos;
34  import com.liferay.portal.kernel.dao.orm.QueryUtil;
35  import com.liferay.portal.kernel.dao.orm.Session;
36  import com.liferay.portal.kernel.log.Log;
37  import com.liferay.portal.kernel.log.LogFactoryUtil;
38  import com.liferay.portal.kernel.util.GetterUtil;
39  import com.liferay.portal.kernel.util.OrderByComparator;
40  import com.liferay.portal.kernel.util.StringPool;
41  import com.liferay.portal.kernel.util.StringUtil;
42  import com.liferay.portal.kernel.util.Validator;
43  import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
44  import com.liferay.portal.model.ModelListener;
45  import com.liferay.portal.service.persistence.BatchSessionUtil;
46  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
47  
48  import com.liferay.portlet.imagegallery.NoSuchImageException;
49  import com.liferay.portlet.imagegallery.model.IGImage;
50  import com.liferay.portlet.imagegallery.model.impl.IGImageImpl;
51  import com.liferay.portlet.imagegallery.model.impl.IGImageModelImpl;
52  
53  import java.util.ArrayList;
54  import java.util.Collections;
55  import java.util.List;
56  
57  /**
58   * <a href="IGImagePersistenceImpl.java.html"><b><i>View Source</i></b></a>
59   *
60   * @author Brian Wing Shun Chan
61   *
62   */
63  public class IGImagePersistenceImpl extends BasePersistenceImpl
64      implements IGImagePersistence {
65      public static final String FINDER_CLASS_NAME_ENTITY = IGImageImpl.class.getName();
66      public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
67          ".List";
68      public static final FinderPath FINDER_PATH_FIND_BY_UUID = new FinderPath(IGImageModelImpl.ENTITY_CACHE_ENABLED,
69              IGImageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
70              "findByUuid", new String[] { String.class.getName() });
71      public static final FinderPath FINDER_PATH_FIND_BY_OBC_UUID = new FinderPath(IGImageModelImpl.ENTITY_CACHE_ENABLED,
72              IGImageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
73              "findByUuid",
74              new String[] {
75                  String.class.getName(),
76                  
77              "java.lang.Integer", "java.lang.Integer",
78                  "com.liferay.portal.kernel.util.OrderByComparator"
79              });
80      public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(IGImageModelImpl.ENTITY_CACHE_ENABLED,
81              IGImageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
82              "countByUuid", new String[] { String.class.getName() });
83      public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(IGImageModelImpl.ENTITY_CACHE_ENABLED,
84              IGImageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
85              "fetchByUUID_G",
86              new String[] { String.class.getName(), Long.class.getName() });
87      public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(IGImageModelImpl.ENTITY_CACHE_ENABLED,
88              IGImageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
89              "countByUUID_G",
90              new String[] { String.class.getName(), Long.class.getName() });
91      public static final FinderPath FINDER_PATH_FIND_BY_GROUPID = new FinderPath(IGImageModelImpl.ENTITY_CACHE_ENABLED,
92              IGImageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
93              "findByGroupId", new String[] { Long.class.getName() });
94      public static final FinderPath FINDER_PATH_FIND_BY_OBC_GROUPID = new FinderPath(IGImageModelImpl.ENTITY_CACHE_ENABLED,
95              IGImageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
96              "findByGroupId",
97              new String[] {
98                  Long.class.getName(),
99                  
100             "java.lang.Integer", "java.lang.Integer",
101                 "com.liferay.portal.kernel.util.OrderByComparator"
102             });
103     public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(IGImageModelImpl.ENTITY_CACHE_ENABLED,
104             IGImageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
105             "countByGroupId", new String[] { Long.class.getName() });
106     public static final FinderPath FINDER_PATH_FIND_BY_FOLDERID = new FinderPath(IGImageModelImpl.ENTITY_CACHE_ENABLED,
107             IGImageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
108             "findByFolderId", new String[] { Long.class.getName() });
109     public static final FinderPath FINDER_PATH_FIND_BY_OBC_FOLDERID = new FinderPath(IGImageModelImpl.ENTITY_CACHE_ENABLED,
110             IGImageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
111             "findByFolderId",
112             new String[] {
113                 Long.class.getName(),
114                 
115             "java.lang.Integer", "java.lang.Integer",
116                 "com.liferay.portal.kernel.util.OrderByComparator"
117             });
118     public static final FinderPath FINDER_PATH_COUNT_BY_FOLDERID = new FinderPath(IGImageModelImpl.ENTITY_CACHE_ENABLED,
119             IGImageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
120             "countByFolderId", new String[] { Long.class.getName() });
121     public static final FinderPath FINDER_PATH_FETCH_BY_SMALLIMAGEID = new FinderPath(IGImageModelImpl.ENTITY_CACHE_ENABLED,
122             IGImageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
123             "fetchBySmallImageId", new String[] { Long.class.getName() });
124     public static final FinderPath FINDER_PATH_COUNT_BY_SMALLIMAGEID = new FinderPath(IGImageModelImpl.ENTITY_CACHE_ENABLED,
125             IGImageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
126             "countBySmallImageId", new String[] { Long.class.getName() });
127     public static final FinderPath FINDER_PATH_FETCH_BY_LARGEIMAGEID = new FinderPath(IGImageModelImpl.ENTITY_CACHE_ENABLED,
128             IGImageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
129             "fetchByLargeImageId", new String[] { Long.class.getName() });
130     public static final FinderPath FINDER_PATH_COUNT_BY_LARGEIMAGEID = new FinderPath(IGImageModelImpl.ENTITY_CACHE_ENABLED,
131             IGImageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
132             "countByLargeImageId", new String[] { Long.class.getName() });
133     public static final FinderPath FINDER_PATH_FETCH_BY_CUSTOM1IMAGEID = new FinderPath(IGImageModelImpl.ENTITY_CACHE_ENABLED,
134             IGImageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
135             "fetchByCustom1ImageId", new String[] { Long.class.getName() });
136     public static final FinderPath FINDER_PATH_COUNT_BY_CUSTOM1IMAGEID = new FinderPath(IGImageModelImpl.ENTITY_CACHE_ENABLED,
137             IGImageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
138             "countByCustom1ImageId", new String[] { Long.class.getName() });
139     public static final FinderPath FINDER_PATH_FETCH_BY_CUSTOM2IMAGEID = new FinderPath(IGImageModelImpl.ENTITY_CACHE_ENABLED,
140             IGImageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
141             "fetchByCustom2ImageId", new String[] { Long.class.getName() });
142     public static final FinderPath FINDER_PATH_COUNT_BY_CUSTOM2IMAGEID = new FinderPath(IGImageModelImpl.ENTITY_CACHE_ENABLED,
143             IGImageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
144             "countByCustom2ImageId", new String[] { Long.class.getName() });
145     public static final FinderPath FINDER_PATH_FIND_BY_G_U = new FinderPath(IGImageModelImpl.ENTITY_CACHE_ENABLED,
146             IGImageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
147             "findByG_U",
148             new String[] { Long.class.getName(), Long.class.getName() });
149     public static final FinderPath FINDER_PATH_FIND_BY_OBC_G_U = new FinderPath(IGImageModelImpl.ENTITY_CACHE_ENABLED,
150             IGImageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
151             "findByG_U",
152             new String[] {
153                 Long.class.getName(), Long.class.getName(),
154                 
155             "java.lang.Integer", "java.lang.Integer",
156                 "com.liferay.portal.kernel.util.OrderByComparator"
157             });
158     public static final FinderPath FINDER_PATH_COUNT_BY_G_U = new FinderPath(IGImageModelImpl.ENTITY_CACHE_ENABLED,
159             IGImageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
160             "countByG_U",
161             new String[] { Long.class.getName(), Long.class.getName() });
162     public static final FinderPath FINDER_PATH_FIND_BY_F_N = new FinderPath(IGImageModelImpl.ENTITY_CACHE_ENABLED,
163             IGImageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
164             "findByF_N",
165             new String[] { Long.class.getName(), String.class.getName() });
166     public static final FinderPath FINDER_PATH_FIND_BY_OBC_F_N = new FinderPath(IGImageModelImpl.ENTITY_CACHE_ENABLED,
167             IGImageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
168             "findByF_N",
169             new String[] {
170                 Long.class.getName(), String.class.getName(),
171                 
172             "java.lang.Integer", "java.lang.Integer",
173                 "com.liferay.portal.kernel.util.OrderByComparator"
174             });
175     public static final FinderPath FINDER_PATH_COUNT_BY_F_N = new FinderPath(IGImageModelImpl.ENTITY_CACHE_ENABLED,
176             IGImageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
177             "countByF_N",
178             new String[] { Long.class.getName(), String.class.getName() });
179     public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(IGImageModelImpl.ENTITY_CACHE_ENABLED,
180             IGImageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
181             "findAll", new String[0]);
182     public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(IGImageModelImpl.ENTITY_CACHE_ENABLED,
183             IGImageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
184             "countAll", new String[0]);
185 
186     public void cacheResult(IGImage igImage) {
187         EntityCacheUtil.putResult(IGImageModelImpl.ENTITY_CACHE_ENABLED,
188             IGImageImpl.class, igImage.getPrimaryKey(), igImage);
189 
190         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
191             new Object[] { igImage.getUuid(), new Long(igImage.getGroupId()) },
192             igImage);
193 
194         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
195             new Object[] { new Long(igImage.getSmallImageId()) }, igImage);
196 
197         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_LARGEIMAGEID,
198             new Object[] { new Long(igImage.getLargeImageId()) }, igImage);
199 
200         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_CUSTOM1IMAGEID,
201             new Object[] { new Long(igImage.getCustom1ImageId()) }, igImage);
202 
203         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_CUSTOM2IMAGEID,
204             new Object[] { new Long(igImage.getCustom2ImageId()) }, igImage);
205     }
206 
207     public void cacheResult(List<IGImage> igImages) {
208         for (IGImage igImage : igImages) {
209             if (EntityCacheUtil.getResult(
210                         IGImageModelImpl.ENTITY_CACHE_ENABLED,
211                         IGImageImpl.class, igImage.getPrimaryKey(), this) == null) {
212                 cacheResult(igImage);
213             }
214         }
215     }
216 
217     public void clearCache() {
218         CacheRegistry.clear(IGImageImpl.class.getName());
219         EntityCacheUtil.clearCache(IGImageImpl.class.getName());
220         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
221         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
222     }
223 
224     public IGImage create(long imageId) {
225         IGImage igImage = new IGImageImpl();
226 
227         igImage.setNew(true);
228         igImage.setPrimaryKey(imageId);
229 
230         String uuid = PortalUUIDUtil.generate();
231 
232         igImage.setUuid(uuid);
233 
234         return igImage;
235     }
236 
237     public IGImage remove(long imageId)
238         throws NoSuchImageException, SystemException {
239         Session session = null;
240 
241         try {
242             session = openSession();
243 
244             IGImage igImage = (IGImage)session.get(IGImageImpl.class,
245                     new Long(imageId));
246 
247             if (igImage == null) {
248                 if (_log.isWarnEnabled()) {
249                     _log.warn("No IGImage exists with the primary key " +
250                         imageId);
251                 }
252 
253                 throw new NoSuchImageException(
254                     "No IGImage exists with the primary key " + imageId);
255             }
256 
257             return remove(igImage);
258         }
259         catch (NoSuchImageException nsee) {
260             throw nsee;
261         }
262         catch (Exception e) {
263             throw processException(e);
264         }
265         finally {
266             closeSession(session);
267         }
268     }
269 
270     public IGImage remove(IGImage igImage) throws SystemException {
271         for (ModelListener<IGImage> listener : listeners) {
272             listener.onBeforeRemove(igImage);
273         }
274 
275         igImage = removeImpl(igImage);
276 
277         for (ModelListener<IGImage> listener : listeners) {
278             listener.onAfterRemove(igImage);
279         }
280 
281         return igImage;
282     }
283 
284     protected IGImage removeImpl(IGImage igImage) throws SystemException {
285         Session session = null;
286 
287         try {
288             session = openSession();
289 
290             if (igImage.isCachedModel() || BatchSessionUtil.isEnabled()) {
291                 Object staleObject = session.get(IGImageImpl.class,
292                         igImage.getPrimaryKeyObj());
293 
294                 if (staleObject != null) {
295                     session.evict(staleObject);
296                 }
297             }
298 
299             session.delete(igImage);
300 
301             session.flush();
302         }
303         catch (Exception e) {
304             throw processException(e);
305         }
306         finally {
307             closeSession(session);
308         }
309 
310         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
311 
312         IGImageModelImpl igImageModelImpl = (IGImageModelImpl)igImage;
313 
314         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
315             new Object[] {
316                 igImageModelImpl.getOriginalUuid(),
317                 new Long(igImageModelImpl.getOriginalGroupId())
318             });
319 
320         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
321             new Object[] { new Long(igImageModelImpl.getOriginalSmallImageId()) });
322 
323         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_LARGEIMAGEID,
324             new Object[] { new Long(igImageModelImpl.getOriginalLargeImageId()) });
325 
326         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_CUSTOM1IMAGEID,
327             new Object[] { new Long(igImageModelImpl.getOriginalCustom1ImageId()) });
328 
329         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_CUSTOM2IMAGEID,
330             new Object[] { new Long(igImageModelImpl.getOriginalCustom2ImageId()) });
331 
332         EntityCacheUtil.removeResult(IGImageModelImpl.ENTITY_CACHE_ENABLED,
333             IGImageImpl.class, igImage.getPrimaryKey());
334 
335         return igImage;
336     }
337 
338     /**
339      * @deprecated Use <code>update(IGImage igImage, boolean merge)</code>.
340      */
341     public IGImage update(IGImage igImage) throws SystemException {
342         if (_log.isWarnEnabled()) {
343             _log.warn(
344                 "Using the deprecated update(IGImage igImage) method. Use update(IGImage igImage, boolean merge) instead.");
345         }
346 
347         return update(igImage, false);
348     }
349 
350     /**
351      * Add, update, or merge, the entity. This method also calls the model
352      * listeners to trigger the proper events associated with adding, deleting,
353      * or updating an entity.
354      *
355      * @param        igImage the entity to add, update, or merge
356      * @param        merge boolean value for whether to merge the entity. The
357      *                default value is false. Setting merge to true is more
358      *                expensive and should only be true when igImage is
359      *                transient. See LEP-5473 for a detailed discussion of this
360      *                method.
361      * @return        true if the portlet can be displayed via Ajax
362      */
363     public IGImage update(IGImage igImage, boolean merge)
364         throws SystemException {
365         boolean isNew = igImage.isNew();
366 
367         for (ModelListener<IGImage> listener : listeners) {
368             if (isNew) {
369                 listener.onBeforeCreate(igImage);
370             }
371             else {
372                 listener.onBeforeUpdate(igImage);
373             }
374         }
375 
376         igImage = updateImpl(igImage, merge);
377 
378         for (ModelListener<IGImage> listener : listeners) {
379             if (isNew) {
380                 listener.onAfterCreate(igImage);
381             }
382             else {
383                 listener.onAfterUpdate(igImage);
384             }
385         }
386 
387         return igImage;
388     }
389 
390     public IGImage updateImpl(
391         com.liferay.portlet.imagegallery.model.IGImage igImage, boolean merge)
392         throws SystemException {
393         boolean isNew = igImage.isNew();
394 
395         IGImageModelImpl igImageModelImpl = (IGImageModelImpl)igImage;
396 
397         if (Validator.isNull(igImage.getUuid())) {
398             String uuid = PortalUUIDUtil.generate();
399 
400             igImage.setUuid(uuid);
401         }
402 
403         Session session = null;
404 
405         try {
406             session = openSession();
407 
408             BatchSessionUtil.update(session, igImage, merge);
409 
410             igImage.setNew(false);
411         }
412         catch (Exception e) {
413             throw processException(e);
414         }
415         finally {
416             closeSession(session);
417         }
418 
419         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
420 
421         EntityCacheUtil.putResult(IGImageModelImpl.ENTITY_CACHE_ENABLED,
422             IGImageImpl.class, igImage.getPrimaryKey(), igImage);
423 
424         if (!isNew &&
425                 (!Validator.equals(igImage.getUuid(),
426                     igImageModelImpl.getOriginalUuid()) ||
427                 (igImage.getGroupId() != igImageModelImpl.getOriginalGroupId()))) {
428             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
429                 new Object[] {
430                     igImageModelImpl.getOriginalUuid(),
431                     new Long(igImageModelImpl.getOriginalGroupId())
432                 });
433         }
434 
435         if (isNew ||
436                 (!Validator.equals(igImage.getUuid(),
437                     igImageModelImpl.getOriginalUuid()) ||
438                 (igImage.getGroupId() != igImageModelImpl.getOriginalGroupId()))) {
439             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
440                 new Object[] { igImage.getUuid(), new Long(igImage.getGroupId()) },
441                 igImage);
442         }
443 
444         if (!isNew &&
445                 (igImage.getSmallImageId() != igImageModelImpl.getOriginalSmallImageId())) {
446             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
447                 new Object[] {
448                     new Long(igImageModelImpl.getOriginalSmallImageId())
449                 });
450         }
451 
452         if (isNew ||
453                 (igImage.getSmallImageId() != igImageModelImpl.getOriginalSmallImageId())) {
454             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
455                 new Object[] { new Long(igImage.getSmallImageId()) }, igImage);
456         }
457 
458         if (!isNew &&
459                 (igImage.getLargeImageId() != igImageModelImpl.getOriginalLargeImageId())) {
460             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_LARGEIMAGEID,
461                 new Object[] {
462                     new Long(igImageModelImpl.getOriginalLargeImageId())
463                 });
464         }
465 
466         if (isNew ||
467                 (igImage.getLargeImageId() != igImageModelImpl.getOriginalLargeImageId())) {
468             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_LARGEIMAGEID,
469                 new Object[] { new Long(igImage.getLargeImageId()) }, igImage);
470         }
471 
472         if (!isNew &&
473                 (igImage.getCustom1ImageId() != igImageModelImpl.getOriginalCustom1ImageId())) {
474             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_CUSTOM1IMAGEID,
475                 new Object[] {
476                     new Long(igImageModelImpl.getOriginalCustom1ImageId())
477                 });
478         }
479 
480         if (isNew ||
481                 (igImage.getCustom1ImageId() != igImageModelImpl.getOriginalCustom1ImageId())) {
482             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_CUSTOM1IMAGEID,
483                 new Object[] { new Long(igImage.getCustom1ImageId()) }, igImage);
484         }
485 
486         if (!isNew &&
487                 (igImage.getCustom2ImageId() != igImageModelImpl.getOriginalCustom2ImageId())) {
488             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_CUSTOM2IMAGEID,
489                 new Object[] {
490                     new Long(igImageModelImpl.getOriginalCustom2ImageId())
491                 });
492         }
493 
494         if (isNew ||
495                 (igImage.getCustom2ImageId() != igImageModelImpl.getOriginalCustom2ImageId())) {
496             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_CUSTOM2IMAGEID,
497                 new Object[] { new Long(igImage.getCustom2ImageId()) }, igImage);
498         }
499 
500         return igImage;
501     }
502 
503     public IGImage findByPrimaryKey(long imageId)
504         throws NoSuchImageException, SystemException {
505         IGImage igImage = fetchByPrimaryKey(imageId);
506 
507         if (igImage == null) {
508             if (_log.isWarnEnabled()) {
509                 _log.warn("No IGImage exists with the primary key " + imageId);
510             }
511 
512             throw new NoSuchImageException(
513                 "No IGImage exists with the primary key " + imageId);
514         }
515 
516         return igImage;
517     }
518 
519     public IGImage fetchByPrimaryKey(long imageId) throws SystemException {
520         IGImage igImage = (IGImage)EntityCacheUtil.getResult(IGImageModelImpl.ENTITY_CACHE_ENABLED,
521                 IGImageImpl.class, imageId, this);
522 
523         if (igImage == null) {
524             Session session = null;
525 
526             try {
527                 session = openSession();
528 
529                 igImage = (IGImage)session.get(IGImageImpl.class,
530                         new Long(imageId));
531             }
532             catch (Exception e) {
533                 throw processException(e);
534             }
535             finally {
536                 if (igImage != null) {
537                     cacheResult(igImage);
538                 }
539 
540                 closeSession(session);
541             }
542         }
543 
544         return igImage;
545     }
546 
547     public List<IGImage> findByUuid(String uuid) throws SystemException {
548         Object[] finderArgs = new Object[] { uuid };
549 
550         List<IGImage> list = (List<IGImage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_UUID,
551                 finderArgs, this);
552 
553         if (list == null) {
554             Session session = null;
555 
556             try {
557                 session = openSession();
558 
559                 StringBuilder query = new StringBuilder();
560 
561                 query.append("SELECT igImage FROM IGImage igImage WHERE ");
562 
563                 if (uuid == null) {
564                     query.append("igImage.uuid IS NULL");
565                 }
566                 else {
567                     query.append("igImage.uuid = ?");
568                 }
569 
570                 query.append(" ");
571 
572                 query.append("ORDER BY ");
573 
574                 query.append("igImage.imageId ASC");
575 
576                 Query q = session.createQuery(query.toString());
577 
578                 QueryPos qPos = QueryPos.getInstance(q);
579 
580                 if (uuid != null) {
581                     qPos.add(uuid);
582                 }
583 
584                 list = q.list();
585             }
586             catch (Exception e) {
587                 throw processException(e);
588             }
589             finally {
590                 if (list == null) {
591                     list = new ArrayList<IGImage>();
592                 }
593 
594                 cacheResult(list);
595 
596                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_UUID, finderArgs,
597                     list);
598 
599                 closeSession(session);
600             }
601         }
602 
603         return list;
604     }
605 
606     public List<IGImage> findByUuid(String uuid, int start, int end)
607         throws SystemException {
608         return findByUuid(uuid, start, end, null);
609     }
610 
611     public List<IGImage> findByUuid(String uuid, int start, int end,
612         OrderByComparator obc) throws SystemException {
613         Object[] finderArgs = new Object[] {
614                 uuid,
615                 
616                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
617             };
618 
619         List<IGImage> list = (List<IGImage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_UUID,
620                 finderArgs, this);
621 
622         if (list == null) {
623             Session session = null;
624 
625             try {
626                 session = openSession();
627 
628                 StringBuilder query = new StringBuilder();
629 
630                 query.append("SELECT igImage FROM IGImage igImage WHERE ");
631 
632                 if (uuid == null) {
633                     query.append("igImage.uuid IS NULL");
634                 }
635                 else {
636                     query.append("igImage.uuid = ?");
637                 }
638 
639                 query.append(" ");
640 
641                 if (obc != null) {
642                     query.append("ORDER BY ");
643 
644                     String[] orderByFields = obc.getOrderByFields();
645 
646                     for (int i = 0; i < orderByFields.length; i++) {
647                         query.append("igImage.");
648                         query.append(orderByFields[i]);
649 
650                         if (obc.isAscending()) {
651                             query.append(" ASC");
652                         }
653                         else {
654                             query.append(" DESC");
655                         }
656 
657                         if ((i + 1) < orderByFields.length) {
658                             query.append(", ");
659                         }
660                     }
661                 }
662 
663                 else {
664                     query.append("ORDER BY ");
665 
666                     query.append("igImage.imageId ASC");
667                 }
668 
669                 Query q = session.createQuery(query.toString());
670 
671                 QueryPos qPos = QueryPos.getInstance(q);
672 
673                 if (uuid != null) {
674                     qPos.add(uuid);
675                 }
676 
677                 list = (List<IGImage>)QueryUtil.list(q, getDialect(), start, end);
678             }
679             catch (Exception e) {
680                 throw processException(e);
681             }
682             finally {
683                 if (list == null) {
684                     list = new ArrayList<IGImage>();
685                 }
686 
687                 cacheResult(list);
688 
689                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_UUID,
690                     finderArgs, list);
691 
692                 closeSession(session);
693             }
694         }
695 
696         return list;
697     }
698 
699     public IGImage findByUuid_First(String uuid, OrderByComparator obc)
700         throws NoSuchImageException, SystemException {
701         List<IGImage> list = findByUuid(uuid, 0, 1, obc);
702 
703         if (list.isEmpty()) {
704             StringBuilder msg = new StringBuilder();
705 
706             msg.append("No IGImage exists with the key {");
707 
708             msg.append("uuid=" + uuid);
709 
710             msg.append(StringPool.CLOSE_CURLY_BRACE);
711 
712             throw new NoSuchImageException(msg.toString());
713         }
714         else {
715             return list.get(0);
716         }
717     }
718 
719     public IGImage findByUuid_Last(String uuid, OrderByComparator obc)
720         throws NoSuchImageException, SystemException {
721         int count = countByUuid(uuid);
722 
723         List<IGImage> list = findByUuid(uuid, count - 1, count, obc);
724 
725         if (list.isEmpty()) {
726             StringBuilder msg = new StringBuilder();
727 
728             msg.append("No IGImage exists with the key {");
729 
730             msg.append("uuid=" + uuid);
731 
732             msg.append(StringPool.CLOSE_CURLY_BRACE);
733 
734             throw new NoSuchImageException(msg.toString());
735         }
736         else {
737             return list.get(0);
738         }
739     }
740 
741     public IGImage[] findByUuid_PrevAndNext(long imageId, String uuid,
742         OrderByComparator obc) throws NoSuchImageException, SystemException {
743         IGImage igImage = findByPrimaryKey(imageId);
744 
745         int count = countByUuid(uuid);
746 
747         Session session = null;
748 
749         try {
750             session = openSession();
751 
752             StringBuilder query = new StringBuilder();
753 
754             query.append("SELECT igImage FROM IGImage igImage WHERE ");
755 
756             if (uuid == null) {
757                 query.append("igImage.uuid IS NULL");
758             }
759             else {
760                 query.append("igImage.uuid = ?");
761             }
762 
763             query.append(" ");
764 
765             if (obc != null) {
766                 query.append("ORDER BY ");
767 
768                 String[] orderByFields = obc.getOrderByFields();
769 
770                 for (int i = 0; i < orderByFields.length; i++) {
771                     query.append("igImage.");
772                     query.append(orderByFields[i]);
773 
774                     if (obc.isAscending()) {
775                         query.append(" ASC");
776                     }
777                     else {
778                         query.append(" DESC");
779                     }
780 
781                     if ((i + 1) < orderByFields.length) {
782                         query.append(", ");
783                     }
784                 }
785             }
786 
787             else {
788                 query.append("ORDER BY ");
789 
790                 query.append("igImage.imageId ASC");
791             }
792 
793             Query q = session.createQuery(query.toString());
794 
795             QueryPos qPos = QueryPos.getInstance(q);
796 
797             if (uuid != null) {
798                 qPos.add(uuid);
799             }
800 
801             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, igImage);
802 
803             IGImage[] array = new IGImageImpl[3];
804 
805             array[0] = (IGImage)objArray[0];
806             array[1] = (IGImage)objArray[1];
807             array[2] = (IGImage)objArray[2];
808 
809             return array;
810         }
811         catch (Exception e) {
812             throw processException(e);
813         }
814         finally {
815             closeSession(session);
816         }
817     }
818 
819     public IGImage findByUUID_G(String uuid, long groupId)
820         throws NoSuchImageException, SystemException {
821         IGImage igImage = fetchByUUID_G(uuid, groupId);
822 
823         if (igImage == null) {
824             StringBuilder msg = new StringBuilder();
825 
826             msg.append("No IGImage exists with the key {");
827 
828             msg.append("uuid=" + uuid);
829 
830             msg.append(", ");
831             msg.append("groupId=" + groupId);
832 
833             msg.append(StringPool.CLOSE_CURLY_BRACE);
834 
835             if (_log.isWarnEnabled()) {
836                 _log.warn(msg.toString());
837             }
838 
839             throw new NoSuchImageException(msg.toString());
840         }
841 
842         return igImage;
843     }
844 
845     public IGImage fetchByUUID_G(String uuid, long groupId)
846         throws SystemException {
847         return fetchByUUID_G(uuid, groupId, true);
848     }
849 
850     public IGImage fetchByUUID_G(String uuid, long groupId,
851         boolean retrieveFromCache) throws SystemException {
852         Object[] finderArgs = new Object[] { uuid, new Long(groupId) };
853 
854         Object result = null;
855 
856         if (retrieveFromCache) {
857             result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
858                     finderArgs, this);
859         }
860 
861         if (result == null) {
862             Session session = null;
863 
864             try {
865                 session = openSession();
866 
867                 StringBuilder query = new StringBuilder();
868 
869                 query.append("SELECT igImage FROM IGImage igImage WHERE ");
870 
871                 if (uuid == null) {
872                     query.append("igImage.uuid IS NULL");
873                 }
874                 else {
875                     query.append("igImage.uuid = ?");
876                 }
877 
878                 query.append(" AND ");
879 
880                 query.append("igImage.groupId = ?");
881 
882                 query.append(" ");
883 
884                 query.append("ORDER BY ");
885 
886                 query.append("igImage.imageId ASC");
887 
888                 Query q = session.createQuery(query.toString());
889 
890                 QueryPos qPos = QueryPos.getInstance(q);
891 
892                 if (uuid != null) {
893                     qPos.add(uuid);
894                 }
895 
896                 qPos.add(groupId);
897 
898                 List<IGImage> list = q.list();
899 
900                 result = list;
901 
902                 IGImage igImage = null;
903 
904                 if (list.isEmpty()) {
905                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
906                         finderArgs, list);
907                 }
908                 else {
909                     igImage = list.get(0);
910 
911                     cacheResult(igImage);
912 
913                     if ((igImage.getUuid() == null) ||
914                             !igImage.getUuid().equals(uuid) ||
915                             (igImage.getGroupId() != groupId)) {
916                         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
917                             finderArgs, igImage);
918                     }
919                 }
920 
921                 return igImage;
922             }
923             catch (Exception e) {
924                 throw processException(e);
925             }
926             finally {
927                 if (result == null) {
928                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
929                         finderArgs, new ArrayList<IGImage>());
930                 }
931 
932                 closeSession(session);
933             }
934         }
935         else {
936             if (result instanceof List) {
937                 return null;
938             }
939             else {
940                 return (IGImage)result;
941             }
942         }
943     }
944 
945     public List<IGImage> findByGroupId(long groupId) throws SystemException {
946         Object[] finderArgs = new Object[] { new Long(groupId) };
947 
948         List<IGImage> list = (List<IGImage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
949                 finderArgs, this);
950 
951         if (list == null) {
952             Session session = null;
953 
954             try {
955                 session = openSession();
956 
957                 StringBuilder query = new StringBuilder();
958 
959                 query.append("SELECT igImage FROM IGImage igImage WHERE ");
960 
961                 query.append("igImage.groupId = ?");
962 
963                 query.append(" ");
964 
965                 query.append("ORDER BY ");
966 
967                 query.append("igImage.imageId ASC");
968 
969                 Query q = session.createQuery(query.toString());
970 
971                 QueryPos qPos = QueryPos.getInstance(q);
972 
973                 qPos.add(groupId);
974 
975                 list = q.list();
976             }
977             catch (Exception e) {
978                 throw processException(e);
979             }
980             finally {
981                 if (list == null) {
982                     list = new ArrayList<IGImage>();
983                 }
984 
985                 cacheResult(list);
986 
987                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
988                     finderArgs, list);
989 
990                 closeSession(session);
991             }
992         }
993 
994         return list;
995     }
996 
997     public List<IGImage> findByGroupId(long groupId, int start, int end)
998         throws SystemException {
999         return findByGroupId(groupId, start, end, null);
1000    }
1001
1002    public List<IGImage> findByGroupId(long groupId, int start, int end,
1003        OrderByComparator obc) throws SystemException {
1004        Object[] finderArgs = new Object[] {
1005                new Long(groupId),
1006                
1007                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1008            };
1009
1010        List<IGImage> list = (List<IGImage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_GROUPID,
1011                finderArgs, this);
1012
1013        if (list == null) {
1014            Session session = null;
1015
1016            try {
1017                session = openSession();
1018
1019                StringBuilder query = new StringBuilder();
1020
1021                query.append("SELECT igImage FROM IGImage igImage WHERE ");
1022
1023                query.append("igImage.groupId = ?");
1024
1025                query.append(" ");
1026
1027                if (obc != null) {
1028                    query.append("ORDER BY ");
1029
1030                    String[] orderByFields = obc.getOrderByFields();
1031
1032                    for (int i = 0; i < orderByFields.length; i++) {
1033                        query.append("igImage.");
1034                        query.append(orderByFields[i]);
1035
1036                        if (obc.isAscending()) {
1037                            query.append(" ASC");
1038                        }
1039                        else {
1040                            query.append(" DESC");
1041                        }
1042
1043                        if ((i + 1) < orderByFields.length) {
1044                            query.append(", ");
1045                        }
1046                    }
1047                }
1048
1049                else {
1050                    query.append("ORDER BY ");
1051
1052                    query.append("igImage.imageId ASC");
1053                }
1054
1055                Query q = session.createQuery(query.toString());
1056
1057                QueryPos qPos = QueryPos.getInstance(q);
1058
1059                qPos.add(groupId);
1060
1061                list = (List<IGImage>)QueryUtil.list(q, getDialect(), start, end);
1062            }
1063            catch (Exception e) {
1064                throw processException(e);
1065            }
1066            finally {
1067                if (list == null) {
1068                    list = new ArrayList<IGImage>();
1069                }
1070
1071                cacheResult(list);
1072
1073                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_GROUPID,
1074                    finderArgs, list);
1075
1076                closeSession(session);
1077            }
1078        }
1079
1080        return list;
1081    }
1082
1083    public IGImage findByGroupId_First(long groupId, OrderByComparator obc)
1084        throws NoSuchImageException, SystemException {
1085        List<IGImage> list = findByGroupId(groupId, 0, 1, obc);
1086
1087        if (list.isEmpty()) {
1088            StringBuilder msg = new StringBuilder();
1089
1090            msg.append("No IGImage exists with the key {");
1091
1092            msg.append("groupId=" + groupId);
1093
1094            msg.append(StringPool.CLOSE_CURLY_BRACE);
1095
1096            throw new NoSuchImageException(msg.toString());
1097        }
1098        else {
1099            return list.get(0);
1100        }
1101    }
1102
1103    public IGImage findByGroupId_Last(long groupId, OrderByComparator obc)
1104        throws NoSuchImageException, SystemException {
1105        int count = countByGroupId(groupId);
1106
1107        List<IGImage> list = findByGroupId(groupId, count - 1, count, obc);
1108
1109        if (list.isEmpty()) {
1110            StringBuilder msg = new StringBuilder();
1111
1112            msg.append("No IGImage exists with the key {");
1113
1114            msg.append("groupId=" + groupId);
1115
1116            msg.append(StringPool.CLOSE_CURLY_BRACE);
1117
1118            throw new NoSuchImageException(msg.toString());
1119        }
1120        else {
1121            return list.get(0);
1122        }
1123    }
1124
1125    public IGImage[] findByGroupId_PrevAndNext(long imageId, long groupId,
1126        OrderByComparator obc) throws NoSuchImageException, SystemException {
1127        IGImage igImage = findByPrimaryKey(imageId);
1128
1129        int count = countByGroupId(groupId);
1130
1131        Session session = null;
1132
1133        try {
1134            session = openSession();
1135
1136            StringBuilder query = new StringBuilder();
1137
1138            query.append("SELECT igImage FROM IGImage igImage WHERE ");
1139
1140            query.append("igImage.groupId = ?");
1141
1142            query.append(" ");
1143
1144            if (obc != null) {
1145                query.append("ORDER BY ");
1146
1147                String[] orderByFields = obc.getOrderByFields();
1148
1149                for (int i = 0; i < orderByFields.length; i++) {
1150                    query.append("igImage.");
1151                    query.append(orderByFields[i]);
1152
1153                    if (obc.isAscending()) {
1154                        query.append(" ASC");
1155                    }
1156                    else {
1157                        query.append(" DESC");
1158                    }
1159
1160                    if ((i + 1) < orderByFields.length) {
1161                        query.append(", ");
1162                    }
1163                }
1164            }
1165
1166            else {
1167                query.append("ORDER BY ");
1168
1169                query.append("igImage.imageId ASC");
1170            }
1171
1172            Query q = session.createQuery(query.toString());
1173
1174            QueryPos qPos = QueryPos.getInstance(q);
1175
1176            qPos.add(groupId);
1177
1178            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, igImage);
1179
1180            IGImage[] array = new IGImageImpl[3];
1181
1182            array[0] = (IGImage)objArray[0];
1183            array[1] = (IGImage)objArray[1];
1184            array[2] = (IGImage)objArray[2];
1185
1186            return array;
1187        }
1188        catch (Exception e) {
1189            throw processException(e);
1190        }
1191        finally {
1192            closeSession(session);
1193        }
1194    }
1195
1196    public List<IGImage> findByFolderId(long folderId)
1197        throws SystemException {
1198        Object[] finderArgs = new Object[] { new Long(folderId) };
1199
1200        List<IGImage> list = (List<IGImage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_FOLDERID,
1201                finderArgs, this);
1202
1203        if (list == null) {
1204            Session session = null;
1205
1206            try {
1207                session = openSession();
1208
1209                StringBuilder query = new StringBuilder();
1210
1211                query.append("SELECT igImage FROM IGImage igImage WHERE ");
1212
1213                query.append("igImage.folderId = ?");
1214
1215                query.append(" ");
1216
1217                query.append("ORDER BY ");
1218
1219                query.append("igImage.imageId ASC");
1220
1221                Query q = session.createQuery(query.toString());
1222
1223                QueryPos qPos = QueryPos.getInstance(q);
1224
1225                qPos.add(folderId);
1226
1227                list = q.list();
1228            }
1229            catch (Exception e) {
1230                throw processException(e);
1231            }
1232            finally {
1233                if (list == null) {
1234                    list = new ArrayList<IGImage>();
1235                }
1236
1237                cacheResult(list);
1238
1239                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_FOLDERID,
1240                    finderArgs, list);
1241
1242                closeSession(session);
1243            }
1244        }
1245
1246        return list;
1247    }
1248
1249    public List<IGImage> findByFolderId(long folderId, int start, int end)
1250        throws SystemException {
1251        return findByFolderId(folderId, start, end, null);
1252    }
1253
1254    public List<IGImage> findByFolderId(long folderId, int start, int end,
1255        OrderByComparator obc) throws SystemException {
1256        Object[] finderArgs = new Object[] {
1257                new Long(folderId),
1258                
1259                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1260            };
1261
1262        List<IGImage> list = (List<IGImage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_FOLDERID,
1263                finderArgs, this);
1264
1265        if (list == null) {
1266            Session session = null;
1267
1268            try {
1269                session = openSession();
1270
1271                StringBuilder query = new StringBuilder();
1272
1273                query.append("SELECT igImage FROM IGImage igImage WHERE ");
1274
1275                query.append("igImage.folderId = ?");
1276
1277                query.append(" ");
1278
1279                if (obc != null) {
1280                    query.append("ORDER BY ");
1281
1282                    String[] orderByFields = obc.getOrderByFields();
1283
1284                    for (int i = 0; i < orderByFields.length; i++) {
1285                        query.append("igImage.");
1286                        query.append(orderByFields[i]);
1287
1288                        if (obc.isAscending()) {
1289                            query.append(" ASC");
1290                        }
1291                        else {
1292                            query.append(" DESC");
1293                        }
1294
1295                        if ((i + 1) < orderByFields.length) {
1296                            query.append(", ");
1297                        }
1298                    }
1299                }
1300
1301                else {
1302                    query.append("ORDER BY ");
1303
1304                    query.append("igImage.imageId ASC");
1305                }
1306
1307                Query q = session.createQuery(query.toString());
1308
1309                QueryPos qPos = QueryPos.getInstance(q);
1310
1311                qPos.add(folderId);
1312
1313                list = (List<IGImage>)QueryUtil.list(q, getDialect(), start, end);
1314            }
1315            catch (Exception e) {
1316                throw processException(e);
1317            }
1318            finally {
1319                if (list == null) {
1320                    list = new ArrayList<IGImage>();
1321                }
1322
1323                cacheResult(list);
1324
1325                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_FOLDERID,
1326                    finderArgs, list);
1327
1328                closeSession(session);
1329            }
1330        }
1331
1332        return list;
1333    }
1334
1335    public IGImage findByFolderId_First(long folderId, OrderByComparator obc)
1336        throws NoSuchImageException, SystemException {
1337        List<IGImage> list = findByFolderId(folderId, 0, 1, obc);
1338
1339        if (list.isEmpty()) {
1340            StringBuilder msg = new StringBuilder();
1341
1342            msg.append("No IGImage exists with the key {");
1343
1344            msg.append("folderId=" + folderId);
1345
1346            msg.append(StringPool.CLOSE_CURLY_BRACE);
1347
1348            throw new NoSuchImageException(msg.toString());
1349        }
1350        else {
1351            return list.get(0);
1352        }
1353    }
1354
1355    public IGImage findByFolderId_Last(long folderId, OrderByComparator obc)
1356        throws NoSuchImageException, SystemException {
1357        int count = countByFolderId(folderId);
1358
1359        List<IGImage> list = findByFolderId(folderId, count - 1, count, obc);
1360
1361        if (list.isEmpty()) {
1362            StringBuilder msg = new StringBuilder();
1363
1364            msg.append("No IGImage exists with the key {");
1365
1366            msg.append("folderId=" + folderId);
1367
1368            msg.append(StringPool.CLOSE_CURLY_BRACE);
1369
1370            throw new NoSuchImageException(msg.toString());
1371        }
1372        else {
1373            return list.get(0);
1374        }
1375    }
1376
1377    public IGImage[] findByFolderId_PrevAndNext(long imageId, long folderId,
1378        OrderByComparator obc) throws NoSuchImageException, SystemException {
1379        IGImage igImage = findByPrimaryKey(imageId);
1380
1381        int count = countByFolderId(folderId);
1382
1383        Session session = null;
1384
1385        try {
1386            session = openSession();
1387
1388            StringBuilder query = new StringBuilder();
1389
1390            query.append("SELECT igImage FROM IGImage igImage WHERE ");
1391
1392            query.append("igImage.folderId = ?");
1393
1394            query.append(" ");
1395
1396            if (obc != null) {
1397                query.append("ORDER BY ");
1398
1399                String[] orderByFields = obc.getOrderByFields();
1400
1401                for (int i = 0; i < orderByFields.length; i++) {
1402                    query.append("igImage.");
1403                    query.append(orderByFields[i]);
1404
1405                    if (obc.isAscending()) {
1406                        query.append(" ASC");
1407                    }
1408                    else {
1409                        query.append(" DESC");
1410                    }
1411
1412                    if ((i + 1) < orderByFields.length) {
1413                        query.append(", ");
1414                    }
1415                }
1416            }
1417
1418            else {
1419                query.append("ORDER BY ");
1420
1421                query.append("igImage.imageId ASC");
1422            }
1423
1424            Query q = session.createQuery(query.toString());
1425
1426            QueryPos qPos = QueryPos.getInstance(q);
1427
1428            qPos.add(folderId);
1429
1430            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, igImage);
1431
1432            IGImage[] array = new IGImageImpl[3];
1433
1434            array[0] = (IGImage)objArray[0];
1435            array[1] = (IGImage)objArray[1];
1436            array[2] = (IGImage)objArray[2];
1437
1438            return array;
1439        }
1440        catch (Exception e) {
1441            throw processException(e);
1442        }
1443        finally {
1444            closeSession(session);
1445        }
1446    }
1447
1448    public IGImage findBySmallImageId(long smallImageId)
1449        throws NoSuchImageException, SystemException {
1450        IGImage igImage = fetchBySmallImageId(smallImageId);
1451
1452        if (igImage == null) {
1453            StringBuilder msg = new StringBuilder();
1454
1455            msg.append("No IGImage exists with the key {");
1456
1457            msg.append("smallImageId=" + smallImageId);
1458
1459            msg.append(StringPool.CLOSE_CURLY_BRACE);
1460
1461            if (_log.isWarnEnabled()) {
1462                _log.warn(msg.toString());
1463            }
1464
1465            throw new NoSuchImageException(msg.toString());
1466        }
1467
1468        return igImage;
1469    }
1470
1471    public IGImage fetchBySmallImageId(long smallImageId)
1472        throws SystemException {
1473        return fetchBySmallImageId(smallImageId, true);
1474    }
1475
1476    public IGImage fetchBySmallImageId(long smallImageId,
1477        boolean retrieveFromCache) throws SystemException {
1478        Object[] finderArgs = new Object[] { new Long(smallImageId) };
1479
1480        Object result = null;
1481
1482        if (retrieveFromCache) {
1483            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
1484                    finderArgs, this);
1485        }
1486
1487        if (result == null) {
1488            Session session = null;
1489
1490            try {
1491                session = openSession();
1492
1493                StringBuilder query = new StringBuilder();
1494
1495                query.append("SELECT igImage FROM IGImage igImage WHERE ");
1496
1497                query.append("igImage.smallImageId = ?");
1498
1499                query.append(" ");
1500
1501                query.append("ORDER BY ");
1502
1503                query.append("igImage.imageId ASC");
1504
1505                Query q = session.createQuery(query.toString());
1506
1507                QueryPos qPos = QueryPos.getInstance(q);
1508
1509                qPos.add(smallImageId);
1510
1511                List<IGImage> list = q.list();
1512
1513                result = list;
1514
1515                IGImage igImage = null;
1516
1517                if (list.isEmpty()) {
1518                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
1519                        finderArgs, list);
1520                }
1521                else {
1522                    igImage = list.get(0);
1523
1524                    cacheResult(igImage);
1525
1526                    if ((igImage.getSmallImageId() != smallImageId)) {
1527                        FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
1528                            finderArgs, igImage);
1529                    }
1530                }
1531
1532                return igImage;
1533            }
1534            catch (Exception e) {
1535                throw processException(e);
1536            }
1537            finally {
1538                if (result == null) {
1539                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
1540                        finderArgs, new ArrayList<IGImage>());
1541                }
1542
1543                closeSession(session);
1544            }
1545        }
1546        else {
1547            if (result instanceof List) {
1548                return null;
1549            }
1550            else {
1551                return (IGImage)result;
1552            }
1553        }
1554    }
1555
1556    public IGImage findByLargeImageId(long largeImageId)
1557        throws NoSuchImageException, SystemException {
1558        IGImage igImage = fetchByLargeImageId(largeImageId);
1559
1560        if (igImage == null) {
1561            StringBuilder msg = new StringBuilder();
1562
1563            msg.append("No IGImage exists with the key {");
1564
1565            msg.append("largeImageId=" + largeImageId);
1566
1567            msg.append(StringPool.CLOSE_CURLY_BRACE);
1568
1569            if (_log.isWarnEnabled()) {
1570                _log.warn(msg.toString());
1571            }
1572
1573            throw new NoSuchImageException(msg.toString());
1574        }
1575
1576        return igImage;
1577    }
1578
1579    public IGImage fetchByLargeImageId(long largeImageId)
1580        throws SystemException {
1581        return fetchByLargeImageId(largeImageId, true);
1582    }
1583
1584    public IGImage fetchByLargeImageId(long largeImageId,
1585        boolean retrieveFromCache) throws SystemException {
1586        Object[] finderArgs = new Object[] { new Long(largeImageId) };
1587
1588        Object result = null;
1589
1590        if (retrieveFromCache) {
1591            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_LARGEIMAGEID,
1592                    finderArgs, this);
1593        }
1594
1595        if (result == null) {
1596            Session session = null;
1597
1598            try {
1599                session = openSession();
1600
1601                StringBuilder query = new StringBuilder();
1602
1603                query.append("SELECT igImage FROM IGImage igImage WHERE ");
1604
1605                query.append("igImage.largeImageId = ?");
1606
1607                query.append(" ");
1608
1609                query.append("ORDER BY ");
1610
1611                query.append("igImage.imageId ASC");
1612
1613                Query q = session.createQuery(query.toString());
1614
1615                QueryPos qPos = QueryPos.getInstance(q);
1616
1617                qPos.add(largeImageId);
1618
1619                List<IGImage> list = q.list();
1620
1621                result = list;
1622
1623                IGImage igImage = null;
1624
1625                if (list.isEmpty()) {
1626                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_LARGEIMAGEID,
1627                        finderArgs, list);
1628                }
1629                else {
1630                    igImage = list.get(0);
1631
1632                    cacheResult(igImage);
1633
1634                    if ((igImage.getLargeImageId() != largeImageId)) {
1635                        FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_LARGEIMAGEID,
1636                            finderArgs, igImage);
1637                    }
1638                }
1639
1640                return igImage;
1641            }
1642            catch (Exception e) {
1643                throw processException(e);
1644            }
1645            finally {
1646                if (result == null) {
1647                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_LARGEIMAGEID,
1648                        finderArgs, new ArrayList<IGImage>());
1649                }
1650
1651                closeSession(session);
1652            }
1653        }
1654        else {
1655            if (result instanceof List) {
1656                return null;
1657            }
1658            else {
1659                return (IGImage)result;
1660            }
1661        }
1662    }
1663
1664    public IGImage findByCustom1ImageId(long custom1ImageId)
1665        throws NoSuchImageException, SystemException {
1666        IGImage igImage = fetchByCustom1ImageId(custom1ImageId);
1667
1668        if (igImage == null) {
1669            StringBuilder msg = new StringBuilder();
1670
1671            msg.append("No IGImage exists with the key {");
1672
1673            msg.append("custom1ImageId=" + custom1ImageId);
1674
1675            msg.append(StringPool.CLOSE_CURLY_BRACE);
1676
1677            if (_log.isWarnEnabled()) {
1678                _log.warn(msg.toString());
1679            }
1680
1681            throw new NoSuchImageException(msg.toString());
1682        }
1683
1684        return igImage;
1685    }
1686
1687    public IGImage fetchByCustom1ImageId(long custom1ImageId)
1688        throws SystemException {
1689        return fetchByCustom1ImageId(custom1ImageId, true);
1690    }
1691
1692    public IGImage fetchByCustom1ImageId(long custom1ImageId,
1693        boolean retrieveFromCache) throws SystemException {
1694        Object[] finderArgs = new Object[] { new Long(custom1ImageId) };
1695
1696        Object result = null;
1697
1698        if (retrieveFromCache) {
1699            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_CUSTOM1IMAGEID,
1700                    finderArgs, this);
1701        }
1702
1703        if (result == null) {
1704            Session session = null;
1705
1706            try {
1707                session = openSession();
1708
1709                StringBuilder query = new StringBuilder();
1710
1711                query.append("SELECT igImage FROM IGImage igImage WHERE ");
1712
1713                query.append("igImage.custom1ImageId = ?");
1714
1715                query.append(" ");
1716
1717                query.append("ORDER BY ");
1718
1719                query.append("igImage.imageId ASC");
1720
1721                Query q = session.createQuery(query.toString());
1722
1723                QueryPos qPos = QueryPos.getInstance(q);
1724
1725                qPos.add(custom1ImageId);
1726
1727                List<IGImage> list = q.list();
1728
1729                result = list;
1730
1731                IGImage igImage = null;
1732
1733                if (list.isEmpty()) {
1734                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_CUSTOM1IMAGEID,
1735                        finderArgs, list);
1736                }
1737                else {
1738                    igImage = list.get(0);
1739
1740                    cacheResult(igImage);
1741
1742                    if ((igImage.getCustom1ImageId() != custom1ImageId)) {
1743                        FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_CUSTOM1IMAGEID,
1744                            finderArgs, igImage);
1745                    }
1746                }
1747
1748                return igImage;
1749            }
1750            catch (Exception e) {
1751                throw processException(e);
1752            }
1753            finally {
1754                if (result == null) {
1755                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_CUSTOM1IMAGEID,
1756                        finderArgs, new ArrayList<IGImage>());
1757                }
1758
1759                closeSession(session);
1760            }
1761        }
1762        else {
1763            if (result instanceof List) {
1764                return null;
1765            }
1766            else {
1767                return (IGImage)result;
1768            }
1769        }
1770    }
1771
1772    public IGImage findByCustom2ImageId(long custom2ImageId)
1773        throws NoSuchImageException, SystemException {
1774        IGImage igImage = fetchByCustom2ImageId(custom2ImageId);
1775
1776        if (igImage == null) {
1777            StringBuilder msg = new StringBuilder();
1778
1779            msg.append("No IGImage exists with the key {");
1780
1781            msg.append("custom2ImageId=" + custom2ImageId);
1782
1783            msg.append(StringPool.CLOSE_CURLY_BRACE);
1784
1785            if (_log.isWarnEnabled()) {
1786                _log.warn(msg.toString());
1787            }
1788
1789            throw new NoSuchImageException(msg.toString());
1790        }
1791
1792        return igImage;
1793    }
1794
1795    public IGImage fetchByCustom2ImageId(long custom2ImageId)
1796        throws SystemException {
1797        return fetchByCustom2ImageId(custom2ImageId, true);
1798    }
1799
1800    public IGImage fetchByCustom2ImageId(long custom2ImageId,
1801        boolean retrieveFromCache) throws SystemException {
1802        Object[] finderArgs = new Object[] { new Long(custom2ImageId) };
1803
1804        Object result = null;
1805
1806        if (retrieveFromCache) {
1807            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_CUSTOM2IMAGEID,
1808                    finderArgs, this);
1809        }
1810
1811        if (result == null) {
1812            Session session = null;
1813
1814            try {
1815                session = openSession();
1816
1817                StringBuilder query = new StringBuilder();
1818
1819                query.append("SELECT igImage FROM IGImage igImage WHERE ");
1820
1821                query.append("igImage.custom2ImageId = ?");
1822
1823                query.append(" ");
1824
1825                query.append("ORDER BY ");
1826
1827                query.append("igImage.imageId ASC");
1828
1829                Query q = session.createQuery(query.toString());
1830
1831                QueryPos qPos = QueryPos.getInstance(q);
1832
1833                qPos.add(custom2ImageId);
1834
1835                List<IGImage> list = q.list();
1836
1837                result = list;
1838
1839                IGImage igImage = null;
1840
1841                if (list.isEmpty()) {
1842                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_CUSTOM2IMAGEID,
1843                        finderArgs, list);
1844                }
1845                else {
1846                    igImage = list.get(0);
1847
1848                    cacheResult(igImage);
1849
1850                    if ((igImage.getCustom2ImageId() != custom2ImageId)) {
1851                        FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_CUSTOM2IMAGEID,
1852                            finderArgs, igImage);
1853                    }
1854                }
1855
1856                return igImage;
1857            }
1858            catch (Exception e) {
1859                throw processException(e);
1860            }
1861            finally {
1862                if (result == null) {
1863                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_CUSTOM2IMAGEID,
1864                        finderArgs, new ArrayList<IGImage>());
1865                }
1866
1867                closeSession(session);
1868            }
1869        }
1870        else {
1871            if (result instanceof List) {
1872                return null;
1873            }
1874            else {
1875                return (IGImage)result;
1876            }
1877        }
1878    }
1879
1880    public List<IGImage> findByG_U(long groupId, long userId)
1881        throws SystemException {
1882        Object[] finderArgs = new Object[] { new Long(groupId), new Long(userId) };
1883
1884        List<IGImage> list = (List<IGImage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_U,
1885                finderArgs, this);
1886
1887        if (list == null) {
1888            Session session = null;
1889
1890            try {
1891                session = openSession();
1892
1893                StringBuilder query = new StringBuilder();
1894
1895                query.append("SELECT igImage FROM IGImage igImage WHERE ");
1896
1897                query.append("igImage.groupId = ?");
1898
1899                query.append(" AND ");
1900
1901                query.append("igImage.userId = ?");
1902
1903                query.append(" ");
1904
1905                query.append("ORDER BY ");
1906
1907                query.append("igImage.imageId ASC");
1908
1909                Query q = session.createQuery(query.toString());
1910
1911                QueryPos qPos = QueryPos.getInstance(q);
1912
1913                qPos.add(groupId);
1914
1915                qPos.add(userId);
1916
1917                list = q.list();
1918            }
1919            catch (Exception e) {
1920                throw processException(e);
1921            }
1922            finally {
1923                if (list == null) {
1924                    list = new ArrayList<IGImage>();
1925                }
1926
1927                cacheResult(list);
1928
1929                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_U, finderArgs,
1930                    list);
1931
1932                closeSession(session);
1933            }
1934        }
1935
1936        return list;
1937    }
1938
1939    public List<IGImage> findByG_U(long groupId, long userId, int start, int end)
1940        throws SystemException {
1941        return findByG_U(groupId, userId, start, end, null);
1942    }
1943
1944    public List<IGImage> findByG_U(long groupId, long userId, int start,
1945        int end, OrderByComparator obc) throws SystemException {
1946        Object[] finderArgs = new Object[] {
1947                new Long(groupId), new Long(userId),
1948                
1949                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1950            };
1951
1952        List<IGImage> list = (List<IGImage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_G_U,
1953                finderArgs, this);
1954
1955        if (list == null) {
1956            Session session = null;
1957
1958            try {
1959                session = openSession();
1960
1961                StringBuilder query = new StringBuilder();
1962
1963                query.append("SELECT igImage FROM IGImage igImage WHERE ");
1964
1965                query.append("igImage.groupId = ?");
1966
1967                query.append(" AND ");
1968
1969                query.append("igImage.userId = ?");
1970
1971                query.append(" ");
1972
1973                if (obc != null) {
1974                    query.append("ORDER BY ");
1975
1976                    String[] orderByFields = obc.getOrderByFields();
1977
1978                    for (int i = 0; i < orderByFields.length; i++) {
1979                        query.append("igImage.");
1980                        query.append(orderByFields[i]);
1981
1982                        if (obc.isAscending()) {
1983                            query.append(" ASC");
1984                        }
1985                        else {
1986                            query.append(" DESC");
1987                        }
1988
1989                        if ((i + 1) < orderByFields.length) {
1990                            query.append(", ");
1991                        }
1992                    }
1993                }
1994
1995                else {
1996                    query.append("ORDER BY ");
1997
1998                    query.append("igImage.imageId ASC");
1999                }
2000
2001                Query q = session.createQuery(query.toString());
2002
2003                QueryPos qPos = QueryPos.getInstance(q);
2004
2005                qPos.add(groupId);
2006
2007                qPos.add(userId);
2008
2009                list = (List<IGImage>)QueryUtil.list(q, getDialect(), start, end);
2010            }
2011            catch (Exception e) {
2012                throw processException(e);
2013            }
2014            finally {
2015                if (list == null) {
2016                    list = new ArrayList<IGImage>();
2017                }
2018
2019                cacheResult(list);
2020
2021                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_G_U,
2022                    finderArgs, list);
2023
2024                closeSession(session);
2025            }
2026        }
2027
2028        return list;
2029    }
2030
2031    public IGImage findByG_U_First(long groupId, long userId,
2032        OrderByComparator obc) throws NoSuchImageException, SystemException {
2033        List<IGImage> list = findByG_U(groupId, userId, 0, 1, obc);
2034
2035        if (list.isEmpty()) {
2036            StringBuilder msg = new StringBuilder();
2037
2038            msg.append("No IGImage exists with the key {");
2039
2040            msg.append("groupId=" + groupId);
2041
2042            msg.append(", ");
2043            msg.append("userId=" + userId);
2044
2045            msg.append(StringPool.CLOSE_CURLY_BRACE);
2046
2047            throw new NoSuchImageException(msg.toString());
2048        }
2049        else {
2050            return list.get(0);
2051        }
2052    }
2053
2054    public IGImage findByG_U_Last(long groupId, long userId,
2055        OrderByComparator obc) throws NoSuchImageException, SystemException {
2056        int count = countByG_U(groupId, userId);
2057
2058        List<IGImage> list = findByG_U(groupId, userId, count - 1, count, obc);
2059
2060        if (list.isEmpty()) {
2061            StringBuilder msg = new StringBuilder();
2062
2063            msg.append("No IGImage exists with the key {");
2064
2065            msg.append("groupId=" + groupId);
2066
2067            msg.append(", ");
2068            msg.append("userId=" + userId);
2069
2070            msg.append(StringPool.CLOSE_CURLY_BRACE);
2071
2072            throw new NoSuchImageException(msg.toString());
2073        }
2074        else {
2075            return list.get(0);
2076        }
2077    }
2078
2079    public IGImage[] findByG_U_PrevAndNext(long imageId, long groupId,
2080        long userId, OrderByComparator obc)
2081        throws NoSuchImageException, SystemException {
2082        IGImage igImage = findByPrimaryKey(imageId);
2083
2084        int count = countByG_U(groupId, userId);
2085
2086        Session session = null;
2087
2088        try {
2089            session = openSession();
2090
2091            StringBuilder query = new StringBuilder();
2092
2093            query.append("SELECT igImage FROM IGImage igImage WHERE ");
2094
2095            query.append("igImage.groupId = ?");
2096
2097            query.append(" AND ");
2098
2099            query.append("igImage.userId = ?");
2100
2101            query.append(" ");
2102
2103            if (obc != null) {
2104                query.append("ORDER BY ");
2105
2106                String[] orderByFields = obc.getOrderByFields();
2107
2108                for (int i = 0; i < orderByFields.length; i++) {
2109                    query.append("igImage.");
2110                    query.append(orderByFields[i]);
2111
2112                    if (obc.isAscending()) {
2113                        query.append(" ASC");
2114                    }
2115                    else {
2116                        query.append(" DESC");
2117                    }
2118
2119                    if ((i + 1) < orderByFields.length) {
2120                        query.append(", ");
2121                    }
2122                }
2123            }
2124
2125            else {
2126                query.append("ORDER BY ");
2127
2128                query.append("igImage.imageId ASC");
2129            }
2130
2131            Query q = session.createQuery(query.toString());
2132
2133            QueryPos qPos = QueryPos.getInstance(q);
2134
2135            qPos.add(groupId);
2136
2137            qPos.add(userId);
2138
2139            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, igImage);
2140
2141            IGImage[] array = new IGImageImpl[3];
2142
2143            array[0] = (IGImage)objArray[0];
2144            array[1] = (IGImage)objArray[1];
2145            array[2] = (IGImage)objArray[2];
2146
2147            return array;
2148        }
2149        catch (Exception e) {
2150            throw processException(e);
2151        }
2152        finally {
2153            closeSession(session);
2154        }
2155    }
2156
2157    public List<IGImage> findByF_N(long folderId, String name)
2158        throws SystemException {
2159        Object[] finderArgs = new Object[] { new Long(folderId), name };
2160
2161        List<IGImage> list = (List<IGImage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_F_N,
2162                finderArgs, this);
2163
2164        if (list == null) {
2165            Session session = null;
2166
2167            try {
2168                session = openSession();
2169
2170                StringBuilder query = new StringBuilder();
2171
2172                query.append("SELECT igImage FROM IGImage igImage WHERE ");
2173
2174                query.append("igImage.folderId = ?");
2175
2176                query.append(" AND ");
2177
2178                if (name == null) {
2179                    query.append("igImage.name IS NULL");
2180                }
2181                else {
2182                    query.append("igImage.name = ?");
2183                }
2184
2185                query.append(" ");
2186
2187                query.append("ORDER BY ");
2188
2189                query.append("igImage.imageId ASC");
2190
2191                Query q = session.createQuery(query.toString());
2192
2193                QueryPos qPos = QueryPos.getInstance(q);
2194
2195                qPos.add(folderId);
2196
2197                if (name != null) {
2198                    qPos.add(name);
2199                }
2200
2201                list = q.list();
2202            }
2203            catch (Exception e) {
2204                throw processException(e);
2205            }
2206            finally {
2207                if (list == null) {
2208                    list = new ArrayList<IGImage>();
2209                }
2210
2211                cacheResult(list);
2212
2213                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_F_N, finderArgs,
2214                    list);
2215
2216                closeSession(session);
2217            }
2218        }
2219
2220        return list;
2221    }
2222
2223    public List<IGImage> findByF_N(long folderId, String name, int start,
2224        int end) throws SystemException {
2225        return findByF_N(folderId, name, start, end, null);
2226    }
2227
2228    public List<IGImage> findByF_N(long folderId, String name, int start,
2229        int end, OrderByComparator obc) throws SystemException {
2230        Object[] finderArgs = new Object[] {
2231                new Long(folderId),
2232                
2233                name,
2234                
2235                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
2236            };
2237
2238        List<IGImage> list = (List<IGImage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_F_N,
2239                finderArgs, this);
2240
2241        if (list == null) {
2242            Session session = null;
2243
2244            try {
2245                session = openSession();
2246
2247                StringBuilder query = new StringBuilder();
2248
2249                query.append("SELECT igImage FROM IGImage igImage WHERE ");
2250
2251                query.append("igImage.folderId = ?");
2252
2253                query.append(" AND ");
2254
2255                if (name == null) {
2256                    query.append("igImage.name IS NULL");
2257                }
2258                else {
2259                    query.append("igImage.name = ?");
2260                }
2261
2262                query.append(" ");
2263
2264                if (obc != null) {
2265                    query.append("ORDER BY ");
2266
2267                    String[] orderByFields = obc.getOrderByFields();
2268
2269                    for (int i = 0; i < orderByFields.length; i++) {
2270                        query.append("igImage.");
2271                        query.append(orderByFields[i]);
2272
2273                        if (obc.isAscending()) {
2274                            query.append(" ASC");
2275                        }
2276                        else {
2277                            query.append(" DESC");
2278                        }
2279
2280                        if ((i + 1) < orderByFields.length) {
2281                            query.append(", ");
2282                        }
2283                    }
2284                }
2285
2286                else {
2287                    query.append("ORDER BY ");
2288
2289                    query.append("igImage.imageId ASC");
2290                }
2291
2292                Query q = session.createQuery(query.toString());
2293
2294                QueryPos qPos = QueryPos.getInstance(q);
2295
2296                qPos.add(folderId);
2297
2298                if (name != null) {
2299                    qPos.add(name);
2300                }
2301
2302                list = (List<IGImage>)QueryUtil.list(q, getDialect(), start, end);
2303            }
2304            catch (Exception e) {
2305                throw processException(e);
2306            }
2307            finally {
2308                if (list == null) {
2309                    list = new ArrayList<IGImage>();
2310                }
2311
2312                cacheResult(list);
2313
2314                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_F_N,
2315                    finderArgs, list);
2316
2317                closeSession(session);
2318            }
2319        }
2320
2321        return list;
2322    }
2323
2324    public IGImage findByF_N_First(long folderId, String name,
2325        OrderByComparator obc) throws NoSuchImageException, SystemException {
2326        List<IGImage> list = findByF_N(folderId, name, 0, 1, obc);
2327
2328        if (list.isEmpty()) {
2329            StringBuilder msg = new StringBuilder();
2330
2331            msg.append("No IGImage exists with the key {");
2332
2333            msg.append("folderId=" + folderId);
2334
2335            msg.append(", ");
2336            msg.append("name=" + name);
2337
2338            msg.append(StringPool.CLOSE_CURLY_BRACE);
2339
2340            throw new NoSuchImageException(msg.toString());
2341        }
2342        else {
2343            return list.get(0);
2344        }
2345    }
2346
2347    public IGImage findByF_N_Last(long folderId, String name,
2348        OrderByComparator obc) throws NoSuchImageException, SystemException {
2349        int count = countByF_N(folderId, name);
2350
2351        List<IGImage> list = findByF_N(folderId, name, count - 1, count, obc);
2352
2353        if (list.isEmpty()) {
2354            StringBuilder msg = new StringBuilder();
2355
2356            msg.append("No IGImage exists with the key {");
2357
2358            msg.append("folderId=" + folderId);
2359
2360            msg.append(", ");
2361            msg.append("name=" + name);
2362
2363            msg.append(StringPool.CLOSE_CURLY_BRACE);
2364
2365            throw new NoSuchImageException(msg.toString());
2366        }
2367        else {
2368            return list.get(0);
2369        }
2370    }
2371
2372    public IGImage[] findByF_N_PrevAndNext(long imageId, long folderId,
2373        String name, OrderByComparator obc)
2374        throws NoSuchImageException, SystemException {
2375        IGImage igImage = findByPrimaryKey(imageId);
2376
2377        int count = countByF_N(folderId, name);
2378
2379        Session session = null;
2380
2381        try {
2382            session = openSession();
2383
2384            StringBuilder query = new StringBuilder();
2385
2386            query.append("SELECT igImage FROM IGImage igImage WHERE ");
2387
2388            query.append("igImage.folderId = ?");
2389
2390            query.append(" AND ");
2391
2392            if (name == null) {
2393                query.append("igImage.name IS NULL");
2394            }
2395            else {
2396                query.append("igImage.name = ?");
2397            }
2398
2399            query.append(" ");
2400
2401            if (obc != null) {
2402                query.append("ORDER BY ");
2403
2404                String[] orderByFields = obc.getOrderByFields();
2405
2406                for (int i = 0; i < orderByFields.length; i++) {
2407                    query.append("igImage.");
2408                    query.append(orderByFields[i]);
2409
2410                    if (obc.isAscending()) {
2411                        query.append(" ASC");
2412                    }
2413                    else {
2414                        query.append(" DESC");
2415                    }
2416
2417                    if ((i + 1) < orderByFields.length) {
2418                        query.append(", ");
2419                    }
2420                }
2421            }
2422
2423            else {
2424                query.append("ORDER BY ");
2425
2426                query.append("igImage.imageId ASC");
2427            }
2428
2429            Query q = session.createQuery(query.toString());
2430
2431            QueryPos qPos = QueryPos.getInstance(q);
2432
2433            qPos.add(folderId);
2434
2435            if (name != null) {
2436                qPos.add(name);
2437            }
2438
2439            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, igImage);
2440
2441            IGImage[] array = new IGImageImpl[3];
2442
2443            array[0] = (IGImage)objArray[0];
2444            array[1] = (IGImage)objArray[1];
2445            array[2] = (IGImage)objArray[2];
2446
2447            return array;
2448        }
2449        catch (Exception e) {
2450            throw processException(e);
2451        }
2452        finally {
2453            closeSession(session);
2454        }
2455    }
2456
2457    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
2458        throws SystemException {
2459        Session session = null;
2460
2461        try {
2462            session = openSession();
2463
2464            dynamicQuery.compile(session);
2465
2466            return dynamicQuery.list();
2467        }
2468        catch (Exception e) {
2469            throw processException(e);
2470        }
2471        finally {
2472            closeSession(session);
2473        }
2474    }
2475
2476    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
2477        int start, int end) throws SystemException {
2478        Session session = null;
2479
2480        try {
2481            session = openSession();
2482
2483            dynamicQuery.setLimit(start, end);
2484
2485            dynamicQuery.compile(session);
2486
2487            return dynamicQuery.list();
2488        }
2489        catch (Exception e) {
2490            throw processException(e);
2491        }
2492        finally {
2493            closeSession(session);
2494        }
2495    }
2496
2497    public List<IGImage> findAll() throws SystemException {
2498        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2499    }
2500
2501    public List<IGImage> findAll(int start, int end) throws SystemException {
2502        return findAll(start, end, null);
2503    }
2504
2505    public List<IGImage> findAll(int start, int end, OrderByComparator obc)
2506        throws SystemException {
2507        Object[] finderArgs = new Object[] {
2508                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
2509            };
2510
2511        List<IGImage> list = (List<IGImage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
2512                finderArgs, this);
2513
2514        if (list == null) {
2515            Session session = null;
2516
2517            try {
2518                session = openSession();
2519
2520                StringBuilder query = new StringBuilder();
2521
2522                query.append("SELECT igImage FROM IGImage igImage ");
2523
2524                if (obc != null) {
2525                    query.append("ORDER BY ");
2526
2527                    String[] orderByFields = obc.getOrderByFields();
2528
2529                    for (int i = 0; i < orderByFields.length; i++) {
2530                        query.append("igImage.");
2531                        query.append(orderByFields[i]);
2532
2533                        if (obc.isAscending()) {
2534                            query.append(" ASC");
2535                        }
2536                        else {
2537                            query.append(" DESC");
2538                        }
2539
2540                        if ((i + 1) < orderByFields.length) {
2541                            query.append(", ");
2542                        }
2543                    }
2544                }
2545
2546                else {
2547                    query.append("ORDER BY ");
2548
2549                    query.append("igImage.imageId ASC");
2550                }
2551
2552                Query q = session.createQuery(query.toString());
2553
2554                if (obc == null) {
2555                    list = (List<IGImage>)QueryUtil.list(q, getDialect(),
2556                            start, end, false);
2557
2558                    Collections.sort(list);
2559                }
2560                else {
2561                    list = (List<IGImage>)QueryUtil.list(q, getDialect(),
2562                            start, end);
2563                }
2564            }
2565            catch (Exception e) {
2566                throw processException(e);
2567            }
2568            finally {
2569                if (list == null) {
2570                    list = new ArrayList<IGImage>();
2571                }
2572
2573                cacheResult(list);
2574
2575                FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
2576
2577                closeSession(session);
2578            }
2579        }
2580
2581        return list;
2582    }
2583
2584    public void removeByUuid(String uuid) throws SystemException {
2585        for (IGImage igImage : findByUuid(uuid)) {
2586            remove(igImage);
2587        }
2588    }
2589
2590    public void removeByUUID_G(String uuid, long groupId)
2591        throws NoSuchImageException, SystemException {
2592        IGImage igImage = findByUUID_G(uuid, groupId);
2593
2594        remove(igImage);
2595    }
2596
2597    public void removeByGroupId(long groupId) throws SystemException {
2598        for (IGImage igImage : findByGroupId(groupId)) {
2599            remove(igImage);
2600        }
2601    }
2602
2603    public void removeByFolderId(long folderId) throws SystemException {
2604        for (IGImage igImage : findByFolderId(folderId)) {
2605            remove(igImage);
2606        }
2607    }
2608
2609    public void removeBySmallImageId(long smallImageId)
2610        throws NoSuchImageException, SystemException {
2611        IGImage igImage = findBySmallImageId(smallImageId);
2612
2613        remove(igImage);
2614    }
2615
2616    public void removeByLargeImageId(long largeImageId)
2617        throws NoSuchImageException, SystemException {
2618        IGImage igImage = findByLargeImageId(largeImageId);
2619
2620        remove(igImage);
2621    }
2622
2623    public void removeByCustom1ImageId(long custom1ImageId)
2624        throws NoSuchImageException, SystemException {
2625        IGImage igImage = findByCustom1ImageId(custom1ImageId);
2626
2627        remove(igImage);
2628    }
2629
2630    public void removeByCustom2ImageId(long custom2ImageId)
2631        throws NoSuchImageException, SystemException {
2632        IGImage igImage = findByCustom2ImageId(custom2ImageId);
2633
2634        remove(igImage);
2635    }
2636
2637    public void removeByG_U(long groupId, long userId)
2638        throws SystemException {
2639        for (IGImage igImage : findByG_U(groupId, userId)) {
2640            remove(igImage);
2641        }
2642    }
2643
2644    public void removeByF_N(long folderId, String name)
2645        throws SystemException {
2646        for (IGImage igImage : findByF_N(folderId, name)) {
2647            remove(igImage);
2648        }
2649    }
2650
2651    public void removeAll() throws SystemException {
2652        for (IGImage igImage : findAll()) {
2653            remove(igImage);
2654        }
2655    }
2656
2657    public int countByUuid(String uuid) throws SystemException {
2658        Object[] finderArgs = new Object[] { uuid };
2659
2660        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
2661                finderArgs, this);
2662
2663        if (count == null) {
2664            Session session = null;
2665
2666            try {
2667                session = openSession();
2668
2669                StringBuilder query = new StringBuilder();
2670
2671                query.append("SELECT COUNT(igImage) ");
2672                query.append("FROM IGImage igImage WHERE ");
2673
2674                if (uuid == null) {
2675                    query.append("igImage.uuid IS NULL");
2676                }
2677                else {
2678                    query.append("igImage.uuid = ?");
2679                }
2680
2681                query.append(" ");
2682
2683                Query q = session.createQuery(query.toString());
2684
2685                QueryPos qPos = QueryPos.getInstance(q);
2686
2687                if (uuid != null) {
2688                    qPos.add(uuid);
2689                }
2690
2691                count = (Long)q.uniqueResult();
2692            }
2693            catch (Exception e) {
2694                throw processException(e);
2695            }
2696            finally {
2697                if (count == null) {
2698                    count = Long.valueOf(0);
2699                }
2700
2701                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
2702                    finderArgs, count);
2703
2704                closeSession(session);
2705            }
2706        }
2707
2708        return count.intValue();
2709    }
2710
2711    public int countByUUID_G(String uuid, long groupId)
2712        throws SystemException {
2713        Object[] finderArgs = new Object[] { uuid, new Long(groupId) };
2714
2715        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
2716                finderArgs, this);
2717
2718        if (count == null) {
2719            Session session = null;
2720
2721            try {
2722                session = openSession();
2723
2724                StringBuilder query = new StringBuilder();
2725
2726                query.append("SELECT COUNT(igImage) ");
2727                query.append("FROM IGImage igImage WHERE ");
2728
2729                if (uuid == null) {
2730                    query.append("igImage.uuid IS NULL");
2731                }
2732                else {
2733                    query.append("igImage.uuid = ?");
2734                }
2735
2736                query.append(" AND ");
2737
2738                query.append("igImage.groupId = ?");
2739
2740                query.append(" ");
2741
2742                Query q = session.createQuery(query.toString());
2743
2744                QueryPos qPos = QueryPos.getInstance(q);
2745
2746                if (uuid != null) {
2747                    qPos.add(uuid);
2748                }
2749
2750                qPos.add(groupId);
2751
2752                count = (Long)q.uniqueResult();
2753            }
2754            catch (Exception e) {
2755                throw processException(e);
2756            }
2757            finally {
2758                if (count == null) {
2759                    count = Long.valueOf(0);
2760                }
2761
2762                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
2763                    finderArgs, count);
2764
2765                closeSession(session);
2766            }
2767        }
2768
2769        return count.intValue();
2770    }
2771
2772    public int countByGroupId(long groupId) throws SystemException {
2773        Object[] finderArgs = new Object[] { new Long(groupId) };
2774
2775        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
2776                finderArgs, this);
2777
2778        if (count == null) {
2779            Session session = null;
2780
2781            try {
2782                session = openSession();
2783
2784                StringBuilder query = new StringBuilder();
2785
2786                query.append("SELECT COUNT(igImage) ");
2787                query.append("FROM IGImage igImage WHERE ");
2788
2789                query.append("igImage.groupId = ?");
2790
2791                query.append(" ");
2792
2793                Query q = session.createQuery(query.toString());
2794
2795                QueryPos qPos = QueryPos.getInstance(q);
2796
2797                qPos.add(groupId);
2798
2799                count = (Long)q.uniqueResult();
2800            }
2801            catch (Exception e) {
2802                throw processException(e);
2803            }
2804            finally {
2805                if (count == null) {
2806                    count = Long.valueOf(0);
2807                }
2808
2809                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
2810                    finderArgs, count);
2811
2812                closeSession(session);
2813            }
2814        }
2815
2816        return count.intValue();
2817    }
2818
2819    public int countByFolderId(long folderId) throws SystemException {
2820        Object[] finderArgs = new Object[] { new Long(folderId) };
2821
2822        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_FOLDERID,
2823                finderArgs, this);
2824
2825        if (count == null) {
2826            Session session = null;
2827
2828            try {
2829                session = openSession();
2830
2831                StringBuilder query = new StringBuilder();
2832
2833                query.append("SELECT COUNT(igImage) ");
2834                query.append("FROM IGImage igImage WHERE ");
2835
2836                query.append("igImage.folderId = ?");
2837
2838                query.append(" ");
2839
2840                Query q = session.createQuery(query.toString());
2841
2842                QueryPos qPos = QueryPos.getInstance(q);
2843
2844                qPos.add(folderId);
2845
2846                count = (Long)q.uniqueResult();
2847            }
2848            catch (Exception e) {
2849                throw processException(e);
2850            }
2851            finally {
2852                if (count == null) {
2853                    count = Long.valueOf(0);
2854                }
2855
2856                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_FOLDERID,
2857                    finderArgs, count);
2858
2859                closeSession(session);
2860            }
2861        }
2862
2863        return count.intValue();
2864    }
2865
2866    public int countBySmallImageId(long smallImageId) throws SystemException {
2867        Object[] finderArgs = new Object[] { new Long(smallImageId) };
2868
2869        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_SMALLIMAGEID,
2870                finderArgs, this);
2871
2872        if (count == null) {
2873            Session session = null;
2874
2875            try {
2876                session = openSession();
2877
2878                StringBuilder query = new StringBuilder();
2879
2880                query.append("SELECT COUNT(igImage) ");
2881                query.append("FROM IGImage igImage WHERE ");
2882
2883                query.append("igImage.smallImageId = ?");
2884
2885                query.append(" ");
2886
2887                Query q = session.createQuery(query.toString());
2888
2889                QueryPos qPos = QueryPos.getInstance(q);
2890
2891                qPos.add(smallImageId);
2892
2893                count = (Long)q.uniqueResult();
2894            }
2895            catch (Exception e) {
2896                throw processException(e);
2897            }
2898            finally {
2899                if (count == null) {
2900                    count = Long.valueOf(0);
2901                }
2902
2903                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_SMALLIMAGEID,
2904                    finderArgs, count);
2905
2906                closeSession(session);
2907            }
2908        }
2909
2910        return count.intValue();
2911    }
2912
2913    public int countByLargeImageId(long largeImageId) throws SystemException {
2914        Object[] finderArgs = new Object[] { new Long(largeImageId) };
2915
2916        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_LARGEIMAGEID,
2917                finderArgs, this);
2918
2919        if (count == null) {
2920            Session session = null;
2921
2922            try {
2923                session = openSession();
2924
2925                StringBuilder query = new StringBuilder();
2926
2927                query.append("SELECT COUNT(igImage) ");
2928                query.append("FROM IGImage igImage WHERE ");
2929
2930                query.append("igImage.largeImageId = ?");
2931
2932                query.append(" ");
2933
2934                Query q = session.createQuery(query.toString());
2935
2936                QueryPos qPos = QueryPos.getInstance(q);
2937
2938                qPos.add(largeImageId);
2939
2940                count = (Long)q.uniqueResult();
2941            }
2942            catch (Exception e) {
2943                throw processException(e);
2944            }
2945            finally {
2946                if (count == null) {
2947                    count = Long.valueOf(0);
2948                }
2949
2950                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_LARGEIMAGEID,
2951                    finderArgs, count);
2952
2953                closeSession(session);
2954            }
2955        }
2956
2957        return count.intValue();
2958    }
2959
2960    public int countByCustom1ImageId(long custom1ImageId)
2961        throws SystemException {
2962        Object[] finderArgs = new Object[] { new Long(custom1ImageId) };
2963
2964        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_CUSTOM1IMAGEID,
2965                finderArgs, this);
2966
2967        if (count == null) {
2968            Session session = null;
2969
2970            try {
2971                session = openSession();
2972
2973                StringBuilder query = new StringBuilder();
2974
2975                query.append("SELECT COUNT(igImage) ");
2976                query.append("FROM IGImage igImage WHERE ");
2977
2978                query.append("igImage.custom1ImageId = ?");
2979
2980                query.append(" ");
2981
2982                Query q = session.createQuery(query.toString());
2983
2984                QueryPos qPos = QueryPos.getInstance(q);
2985
2986                qPos.add(custom1ImageId);
2987
2988                count = (Long)q.uniqueResult();
2989            }
2990            catch (Exception e) {
2991                throw processException(e);
2992            }
2993            finally {
2994                if (count == null) {
2995                    count = Long.valueOf(0);
2996                }
2997
2998                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_CUSTOM1IMAGEID,
2999                    finderArgs, count);
3000
3001                closeSession(session);
3002            }
3003        }
3004
3005        return count.intValue();
3006    }
3007
3008    public int countByCustom2ImageId(long custom2ImageId)
3009        throws SystemException {
3010        Object[] finderArgs = new Object[] { new Long(custom2ImageId) };
3011
3012        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_CUSTOM2IMAGEID,
3013                finderArgs, this);
3014
3015        if (count == null) {
3016            Session session = null;
3017
3018            try {
3019                session = openSession();
3020
3021                StringBuilder query = new StringBuilder();
3022
3023                query.append("SELECT COUNT(igImage) ");
3024                query.append("FROM IGImage igImage WHERE ");
3025
3026                query.append("igImage.custom2ImageId = ?");
3027
3028                query.append(" ");
3029
3030                Query q = session.createQuery(query.toString());
3031
3032                QueryPos qPos = QueryPos.getInstance(q);
3033
3034                qPos.add(custom2ImageId);
3035
3036                count = (Long)q.uniqueResult();
3037            }
3038            catch (Exception e) {
3039                throw processException(e);
3040            }
3041            finally {
3042                if (count == null) {
3043                    count = Long.valueOf(0);
3044                }
3045
3046                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_CUSTOM2IMAGEID,
3047                    finderArgs, count);
3048
3049                closeSession(session);
3050            }
3051        }
3052
3053        return count.intValue();
3054    }
3055
3056    public int countByG_U(long groupId, long userId) throws SystemException {
3057        Object[] finderArgs = new Object[] { new Long(groupId), new Long(userId) };
3058
3059        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_U,
3060                finderArgs, this);
3061
3062        if (count == null) {
3063            Session session = null;
3064
3065            try {
3066                session = openSession();
3067
3068                StringBuilder query = new StringBuilder();
3069
3070                query.append("SELECT COUNT(igImage) ");
3071                query.append("FROM IGImage igImage WHERE ");
3072
3073                query.append("igImage.groupId = ?");
3074
3075                query.append(" AND ");
3076
3077                query.append("igImage.userId = ?");
3078
3079                query.append(" ");
3080
3081                Query q = session.createQuery(query.toString());
3082
3083                QueryPos qPos = QueryPos.getInstance(q);
3084
3085                qPos.add(groupId);
3086
3087                qPos.add(userId);
3088
3089                count = (Long)q.uniqueResult();
3090            }
3091            catch (Exception e) {
3092                throw processException(e);
3093            }
3094            finally {
3095                if (count == null) {
3096                    count = Long.valueOf(0);
3097                }
3098
3099                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_U, finderArgs,
3100                    count);
3101
3102                closeSession(session);
3103            }
3104        }
3105
3106        return count.intValue();
3107    }
3108
3109    public int countByF_N(long folderId, String name) throws SystemException {
3110        Object[] finderArgs = new Object[] { new Long(folderId), name };
3111
3112        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_F_N,
3113                finderArgs, this);
3114
3115        if (count == null) {
3116            Session session = null;
3117
3118            try {
3119                session = openSession();
3120
3121                StringBuilder query = new StringBuilder();
3122
3123                query.append("SELECT COUNT(igImage) ");
3124                query.append("FROM IGImage igImage WHERE ");
3125
3126                query.append("igImage.folderId = ?");
3127
3128                query.append(" AND ");
3129
3130                if (name == null) {
3131                    query.append("igImage.name IS NULL");
3132                }
3133                else {
3134                    query.append("igImage.name = ?");
3135                }
3136
3137                query.append(" ");
3138
3139                Query q = session.createQuery(query.toString());
3140
3141                QueryPos qPos = QueryPos.getInstance(q);
3142
3143                qPos.add(folderId);
3144
3145                if (name != null) {
3146                    qPos.add(name);
3147                }
3148
3149                count = (Long)q.uniqueResult();
3150            }
3151            catch (Exception e) {
3152                throw processException(e);
3153            }
3154            finally {
3155                if (count == null) {
3156                    count = Long.valueOf(0);
3157                }
3158
3159                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_F_N, finderArgs,
3160                    count);
3161
3162                closeSession(session);
3163            }
3164        }
3165
3166        return count.intValue();
3167    }
3168
3169    public int countAll() throws SystemException {
3170        Object[] finderArgs = new Object[0];
3171
3172        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
3173                finderArgs, this);
3174
3175        if (count == null) {
3176            Session session = null;
3177
3178            try {
3179                session = openSession();
3180
3181                Query q = session.createQuery(
3182                        "SELECT COUNT(igImage) FROM IGImage igImage");
3183
3184                count = (Long)q.uniqueResult();
3185            }
3186            catch (Exception e) {
3187                throw processException(e);
3188            }
3189            finally {
3190                if (count == null) {
3191                    count = Long.valueOf(0);
3192                }
3193
3194                FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
3195                    count);
3196
3197                closeSession(session);
3198            }
3199        }
3200
3201        return count.intValue();
3202    }
3203
3204    public void afterPropertiesSet() {
3205        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
3206                    com.liferay.portal.util.PropsUtil.get(
3207                        "value.object.listener.com.liferay.portlet.imagegallery.model.IGImage")));
3208
3209        if (listenerClassNames.length > 0) {
3210            try {
3211                List<ModelListener<IGImage>> listenersList = new ArrayList<ModelListener<IGImage>>();
3212
3213                for (String listenerClassName : listenerClassNames) {
3214                    listenersList.add((ModelListener<IGImage>)Class.forName(
3215                            listenerClassName).newInstance());
3216                }
3217
3218                listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
3219            }
3220            catch (Exception e) {
3221                _log.error(e);
3222            }
3223        }
3224    }
3225
3226    @BeanReference(name = "com.liferay.portlet.imagegallery.service.persistence.IGFolderPersistence.impl")
3227    protected com.liferay.portlet.imagegallery.service.persistence.IGFolderPersistence igFolderPersistence;
3228    @BeanReference(name = "com.liferay.portlet.imagegallery.service.persistence.IGImagePersistence.impl")
3229    protected com.liferay.portlet.imagegallery.service.persistence.IGImagePersistence igImagePersistence;
3230    @BeanReference(name = "com.liferay.portal.service.persistence.ImagePersistence.impl")
3231    protected com.liferay.portal.service.persistence.ImagePersistence imagePersistence;
3232    @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence.impl")
3233    protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
3234    @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence.impl")
3235    protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
3236    @BeanReference(name = "com.liferay.portlet.tags.service.persistence.TagsAssetPersistence.impl")
3237    protected com.liferay.portlet.tags.service.persistence.TagsAssetPersistence tagsAssetPersistence;
3238    @BeanReference(name = "com.liferay.portlet.tags.service.persistence.TagsEntryPersistence.impl")
3239    protected com.liferay.portlet.tags.service.persistence.TagsEntryPersistence tagsEntryPersistence;
3240    @BeanReference(name = "com.liferay.portlet.social.service.persistence.SocialActivityPersistence.impl")
3241    protected com.liferay.portlet.social.service.persistence.SocialActivityPersistence socialActivityPersistence;
3242    private static Log _log = LogFactoryUtil.getLog(IGImagePersistenceImpl.class);
3243}