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