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