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