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