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