001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.imagegallery.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.kernel.annotation.BeanReference;
019    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.SQLQuery;
027    import com.liferay.portal.kernel.dao.orm.Session;
028    import com.liferay.portal.kernel.exception.SystemException;
029    import com.liferay.portal.kernel.log.Log;
030    import com.liferay.portal.kernel.log.LogFactoryUtil;
031    import com.liferay.portal.kernel.util.GetterUtil;
032    import com.liferay.portal.kernel.util.InstanceFactory;
033    import com.liferay.portal.kernel.util.OrderByComparator;
034    import com.liferay.portal.kernel.util.StringBundler;
035    import com.liferay.portal.kernel.util.StringPool;
036    import com.liferay.portal.kernel.util.StringUtil;
037    import com.liferay.portal.kernel.util.Validator;
038    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
039    import com.liferay.portal.model.ModelListener;
040    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
041    import com.liferay.portal.service.persistence.BatchSessionUtil;
042    import com.liferay.portal.service.persistence.ImagePersistence;
043    import com.liferay.portal.service.persistence.ResourcePersistence;
044    import com.liferay.portal.service.persistence.UserPersistence;
045    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
046    
047    import com.liferay.portlet.asset.service.persistence.AssetCategoryPersistence;
048    import com.liferay.portlet.asset.service.persistence.AssetEntryPersistence;
049    import com.liferay.portlet.asset.service.persistence.AssetTagPersistence;
050    import com.liferay.portlet.expando.service.persistence.ExpandoValuePersistence;
051    import com.liferay.portlet.imagegallery.NoSuchImageException;
052    import com.liferay.portlet.imagegallery.model.IGImage;
053    import com.liferay.portlet.imagegallery.model.impl.IGImageImpl;
054    import com.liferay.portlet.imagegallery.model.impl.IGImageModelImpl;
055    import com.liferay.portlet.social.service.persistence.SocialActivityPersistence;
056    
057    import java.io.Serializable;
058    
059    import java.util.ArrayList;
060    import java.util.Collections;
061    import java.util.List;
062    
063    /**
064     * The persistence implementation for the i g image service.
065     *
066     * <p>
067     * Never modify or reference this class directly. Always use {@link IGImageUtil} to access the i g image persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
068     * </p>
069     *
070     * <p>
071     * Caching information and settings can be found in <code>portal.properties</code>
072     * </p>
073     *
074     * @author Brian Wing Shun Chan
075     * @see IGImagePersistence
076     * @see IGImageUtil
077     * @generated
078     */
079    public class IGImagePersistenceImpl extends BasePersistenceImpl<IGImage>
080            implements IGImagePersistence {
081            public static final String FINDER_CLASS_NAME_ENTITY = IGImageImpl.class.getName();
082            public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
083                    ".List";
084            public static final FinderPath FINDER_PATH_FIND_BY_UUID = new FinderPath(IGImageModelImpl.ENTITY_CACHE_ENABLED,
085                            IGImageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
086                            "findByUuid",
087                            new String[] {
088                                    String.class.getName(),
089                                    
090                            "java.lang.Integer", "java.lang.Integer",
091                                    "com.liferay.portal.kernel.util.OrderByComparator"
092                            });
093            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(IGImageModelImpl.ENTITY_CACHE_ENABLED,
094                            IGImageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
095                            "countByUuid", new String[] { String.class.getName() });
096            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(IGImageModelImpl.ENTITY_CACHE_ENABLED,
097                            IGImageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
098                            "fetchByUUID_G",
099                            new String[] { String.class.getName(), Long.class.getName() });
100            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(IGImageModelImpl.ENTITY_CACHE_ENABLED,
101                            IGImageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
102                            "countByUUID_G",
103                            new String[] { String.class.getName(), Long.class.getName() });
104            public static final FinderPath FINDER_PATH_FIND_BY_GROUPID = new FinderPath(IGImageModelImpl.ENTITY_CACHE_ENABLED,
105                            IGImageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
106                            "findByGroupId",
107                            new String[] {
108                                    Long.class.getName(),
109                                    
110                            "java.lang.Integer", "java.lang.Integer",
111                                    "com.liferay.portal.kernel.util.OrderByComparator"
112                            });
113            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(IGImageModelImpl.ENTITY_CACHE_ENABLED,
114                            IGImageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
115                            "countByGroupId", new String[] { Long.class.getName() });
116            public static final FinderPath FINDER_PATH_FETCH_BY_SMALLIMAGEID = new FinderPath(IGImageModelImpl.ENTITY_CACHE_ENABLED,
117                            IGImageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
118                            "fetchBySmallImageId", new String[] { Long.class.getName() });
119            public static final FinderPath FINDER_PATH_COUNT_BY_SMALLIMAGEID = new FinderPath(IGImageModelImpl.ENTITY_CACHE_ENABLED,
120                            IGImageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
121                            "countBySmallImageId", new String[] { Long.class.getName() });
122            public static final FinderPath FINDER_PATH_FETCH_BY_LARGEIMAGEID = new FinderPath(IGImageModelImpl.ENTITY_CACHE_ENABLED,
123                            IGImageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
124                            "fetchByLargeImageId", new String[] { Long.class.getName() });
125            public static final FinderPath FINDER_PATH_COUNT_BY_LARGEIMAGEID = new FinderPath(IGImageModelImpl.ENTITY_CACHE_ENABLED,
126                            IGImageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
127                            "countByLargeImageId", new String[] { Long.class.getName() });
128            public static final FinderPath FINDER_PATH_FETCH_BY_CUSTOM1IMAGEID = new FinderPath(IGImageModelImpl.ENTITY_CACHE_ENABLED,
129                            IGImageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
130                            "fetchByCustom1ImageId", new String[] { Long.class.getName() });
131            public static final FinderPath FINDER_PATH_COUNT_BY_CUSTOM1IMAGEID = new FinderPath(IGImageModelImpl.ENTITY_CACHE_ENABLED,
132                            IGImageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
133                            "countByCustom1ImageId", new String[] { Long.class.getName() });
134            public static final FinderPath FINDER_PATH_FETCH_BY_CUSTOM2IMAGEID = new FinderPath(IGImageModelImpl.ENTITY_CACHE_ENABLED,
135                            IGImageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
136                            "fetchByCustom2ImageId", new String[] { Long.class.getName() });
137            public static final FinderPath FINDER_PATH_COUNT_BY_CUSTOM2IMAGEID = new FinderPath(IGImageModelImpl.ENTITY_CACHE_ENABLED,
138                            IGImageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
139                            "countByCustom2ImageId", new String[] { Long.class.getName() });
140            public static final FinderPath FINDER_PATH_FIND_BY_G_U = new FinderPath(IGImageModelImpl.ENTITY_CACHE_ENABLED,
141                            IGImageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
142                            "findByG_U",
143                            new String[] {
144                                    Long.class.getName(), Long.class.getName(),
145                                    
146                            "java.lang.Integer", "java.lang.Integer",
147                                    "com.liferay.portal.kernel.util.OrderByComparator"
148                            });
149            public static final FinderPath FINDER_PATH_COUNT_BY_G_U = new FinderPath(IGImageModelImpl.ENTITY_CACHE_ENABLED,
150                            IGImageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
151                            "countByG_U",
152                            new String[] { Long.class.getName(), Long.class.getName() });
153            public static final FinderPath FINDER_PATH_FIND_BY_G_F = new FinderPath(IGImageModelImpl.ENTITY_CACHE_ENABLED,
154                            IGImageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
155                            "findByG_F",
156                            new String[] {
157                                    Long.class.getName(), Long.class.getName(),
158                                    
159                            "java.lang.Integer", "java.lang.Integer",
160                                    "com.liferay.portal.kernel.util.OrderByComparator"
161                            });
162            public static final FinderPath FINDER_PATH_COUNT_BY_G_F = new FinderPath(IGImageModelImpl.ENTITY_CACHE_ENABLED,
163                            IGImageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
164                            "countByG_F",
165                            new String[] { Long.class.getName(), Long.class.getName() });
166            public static final FinderPath FINDER_PATH_FIND_BY_G_F_N = new FinderPath(IGImageModelImpl.ENTITY_CACHE_ENABLED,
167                            IGImageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
168                            "findByG_F_N",
169                            new String[] {
170                                    Long.class.getName(), Long.class.getName(),
171                                    String.class.getName(),
172                                    
173                            "java.lang.Integer", "java.lang.Integer",
174                                    "com.liferay.portal.kernel.util.OrderByComparator"
175                            });
176            public static final FinderPath FINDER_PATH_COUNT_BY_G_F_N = new FinderPath(IGImageModelImpl.ENTITY_CACHE_ENABLED,
177                            IGImageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
178                            "countByG_F_N",
179                            new String[] {
180                                    Long.class.getName(), Long.class.getName(),
181                                    String.class.getName()
182                            });
183            public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(IGImageModelImpl.ENTITY_CACHE_ENABLED,
184                            IGImageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
185                            "findAll", new String[0]);
186            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(IGImageModelImpl.ENTITY_CACHE_ENABLED,
187                            IGImageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
188                            "countAll", new String[0]);
189    
190            /**
191             * Caches the i g image in the entity cache if it is enabled.
192             *
193             * @param igImage the i g image to cache
194             */
195            public void cacheResult(IGImage igImage) {
196                    EntityCacheUtil.putResult(IGImageModelImpl.ENTITY_CACHE_ENABLED,
197                            IGImageImpl.class, igImage.getPrimaryKey(), igImage);
198    
199                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
200                            new Object[] { igImage.getUuid(), new Long(igImage.getGroupId()) },
201                            igImage);
202    
203                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
204                            new Object[] { new Long(igImage.getSmallImageId()) }, igImage);
205    
206                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_LARGEIMAGEID,
207                            new Object[] { new Long(igImage.getLargeImageId()) }, igImage);
208    
209                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_CUSTOM1IMAGEID,
210                            new Object[] { new Long(igImage.getCustom1ImageId()) }, igImage);
211    
212                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_CUSTOM2IMAGEID,
213                            new Object[] { new Long(igImage.getCustom2ImageId()) }, igImage);
214            }
215    
216            /**
217             * Caches the i g images in the entity cache if it is enabled.
218             *
219             * @param igImages the i g images to cache
220             */
221            public void cacheResult(List<IGImage> igImages) {
222                    for (IGImage igImage : igImages) {
223                            if (EntityCacheUtil.getResult(
224                                                    IGImageModelImpl.ENTITY_CACHE_ENABLED,
225                                                    IGImageImpl.class, igImage.getPrimaryKey(), this) == null) {
226                                    cacheResult(igImage);
227                            }
228                    }
229            }
230    
231            /**
232             * Clears the cache for all i g images.
233             *
234             * <p>
235             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
236             * </p>
237             */
238            public void clearCache() {
239                    CacheRegistryUtil.clear(IGImageImpl.class.getName());
240                    EntityCacheUtil.clearCache(IGImageImpl.class.getName());
241                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
242                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
243            }
244    
245            /**
246             * Clears the cache for the i g image.
247             *
248             * <p>
249             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
250             * </p>
251             */
252            public void clearCache(IGImage igImage) {
253                    EntityCacheUtil.removeResult(IGImageModelImpl.ENTITY_CACHE_ENABLED,
254                            IGImageImpl.class, igImage.getPrimaryKey());
255    
256                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
257                            new Object[] { igImage.getUuid(), new Long(igImage.getGroupId()) });
258    
259                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
260                            new Object[] { new Long(igImage.getSmallImageId()) });
261    
262                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_LARGEIMAGEID,
263                            new Object[] { new Long(igImage.getLargeImageId()) });
264    
265                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_CUSTOM1IMAGEID,
266                            new Object[] { new Long(igImage.getCustom1ImageId()) });
267    
268                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_CUSTOM2IMAGEID,
269                            new Object[] { new Long(igImage.getCustom2ImageId()) });
270            }
271    
272            /**
273             * Creates a new i g image with the primary key. Does not add the i g image to the database.
274             *
275             * @param imageId the primary key for the new i g image
276             * @return the new i g image
277             */
278            public IGImage create(long imageId) {
279                    IGImage igImage = new IGImageImpl();
280    
281                    igImage.setNew(true);
282                    igImage.setPrimaryKey(imageId);
283    
284                    String uuid = PortalUUIDUtil.generate();
285    
286                    igImage.setUuid(uuid);
287    
288                    return igImage;
289            }
290    
291            /**
292             * Removes the i g image with the primary key from the database. Also notifies the appropriate model listeners.
293             *
294             * @param primaryKey the primary key of the i g image to remove
295             * @return the i g image that was removed
296             * @throws com.liferay.portal.NoSuchModelException if a i g image with the primary key could not be found
297             * @throws SystemException if a system exception occurred
298             */
299            public IGImage remove(Serializable primaryKey)
300                    throws NoSuchModelException, SystemException {
301                    return remove(((Long)primaryKey).longValue());
302            }
303    
304            /**
305             * Removes the i g image with the primary key from the database. Also notifies the appropriate model listeners.
306             *
307             * @param imageId the primary key of the i g image to remove
308             * @return the i g image that was removed
309             * @throws com.liferay.portlet.imagegallery.NoSuchImageException if a i g image with the primary key could not be found
310             * @throws SystemException if a system exception occurred
311             */
312            public IGImage remove(long imageId)
313                    throws NoSuchImageException, SystemException {
314                    Session session = null;
315    
316                    try {
317                            session = openSession();
318    
319                            IGImage igImage = (IGImage)session.get(IGImageImpl.class,
320                                            new Long(imageId));
321    
322                            if (igImage == null) {
323                                    if (_log.isWarnEnabled()) {
324                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + imageId);
325                                    }
326    
327                                    throw new NoSuchImageException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
328                                            imageId);
329                            }
330    
331                            return remove(igImage);
332                    }
333                    catch (NoSuchImageException nsee) {
334                            throw nsee;
335                    }
336                    catch (Exception e) {
337                            throw processException(e);
338                    }
339                    finally {
340                            closeSession(session);
341                    }
342            }
343    
344            protected IGImage removeImpl(IGImage igImage) throws SystemException {
345                    igImage = toUnwrappedModel(igImage);
346    
347                    Session session = null;
348    
349                    try {
350                            session = openSession();
351    
352                            if (igImage.isCachedModel() || BatchSessionUtil.isEnabled()) {
353                                    Object staleObject = session.get(IGImageImpl.class,
354                                                    igImage.getPrimaryKeyObj());
355    
356                                    if (staleObject != null) {
357                                            session.evict(staleObject);
358                                    }
359                            }
360    
361                            session.delete(igImage);
362    
363                            session.flush();
364                    }
365                    catch (Exception e) {
366                            throw processException(e);
367                    }
368                    finally {
369                            closeSession(session);
370                    }
371    
372                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
373    
374                    IGImageModelImpl igImageModelImpl = (IGImageModelImpl)igImage;
375    
376                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
377                            new Object[] {
378                                    igImageModelImpl.getOriginalUuid(),
379                                    new Long(igImageModelImpl.getOriginalGroupId())
380                            });
381    
382                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
383                            new Object[] { new Long(igImageModelImpl.getOriginalSmallImageId()) });
384    
385                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_LARGEIMAGEID,
386                            new Object[] { new Long(igImageModelImpl.getOriginalLargeImageId()) });
387    
388                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_CUSTOM1IMAGEID,
389                            new Object[] { new Long(igImageModelImpl.getOriginalCustom1ImageId()) });
390    
391                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_CUSTOM2IMAGEID,
392                            new Object[] { new Long(igImageModelImpl.getOriginalCustom2ImageId()) });
393    
394                    EntityCacheUtil.removeResult(IGImageModelImpl.ENTITY_CACHE_ENABLED,
395                            IGImageImpl.class, igImage.getPrimaryKey());
396    
397                    return igImage;
398            }
399    
400            public IGImage updateImpl(
401                    com.liferay.portlet.imagegallery.model.IGImage igImage, boolean merge)
402                    throws SystemException {
403                    igImage = toUnwrappedModel(igImage);
404    
405                    boolean isNew = igImage.isNew();
406    
407                    IGImageModelImpl igImageModelImpl = (IGImageModelImpl)igImage;
408    
409                    if (Validator.isNull(igImage.getUuid())) {
410                            String uuid = PortalUUIDUtil.generate();
411    
412                            igImage.setUuid(uuid);
413                    }
414    
415                    Session session = null;
416    
417                    try {
418                            session = openSession();
419    
420                            BatchSessionUtil.update(session, igImage, merge);
421    
422                            igImage.setNew(false);
423                    }
424                    catch (Exception e) {
425                            throw processException(e);
426                    }
427                    finally {
428                            closeSession(session);
429                    }
430    
431                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
432    
433                    EntityCacheUtil.putResult(IGImageModelImpl.ENTITY_CACHE_ENABLED,
434                            IGImageImpl.class, igImage.getPrimaryKey(), igImage);
435    
436                    if (!isNew &&
437                                    (!Validator.equals(igImage.getUuid(),
438                                            igImageModelImpl.getOriginalUuid()) ||
439                                    (igImage.getGroupId() != igImageModelImpl.getOriginalGroupId()))) {
440                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
441                                    new Object[] {
442                                            igImageModelImpl.getOriginalUuid(),
443                                            new Long(igImageModelImpl.getOriginalGroupId())
444                                    });
445                    }
446    
447                    if (isNew ||
448                                    (!Validator.equals(igImage.getUuid(),
449                                            igImageModelImpl.getOriginalUuid()) ||
450                                    (igImage.getGroupId() != igImageModelImpl.getOriginalGroupId()))) {
451                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
452                                    new Object[] { igImage.getUuid(), new Long(igImage.getGroupId()) },
453                                    igImage);
454                    }
455    
456                    if (!isNew &&
457                                    (igImage.getSmallImageId() != igImageModelImpl.getOriginalSmallImageId())) {
458                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
459                                    new Object[] {
460                                            new Long(igImageModelImpl.getOriginalSmallImageId())
461                                    });
462                    }
463    
464                    if (isNew ||
465                                    (igImage.getSmallImageId() != igImageModelImpl.getOriginalSmallImageId())) {
466                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
467                                    new Object[] { new Long(igImage.getSmallImageId()) }, igImage);
468                    }
469    
470                    if (!isNew &&
471                                    (igImage.getLargeImageId() != igImageModelImpl.getOriginalLargeImageId())) {
472                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_LARGEIMAGEID,
473                                    new Object[] {
474                                            new Long(igImageModelImpl.getOriginalLargeImageId())
475                                    });
476                    }
477    
478                    if (isNew ||
479                                    (igImage.getLargeImageId() != igImageModelImpl.getOriginalLargeImageId())) {
480                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_LARGEIMAGEID,
481                                    new Object[] { new Long(igImage.getLargeImageId()) }, igImage);
482                    }
483    
484                    if (!isNew &&
485                                    (igImage.getCustom1ImageId() != igImageModelImpl.getOriginalCustom1ImageId())) {
486                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_CUSTOM1IMAGEID,
487                                    new Object[] {
488                                            new Long(igImageModelImpl.getOriginalCustom1ImageId())
489                                    });
490                    }
491    
492                    if (isNew ||
493                                    (igImage.getCustom1ImageId() != igImageModelImpl.getOriginalCustom1ImageId())) {
494                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_CUSTOM1IMAGEID,
495                                    new Object[] { new Long(igImage.getCustom1ImageId()) }, igImage);
496                    }
497    
498                    if (!isNew &&
499                                    (igImage.getCustom2ImageId() != igImageModelImpl.getOriginalCustom2ImageId())) {
500                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_CUSTOM2IMAGEID,
501                                    new Object[] {
502                                            new Long(igImageModelImpl.getOriginalCustom2ImageId())
503                                    });
504                    }
505    
506                    if (isNew ||
507                                    (igImage.getCustom2ImageId() != igImageModelImpl.getOriginalCustom2ImageId())) {
508                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_CUSTOM2IMAGEID,
509                                    new Object[] { new Long(igImage.getCustom2ImageId()) }, igImage);
510                    }
511    
512                    return igImage;
513            }
514    
515            protected IGImage toUnwrappedModel(IGImage igImage) {
516                    if (igImage instanceof IGImageImpl) {
517                            return igImage;
518                    }
519    
520                    IGImageImpl igImageImpl = new IGImageImpl();
521    
522                    igImageImpl.setNew(igImage.isNew());
523                    igImageImpl.setPrimaryKey(igImage.getPrimaryKey());
524    
525                    igImageImpl.setUuid(igImage.getUuid());
526                    igImageImpl.setImageId(igImage.getImageId());
527                    igImageImpl.setGroupId(igImage.getGroupId());
528                    igImageImpl.setCompanyId(igImage.getCompanyId());
529                    igImageImpl.setUserId(igImage.getUserId());
530                    igImageImpl.setCreateDate(igImage.getCreateDate());
531                    igImageImpl.setModifiedDate(igImage.getModifiedDate());
532                    igImageImpl.setFolderId(igImage.getFolderId());
533                    igImageImpl.setName(igImage.getName());
534                    igImageImpl.setDescription(igImage.getDescription());
535                    igImageImpl.setSmallImageId(igImage.getSmallImageId());
536                    igImageImpl.setLargeImageId(igImage.getLargeImageId());
537                    igImageImpl.setCustom1ImageId(igImage.getCustom1ImageId());
538                    igImageImpl.setCustom2ImageId(igImage.getCustom2ImageId());
539    
540                    return igImageImpl;
541            }
542    
543            /**
544             * Finds the i g image with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
545             *
546             * @param primaryKey the primary key of the i g image to find
547             * @return the i g image
548             * @throws com.liferay.portal.NoSuchModelException if a i g image with the primary key could not be found
549             * @throws SystemException if a system exception occurred
550             */
551            public IGImage findByPrimaryKey(Serializable primaryKey)
552                    throws NoSuchModelException, SystemException {
553                    return findByPrimaryKey(((Long)primaryKey).longValue());
554            }
555    
556            /**
557             * Finds the i g image with the primary key or throws a {@link com.liferay.portlet.imagegallery.NoSuchImageException} if it could not be found.
558             *
559             * @param imageId the primary key of the i g image to find
560             * @return the i g image
561             * @throws com.liferay.portlet.imagegallery.NoSuchImageException if a i g image with the primary key could not be found
562             * @throws SystemException if a system exception occurred
563             */
564            public IGImage findByPrimaryKey(long imageId)
565                    throws NoSuchImageException, SystemException {
566                    IGImage igImage = fetchByPrimaryKey(imageId);
567    
568                    if (igImage == null) {
569                            if (_log.isWarnEnabled()) {
570                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + imageId);
571                            }
572    
573                            throw new NoSuchImageException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
574                                    imageId);
575                    }
576    
577                    return igImage;
578            }
579    
580            /**
581             * Finds the i g image with the primary key or returns <code>null</code> if it could not be found.
582             *
583             * @param primaryKey the primary key of the i g image to find
584             * @return the i g image, or <code>null</code> if a i g image with the primary key could not be found
585             * @throws SystemException if a system exception occurred
586             */
587            public IGImage fetchByPrimaryKey(Serializable primaryKey)
588                    throws SystemException {
589                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
590            }
591    
592            /**
593             * Finds the i g image with the primary key or returns <code>null</code> if it could not be found.
594             *
595             * @param imageId the primary key of the i g image to find
596             * @return the i g image, or <code>null</code> if a i g image with the primary key could not be found
597             * @throws SystemException if a system exception occurred
598             */
599            public IGImage fetchByPrimaryKey(long imageId) throws SystemException {
600                    IGImage igImage = (IGImage)EntityCacheUtil.getResult(IGImageModelImpl.ENTITY_CACHE_ENABLED,
601                                    IGImageImpl.class, imageId, this);
602    
603                    if (igImage == null) {
604                            Session session = null;
605    
606                            try {
607                                    session = openSession();
608    
609                                    igImage = (IGImage)session.get(IGImageImpl.class,
610                                                    new Long(imageId));
611                            }
612                            catch (Exception e) {
613                                    throw processException(e);
614                            }
615                            finally {
616                                    if (igImage != null) {
617                                            cacheResult(igImage);
618                                    }
619    
620                                    closeSession(session);
621                            }
622                    }
623    
624                    return igImage;
625            }
626    
627            /**
628             * Finds all the i g images where uuid = &#63;.
629             *
630             * @param uuid the uuid to search with
631             * @return the matching i g images
632             * @throws SystemException if a system exception occurred
633             */
634            public List<IGImage> findByUuid(String uuid) throws SystemException {
635                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
636            }
637    
638            /**
639             * Finds a range of all the i g images where uuid = &#63;.
640             *
641             * <p>
642             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
643             * </p>
644             *
645             * @param uuid the uuid to search with
646             * @param start the lower bound of the range of i g images to return
647             * @param end the upper bound of the range of i g images to return (not inclusive)
648             * @return the range of matching i g images
649             * @throws SystemException if a system exception occurred
650             */
651            public List<IGImage> findByUuid(String uuid, int start, int end)
652                    throws SystemException {
653                    return findByUuid(uuid, start, end, null);
654            }
655    
656            /**
657             * Finds an ordered range of all the i g images where uuid = &#63;.
658             *
659             * <p>
660             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
661             * </p>
662             *
663             * @param uuid the uuid to search with
664             * @param start the lower bound of the range of i g images to return
665             * @param end the upper bound of the range of i g images to return (not inclusive)
666             * @param orderByComparator the comparator to order the results by
667             * @return the ordered range of matching i g images
668             * @throws SystemException if a system exception occurred
669             */
670            public List<IGImage> findByUuid(String uuid, int start, int end,
671                    OrderByComparator orderByComparator) throws SystemException {
672                    Object[] finderArgs = new Object[] {
673                                    uuid,
674                                    
675                                    String.valueOf(start), String.valueOf(end),
676                                    String.valueOf(orderByComparator)
677                            };
678    
679                    List<IGImage> list = (List<IGImage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_UUID,
680                                    finderArgs, this);
681    
682                    if (list == null) {
683                            Session session = null;
684    
685                            try {
686                                    session = openSession();
687    
688                                    StringBundler query = null;
689    
690                                    if (orderByComparator != null) {
691                                            query = new StringBundler(3 +
692                                                            (orderByComparator.getOrderByFields().length * 3));
693                                    }
694                                    else {
695                                            query = new StringBundler(3);
696                                    }
697    
698                                    query.append(_SQL_SELECT_IGIMAGE_WHERE);
699    
700                                    if (uuid == null) {
701                                            query.append(_FINDER_COLUMN_UUID_UUID_1);
702                                    }
703                                    else {
704                                            if (uuid.equals(StringPool.BLANK)) {
705                                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
706                                            }
707                                            else {
708                                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
709                                            }
710                                    }
711    
712                                    if (orderByComparator != null) {
713                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
714                                                    orderByComparator);
715                                    }
716    
717                                    else {
718                                            query.append(IGImageModelImpl.ORDER_BY_JPQL);
719                                    }
720    
721                                    String sql = query.toString();
722    
723                                    Query q = session.createQuery(sql);
724    
725                                    QueryPos qPos = QueryPos.getInstance(q);
726    
727                                    if (uuid != null) {
728                                            qPos.add(uuid);
729                                    }
730    
731                                    list = (List<IGImage>)QueryUtil.list(q, getDialect(), start, end);
732                            }
733                            catch (Exception e) {
734                                    throw processException(e);
735                            }
736                            finally {
737                                    if (list == null) {
738                                            list = new ArrayList<IGImage>();
739                                    }
740    
741                                    cacheResult(list);
742    
743                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_UUID, finderArgs,
744                                            list);
745    
746                                    closeSession(session);
747                            }
748                    }
749    
750                    return list;
751            }
752    
753            /**
754             * Finds the first i g image in the ordered set where uuid = &#63;.
755             *
756             * <p>
757             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
758             * </p>
759             *
760             * @param uuid the uuid to search with
761             * @param orderByComparator the comparator to order the set by
762             * @return the first matching i g image
763             * @throws com.liferay.portlet.imagegallery.NoSuchImageException if a matching i g image could not be found
764             * @throws SystemException if a system exception occurred
765             */
766            public IGImage findByUuid_First(String uuid,
767                    OrderByComparator orderByComparator)
768                    throws NoSuchImageException, SystemException {
769                    List<IGImage> list = findByUuid(uuid, 0, 1, orderByComparator);
770    
771                    if (list.isEmpty()) {
772                            StringBundler msg = new StringBundler(4);
773    
774                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
775    
776                            msg.append("uuid=");
777                            msg.append(uuid);
778    
779                            msg.append(StringPool.CLOSE_CURLY_BRACE);
780    
781                            throw new NoSuchImageException(msg.toString());
782                    }
783                    else {
784                            return list.get(0);
785                    }
786            }
787    
788            /**
789             * Finds the last i g image in the ordered set where uuid = &#63;.
790             *
791             * <p>
792             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
793             * </p>
794             *
795             * @param uuid the uuid to search with
796             * @param orderByComparator the comparator to order the set by
797             * @return the last matching i g image
798             * @throws com.liferay.portlet.imagegallery.NoSuchImageException if a matching i g image could not be found
799             * @throws SystemException if a system exception occurred
800             */
801            public IGImage findByUuid_Last(String uuid,
802                    OrderByComparator orderByComparator)
803                    throws NoSuchImageException, SystemException {
804                    int count = countByUuid(uuid);
805    
806                    List<IGImage> list = findByUuid(uuid, count - 1, count,
807                                    orderByComparator);
808    
809                    if (list.isEmpty()) {
810                            StringBundler msg = new StringBundler(4);
811    
812                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
813    
814                            msg.append("uuid=");
815                            msg.append(uuid);
816    
817                            msg.append(StringPool.CLOSE_CURLY_BRACE);
818    
819                            throw new NoSuchImageException(msg.toString());
820                    }
821                    else {
822                            return list.get(0);
823                    }
824            }
825    
826            /**
827             * Finds the i g images before and after the current i g image in the ordered set where uuid = &#63;.
828             *
829             * <p>
830             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
831             * </p>
832             *
833             * @param imageId the primary key of the current i g image
834             * @param uuid the uuid to search with
835             * @param orderByComparator the comparator to order the set by
836             * @return the previous, current, and next i g image
837             * @throws com.liferay.portlet.imagegallery.NoSuchImageException if a i g image with the primary key could not be found
838             * @throws SystemException if a system exception occurred
839             */
840            public IGImage[] findByUuid_PrevAndNext(long imageId, String uuid,
841                    OrderByComparator orderByComparator)
842                    throws NoSuchImageException, SystemException {
843                    IGImage igImage = findByPrimaryKey(imageId);
844    
845                    Session session = null;
846    
847                    try {
848                            session = openSession();
849    
850                            IGImage[] array = new IGImageImpl[3];
851    
852                            array[0] = getByUuid_PrevAndNext(session, igImage, uuid,
853                                            orderByComparator, true);
854    
855                            array[1] = igImage;
856    
857                            array[2] = getByUuid_PrevAndNext(session, igImage, uuid,
858                                            orderByComparator, false);
859    
860                            return array;
861                    }
862                    catch (Exception e) {
863                            throw processException(e);
864                    }
865                    finally {
866                            closeSession(session);
867                    }
868            }
869    
870            protected IGImage getByUuid_PrevAndNext(Session session, IGImage igImage,
871                    String uuid, OrderByComparator orderByComparator, boolean previous) {
872                    StringBundler query = null;
873    
874                    if (orderByComparator != null) {
875                            query = new StringBundler(6 +
876                                            (orderByComparator.getOrderByFields().length * 6));
877                    }
878                    else {
879                            query = new StringBundler(3);
880                    }
881    
882                    query.append(_SQL_SELECT_IGIMAGE_WHERE);
883    
884                    if (uuid == null) {
885                            query.append(_FINDER_COLUMN_UUID_UUID_1);
886                    }
887                    else {
888                            if (uuid.equals(StringPool.BLANK)) {
889                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
890                            }
891                            else {
892                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
893                            }
894                    }
895    
896                    if (orderByComparator != null) {
897                            String[] orderByFields = orderByComparator.getOrderByFields();
898    
899                            if (orderByFields.length > 0) {
900                                    query.append(WHERE_AND);
901                            }
902    
903                            for (int i = 0; i < orderByFields.length; i++) {
904                                    query.append(_ORDER_BY_ENTITY_ALIAS);
905                                    query.append(orderByFields[i]);
906    
907                                    if ((i + 1) < orderByFields.length) {
908                                            if (orderByComparator.isAscending() ^ previous) {
909                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
910                                            }
911                                            else {
912                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
913                                            }
914                                    }
915                                    else {
916                                            if (orderByComparator.isAscending() ^ previous) {
917                                                    query.append(WHERE_GREATER_THAN);
918                                            }
919                                            else {
920                                                    query.append(WHERE_LESSER_THAN);
921                                            }
922                                    }
923                            }
924    
925                            query.append(ORDER_BY_CLAUSE);
926    
927                            for (int i = 0; i < orderByFields.length; i++) {
928                                    query.append(_ORDER_BY_ENTITY_ALIAS);
929                                    query.append(orderByFields[i]);
930    
931                                    if ((i + 1) < orderByFields.length) {
932                                            if (orderByComparator.isAscending() ^ previous) {
933                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
934                                            }
935                                            else {
936                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
937                                            }
938                                    }
939                                    else {
940                                            if (orderByComparator.isAscending() ^ previous) {
941                                                    query.append(ORDER_BY_ASC);
942                                            }
943                                            else {
944                                                    query.append(ORDER_BY_DESC);
945                                            }
946                                    }
947                            }
948                    }
949    
950                    else {
951                            query.append(IGImageModelImpl.ORDER_BY_JPQL);
952                    }
953    
954                    String sql = query.toString();
955    
956                    Query q = session.createQuery(sql);
957    
958                    q.setFirstResult(0);
959                    q.setMaxResults(2);
960    
961                    QueryPos qPos = QueryPos.getInstance(q);
962    
963                    if (uuid != null) {
964                            qPos.add(uuid);
965                    }
966    
967                    if (orderByComparator != null) {
968                            Object[] values = orderByComparator.getOrderByValues(igImage);
969    
970                            for (Object value : values) {
971                                    qPos.add(value);
972                            }
973                    }
974    
975                    List<IGImage> list = q.list();
976    
977                    if (list.size() == 2) {
978                            return list.get(1);
979                    }
980                    else {
981                            return null;
982                    }
983            }
984    
985            /**
986             * Finds the i g image where uuid = &#63; and groupId = &#63; or throws a {@link com.liferay.portlet.imagegallery.NoSuchImageException} if it could not be found.
987             *
988             * @param uuid the uuid to search with
989             * @param groupId the group id to search with
990             * @return the matching i g image
991             * @throws com.liferay.portlet.imagegallery.NoSuchImageException if a matching i g image could not be found
992             * @throws SystemException if a system exception occurred
993             */
994            public IGImage findByUUID_G(String uuid, long groupId)
995                    throws NoSuchImageException, SystemException {
996                    IGImage igImage = fetchByUUID_G(uuid, groupId);
997    
998                    if (igImage == null) {
999                            StringBundler msg = new StringBundler(6);
1000    
1001                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1002    
1003                            msg.append("uuid=");
1004                            msg.append(uuid);
1005    
1006                            msg.append(", groupId=");
1007                            msg.append(groupId);
1008    
1009                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1010    
1011                            if (_log.isWarnEnabled()) {
1012                                    _log.warn(msg.toString());
1013                            }
1014    
1015                            throw new NoSuchImageException(msg.toString());
1016                    }
1017    
1018                    return igImage;
1019            }
1020    
1021            /**
1022             * Finds the i g image where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
1023             *
1024             * @param uuid the uuid to search with
1025             * @param groupId the group id to search with
1026             * @return the matching i g image, or <code>null</code> if a matching i g image could not be found
1027             * @throws SystemException if a system exception occurred
1028             */
1029            public IGImage fetchByUUID_G(String uuid, long groupId)
1030                    throws SystemException {
1031                    return fetchByUUID_G(uuid, groupId, true);
1032            }
1033    
1034            /**
1035             * Finds the i g image where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
1036             *
1037             * @param uuid the uuid to search with
1038             * @param groupId the group id to search with
1039             * @return the matching i g image, or <code>null</code> if a matching i g image could not be found
1040             * @throws SystemException if a system exception occurred
1041             */
1042            public IGImage fetchByUUID_G(String uuid, long groupId,
1043                    boolean retrieveFromCache) throws SystemException {
1044                    Object[] finderArgs = new Object[] { uuid, groupId };
1045    
1046                    Object result = null;
1047    
1048                    if (retrieveFromCache) {
1049                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
1050                                            finderArgs, this);
1051                    }
1052    
1053                    if (result == null) {
1054                            Session session = null;
1055    
1056                            try {
1057                                    session = openSession();
1058    
1059                                    StringBundler query = new StringBundler(4);
1060    
1061                                    query.append(_SQL_SELECT_IGIMAGE_WHERE);
1062    
1063                                    if (uuid == null) {
1064                                            query.append(_FINDER_COLUMN_UUID_G_UUID_1);
1065                                    }
1066                                    else {
1067                                            if (uuid.equals(StringPool.BLANK)) {
1068                                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
1069                                            }
1070                                            else {
1071                                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
1072                                            }
1073                                    }
1074    
1075                                    query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
1076    
1077                                    query.append(IGImageModelImpl.ORDER_BY_JPQL);
1078    
1079                                    String sql = query.toString();
1080    
1081                                    Query q = session.createQuery(sql);
1082    
1083                                    QueryPos qPos = QueryPos.getInstance(q);
1084    
1085                                    if (uuid != null) {
1086                                            qPos.add(uuid);
1087                                    }
1088    
1089                                    qPos.add(groupId);
1090    
1091                                    List<IGImage> list = q.list();
1092    
1093                                    result = list;
1094    
1095                                    IGImage igImage = null;
1096    
1097                                    if (list.isEmpty()) {
1098                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1099                                                    finderArgs, list);
1100                                    }
1101                                    else {
1102                                            igImage = list.get(0);
1103    
1104                                            cacheResult(igImage);
1105    
1106                                            if ((igImage.getUuid() == null) ||
1107                                                            !igImage.getUuid().equals(uuid) ||
1108                                                            (igImage.getGroupId() != groupId)) {
1109                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1110                                                            finderArgs, igImage);
1111                                            }
1112                                    }
1113    
1114                                    return igImage;
1115                            }
1116                            catch (Exception e) {
1117                                    throw processException(e);
1118                            }
1119                            finally {
1120                                    if (result == null) {
1121                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1122                                                    finderArgs, new ArrayList<IGImage>());
1123                                    }
1124    
1125                                    closeSession(session);
1126                            }
1127                    }
1128                    else {
1129                            if (result instanceof List<?>) {
1130                                    return null;
1131                            }
1132                            else {
1133                                    return (IGImage)result;
1134                            }
1135                    }
1136            }
1137    
1138            /**
1139             * Finds all the i g images where groupId = &#63;.
1140             *
1141             * @param groupId the group id to search with
1142             * @return the matching i g images
1143             * @throws SystemException if a system exception occurred
1144             */
1145            public List<IGImage> findByGroupId(long groupId) throws SystemException {
1146                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1147            }
1148    
1149            /**
1150             * Finds a range of all the i g images where groupId = &#63;.
1151             *
1152             * <p>
1153             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1154             * </p>
1155             *
1156             * @param groupId the group id to search with
1157             * @param start the lower bound of the range of i g images to return
1158             * @param end the upper bound of the range of i g images to return (not inclusive)
1159             * @return the range of matching i g images
1160             * @throws SystemException if a system exception occurred
1161             */
1162            public List<IGImage> findByGroupId(long groupId, int start, int end)
1163                    throws SystemException {
1164                    return findByGroupId(groupId, start, end, null);
1165            }
1166    
1167            /**
1168             * Finds an ordered range of all the i g images where groupId = &#63;.
1169             *
1170             * <p>
1171             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1172             * </p>
1173             *
1174             * @param groupId the group id to search with
1175             * @param start the lower bound of the range of i g images to return
1176             * @param end the upper bound of the range of i g images to return (not inclusive)
1177             * @param orderByComparator the comparator to order the results by
1178             * @return the ordered range of matching i g images
1179             * @throws SystemException if a system exception occurred
1180             */
1181            public List<IGImage> findByGroupId(long groupId, int start, int end,
1182                    OrderByComparator orderByComparator) throws SystemException {
1183                    Object[] finderArgs = new Object[] {
1184                                    groupId,
1185                                    
1186                                    String.valueOf(start), String.valueOf(end),
1187                                    String.valueOf(orderByComparator)
1188                            };
1189    
1190                    List<IGImage> list = (List<IGImage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
1191                                    finderArgs, this);
1192    
1193                    if (list == null) {
1194                            Session session = null;
1195    
1196                            try {
1197                                    session = openSession();
1198    
1199                                    StringBundler query = null;
1200    
1201                                    if (orderByComparator != null) {
1202                                            query = new StringBundler(3 +
1203                                                            (orderByComparator.getOrderByFields().length * 3));
1204                                    }
1205                                    else {
1206                                            query = new StringBundler(3);
1207                                    }
1208    
1209                                    query.append(_SQL_SELECT_IGIMAGE_WHERE);
1210    
1211                                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1212    
1213                                    if (orderByComparator != null) {
1214                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1215                                                    orderByComparator);
1216                                    }
1217    
1218                                    else {
1219                                            query.append(IGImageModelImpl.ORDER_BY_JPQL);
1220                                    }
1221    
1222                                    String sql = query.toString();
1223    
1224                                    Query q = session.createQuery(sql);
1225    
1226                                    QueryPos qPos = QueryPos.getInstance(q);
1227    
1228                                    qPos.add(groupId);
1229    
1230                                    list = (List<IGImage>)QueryUtil.list(q, getDialect(), start, end);
1231                            }
1232                            catch (Exception e) {
1233                                    throw processException(e);
1234                            }
1235                            finally {
1236                                    if (list == null) {
1237                                            list = new ArrayList<IGImage>();
1238                                    }
1239    
1240                                    cacheResult(list);
1241    
1242                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
1243                                            finderArgs, list);
1244    
1245                                    closeSession(session);
1246                            }
1247                    }
1248    
1249                    return list;
1250            }
1251    
1252            /**
1253             * Finds the first i g image in the ordered set where groupId = &#63;.
1254             *
1255             * <p>
1256             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1257             * </p>
1258             *
1259             * @param groupId the group id to search with
1260             * @param orderByComparator the comparator to order the set by
1261             * @return the first matching i g image
1262             * @throws com.liferay.portlet.imagegallery.NoSuchImageException if a matching i g image could not be found
1263             * @throws SystemException if a system exception occurred
1264             */
1265            public IGImage findByGroupId_First(long groupId,
1266                    OrderByComparator orderByComparator)
1267                    throws NoSuchImageException, SystemException {
1268                    List<IGImage> list = findByGroupId(groupId, 0, 1, orderByComparator);
1269    
1270                    if (list.isEmpty()) {
1271                            StringBundler msg = new StringBundler(4);
1272    
1273                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1274    
1275                            msg.append("groupId=");
1276                            msg.append(groupId);
1277    
1278                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1279    
1280                            throw new NoSuchImageException(msg.toString());
1281                    }
1282                    else {
1283                            return list.get(0);
1284                    }
1285            }
1286    
1287            /**
1288             * Finds the last i g image in the ordered set where groupId = &#63;.
1289             *
1290             * <p>
1291             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1292             * </p>
1293             *
1294             * @param groupId the group id to search with
1295             * @param orderByComparator the comparator to order the set by
1296             * @return the last matching i g image
1297             * @throws com.liferay.portlet.imagegallery.NoSuchImageException if a matching i g image could not be found
1298             * @throws SystemException if a system exception occurred
1299             */
1300            public IGImage findByGroupId_Last(long groupId,
1301                    OrderByComparator orderByComparator)
1302                    throws NoSuchImageException, SystemException {
1303                    int count = countByGroupId(groupId);
1304    
1305                    List<IGImage> list = findByGroupId(groupId, count - 1, count,
1306                                    orderByComparator);
1307    
1308                    if (list.isEmpty()) {
1309                            StringBundler msg = new StringBundler(4);
1310    
1311                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1312    
1313                            msg.append("groupId=");
1314                            msg.append(groupId);
1315    
1316                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1317    
1318                            throw new NoSuchImageException(msg.toString());
1319                    }
1320                    else {
1321                            return list.get(0);
1322                    }
1323            }
1324    
1325            /**
1326             * Finds the i g images before and after the current i g image in the ordered set where groupId = &#63;.
1327             *
1328             * <p>
1329             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1330             * </p>
1331             *
1332             * @param imageId the primary key of the current i g image
1333             * @param groupId the group id to search with
1334             * @param orderByComparator the comparator to order the set by
1335             * @return the previous, current, and next i g image
1336             * @throws com.liferay.portlet.imagegallery.NoSuchImageException if a i g image with the primary key could not be found
1337             * @throws SystemException if a system exception occurred
1338             */
1339            public IGImage[] findByGroupId_PrevAndNext(long imageId, long groupId,
1340                    OrderByComparator orderByComparator)
1341                    throws NoSuchImageException, SystemException {
1342                    IGImage igImage = findByPrimaryKey(imageId);
1343    
1344                    Session session = null;
1345    
1346                    try {
1347                            session = openSession();
1348    
1349                            IGImage[] array = new IGImageImpl[3];
1350    
1351                            array[0] = getByGroupId_PrevAndNext(session, igImage, groupId,
1352                                            orderByComparator, true);
1353    
1354                            array[1] = igImage;
1355    
1356                            array[2] = getByGroupId_PrevAndNext(session, igImage, groupId,
1357                                            orderByComparator, false);
1358    
1359                            return array;
1360                    }
1361                    catch (Exception e) {
1362                            throw processException(e);
1363                    }
1364                    finally {
1365                            closeSession(session);
1366                    }
1367            }
1368    
1369            protected IGImage getByGroupId_PrevAndNext(Session session,
1370                    IGImage igImage, long groupId, OrderByComparator orderByComparator,
1371                    boolean previous) {
1372                    StringBundler query = null;
1373    
1374                    if (orderByComparator != null) {
1375                            query = new StringBundler(6 +
1376                                            (orderByComparator.getOrderByFields().length * 6));
1377                    }
1378                    else {
1379                            query = new StringBundler(3);
1380                    }
1381    
1382                    query.append(_SQL_SELECT_IGIMAGE_WHERE);
1383    
1384                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1385    
1386                    if (orderByComparator != null) {
1387                            String[] orderByFields = orderByComparator.getOrderByFields();
1388    
1389                            if (orderByFields.length > 0) {
1390                                    query.append(WHERE_AND);
1391                            }
1392    
1393                            for (int i = 0; i < orderByFields.length; i++) {
1394                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1395                                    query.append(orderByFields[i]);
1396    
1397                                    if ((i + 1) < orderByFields.length) {
1398                                            if (orderByComparator.isAscending() ^ previous) {
1399                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1400                                            }
1401                                            else {
1402                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1403                                            }
1404                                    }
1405                                    else {
1406                                            if (orderByComparator.isAscending() ^ previous) {
1407                                                    query.append(WHERE_GREATER_THAN);
1408                                            }
1409                                            else {
1410                                                    query.append(WHERE_LESSER_THAN);
1411                                            }
1412                                    }
1413                            }
1414    
1415                            query.append(ORDER_BY_CLAUSE);
1416    
1417                            for (int i = 0; i < orderByFields.length; i++) {
1418                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1419                                    query.append(orderByFields[i]);
1420    
1421                                    if ((i + 1) < orderByFields.length) {
1422                                            if (orderByComparator.isAscending() ^ previous) {
1423                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1424                                            }
1425                                            else {
1426                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1427                                            }
1428                                    }
1429                                    else {
1430                                            if (orderByComparator.isAscending() ^ previous) {
1431                                                    query.append(ORDER_BY_ASC);
1432                                            }
1433                                            else {
1434                                                    query.append(ORDER_BY_DESC);
1435                                            }
1436                                    }
1437                            }
1438                    }
1439    
1440                    else {
1441                            query.append(IGImageModelImpl.ORDER_BY_JPQL);
1442                    }
1443    
1444                    String sql = query.toString();
1445    
1446                    Query q = session.createQuery(sql);
1447    
1448                    q.setFirstResult(0);
1449                    q.setMaxResults(2);
1450    
1451                    QueryPos qPos = QueryPos.getInstance(q);
1452    
1453                    qPos.add(groupId);
1454    
1455                    if (orderByComparator != null) {
1456                            Object[] values = orderByComparator.getOrderByValues(igImage);
1457    
1458                            for (Object value : values) {
1459                                    qPos.add(value);
1460                            }
1461                    }
1462    
1463                    List<IGImage> list = q.list();
1464    
1465                    if (list.size() == 2) {
1466                            return list.get(1);
1467                    }
1468                    else {
1469                            return null;
1470                    }
1471            }
1472    
1473            /**
1474             * Filters by the user's permissions and finds all the i g images where groupId = &#63;.
1475             *
1476             * @param groupId the group id to search with
1477             * @return the matching i g images that the user has permission to view
1478             * @throws SystemException if a system exception occurred
1479             */
1480            public List<IGImage> filterFindByGroupId(long groupId)
1481                    throws SystemException {
1482                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1483                            QueryUtil.ALL_POS, null);
1484            }
1485    
1486            /**
1487             * Filters by the user's permissions and finds a range of all the i g images where groupId = &#63;.
1488             *
1489             * <p>
1490             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1491             * </p>
1492             *
1493             * @param groupId the group id to search with
1494             * @param start the lower bound of the range of i g images to return
1495             * @param end the upper bound of the range of i g images to return (not inclusive)
1496             * @return the range of matching i g images that the user has permission to view
1497             * @throws SystemException if a system exception occurred
1498             */
1499            public List<IGImage> filterFindByGroupId(long groupId, int start, int end)
1500                    throws SystemException {
1501                    return filterFindByGroupId(groupId, start, end, null);
1502            }
1503    
1504            /**
1505             * Filters by the user's permissions and finds an ordered range of all the i g images where groupId = &#63;.
1506             *
1507             * <p>
1508             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1509             * </p>
1510             *
1511             * @param groupId the group id to search with
1512             * @param start the lower bound of the range of i g images to return
1513             * @param end the upper bound of the range of i g images to return (not inclusive)
1514             * @param orderByComparator the comparator to order the results by
1515             * @return the ordered range of matching i g images that the user has permission to view
1516             * @throws SystemException if a system exception occurred
1517             */
1518            public List<IGImage> filterFindByGroupId(long groupId, int start, int end,
1519                    OrderByComparator orderByComparator) throws SystemException {
1520                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1521                            return findByGroupId(groupId, start, end, orderByComparator);
1522                    }
1523    
1524                    Session session = null;
1525    
1526                    try {
1527                            session = openSession();
1528    
1529                            StringBundler query = null;
1530    
1531                            if (orderByComparator != null) {
1532                                    query = new StringBundler(3 +
1533                                                    (orderByComparator.getOrderByFields().length * 3));
1534                            }
1535                            else {
1536                                    query = new StringBundler(3);
1537                            }
1538    
1539                            query.append(_FILTER_SQL_SELECT_IGIMAGE_WHERE);
1540    
1541                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1542    
1543                            if (orderByComparator != null) {
1544                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1545                                            orderByComparator);
1546                            }
1547    
1548                            else {
1549                                    query.append(IGImageModelImpl.ORDER_BY_JPQL);
1550                            }
1551    
1552                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1553                                            IGImage.class.getName(), _FILTER_COLUMN_PK,
1554                                            _FILTER_COLUMN_USERID, groupId);
1555    
1556                            SQLQuery q = session.createSQLQuery(sql);
1557    
1558                            q.addEntity(_FILTER_ENTITY_ALIAS, IGImageImpl.class);
1559    
1560                            QueryPos qPos = QueryPos.getInstance(q);
1561    
1562                            qPos.add(groupId);
1563    
1564                            return (List<IGImage>)QueryUtil.list(q, getDialect(), start, end);
1565                    }
1566                    catch (Exception e) {
1567                            throw processException(e);
1568                    }
1569                    finally {
1570                            closeSession(session);
1571                    }
1572            }
1573    
1574            /**
1575             * Finds the i g image where smallImageId = &#63; or throws a {@link com.liferay.portlet.imagegallery.NoSuchImageException} if it could not be found.
1576             *
1577             * @param smallImageId the small image id to search with
1578             * @return the matching i g image
1579             * @throws com.liferay.portlet.imagegallery.NoSuchImageException if a matching i g image could not be found
1580             * @throws SystemException if a system exception occurred
1581             */
1582            public IGImage findBySmallImageId(long smallImageId)
1583                    throws NoSuchImageException, SystemException {
1584                    IGImage igImage = fetchBySmallImageId(smallImageId);
1585    
1586                    if (igImage == null) {
1587                            StringBundler msg = new StringBundler(4);
1588    
1589                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1590    
1591                            msg.append("smallImageId=");
1592                            msg.append(smallImageId);
1593    
1594                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1595    
1596                            if (_log.isWarnEnabled()) {
1597                                    _log.warn(msg.toString());
1598                            }
1599    
1600                            throw new NoSuchImageException(msg.toString());
1601                    }
1602    
1603                    return igImage;
1604            }
1605    
1606            /**
1607             * Finds the i g image where smallImageId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
1608             *
1609             * @param smallImageId the small image id to search with
1610             * @return the matching i g image, or <code>null</code> if a matching i g image could not be found
1611             * @throws SystemException if a system exception occurred
1612             */
1613            public IGImage fetchBySmallImageId(long smallImageId)
1614                    throws SystemException {
1615                    return fetchBySmallImageId(smallImageId, true);
1616            }
1617    
1618            /**
1619             * Finds the i g image where smallImageId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
1620             *
1621             * @param smallImageId the small image id to search with
1622             * @return the matching i g image, or <code>null</code> if a matching i g image could not be found
1623             * @throws SystemException if a system exception occurred
1624             */
1625            public IGImage fetchBySmallImageId(long smallImageId,
1626                    boolean retrieveFromCache) throws SystemException {
1627                    Object[] finderArgs = new Object[] { smallImageId };
1628    
1629                    Object result = null;
1630    
1631                    if (retrieveFromCache) {
1632                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
1633                                            finderArgs, this);
1634                    }
1635    
1636                    if (result == null) {
1637                            Session session = null;
1638    
1639                            try {
1640                                    session = openSession();
1641    
1642                                    StringBundler query = new StringBundler(3);
1643    
1644                                    query.append(_SQL_SELECT_IGIMAGE_WHERE);
1645    
1646                                    query.append(_FINDER_COLUMN_SMALLIMAGEID_SMALLIMAGEID_2);
1647    
1648                                    query.append(IGImageModelImpl.ORDER_BY_JPQL);
1649    
1650                                    String sql = query.toString();
1651    
1652                                    Query q = session.createQuery(sql);
1653    
1654                                    QueryPos qPos = QueryPos.getInstance(q);
1655    
1656                                    qPos.add(smallImageId);
1657    
1658                                    List<IGImage> list = q.list();
1659    
1660                                    result = list;
1661    
1662                                    IGImage igImage = null;
1663    
1664                                    if (list.isEmpty()) {
1665                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
1666                                                    finderArgs, list);
1667                                    }
1668                                    else {
1669                                            igImage = list.get(0);
1670    
1671                                            cacheResult(igImage);
1672    
1673                                            if ((igImage.getSmallImageId() != smallImageId)) {
1674                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
1675                                                            finderArgs, igImage);
1676                                            }
1677                                    }
1678    
1679                                    return igImage;
1680                            }
1681                            catch (Exception e) {
1682                                    throw processException(e);
1683                            }
1684                            finally {
1685                                    if (result == null) {
1686                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
1687                                                    finderArgs, new ArrayList<IGImage>());
1688                                    }
1689    
1690                                    closeSession(session);
1691                            }
1692                    }
1693                    else {
1694                            if (result instanceof List<?>) {
1695                                    return null;
1696                            }
1697                            else {
1698                                    return (IGImage)result;
1699                            }
1700                    }
1701            }
1702    
1703            /**
1704             * Finds the i g image where largeImageId = &#63; or throws a {@link com.liferay.portlet.imagegallery.NoSuchImageException} if it could not be found.
1705             *
1706             * @param largeImageId the large image id to search with
1707             * @return the matching i g image
1708             * @throws com.liferay.portlet.imagegallery.NoSuchImageException if a matching i g image could not be found
1709             * @throws SystemException if a system exception occurred
1710             */
1711            public IGImage findByLargeImageId(long largeImageId)
1712                    throws NoSuchImageException, SystemException {
1713                    IGImage igImage = fetchByLargeImageId(largeImageId);
1714    
1715                    if (igImage == null) {
1716                            StringBundler msg = new StringBundler(4);
1717    
1718                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1719    
1720                            msg.append("largeImageId=");
1721                            msg.append(largeImageId);
1722    
1723                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1724    
1725                            if (_log.isWarnEnabled()) {
1726                                    _log.warn(msg.toString());
1727                            }
1728    
1729                            throw new NoSuchImageException(msg.toString());
1730                    }
1731    
1732                    return igImage;
1733            }
1734    
1735            /**
1736             * Finds the i g image where largeImageId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
1737             *
1738             * @param largeImageId the large image id to search with
1739             * @return the matching i g image, or <code>null</code> if a matching i g image could not be found
1740             * @throws SystemException if a system exception occurred
1741             */
1742            public IGImage fetchByLargeImageId(long largeImageId)
1743                    throws SystemException {
1744                    return fetchByLargeImageId(largeImageId, true);
1745            }
1746    
1747            /**
1748             * Finds the i g image where largeImageId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
1749             *
1750             * @param largeImageId the large image id to search with
1751             * @return the matching i g image, or <code>null</code> if a matching i g image could not be found
1752             * @throws SystemException if a system exception occurred
1753             */
1754            public IGImage fetchByLargeImageId(long largeImageId,
1755                    boolean retrieveFromCache) throws SystemException {
1756                    Object[] finderArgs = new Object[] { largeImageId };
1757    
1758                    Object result = null;
1759    
1760                    if (retrieveFromCache) {
1761                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_LARGEIMAGEID,
1762                                            finderArgs, this);
1763                    }
1764    
1765                    if (result == null) {
1766                            Session session = null;
1767    
1768                            try {
1769                                    session = openSession();
1770    
1771                                    StringBundler query = new StringBundler(3);
1772    
1773                                    query.append(_SQL_SELECT_IGIMAGE_WHERE);
1774    
1775                                    query.append(_FINDER_COLUMN_LARGEIMAGEID_LARGEIMAGEID_2);
1776    
1777                                    query.append(IGImageModelImpl.ORDER_BY_JPQL);
1778    
1779                                    String sql = query.toString();
1780    
1781                                    Query q = session.createQuery(sql);
1782    
1783                                    QueryPos qPos = QueryPos.getInstance(q);
1784    
1785                                    qPos.add(largeImageId);
1786    
1787                                    List<IGImage> list = q.list();
1788    
1789                                    result = list;
1790    
1791                                    IGImage igImage = null;
1792    
1793                                    if (list.isEmpty()) {
1794                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_LARGEIMAGEID,
1795                                                    finderArgs, list);
1796                                    }
1797                                    else {
1798                                            igImage = list.get(0);
1799    
1800                                            cacheResult(igImage);
1801    
1802                                            if ((igImage.getLargeImageId() != largeImageId)) {
1803                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_LARGEIMAGEID,
1804                                                            finderArgs, igImage);
1805                                            }
1806                                    }
1807    
1808                                    return igImage;
1809                            }
1810                            catch (Exception e) {
1811                                    throw processException(e);
1812                            }
1813                            finally {
1814                                    if (result == null) {
1815                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_LARGEIMAGEID,
1816                                                    finderArgs, new ArrayList<IGImage>());
1817                                    }
1818    
1819                                    closeSession(session);
1820                            }
1821                    }
1822                    else {
1823                            if (result instanceof List<?>) {
1824                                    return null;
1825                            }
1826                            else {
1827                                    return (IGImage)result;
1828                            }
1829                    }
1830            }
1831    
1832            /**
1833             * Finds the i g image where custom1ImageId = &#63; or throws a {@link com.liferay.portlet.imagegallery.NoSuchImageException} if it could not be found.
1834             *
1835             * @param custom1ImageId the custom1 image id to search with
1836             * @return the matching i g image
1837             * @throws com.liferay.portlet.imagegallery.NoSuchImageException if a matching i g image could not be found
1838             * @throws SystemException if a system exception occurred
1839             */
1840            public IGImage findByCustom1ImageId(long custom1ImageId)
1841                    throws NoSuchImageException, SystemException {
1842                    IGImage igImage = fetchByCustom1ImageId(custom1ImageId);
1843    
1844                    if (igImage == null) {
1845                            StringBundler msg = new StringBundler(4);
1846    
1847                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1848    
1849                            msg.append("custom1ImageId=");
1850                            msg.append(custom1ImageId);
1851    
1852                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1853    
1854                            if (_log.isWarnEnabled()) {
1855                                    _log.warn(msg.toString());
1856                            }
1857    
1858                            throw new NoSuchImageException(msg.toString());
1859                    }
1860    
1861                    return igImage;
1862            }
1863    
1864            /**
1865             * Finds the i g image where custom1ImageId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
1866             *
1867             * @param custom1ImageId the custom1 image id to search with
1868             * @return the matching i g image, or <code>null</code> if a matching i g image could not be found
1869             * @throws SystemException if a system exception occurred
1870             */
1871            public IGImage fetchByCustom1ImageId(long custom1ImageId)
1872                    throws SystemException {
1873                    return fetchByCustom1ImageId(custom1ImageId, true);
1874            }
1875    
1876            /**
1877             * Finds the i g image where custom1ImageId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
1878             *
1879             * @param custom1ImageId the custom1 image id to search with
1880             * @return the matching i g image, or <code>null</code> if a matching i g image could not be found
1881             * @throws SystemException if a system exception occurred
1882             */
1883            public IGImage fetchByCustom1ImageId(long custom1ImageId,
1884                    boolean retrieveFromCache) throws SystemException {
1885                    Object[] finderArgs = new Object[] { custom1ImageId };
1886    
1887                    Object result = null;
1888    
1889                    if (retrieveFromCache) {
1890                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_CUSTOM1IMAGEID,
1891                                            finderArgs, this);
1892                    }
1893    
1894                    if (result == null) {
1895                            Session session = null;
1896    
1897                            try {
1898                                    session = openSession();
1899    
1900                                    StringBundler query = new StringBundler(3);
1901    
1902                                    query.append(_SQL_SELECT_IGIMAGE_WHERE);
1903    
1904                                    query.append(_FINDER_COLUMN_CUSTOM1IMAGEID_CUSTOM1IMAGEID_2);
1905    
1906                                    query.append(IGImageModelImpl.ORDER_BY_JPQL);
1907    
1908                                    String sql = query.toString();
1909    
1910                                    Query q = session.createQuery(sql);
1911    
1912                                    QueryPos qPos = QueryPos.getInstance(q);
1913    
1914                                    qPos.add(custom1ImageId);
1915    
1916                                    List<IGImage> list = q.list();
1917    
1918                                    result = list;
1919    
1920                                    IGImage igImage = null;
1921    
1922                                    if (list.isEmpty()) {
1923                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_CUSTOM1IMAGEID,
1924                                                    finderArgs, list);
1925                                    }
1926                                    else {
1927                                            igImage = list.get(0);
1928    
1929                                            cacheResult(igImage);
1930    
1931                                            if ((igImage.getCustom1ImageId() != custom1ImageId)) {
1932                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_CUSTOM1IMAGEID,
1933                                                            finderArgs, igImage);
1934                                            }
1935                                    }
1936    
1937                                    return igImage;
1938                            }
1939                            catch (Exception e) {
1940                                    throw processException(e);
1941                            }
1942                            finally {
1943                                    if (result == null) {
1944                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_CUSTOM1IMAGEID,
1945                                                    finderArgs, new ArrayList<IGImage>());
1946                                    }
1947    
1948                                    closeSession(session);
1949                            }
1950                    }
1951                    else {
1952                            if (result instanceof List<?>) {
1953                                    return null;
1954                            }
1955                            else {
1956                                    return (IGImage)result;
1957                            }
1958                    }
1959            }
1960    
1961            /**
1962             * Finds the i g image where custom2ImageId = &#63; or throws a {@link com.liferay.portlet.imagegallery.NoSuchImageException} if it could not be found.
1963             *
1964             * @param custom2ImageId the custom2 image id to search with
1965             * @return the matching i g image
1966             * @throws com.liferay.portlet.imagegallery.NoSuchImageException if a matching i g image could not be found
1967             * @throws SystemException if a system exception occurred
1968             */
1969            public IGImage findByCustom2ImageId(long custom2ImageId)
1970                    throws NoSuchImageException, SystemException {
1971                    IGImage igImage = fetchByCustom2ImageId(custom2ImageId);
1972    
1973                    if (igImage == null) {
1974                            StringBundler msg = new StringBundler(4);
1975    
1976                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1977    
1978                            msg.append("custom2ImageId=");
1979                            msg.append(custom2ImageId);
1980    
1981                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1982    
1983                            if (_log.isWarnEnabled()) {
1984                                    _log.warn(msg.toString());
1985                            }
1986    
1987                            throw new NoSuchImageException(msg.toString());
1988                    }
1989    
1990                    return igImage;
1991            }
1992    
1993            /**
1994             * Finds the i g image where custom2ImageId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
1995             *
1996             * @param custom2ImageId the custom2 image id to search with
1997             * @return the matching i g image, or <code>null</code> if a matching i g image could not be found
1998             * @throws SystemException if a system exception occurred
1999             */
2000            public IGImage fetchByCustom2ImageId(long custom2ImageId)
2001                    throws SystemException {
2002                    return fetchByCustom2ImageId(custom2ImageId, true);
2003            }
2004    
2005            /**
2006             * Finds the i g image where custom2ImageId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
2007             *
2008             * @param custom2ImageId the custom2 image id to search with
2009             * @return the matching i g image, or <code>null</code> if a matching i g image could not be found
2010             * @throws SystemException if a system exception occurred
2011             */
2012            public IGImage fetchByCustom2ImageId(long custom2ImageId,
2013                    boolean retrieveFromCache) throws SystemException {
2014                    Object[] finderArgs = new Object[] { custom2ImageId };
2015    
2016                    Object result = null;
2017    
2018                    if (retrieveFromCache) {
2019                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_CUSTOM2IMAGEID,
2020                                            finderArgs, this);
2021                    }
2022    
2023                    if (result == null) {
2024                            Session session = null;
2025    
2026                            try {
2027                                    session = openSession();
2028    
2029                                    StringBundler query = new StringBundler(3);
2030    
2031                                    query.append(_SQL_SELECT_IGIMAGE_WHERE);
2032    
2033                                    query.append(_FINDER_COLUMN_CUSTOM2IMAGEID_CUSTOM2IMAGEID_2);
2034    
2035                                    query.append(IGImageModelImpl.ORDER_BY_JPQL);
2036    
2037                                    String sql = query.toString();
2038    
2039                                    Query q = session.createQuery(sql);
2040    
2041                                    QueryPos qPos = QueryPos.getInstance(q);
2042    
2043                                    qPos.add(custom2ImageId);
2044    
2045                                    List<IGImage> list = q.list();
2046    
2047                                    result = list;
2048    
2049                                    IGImage igImage = null;
2050    
2051                                    if (list.isEmpty()) {
2052                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_CUSTOM2IMAGEID,
2053                                                    finderArgs, list);
2054                                    }
2055                                    else {
2056                                            igImage = list.get(0);
2057    
2058                                            cacheResult(igImage);
2059    
2060                                            if ((igImage.getCustom2ImageId() != custom2ImageId)) {
2061                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_CUSTOM2IMAGEID,
2062                                                            finderArgs, igImage);
2063                                            }
2064                                    }
2065    
2066                                    return igImage;
2067                            }
2068                            catch (Exception e) {
2069                                    throw processException(e);
2070                            }
2071                            finally {
2072                                    if (result == null) {
2073                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_CUSTOM2IMAGEID,
2074                                                    finderArgs, new ArrayList<IGImage>());
2075                                    }
2076    
2077                                    closeSession(session);
2078                            }
2079                    }
2080                    else {
2081                            if (result instanceof List<?>) {
2082                                    return null;
2083                            }
2084                            else {
2085                                    return (IGImage)result;
2086                            }
2087                    }
2088            }
2089    
2090            /**
2091             * Finds all the i g images where groupId = &#63; and userId = &#63;.
2092             *
2093             * @param groupId the group id to search with
2094             * @param userId the user id to search with
2095             * @return the matching i g images
2096             * @throws SystemException if a system exception occurred
2097             */
2098            public List<IGImage> findByG_U(long groupId, long userId)
2099                    throws SystemException {
2100                    return findByG_U(groupId, userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2101                            null);
2102            }
2103    
2104            /**
2105             * Finds a range of all the i g images where groupId = &#63; and userId = &#63;.
2106             *
2107             * <p>
2108             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2109             * </p>
2110             *
2111             * @param groupId the group id to search with
2112             * @param userId the user id to search with
2113             * @param start the lower bound of the range of i g images to return
2114             * @param end the upper bound of the range of i g images to return (not inclusive)
2115             * @return the range of matching i g images
2116             * @throws SystemException if a system exception occurred
2117             */
2118            public List<IGImage> findByG_U(long groupId, long userId, int start, int end)
2119                    throws SystemException {
2120                    return findByG_U(groupId, userId, start, end, null);
2121            }
2122    
2123            /**
2124             * Finds an ordered range of all the i g images where groupId = &#63; and userId = &#63;.
2125             *
2126             * <p>
2127             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2128             * </p>
2129             *
2130             * @param groupId the group id to search with
2131             * @param userId the user id to search with
2132             * @param start the lower bound of the range of i g images to return
2133             * @param end the upper bound of the range of i g images to return (not inclusive)
2134             * @param orderByComparator the comparator to order the results by
2135             * @return the ordered range of matching i g images
2136             * @throws SystemException if a system exception occurred
2137             */
2138            public List<IGImage> findByG_U(long groupId, long userId, int start,
2139                    int end, OrderByComparator orderByComparator) throws SystemException {
2140                    Object[] finderArgs = new Object[] {
2141                                    groupId, userId,
2142                                    
2143                                    String.valueOf(start), String.valueOf(end),
2144                                    String.valueOf(orderByComparator)
2145                            };
2146    
2147                    List<IGImage> list = (List<IGImage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_U,
2148                                    finderArgs, this);
2149    
2150                    if (list == null) {
2151                            Session session = null;
2152    
2153                            try {
2154                                    session = openSession();
2155    
2156                                    StringBundler query = null;
2157    
2158                                    if (orderByComparator != null) {
2159                                            query = new StringBundler(4 +
2160                                                            (orderByComparator.getOrderByFields().length * 3));
2161                                    }
2162                                    else {
2163                                            query = new StringBundler(4);
2164                                    }
2165    
2166                                    query.append(_SQL_SELECT_IGIMAGE_WHERE);
2167    
2168                                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
2169    
2170                                    query.append(_FINDER_COLUMN_G_U_USERID_2);
2171    
2172                                    if (orderByComparator != null) {
2173                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2174                                                    orderByComparator);
2175                                    }
2176    
2177                                    else {
2178                                            query.append(IGImageModelImpl.ORDER_BY_JPQL);
2179                                    }
2180    
2181                                    String sql = query.toString();
2182    
2183                                    Query q = session.createQuery(sql);
2184    
2185                                    QueryPos qPos = QueryPos.getInstance(q);
2186    
2187                                    qPos.add(groupId);
2188    
2189                                    qPos.add(userId);
2190    
2191                                    list = (List<IGImage>)QueryUtil.list(q, getDialect(), start, end);
2192                            }
2193                            catch (Exception e) {
2194                                    throw processException(e);
2195                            }
2196                            finally {
2197                                    if (list == null) {
2198                                            list = new ArrayList<IGImage>();
2199                                    }
2200    
2201                                    cacheResult(list);
2202    
2203                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_U, finderArgs,
2204                                            list);
2205    
2206                                    closeSession(session);
2207                            }
2208                    }
2209    
2210                    return list;
2211            }
2212    
2213            /**
2214             * Finds the first i g image in the ordered set where groupId = &#63; and userId = &#63;.
2215             *
2216             * <p>
2217             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2218             * </p>
2219             *
2220             * @param groupId the group id to search with
2221             * @param userId the user id to search with
2222             * @param orderByComparator the comparator to order the set by
2223             * @return the first matching i g image
2224             * @throws com.liferay.portlet.imagegallery.NoSuchImageException if a matching i g image could not be found
2225             * @throws SystemException if a system exception occurred
2226             */
2227            public IGImage findByG_U_First(long groupId, long userId,
2228                    OrderByComparator orderByComparator)
2229                    throws NoSuchImageException, SystemException {
2230                    List<IGImage> list = findByG_U(groupId, userId, 0, 1, orderByComparator);
2231    
2232                    if (list.isEmpty()) {
2233                            StringBundler msg = new StringBundler(6);
2234    
2235                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2236    
2237                            msg.append("groupId=");
2238                            msg.append(groupId);
2239    
2240                            msg.append(", userId=");
2241                            msg.append(userId);
2242    
2243                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2244    
2245                            throw new NoSuchImageException(msg.toString());
2246                    }
2247                    else {
2248                            return list.get(0);
2249                    }
2250            }
2251    
2252            /**
2253             * Finds the last i g image in the ordered set where groupId = &#63; and userId = &#63;.
2254             *
2255             * <p>
2256             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2257             * </p>
2258             *
2259             * @param groupId the group id to search with
2260             * @param userId the user id to search with
2261             * @param orderByComparator the comparator to order the set by
2262             * @return the last matching i g image
2263             * @throws com.liferay.portlet.imagegallery.NoSuchImageException if a matching i g image could not be found
2264             * @throws SystemException if a system exception occurred
2265             */
2266            public IGImage findByG_U_Last(long groupId, long userId,
2267                    OrderByComparator orderByComparator)
2268                    throws NoSuchImageException, SystemException {
2269                    int count = countByG_U(groupId, userId);
2270    
2271                    List<IGImage> list = findByG_U(groupId, userId, count - 1, count,
2272                                    orderByComparator);
2273    
2274                    if (list.isEmpty()) {
2275                            StringBundler msg = new StringBundler(6);
2276    
2277                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2278    
2279                            msg.append("groupId=");
2280                            msg.append(groupId);
2281    
2282                            msg.append(", userId=");
2283                            msg.append(userId);
2284    
2285                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2286    
2287                            throw new NoSuchImageException(msg.toString());
2288                    }
2289                    else {
2290                            return list.get(0);
2291                    }
2292            }
2293    
2294            /**
2295             * Finds the i g images before and after the current i g image in the ordered set where groupId = &#63; and userId = &#63;.
2296             *
2297             * <p>
2298             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2299             * </p>
2300             *
2301             * @param imageId the primary key of the current i g image
2302             * @param groupId the group id to search with
2303             * @param userId the user id to search with
2304             * @param orderByComparator the comparator to order the set by
2305             * @return the previous, current, and next i g image
2306             * @throws com.liferay.portlet.imagegallery.NoSuchImageException if a i g image with the primary key could not be found
2307             * @throws SystemException if a system exception occurred
2308             */
2309            public IGImage[] findByG_U_PrevAndNext(long imageId, long groupId,
2310                    long userId, OrderByComparator orderByComparator)
2311                    throws NoSuchImageException, SystemException {
2312                    IGImage igImage = findByPrimaryKey(imageId);
2313    
2314                    Session session = null;
2315    
2316                    try {
2317                            session = openSession();
2318    
2319                            IGImage[] array = new IGImageImpl[3];
2320    
2321                            array[0] = getByG_U_PrevAndNext(session, igImage, groupId, userId,
2322                                            orderByComparator, true);
2323    
2324                            array[1] = igImage;
2325    
2326                            array[2] = getByG_U_PrevAndNext(session, igImage, groupId, userId,
2327                                            orderByComparator, false);
2328    
2329                            return array;
2330                    }
2331                    catch (Exception e) {
2332                            throw processException(e);
2333                    }
2334                    finally {
2335                            closeSession(session);
2336                    }
2337            }
2338    
2339            protected IGImage getByG_U_PrevAndNext(Session session, IGImage igImage,
2340                    long groupId, long userId, OrderByComparator orderByComparator,
2341                    boolean previous) {
2342                    StringBundler query = null;
2343    
2344                    if (orderByComparator != null) {
2345                            query = new StringBundler(6 +
2346                                            (orderByComparator.getOrderByFields().length * 6));
2347                    }
2348                    else {
2349                            query = new StringBundler(3);
2350                    }
2351    
2352                    query.append(_SQL_SELECT_IGIMAGE_WHERE);
2353    
2354                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
2355    
2356                    query.append(_FINDER_COLUMN_G_U_USERID_2);
2357    
2358                    if (orderByComparator != null) {
2359                            String[] orderByFields = orderByComparator.getOrderByFields();
2360    
2361                            if (orderByFields.length > 0) {
2362                                    query.append(WHERE_AND);
2363                            }
2364    
2365                            for (int i = 0; i < orderByFields.length; i++) {
2366                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2367                                    query.append(orderByFields[i]);
2368    
2369                                    if ((i + 1) < orderByFields.length) {
2370                                            if (orderByComparator.isAscending() ^ previous) {
2371                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2372                                            }
2373                                            else {
2374                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2375                                            }
2376                                    }
2377                                    else {
2378                                            if (orderByComparator.isAscending() ^ previous) {
2379                                                    query.append(WHERE_GREATER_THAN);
2380                                            }
2381                                            else {
2382                                                    query.append(WHERE_LESSER_THAN);
2383                                            }
2384                                    }
2385                            }
2386    
2387                            query.append(ORDER_BY_CLAUSE);
2388    
2389                            for (int i = 0; i < orderByFields.length; i++) {
2390                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2391                                    query.append(orderByFields[i]);
2392    
2393                                    if ((i + 1) < orderByFields.length) {
2394                                            if (orderByComparator.isAscending() ^ previous) {
2395                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2396                                            }
2397                                            else {
2398                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2399                                            }
2400                                    }
2401                                    else {
2402                                            if (orderByComparator.isAscending() ^ previous) {
2403                                                    query.append(ORDER_BY_ASC);
2404                                            }
2405                                            else {
2406                                                    query.append(ORDER_BY_DESC);
2407                                            }
2408                                    }
2409                            }
2410                    }
2411    
2412                    else {
2413                            query.append(IGImageModelImpl.ORDER_BY_JPQL);
2414                    }
2415    
2416                    String sql = query.toString();
2417    
2418                    Query q = session.createQuery(sql);
2419    
2420                    q.setFirstResult(0);
2421                    q.setMaxResults(2);
2422    
2423                    QueryPos qPos = QueryPos.getInstance(q);
2424    
2425                    qPos.add(groupId);
2426    
2427                    qPos.add(userId);
2428    
2429                    if (orderByComparator != null) {
2430                            Object[] values = orderByComparator.getOrderByValues(igImage);
2431    
2432                            for (Object value : values) {
2433                                    qPos.add(value);
2434                            }
2435                    }
2436    
2437                    List<IGImage> list = q.list();
2438    
2439                    if (list.size() == 2) {
2440                            return list.get(1);
2441                    }
2442                    else {
2443                            return null;
2444                    }
2445            }
2446    
2447            /**
2448             * Filters by the user's permissions and finds all the i g images where groupId = &#63; and userId = &#63;.
2449             *
2450             * @param groupId the group id to search with
2451             * @param userId the user id to search with
2452             * @return the matching i g images that the user has permission to view
2453             * @throws SystemException if a system exception occurred
2454             */
2455            public List<IGImage> filterFindByG_U(long groupId, long userId)
2456                    throws SystemException {
2457                    return filterFindByG_U(groupId, userId, QueryUtil.ALL_POS,
2458                            QueryUtil.ALL_POS, null);
2459            }
2460    
2461            /**
2462             * Filters by the user's permissions and finds a range of all the i g images where groupId = &#63; and userId = &#63;.
2463             *
2464             * <p>
2465             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2466             * </p>
2467             *
2468             * @param groupId the group id to search with
2469             * @param userId the user id to search with
2470             * @param start the lower bound of the range of i g images to return
2471             * @param end the upper bound of the range of i g images to return (not inclusive)
2472             * @return the range of matching i g images that the user has permission to view
2473             * @throws SystemException if a system exception occurred
2474             */
2475            public List<IGImage> filterFindByG_U(long groupId, long userId, int start,
2476                    int end) throws SystemException {
2477                    return filterFindByG_U(groupId, userId, start, end, null);
2478            }
2479    
2480            /**
2481             * Filters by the user's permissions and finds an ordered range of all the i g images where groupId = &#63; and userId = &#63;.
2482             *
2483             * <p>
2484             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2485             * </p>
2486             *
2487             * @param groupId the group id to search with
2488             * @param userId the user id to search with
2489             * @param start the lower bound of the range of i g images to return
2490             * @param end the upper bound of the range of i g images to return (not inclusive)
2491             * @param orderByComparator the comparator to order the results by
2492             * @return the ordered range of matching i g images that the user has permission to view
2493             * @throws SystemException if a system exception occurred
2494             */
2495            public List<IGImage> filterFindByG_U(long groupId, long userId, int start,
2496                    int end, OrderByComparator orderByComparator) throws SystemException {
2497                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2498                            return findByG_U(groupId, userId, start, end, orderByComparator);
2499                    }
2500    
2501                    Session session = null;
2502    
2503                    try {
2504                            session = openSession();
2505    
2506                            StringBundler query = null;
2507    
2508                            if (orderByComparator != null) {
2509                                    query = new StringBundler(4 +
2510                                                    (orderByComparator.getOrderByFields().length * 3));
2511                            }
2512                            else {
2513                                    query = new StringBundler(4);
2514                            }
2515    
2516                            query.append(_FILTER_SQL_SELECT_IGIMAGE_WHERE);
2517    
2518                            query.append(_FINDER_COLUMN_G_U_GROUPID_2);
2519    
2520                            query.append(_FINDER_COLUMN_G_U_USERID_2);
2521    
2522                            if (orderByComparator != null) {
2523                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2524                                            orderByComparator);
2525                            }
2526    
2527                            else {
2528                                    query.append(IGImageModelImpl.ORDER_BY_JPQL);
2529                            }
2530    
2531                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2532                                            IGImage.class.getName(), _FILTER_COLUMN_PK,
2533                                            _FILTER_COLUMN_USERID, groupId);
2534    
2535                            SQLQuery q = session.createSQLQuery(sql);
2536    
2537                            q.addEntity(_FILTER_ENTITY_ALIAS, IGImageImpl.class);
2538    
2539                            QueryPos qPos = QueryPos.getInstance(q);
2540    
2541                            qPos.add(groupId);
2542    
2543                            qPos.add(userId);
2544    
2545                            return (List<IGImage>)QueryUtil.list(q, getDialect(), start, end);
2546                    }
2547                    catch (Exception e) {
2548                            throw processException(e);
2549                    }
2550                    finally {
2551                            closeSession(session);
2552                    }
2553            }
2554    
2555            /**
2556             * Finds all the i g images where groupId = &#63; and folderId = &#63;.
2557             *
2558             * @param groupId the group id to search with
2559             * @param folderId the folder id to search with
2560             * @return the matching i g images
2561             * @throws SystemException if a system exception occurred
2562             */
2563            public List<IGImage> findByG_F(long groupId, long folderId)
2564                    throws SystemException {
2565                    return findByG_F(groupId, folderId, QueryUtil.ALL_POS,
2566                            QueryUtil.ALL_POS, null);
2567            }
2568    
2569            /**
2570             * Finds a range of all the i g images where groupId = &#63; and folderId = &#63;.
2571             *
2572             * <p>
2573             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2574             * </p>
2575             *
2576             * @param groupId the group id to search with
2577             * @param folderId the folder id to search with
2578             * @param start the lower bound of the range of i g images to return
2579             * @param end the upper bound of the range of i g images to return (not inclusive)
2580             * @return the range of matching i g images
2581             * @throws SystemException if a system exception occurred
2582             */
2583            public List<IGImage> findByG_F(long groupId, long folderId, int start,
2584                    int end) throws SystemException {
2585                    return findByG_F(groupId, folderId, start, end, null);
2586            }
2587    
2588            /**
2589             * Finds an ordered range of all the i g images where groupId = &#63; and folderId = &#63;.
2590             *
2591             * <p>
2592             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2593             * </p>
2594             *
2595             * @param groupId the group id to search with
2596             * @param folderId the folder id to search with
2597             * @param start the lower bound of the range of i g images to return
2598             * @param end the upper bound of the range of i g images to return (not inclusive)
2599             * @param orderByComparator the comparator to order the results by
2600             * @return the ordered range of matching i g images
2601             * @throws SystemException if a system exception occurred
2602             */
2603            public List<IGImage> findByG_F(long groupId, long folderId, int start,
2604                    int end, OrderByComparator orderByComparator) throws SystemException {
2605                    Object[] finderArgs = new Object[] {
2606                                    groupId, folderId,
2607                                    
2608                                    String.valueOf(start), String.valueOf(end),
2609                                    String.valueOf(orderByComparator)
2610                            };
2611    
2612                    List<IGImage> list = (List<IGImage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_F,
2613                                    finderArgs, this);
2614    
2615                    if (list == null) {
2616                            Session session = null;
2617    
2618                            try {
2619                                    session = openSession();
2620    
2621                                    StringBundler query = null;
2622    
2623                                    if (orderByComparator != null) {
2624                                            query = new StringBundler(4 +
2625                                                            (orderByComparator.getOrderByFields().length * 3));
2626                                    }
2627                                    else {
2628                                            query = new StringBundler(4);
2629                                    }
2630    
2631                                    query.append(_SQL_SELECT_IGIMAGE_WHERE);
2632    
2633                                    query.append(_FINDER_COLUMN_G_F_GROUPID_2);
2634    
2635                                    query.append(_FINDER_COLUMN_G_F_FOLDERID_2);
2636    
2637                                    if (orderByComparator != null) {
2638                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2639                                                    orderByComparator);
2640                                    }
2641    
2642                                    else {
2643                                            query.append(IGImageModelImpl.ORDER_BY_JPQL);
2644                                    }
2645    
2646                                    String sql = query.toString();
2647    
2648                                    Query q = session.createQuery(sql);
2649    
2650                                    QueryPos qPos = QueryPos.getInstance(q);
2651    
2652                                    qPos.add(groupId);
2653    
2654                                    qPos.add(folderId);
2655    
2656                                    list = (List<IGImage>)QueryUtil.list(q, getDialect(), start, end);
2657                            }
2658                            catch (Exception e) {
2659                                    throw processException(e);
2660                            }
2661                            finally {
2662                                    if (list == null) {
2663                                            list = new ArrayList<IGImage>();
2664                                    }
2665    
2666                                    cacheResult(list);
2667    
2668                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_F, finderArgs,
2669                                            list);
2670    
2671                                    closeSession(session);
2672                            }
2673                    }
2674    
2675                    return list;
2676            }
2677    
2678            /**
2679             * Finds the first i g image in the ordered set where groupId = &#63; and folderId = &#63;.
2680             *
2681             * <p>
2682             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2683             * </p>
2684             *
2685             * @param groupId the group id to search with
2686             * @param folderId the folder id to search with
2687             * @param orderByComparator the comparator to order the set by
2688             * @return the first matching i g image
2689             * @throws com.liferay.portlet.imagegallery.NoSuchImageException if a matching i g image could not be found
2690             * @throws SystemException if a system exception occurred
2691             */
2692            public IGImage findByG_F_First(long groupId, long folderId,
2693                    OrderByComparator orderByComparator)
2694                    throws NoSuchImageException, SystemException {
2695                    List<IGImage> list = findByG_F(groupId, folderId, 0, 1,
2696                                    orderByComparator);
2697    
2698                    if (list.isEmpty()) {
2699                            StringBundler msg = new StringBundler(6);
2700    
2701                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2702    
2703                            msg.append("groupId=");
2704                            msg.append(groupId);
2705    
2706                            msg.append(", folderId=");
2707                            msg.append(folderId);
2708    
2709                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2710    
2711                            throw new NoSuchImageException(msg.toString());
2712                    }
2713                    else {
2714                            return list.get(0);
2715                    }
2716            }
2717    
2718            /**
2719             * Finds the last i g image in the ordered set where groupId = &#63; and folderId = &#63;.
2720             *
2721             * <p>
2722             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2723             * </p>
2724             *
2725             * @param groupId the group id to search with
2726             * @param folderId the folder id to search with
2727             * @param orderByComparator the comparator to order the set by
2728             * @return the last matching i g image
2729             * @throws com.liferay.portlet.imagegallery.NoSuchImageException if a matching i g image could not be found
2730             * @throws SystemException if a system exception occurred
2731             */
2732            public IGImage findByG_F_Last(long groupId, long folderId,
2733                    OrderByComparator orderByComparator)
2734                    throws NoSuchImageException, SystemException {
2735                    int count = countByG_F(groupId, folderId);
2736    
2737                    List<IGImage> list = findByG_F(groupId, folderId, count - 1, count,
2738                                    orderByComparator);
2739    
2740                    if (list.isEmpty()) {
2741                            StringBundler msg = new StringBundler(6);
2742    
2743                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2744    
2745                            msg.append("groupId=");
2746                            msg.append(groupId);
2747    
2748                            msg.append(", folderId=");
2749                            msg.append(folderId);
2750    
2751                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2752    
2753                            throw new NoSuchImageException(msg.toString());
2754                    }
2755                    else {
2756                            return list.get(0);
2757                    }
2758            }
2759    
2760            /**
2761             * Finds the i g images before and after the current i g image in the ordered set where groupId = &#63; and folderId = &#63;.
2762             *
2763             * <p>
2764             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2765             * </p>
2766             *
2767             * @param imageId the primary key of the current i g image
2768             * @param groupId the group id to search with
2769             * @param folderId the folder id to search with
2770             * @param orderByComparator the comparator to order the set by
2771             * @return the previous, current, and next i g image
2772             * @throws com.liferay.portlet.imagegallery.NoSuchImageException if a i g image with the primary key could not be found
2773             * @throws SystemException if a system exception occurred
2774             */
2775            public IGImage[] findByG_F_PrevAndNext(long imageId, long groupId,
2776                    long folderId, OrderByComparator orderByComparator)
2777                    throws NoSuchImageException, SystemException {
2778                    IGImage igImage = findByPrimaryKey(imageId);
2779    
2780                    Session session = null;
2781    
2782                    try {
2783                            session = openSession();
2784    
2785                            IGImage[] array = new IGImageImpl[3];
2786    
2787                            array[0] = getByG_F_PrevAndNext(session, igImage, groupId,
2788                                            folderId, orderByComparator, true);
2789    
2790                            array[1] = igImage;
2791    
2792                            array[2] = getByG_F_PrevAndNext(session, igImage, groupId,
2793                                            folderId, orderByComparator, false);
2794    
2795                            return array;
2796                    }
2797                    catch (Exception e) {
2798                            throw processException(e);
2799                    }
2800                    finally {
2801                            closeSession(session);
2802                    }
2803            }
2804    
2805            protected IGImage getByG_F_PrevAndNext(Session session, IGImage igImage,
2806                    long groupId, long folderId, OrderByComparator orderByComparator,
2807                    boolean previous) {
2808                    StringBundler query = null;
2809    
2810                    if (orderByComparator != null) {
2811                            query = new StringBundler(6 +
2812                                            (orderByComparator.getOrderByFields().length * 6));
2813                    }
2814                    else {
2815                            query = new StringBundler(3);
2816                    }
2817    
2818                    query.append(_SQL_SELECT_IGIMAGE_WHERE);
2819    
2820                    query.append(_FINDER_COLUMN_G_F_GROUPID_2);
2821    
2822                    query.append(_FINDER_COLUMN_G_F_FOLDERID_2);
2823    
2824                    if (orderByComparator != null) {
2825                            String[] orderByFields = orderByComparator.getOrderByFields();
2826    
2827                            if (orderByFields.length > 0) {
2828                                    query.append(WHERE_AND);
2829                            }
2830    
2831                            for (int i = 0; i < orderByFields.length; i++) {
2832                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2833                                    query.append(orderByFields[i]);
2834    
2835                                    if ((i + 1) < orderByFields.length) {
2836                                            if (orderByComparator.isAscending() ^ previous) {
2837                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2838                                            }
2839                                            else {
2840                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2841                                            }
2842                                    }
2843                                    else {
2844                                            if (orderByComparator.isAscending() ^ previous) {
2845                                                    query.append(WHERE_GREATER_THAN);
2846                                            }
2847                                            else {
2848                                                    query.append(WHERE_LESSER_THAN);
2849                                            }
2850                                    }
2851                            }
2852    
2853                            query.append(ORDER_BY_CLAUSE);
2854    
2855                            for (int i = 0; i < orderByFields.length; i++) {
2856                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2857                                    query.append(orderByFields[i]);
2858    
2859                                    if ((i + 1) < orderByFields.length) {
2860                                            if (orderByComparator.isAscending() ^ previous) {
2861                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2862                                            }
2863                                            else {
2864                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2865                                            }
2866                                    }
2867                                    else {
2868                                            if (orderByComparator.isAscending() ^ previous) {
2869                                                    query.append(ORDER_BY_ASC);
2870                                            }
2871                                            else {
2872                                                    query.append(ORDER_BY_DESC);
2873                                            }
2874                                    }
2875                            }
2876                    }
2877    
2878                    else {
2879                            query.append(IGImageModelImpl.ORDER_BY_JPQL);
2880                    }
2881    
2882                    String sql = query.toString();
2883    
2884                    Query q = session.createQuery(sql);
2885    
2886                    q.setFirstResult(0);
2887                    q.setMaxResults(2);
2888    
2889                    QueryPos qPos = QueryPos.getInstance(q);
2890    
2891                    qPos.add(groupId);
2892    
2893                    qPos.add(folderId);
2894    
2895                    if (orderByComparator != null) {
2896                            Object[] values = orderByComparator.getOrderByValues(igImage);
2897    
2898                            for (Object value : values) {
2899                                    qPos.add(value);
2900                            }
2901                    }
2902    
2903                    List<IGImage> list = q.list();
2904    
2905                    if (list.size() == 2) {
2906                            return list.get(1);
2907                    }
2908                    else {
2909                            return null;
2910                    }
2911            }
2912    
2913            /**
2914             * Finds all the i g images where groupId = &#63; and folderId = any &#63;.
2915             *
2916             * <p>
2917             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2918             * </p>
2919             *
2920             * @param groupId the group id to search with
2921             * @param folderIds the folder ids to search with
2922             * @return the matching i g images
2923             * @throws SystemException if a system exception occurred
2924             */
2925            public List<IGImage> findByG_F(long groupId, long[] folderIds)
2926                    throws SystemException {
2927                    return findByG_F(groupId, folderIds, QueryUtil.ALL_POS,
2928                            QueryUtil.ALL_POS, null);
2929            }
2930    
2931            /**
2932             * Finds a range of all the i g images where groupId = &#63; and folderId = any &#63;.
2933             *
2934             * <p>
2935             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2936             * </p>
2937             *
2938             * @param groupId the group id to search with
2939             * @param folderIds the folder ids to search with
2940             * @param start the lower bound of the range of i g images to return
2941             * @param end the upper bound of the range of i g images to return (not inclusive)
2942             * @return the range of matching i g images
2943             * @throws SystemException if a system exception occurred
2944             */
2945            public List<IGImage> findByG_F(long groupId, long[] folderIds, int start,
2946                    int end) throws SystemException {
2947                    return findByG_F(groupId, folderIds, start, end, null);
2948            }
2949    
2950            /**
2951             * Finds an ordered range of all the i g images where groupId = &#63; and folderId = any &#63;.
2952             *
2953             * <p>
2954             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2955             * </p>
2956             *
2957             * @param groupId the group id to search with
2958             * @param folderIds the folder ids to search with
2959             * @param start the lower bound of the range of i g images to return
2960             * @param end the upper bound of the range of i g images to return (not inclusive)
2961             * @param orderByComparator the comparator to order the results by
2962             * @return the ordered range of matching i g images
2963             * @throws SystemException if a system exception occurred
2964             */
2965            public List<IGImage> findByG_F(long groupId, long[] folderIds, int start,
2966                    int end, OrderByComparator orderByComparator) throws SystemException {
2967                    Object[] finderArgs = new Object[] {
2968                                    groupId, StringUtil.merge(folderIds),
2969                                    
2970                                    String.valueOf(start), String.valueOf(end),
2971                                    String.valueOf(orderByComparator)
2972                            };
2973    
2974                    List<IGImage> list = (List<IGImage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_F,
2975                                    finderArgs, this);
2976    
2977                    if (list == null) {
2978                            Session session = null;
2979    
2980                            try {
2981                                    session = openSession();
2982    
2983                                    StringBundler query = new StringBundler();
2984    
2985                                    query.append(_SQL_SELECT_IGIMAGE_WHERE);
2986    
2987                                    boolean conjunctionable = false;
2988    
2989                                    if (conjunctionable) {
2990                                            query.append(WHERE_AND);
2991                                    }
2992    
2993                                    query.append(_FINDER_COLUMN_G_F_GROUPID_5);
2994    
2995                                    conjunctionable = true;
2996    
2997                                    if ((folderIds == null) || (folderIds.length > 0)) {
2998                                            if (conjunctionable) {
2999                                                    query.append(WHERE_AND);
3000                                            }
3001    
3002                                            query.append(StringPool.OPEN_PARENTHESIS);
3003    
3004                                            for (int i = 0; i < folderIds.length; i++) {
3005                                                    query.append(_FINDER_COLUMN_G_F_FOLDERID_5);
3006    
3007                                                    if ((i + 1) < folderIds.length) {
3008                                                            query.append(WHERE_OR);
3009                                                    }
3010                                            }
3011    
3012                                            query.append(StringPool.CLOSE_PARENTHESIS);
3013    
3014                                            conjunctionable = true;
3015                                    }
3016    
3017                                    if (orderByComparator != null) {
3018                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3019                                                    orderByComparator);
3020                                    }
3021    
3022                                    else {
3023                                            query.append(IGImageModelImpl.ORDER_BY_JPQL);
3024                                    }
3025    
3026                                    String sql = query.toString();
3027    
3028                                    Query q = session.createQuery(sql);
3029    
3030                                    QueryPos qPos = QueryPos.getInstance(q);
3031    
3032                                    qPos.add(groupId);
3033    
3034                                    if (folderIds != null) {
3035                                            qPos.add(folderIds);
3036                                    }
3037    
3038                                    list = (List<IGImage>)QueryUtil.list(q, getDialect(), start, end);
3039                            }
3040                            catch (Exception e) {
3041                                    throw processException(e);
3042                            }
3043                            finally {
3044                                    if (list == null) {
3045                                            list = new ArrayList<IGImage>();
3046                                    }
3047    
3048                                    cacheResult(list);
3049    
3050                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_F, finderArgs,
3051                                            list);
3052    
3053                                    closeSession(session);
3054                            }
3055                    }
3056    
3057                    return list;
3058            }
3059    
3060            /**
3061             * Filters by the user's permissions and finds all the i g images where groupId = &#63; and folderId = &#63;.
3062             *
3063             * @param groupId the group id to search with
3064             * @param folderId the folder id to search with
3065             * @return the matching i g images that the user has permission to view
3066             * @throws SystemException if a system exception occurred
3067             */
3068            public List<IGImage> filterFindByG_F(long groupId, long folderId)
3069                    throws SystemException {
3070                    return filterFindByG_F(groupId, folderId, QueryUtil.ALL_POS,
3071                            QueryUtil.ALL_POS, null);
3072            }
3073    
3074            /**
3075             * Filters by the user's permissions and finds a range of all the i g images where groupId = &#63; and folderId = &#63;.
3076             *
3077             * <p>
3078             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3079             * </p>
3080             *
3081             * @param groupId the group id to search with
3082             * @param folderId the folder id to search with
3083             * @param start the lower bound of the range of i g images to return
3084             * @param end the upper bound of the range of i g images to return (not inclusive)
3085             * @return the range of matching i g images that the user has permission to view
3086             * @throws SystemException if a system exception occurred
3087             */
3088            public List<IGImage> filterFindByG_F(long groupId, long folderId,
3089                    int start, int end) throws SystemException {
3090                    return filterFindByG_F(groupId, folderId, start, end, null);
3091            }
3092    
3093            /**
3094             * Filters by the user's permissions and finds an ordered range of all the i g images where groupId = &#63; and folderId = &#63;.
3095             *
3096             * <p>
3097             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3098             * </p>
3099             *
3100             * @param groupId the group id to search with
3101             * @param folderId the folder id to search with
3102             * @param start the lower bound of the range of i g images to return
3103             * @param end the upper bound of the range of i g images to return (not inclusive)
3104             * @param orderByComparator the comparator to order the results by
3105             * @return the ordered range of matching i g images that the user has permission to view
3106             * @throws SystemException if a system exception occurred
3107             */
3108            public List<IGImage> filterFindByG_F(long groupId, long folderId,
3109                    int start, int end, OrderByComparator orderByComparator)
3110                    throws SystemException {
3111                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3112                            return findByG_F(groupId, folderId, start, end, orderByComparator);
3113                    }
3114    
3115                    Session session = null;
3116    
3117                    try {
3118                            session = openSession();
3119    
3120                            StringBundler query = null;
3121    
3122                            if (orderByComparator != null) {
3123                                    query = new StringBundler(4 +
3124                                                    (orderByComparator.getOrderByFields().length * 3));
3125                            }
3126                            else {
3127                                    query = new StringBundler(4);
3128                            }
3129    
3130                            query.append(_FILTER_SQL_SELECT_IGIMAGE_WHERE);
3131    
3132                            query.append(_FINDER_COLUMN_G_F_GROUPID_2);
3133    
3134                            query.append(_FINDER_COLUMN_G_F_FOLDERID_2);
3135    
3136                            if (orderByComparator != null) {
3137                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3138                                            orderByComparator);
3139                            }
3140    
3141                            else {
3142                                    query.append(IGImageModelImpl.ORDER_BY_JPQL);
3143                            }
3144    
3145                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3146                                            IGImage.class.getName(), _FILTER_COLUMN_PK,
3147                                            _FILTER_COLUMN_USERID, groupId);
3148    
3149                            SQLQuery q = session.createSQLQuery(sql);
3150    
3151                            q.addEntity(_FILTER_ENTITY_ALIAS, IGImageImpl.class);
3152    
3153                            QueryPos qPos = QueryPos.getInstance(q);
3154    
3155                            qPos.add(groupId);
3156    
3157                            qPos.add(folderId);
3158    
3159                            return (List<IGImage>)QueryUtil.list(q, getDialect(), start, end);
3160                    }
3161                    catch (Exception e) {
3162                            throw processException(e);
3163                    }
3164                    finally {
3165                            closeSession(session);
3166                    }
3167            }
3168    
3169            /**
3170             * Filters by the user's permissions and finds all the i g images where groupId = &#63; and folderId = any &#63;.
3171             *
3172             * <p>
3173             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3174             * </p>
3175             *
3176             * @param groupId the group id to search with
3177             * @param folderIds the folder ids to search with
3178             * @return the matching i g images that the user has permission to view
3179             * @throws SystemException if a system exception occurred
3180             */
3181            public List<IGImage> filterFindByG_F(long groupId, long[] folderIds)
3182                    throws SystemException {
3183                    return filterFindByG_F(groupId, folderIds, QueryUtil.ALL_POS,
3184                            QueryUtil.ALL_POS, null);
3185            }
3186    
3187            /**
3188             * Filters by the user's permissions and finds a range of all the i g images where groupId = &#63; and folderId = any &#63;.
3189             *
3190             * <p>
3191             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3192             * </p>
3193             *
3194             * @param groupId the group id to search with
3195             * @param folderIds the folder ids to search with
3196             * @param start the lower bound of the range of i g images to return
3197             * @param end the upper bound of the range of i g images to return (not inclusive)
3198             * @return the range of matching i g images that the user has permission to view
3199             * @throws SystemException if a system exception occurred
3200             */
3201            public List<IGImage> filterFindByG_F(long groupId, long[] folderIds,
3202                    int start, int end) throws SystemException {
3203                    return filterFindByG_F(groupId, folderIds, start, end, null);
3204            }
3205    
3206            /**
3207             * Filters by the user's permissions and finds an ordered range of all the i g images where groupId = &#63; and folderId = any &#63;.
3208             *
3209             * <p>
3210             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3211             * </p>
3212             *
3213             * @param groupId the group id to search with
3214             * @param folderIds the folder ids to search with
3215             * @param start the lower bound of the range of i g images to return
3216             * @param end the upper bound of the range of i g images to return (not inclusive)
3217             * @param orderByComparator the comparator to order the results by
3218             * @return the ordered range of matching i g images that the user has permission to view
3219             * @throws SystemException if a system exception occurred
3220             */
3221            public List<IGImage> filterFindByG_F(long groupId, long[] folderIds,
3222                    int start, int end, OrderByComparator orderByComparator)
3223                    throws SystemException {
3224                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3225                            return findByG_F(groupId, folderIds, start, end, orderByComparator);
3226                    }
3227    
3228                    Session session = null;
3229    
3230                    try {
3231                            session = openSession();
3232    
3233                            StringBundler query = new StringBundler();
3234    
3235                            query.append(_FILTER_SQL_SELECT_IGIMAGE_WHERE);
3236    
3237                            boolean conjunctionable = false;
3238    
3239                            if (conjunctionable) {
3240                                    query.append(WHERE_AND);
3241                            }
3242    
3243                            query.append(_FINDER_COLUMN_G_F_GROUPID_5);
3244    
3245                            conjunctionable = true;
3246    
3247                            if ((folderIds == null) || (folderIds.length > 0)) {
3248                                    if (conjunctionable) {
3249                                            query.append(WHERE_AND);
3250                                    }
3251    
3252                                    query.append(StringPool.OPEN_PARENTHESIS);
3253    
3254                                    for (int i = 0; i < folderIds.length; i++) {
3255                                            query.append(_FINDER_COLUMN_G_F_FOLDERID_5);
3256    
3257                                            if ((i + 1) < folderIds.length) {
3258                                                    query.append(WHERE_OR);
3259                                            }
3260                                    }
3261    
3262                                    query.append(StringPool.CLOSE_PARENTHESIS);
3263    
3264                                    conjunctionable = true;
3265                            }
3266    
3267                            if (orderByComparator != null) {
3268                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3269                                            orderByComparator);
3270                            }
3271    
3272                            else {
3273                                    query.append(IGImageModelImpl.ORDER_BY_JPQL);
3274                            }
3275    
3276                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3277                                            IGImage.class.getName(), _FILTER_COLUMN_PK,
3278                                            _FILTER_COLUMN_USERID, groupId);
3279    
3280                            SQLQuery q = session.createSQLQuery(sql);
3281    
3282                            q.addEntity(_FILTER_ENTITY_ALIAS, IGImageImpl.class);
3283    
3284                            QueryPos qPos = QueryPos.getInstance(q);
3285    
3286                            qPos.add(groupId);
3287    
3288                            if (folderIds != null) {
3289                                    qPos.add(folderIds);
3290                            }
3291    
3292                            return (List<IGImage>)QueryUtil.list(q, getDialect(), start, end);
3293                    }
3294                    catch (Exception e) {
3295                            throw processException(e);
3296                    }
3297                    finally {
3298                            closeSession(session);
3299                    }
3300            }
3301    
3302            /**
3303             * Finds all the i g images where groupId = &#63; and folderId = &#63; and name = &#63;.
3304             *
3305             * @param groupId the group id to search with
3306             * @param folderId the folder id to search with
3307             * @param name the name to search with
3308             * @return the matching i g images
3309             * @throws SystemException if a system exception occurred
3310             */
3311            public List<IGImage> findByG_F_N(long groupId, long folderId, String name)
3312                    throws SystemException {
3313                    return findByG_F_N(groupId, folderId, name, QueryUtil.ALL_POS,
3314                            QueryUtil.ALL_POS, null);
3315            }
3316    
3317            /**
3318             * Finds a range of all the i g images where groupId = &#63; and folderId = &#63; and name = &#63;.
3319             *
3320             * <p>
3321             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3322             * </p>
3323             *
3324             * @param groupId the group id to search with
3325             * @param folderId the folder id to search with
3326             * @param name the name to search with
3327             * @param start the lower bound of the range of i g images to return
3328             * @param end the upper bound of the range of i g images to return (not inclusive)
3329             * @return the range of matching i g images
3330             * @throws SystemException if a system exception occurred
3331             */
3332            public List<IGImage> findByG_F_N(long groupId, long folderId, String name,
3333                    int start, int end) throws SystemException {
3334                    return findByG_F_N(groupId, folderId, name, start, end, null);
3335            }
3336    
3337            /**
3338             * Finds an ordered range of all the i g images where groupId = &#63; and folderId = &#63; and name = &#63;.
3339             *
3340             * <p>
3341             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3342             * </p>
3343             *
3344             * @param groupId the group id to search with
3345             * @param folderId the folder id to search with
3346             * @param name the name to search with
3347             * @param start the lower bound of the range of i g images to return
3348             * @param end the upper bound of the range of i g images to return (not inclusive)
3349             * @param orderByComparator the comparator to order the results by
3350             * @return the ordered range of matching i g images
3351             * @throws SystemException if a system exception occurred
3352             */
3353            public List<IGImage> findByG_F_N(long groupId, long folderId, String name,
3354                    int start, int end, OrderByComparator orderByComparator)
3355                    throws SystemException {
3356                    Object[] finderArgs = new Object[] {
3357                                    groupId, folderId, name,
3358                                    
3359                                    String.valueOf(start), String.valueOf(end),
3360                                    String.valueOf(orderByComparator)
3361                            };
3362    
3363                    List<IGImage> list = (List<IGImage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_F_N,
3364                                    finderArgs, this);
3365    
3366                    if (list == null) {
3367                            Session session = null;
3368    
3369                            try {
3370                                    session = openSession();
3371    
3372                                    StringBundler query = null;
3373    
3374                                    if (orderByComparator != null) {
3375                                            query = new StringBundler(5 +
3376                                                            (orderByComparator.getOrderByFields().length * 3));
3377                                    }
3378                                    else {
3379                                            query = new StringBundler(5);
3380                                    }
3381    
3382                                    query.append(_SQL_SELECT_IGIMAGE_WHERE);
3383    
3384                                    query.append(_FINDER_COLUMN_G_F_N_GROUPID_2);
3385    
3386                                    query.append(_FINDER_COLUMN_G_F_N_FOLDERID_2);
3387    
3388                                    if (name == null) {
3389                                            query.append(_FINDER_COLUMN_G_F_N_NAME_1);
3390                                    }
3391                                    else {
3392                                            if (name.equals(StringPool.BLANK)) {
3393                                                    query.append(_FINDER_COLUMN_G_F_N_NAME_3);
3394                                            }
3395                                            else {
3396                                                    query.append(_FINDER_COLUMN_G_F_N_NAME_2);
3397                                            }
3398                                    }
3399    
3400                                    if (orderByComparator != null) {
3401                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3402                                                    orderByComparator);
3403                                    }
3404    
3405                                    else {
3406                                            query.append(IGImageModelImpl.ORDER_BY_JPQL);
3407                                    }
3408    
3409                                    String sql = query.toString();
3410    
3411                                    Query q = session.createQuery(sql);
3412    
3413                                    QueryPos qPos = QueryPos.getInstance(q);
3414    
3415                                    qPos.add(groupId);
3416    
3417                                    qPos.add(folderId);
3418    
3419                                    if (name != null) {
3420                                            qPos.add(name);
3421                                    }
3422    
3423                                    list = (List<IGImage>)QueryUtil.list(q, getDialect(), start, end);
3424                            }
3425                            catch (Exception e) {
3426                                    throw processException(e);
3427                            }
3428                            finally {
3429                                    if (list == null) {
3430                                            list = new ArrayList<IGImage>();
3431                                    }
3432    
3433                                    cacheResult(list);
3434    
3435                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_F_N,
3436                                            finderArgs, list);
3437    
3438                                    closeSession(session);
3439                            }
3440                    }
3441    
3442                    return list;
3443            }
3444    
3445            /**
3446             * Finds the first i g image in the ordered set where groupId = &#63; and folderId = &#63; and name = &#63;.
3447             *
3448             * <p>
3449             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3450             * </p>
3451             *
3452             * @param groupId the group id to search with
3453             * @param folderId the folder id to search with
3454             * @param name the name to search with
3455             * @param orderByComparator the comparator to order the set by
3456             * @return the first matching i g image
3457             * @throws com.liferay.portlet.imagegallery.NoSuchImageException if a matching i g image could not be found
3458             * @throws SystemException if a system exception occurred
3459             */
3460            public IGImage findByG_F_N_First(long groupId, long folderId, String name,
3461                    OrderByComparator orderByComparator)
3462                    throws NoSuchImageException, SystemException {
3463                    List<IGImage> list = findByG_F_N(groupId, folderId, name, 0, 1,
3464                                    orderByComparator);
3465    
3466                    if (list.isEmpty()) {
3467                            StringBundler msg = new StringBundler(8);
3468    
3469                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3470    
3471                            msg.append("groupId=");
3472                            msg.append(groupId);
3473    
3474                            msg.append(", folderId=");
3475                            msg.append(folderId);
3476    
3477                            msg.append(", name=");
3478                            msg.append(name);
3479    
3480                            msg.append(StringPool.CLOSE_CURLY_BRACE);
3481    
3482                            throw new NoSuchImageException(msg.toString());
3483                    }
3484                    else {
3485                            return list.get(0);
3486                    }
3487            }
3488    
3489            /**
3490             * Finds the last i g image in the ordered set where groupId = &#63; and folderId = &#63; and name = &#63;.
3491             *
3492             * <p>
3493             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3494             * </p>
3495             *
3496             * @param groupId the group id to search with
3497             * @param folderId the folder id to search with
3498             * @param name the name to search with
3499             * @param orderByComparator the comparator to order the set by
3500             * @return the last matching i g image
3501             * @throws com.liferay.portlet.imagegallery.NoSuchImageException if a matching i g image could not be found
3502             * @throws SystemException if a system exception occurred
3503             */
3504            public IGImage findByG_F_N_Last(long groupId, long folderId, String name,
3505                    OrderByComparator orderByComparator)
3506                    throws NoSuchImageException, SystemException {
3507                    int count = countByG_F_N(groupId, folderId, name);
3508    
3509                    List<IGImage> list = findByG_F_N(groupId, folderId, name, count - 1,
3510                                    count, orderByComparator);
3511    
3512                    if (list.isEmpty()) {
3513                            StringBundler msg = new StringBundler(8);
3514    
3515                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3516    
3517                            msg.append("groupId=");
3518                            msg.append(groupId);
3519    
3520                            msg.append(", folderId=");
3521                            msg.append(folderId);
3522    
3523                            msg.append(", name=");
3524                            msg.append(name);
3525    
3526                            msg.append(StringPool.CLOSE_CURLY_BRACE);
3527    
3528                            throw new NoSuchImageException(msg.toString());
3529                    }
3530                    else {
3531                            return list.get(0);
3532                    }
3533            }
3534    
3535            /**
3536             * Finds the i g images before and after the current i g image in the ordered set where groupId = &#63; and folderId = &#63; and name = &#63;.
3537             *
3538             * <p>
3539             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3540             * </p>
3541             *
3542             * @param imageId the primary key of the current i g image
3543             * @param groupId the group id to search with
3544             * @param folderId the folder id to search with
3545             * @param name the name to search with
3546             * @param orderByComparator the comparator to order the set by
3547             * @return the previous, current, and next i g image
3548             * @throws com.liferay.portlet.imagegallery.NoSuchImageException if a i g image with the primary key could not be found
3549             * @throws SystemException if a system exception occurred
3550             */
3551            public IGImage[] findByG_F_N_PrevAndNext(long imageId, long groupId,
3552                    long folderId, String name, OrderByComparator orderByComparator)
3553                    throws NoSuchImageException, SystemException {
3554                    IGImage igImage = findByPrimaryKey(imageId);
3555    
3556                    Session session = null;
3557    
3558                    try {
3559                            session = openSession();
3560    
3561                            IGImage[] array = new IGImageImpl[3];
3562    
3563                            array[0] = getByG_F_N_PrevAndNext(session, igImage, groupId,
3564                                            folderId, name, orderByComparator, true);
3565    
3566                            array[1] = igImage;
3567    
3568                            array[2] = getByG_F_N_PrevAndNext(session, igImage, groupId,
3569                                            folderId, name, orderByComparator, false);
3570    
3571                            return array;
3572                    }
3573                    catch (Exception e) {
3574                            throw processException(e);
3575                    }
3576                    finally {
3577                            closeSession(session);
3578                    }
3579            }
3580    
3581            protected IGImage getByG_F_N_PrevAndNext(Session session, IGImage igImage,
3582                    long groupId, long folderId, String name,
3583                    OrderByComparator orderByComparator, boolean previous) {
3584                    StringBundler query = null;
3585    
3586                    if (orderByComparator != null) {
3587                            query = new StringBundler(6 +
3588                                            (orderByComparator.getOrderByFields().length * 6));
3589                    }
3590                    else {
3591                            query = new StringBundler(3);
3592                    }
3593    
3594                    query.append(_SQL_SELECT_IGIMAGE_WHERE);
3595    
3596                    query.append(_FINDER_COLUMN_G_F_N_GROUPID_2);
3597    
3598                    query.append(_FINDER_COLUMN_G_F_N_FOLDERID_2);
3599    
3600                    if (name == null) {
3601                            query.append(_FINDER_COLUMN_G_F_N_NAME_1);
3602                    }
3603                    else {
3604                            if (name.equals(StringPool.BLANK)) {
3605                                    query.append(_FINDER_COLUMN_G_F_N_NAME_3);
3606                            }
3607                            else {
3608                                    query.append(_FINDER_COLUMN_G_F_N_NAME_2);
3609                            }
3610                    }
3611    
3612                    if (orderByComparator != null) {
3613                            String[] orderByFields = orderByComparator.getOrderByFields();
3614    
3615                            if (orderByFields.length > 0) {
3616                                    query.append(WHERE_AND);
3617                            }
3618    
3619                            for (int i = 0; i < orderByFields.length; i++) {
3620                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3621                                    query.append(orderByFields[i]);
3622    
3623                                    if ((i + 1) < orderByFields.length) {
3624                                            if (orderByComparator.isAscending() ^ previous) {
3625                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3626                                            }
3627                                            else {
3628                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3629                                            }
3630                                    }
3631                                    else {
3632                                            if (orderByComparator.isAscending() ^ previous) {
3633                                                    query.append(WHERE_GREATER_THAN);
3634                                            }
3635                                            else {
3636                                                    query.append(WHERE_LESSER_THAN);
3637                                            }
3638                                    }
3639                            }
3640    
3641                            query.append(ORDER_BY_CLAUSE);
3642    
3643                            for (int i = 0; i < orderByFields.length; i++) {
3644                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3645                                    query.append(orderByFields[i]);
3646    
3647                                    if ((i + 1) < orderByFields.length) {
3648                                            if (orderByComparator.isAscending() ^ previous) {
3649                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3650                                            }
3651                                            else {
3652                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3653                                            }
3654                                    }
3655                                    else {
3656                                            if (orderByComparator.isAscending() ^ previous) {
3657                                                    query.append(ORDER_BY_ASC);
3658                                            }
3659                                            else {
3660                                                    query.append(ORDER_BY_DESC);
3661                                            }
3662                                    }
3663                            }
3664                    }
3665    
3666                    else {
3667                            query.append(IGImageModelImpl.ORDER_BY_JPQL);
3668                    }
3669    
3670                    String sql = query.toString();
3671    
3672                    Query q = session.createQuery(sql);
3673    
3674                    q.setFirstResult(0);
3675                    q.setMaxResults(2);
3676    
3677                    QueryPos qPos = QueryPos.getInstance(q);
3678    
3679                    qPos.add(groupId);
3680    
3681                    qPos.add(folderId);
3682    
3683                    if (name != null) {
3684                            qPos.add(name);
3685                    }
3686    
3687                    if (orderByComparator != null) {
3688                            Object[] values = orderByComparator.getOrderByValues(igImage);
3689    
3690                            for (Object value : values) {
3691                                    qPos.add(value);
3692                            }
3693                    }
3694    
3695                    List<IGImage> list = q.list();
3696    
3697                    if (list.size() == 2) {
3698                            return list.get(1);
3699                    }
3700                    else {
3701                            return null;
3702                    }
3703            }
3704    
3705            /**
3706             * Filters by the user's permissions and finds all the i g images where groupId = &#63; and folderId = &#63; and name = &#63;.
3707             *
3708             * @param groupId the group id to search with
3709             * @param folderId the folder id to search with
3710             * @param name the name to search with
3711             * @return the matching i g images that the user has permission to view
3712             * @throws SystemException if a system exception occurred
3713             */
3714            public List<IGImage> filterFindByG_F_N(long groupId, long folderId,
3715                    String name) throws SystemException {
3716                    return filterFindByG_F_N(groupId, folderId, name, QueryUtil.ALL_POS,
3717                            QueryUtil.ALL_POS, null);
3718            }
3719    
3720            /**
3721             * Filters by the user's permissions and finds a range of all the i g images where groupId = &#63; and folderId = &#63; and name = &#63;.
3722             *
3723             * <p>
3724             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3725             * </p>
3726             *
3727             * @param groupId the group id to search with
3728             * @param folderId the folder id to search with
3729             * @param name the name to search with
3730             * @param start the lower bound of the range of i g images to return
3731             * @param end the upper bound of the range of i g images to return (not inclusive)
3732             * @return the range of matching i g images that the user has permission to view
3733             * @throws SystemException if a system exception occurred
3734             */
3735            public List<IGImage> filterFindByG_F_N(long groupId, long folderId,
3736                    String name, int start, int end) throws SystemException {
3737                    return filterFindByG_F_N(groupId, folderId, name, start, end, null);
3738            }
3739    
3740            /**
3741             * Filters by the user's permissions and finds an ordered range of all the i g images where groupId = &#63; and folderId = &#63; and name = &#63;.
3742             *
3743             * <p>
3744             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3745             * </p>
3746             *
3747             * @param groupId the group id to search with
3748             * @param folderId the folder id to search with
3749             * @param name the name to search with
3750             * @param start the lower bound of the range of i g images to return
3751             * @param end the upper bound of the range of i g images to return (not inclusive)
3752             * @param orderByComparator the comparator to order the results by
3753             * @return the ordered range of matching i g images that the user has permission to view
3754             * @throws SystemException if a system exception occurred
3755             */
3756            public List<IGImage> filterFindByG_F_N(long groupId, long folderId,
3757                    String name, int start, int end, OrderByComparator orderByComparator)
3758                    throws SystemException {
3759                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3760                            return findByG_F_N(groupId, folderId, name, start, end,
3761                                    orderByComparator);
3762                    }
3763    
3764                    Session session = null;
3765    
3766                    try {
3767                            session = openSession();
3768    
3769                            StringBundler query = null;
3770    
3771                            if (orderByComparator != null) {
3772                                    query = new StringBundler(5 +
3773                                                    (orderByComparator.getOrderByFields().length * 3));
3774                            }
3775                            else {
3776                                    query = new StringBundler(5);
3777                            }
3778    
3779                            query.append(_FILTER_SQL_SELECT_IGIMAGE_WHERE);
3780    
3781                            query.append(_FINDER_COLUMN_G_F_N_GROUPID_2);
3782    
3783                            query.append(_FINDER_COLUMN_G_F_N_FOLDERID_2);
3784    
3785                            if (name == null) {
3786                                    query.append(_FINDER_COLUMN_G_F_N_NAME_1);
3787                            }
3788                            else {
3789                                    if (name.equals(StringPool.BLANK)) {
3790                                            query.append(_FINDER_COLUMN_G_F_N_NAME_3);
3791                                    }
3792                                    else {
3793                                            query.append(_FINDER_COLUMN_G_F_N_NAME_2);
3794                                    }
3795                            }
3796    
3797                            if (orderByComparator != null) {
3798                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3799                                            orderByComparator);
3800                            }
3801    
3802                            else {
3803                                    query.append(IGImageModelImpl.ORDER_BY_JPQL);
3804                            }
3805    
3806                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3807                                            IGImage.class.getName(), _FILTER_COLUMN_PK,
3808                                            _FILTER_COLUMN_USERID, groupId);
3809    
3810                            SQLQuery q = session.createSQLQuery(sql);
3811    
3812                            q.addEntity(_FILTER_ENTITY_ALIAS, IGImageImpl.class);
3813    
3814                            QueryPos qPos = QueryPos.getInstance(q);
3815    
3816                            qPos.add(groupId);
3817    
3818                            qPos.add(folderId);
3819    
3820                            if (name != null) {
3821                                    qPos.add(name);
3822                            }
3823    
3824                            return (List<IGImage>)QueryUtil.list(q, getDialect(), start, end);
3825                    }
3826                    catch (Exception e) {
3827                            throw processException(e);
3828                    }
3829                    finally {
3830                            closeSession(session);
3831                    }
3832            }
3833    
3834            /**
3835             * Finds all the i g images.
3836             *
3837             * @return the i g images
3838             * @throws SystemException if a system exception occurred
3839             */
3840            public List<IGImage> findAll() throws SystemException {
3841                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3842            }
3843    
3844            /**
3845             * Finds a range of all the i g images.
3846             *
3847             * <p>
3848             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3849             * </p>
3850             *
3851             * @param start the lower bound of the range of i g images to return
3852             * @param end the upper bound of the range of i g images to return (not inclusive)
3853             * @return the range of i g images
3854             * @throws SystemException if a system exception occurred
3855             */
3856            public List<IGImage> findAll(int start, int end) throws SystemException {
3857                    return findAll(start, end, null);
3858            }
3859    
3860            /**
3861             * Finds an ordered range of all the i g images.
3862             *
3863             * <p>
3864             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3865             * </p>
3866             *
3867             * @param start the lower bound of the range of i g images to return
3868             * @param end the upper bound of the range of i g images to return (not inclusive)
3869             * @param orderByComparator the comparator to order the results by
3870             * @return the ordered range of i g images
3871             * @throws SystemException if a system exception occurred
3872             */
3873            public List<IGImage> findAll(int start, int end,
3874                    OrderByComparator orderByComparator) throws SystemException {
3875                    Object[] finderArgs = new Object[] {
3876                                    String.valueOf(start), String.valueOf(end),
3877                                    String.valueOf(orderByComparator)
3878                            };
3879    
3880                    List<IGImage> list = (List<IGImage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
3881                                    finderArgs, this);
3882    
3883                    if (list == null) {
3884                            Session session = null;
3885    
3886                            try {
3887                                    session = openSession();
3888    
3889                                    StringBundler query = null;
3890                                    String sql = null;
3891    
3892                                    if (orderByComparator != null) {
3893                                            query = new StringBundler(2 +
3894                                                            (orderByComparator.getOrderByFields().length * 3));
3895    
3896                                            query.append(_SQL_SELECT_IGIMAGE);
3897    
3898                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3899                                                    orderByComparator);
3900    
3901                                            sql = query.toString();
3902                                    }
3903                                    else {
3904                                            sql = _SQL_SELECT_IGIMAGE.concat(IGImageModelImpl.ORDER_BY_JPQL);
3905                                    }
3906    
3907                                    Query q = session.createQuery(sql);
3908    
3909                                    if (orderByComparator == null) {
3910                                            list = (List<IGImage>)QueryUtil.list(q, getDialect(),
3911                                                            start, end, false);
3912    
3913                                            Collections.sort(list);
3914                                    }
3915                                    else {
3916                                            list = (List<IGImage>)QueryUtil.list(q, getDialect(),
3917                                                            start, end);
3918                                    }
3919                            }
3920                            catch (Exception e) {
3921                                    throw processException(e);
3922                            }
3923                            finally {
3924                                    if (list == null) {
3925                                            list = new ArrayList<IGImage>();
3926                                    }
3927    
3928                                    cacheResult(list);
3929    
3930                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
3931    
3932                                    closeSession(session);
3933                            }
3934                    }
3935    
3936                    return list;
3937            }
3938    
3939            /**
3940             * Removes all the i g images where uuid = &#63; from the database.
3941             *
3942             * @param uuid the uuid to search with
3943             * @throws SystemException if a system exception occurred
3944             */
3945            public void removeByUuid(String uuid) throws SystemException {
3946                    for (IGImage igImage : findByUuid(uuid)) {
3947                            remove(igImage);
3948                    }
3949            }
3950    
3951            /**
3952             * Removes the i g image where uuid = &#63; and groupId = &#63; from the database.
3953             *
3954             * @param uuid the uuid to search with
3955             * @param groupId the group id to search with
3956             * @throws SystemException if a system exception occurred
3957             */
3958            public void removeByUUID_G(String uuid, long groupId)
3959                    throws NoSuchImageException, SystemException {
3960                    IGImage igImage = findByUUID_G(uuid, groupId);
3961    
3962                    remove(igImage);
3963            }
3964    
3965            /**
3966             * Removes all the i g images where groupId = &#63; from the database.
3967             *
3968             * @param groupId the group id to search with
3969             * @throws SystemException if a system exception occurred
3970             */
3971            public void removeByGroupId(long groupId) throws SystemException {
3972                    for (IGImage igImage : findByGroupId(groupId)) {
3973                            remove(igImage);
3974                    }
3975            }
3976    
3977            /**
3978             * Removes the i g image where smallImageId = &#63; from the database.
3979             *
3980             * @param smallImageId the small image id to search with
3981             * @throws SystemException if a system exception occurred
3982             */
3983            public void removeBySmallImageId(long smallImageId)
3984                    throws NoSuchImageException, SystemException {
3985                    IGImage igImage = findBySmallImageId(smallImageId);
3986    
3987                    remove(igImage);
3988            }
3989    
3990            /**
3991             * Removes the i g image where largeImageId = &#63; from the database.
3992             *
3993             * @param largeImageId the large image id to search with
3994             * @throws SystemException if a system exception occurred
3995             */
3996            public void removeByLargeImageId(long largeImageId)
3997                    throws NoSuchImageException, SystemException {
3998                    IGImage igImage = findByLargeImageId(largeImageId);
3999    
4000                    remove(igImage);
4001            }
4002    
4003            /**
4004             * Removes the i g image where custom1ImageId = &#63; from the database.
4005             *
4006             * @param custom1ImageId the custom1 image id to search with
4007             * @throws SystemException if a system exception occurred
4008             */
4009            public void removeByCustom1ImageId(long custom1ImageId)
4010                    throws NoSuchImageException, SystemException {
4011                    IGImage igImage = findByCustom1ImageId(custom1ImageId);
4012    
4013                    remove(igImage);
4014            }
4015    
4016            /**
4017             * Removes the i g image where custom2ImageId = &#63; from the database.
4018             *
4019             * @param custom2ImageId the custom2 image id to search with
4020             * @throws SystemException if a system exception occurred
4021             */
4022            public void removeByCustom2ImageId(long custom2ImageId)
4023                    throws NoSuchImageException, SystemException {
4024                    IGImage igImage = findByCustom2ImageId(custom2ImageId);
4025    
4026                    remove(igImage);
4027            }
4028    
4029            /**
4030             * Removes all the i g images where groupId = &#63; and userId = &#63; from the database.
4031             *
4032             * @param groupId the group id to search with
4033             * @param userId the user id to search with
4034             * @throws SystemException if a system exception occurred
4035             */
4036            public void removeByG_U(long groupId, long userId)
4037                    throws SystemException {
4038                    for (IGImage igImage : findByG_U(groupId, userId)) {
4039                            remove(igImage);
4040                    }
4041            }
4042    
4043            /**
4044             * Removes all the i g images where groupId = &#63; and folderId = &#63; from the database.
4045             *
4046             * @param groupId the group id to search with
4047             * @param folderId the folder id to search with
4048             * @throws SystemException if a system exception occurred
4049             */
4050            public void removeByG_F(long groupId, long folderId)
4051                    throws SystemException {
4052                    for (IGImage igImage : findByG_F(groupId, folderId)) {
4053                            remove(igImage);
4054                    }
4055            }
4056    
4057            /**
4058             * Removes all the i g images where groupId = &#63; and folderId = &#63; and name = &#63; from the database.
4059             *
4060             * @param groupId the group id to search with
4061             * @param folderId the folder id to search with
4062             * @param name the name to search with
4063             * @throws SystemException if a system exception occurred
4064             */
4065            public void removeByG_F_N(long groupId, long folderId, String name)
4066                    throws SystemException {
4067                    for (IGImage igImage : findByG_F_N(groupId, folderId, name)) {
4068                            remove(igImage);
4069                    }
4070            }
4071    
4072            /**
4073             * Removes all the i g images from the database.
4074             *
4075             * @throws SystemException if a system exception occurred
4076             */
4077            public void removeAll() throws SystemException {
4078                    for (IGImage igImage : findAll()) {
4079                            remove(igImage);
4080                    }
4081            }
4082    
4083            /**
4084             * Counts all the i g images where uuid = &#63;.
4085             *
4086             * @param uuid the uuid to search with
4087             * @return the number of matching i g images
4088             * @throws SystemException if a system exception occurred
4089             */
4090            public int countByUuid(String uuid) throws SystemException {
4091                    Object[] finderArgs = new Object[] { uuid };
4092    
4093                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
4094                                    finderArgs, this);
4095    
4096                    if (count == null) {
4097                            Session session = null;
4098    
4099                            try {
4100                                    session = openSession();
4101    
4102                                    StringBundler query = new StringBundler(2);
4103    
4104                                    query.append(_SQL_COUNT_IGIMAGE_WHERE);
4105    
4106                                    if (uuid == null) {
4107                                            query.append(_FINDER_COLUMN_UUID_UUID_1);
4108                                    }
4109                                    else {
4110                                            if (uuid.equals(StringPool.BLANK)) {
4111                                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
4112                                            }
4113                                            else {
4114                                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
4115                                            }
4116                                    }
4117    
4118                                    String sql = query.toString();
4119    
4120                                    Query q = session.createQuery(sql);
4121    
4122                                    QueryPos qPos = QueryPos.getInstance(q);
4123    
4124                                    if (uuid != null) {
4125                                            qPos.add(uuid);
4126                                    }
4127    
4128                                    count = (Long)q.uniqueResult();
4129                            }
4130                            catch (Exception e) {
4131                                    throw processException(e);
4132                            }
4133                            finally {
4134                                    if (count == null) {
4135                                            count = Long.valueOf(0);
4136                                    }
4137    
4138                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
4139                                            finderArgs, count);
4140    
4141                                    closeSession(session);
4142                            }
4143                    }
4144    
4145                    return count.intValue();
4146            }
4147    
4148            /**
4149             * Counts all the i g images where uuid = &#63; and groupId = &#63;.
4150             *
4151             * @param uuid the uuid to search with
4152             * @param groupId the group id to search with
4153             * @return the number of matching i g images
4154             * @throws SystemException if a system exception occurred
4155             */
4156            public int countByUUID_G(String uuid, long groupId)
4157                    throws SystemException {
4158                    Object[] finderArgs = new Object[] { uuid, groupId };
4159    
4160                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
4161                                    finderArgs, this);
4162    
4163                    if (count == null) {
4164                            Session session = null;
4165    
4166                            try {
4167                                    session = openSession();
4168    
4169                                    StringBundler query = new StringBundler(3);
4170    
4171                                    query.append(_SQL_COUNT_IGIMAGE_WHERE);
4172    
4173                                    if (uuid == null) {
4174                                            query.append(_FINDER_COLUMN_UUID_G_UUID_1);
4175                                    }
4176                                    else {
4177                                            if (uuid.equals(StringPool.BLANK)) {
4178                                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
4179                                            }
4180                                            else {
4181                                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
4182                                            }
4183                                    }
4184    
4185                                    query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
4186    
4187                                    String sql = query.toString();
4188    
4189                                    Query q = session.createQuery(sql);
4190    
4191                                    QueryPos qPos = QueryPos.getInstance(q);
4192    
4193                                    if (uuid != null) {
4194                                            qPos.add(uuid);
4195                                    }
4196    
4197                                    qPos.add(groupId);
4198    
4199                                    count = (Long)q.uniqueResult();
4200                            }
4201                            catch (Exception e) {
4202                                    throw processException(e);
4203                            }
4204                            finally {
4205                                    if (count == null) {
4206                                            count = Long.valueOf(0);
4207                                    }
4208    
4209                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
4210                                            finderArgs, count);
4211    
4212                                    closeSession(session);
4213                            }
4214                    }
4215    
4216                    return count.intValue();
4217            }
4218    
4219            /**
4220             * Counts all the i g images where groupId = &#63;.
4221             *
4222             * @param groupId the group id to search with
4223             * @return the number of matching i g images
4224             * @throws SystemException if a system exception occurred
4225             */
4226            public int countByGroupId(long groupId) throws SystemException {
4227                    Object[] finderArgs = new Object[] { groupId };
4228    
4229                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
4230                                    finderArgs, this);
4231    
4232                    if (count == null) {
4233                            Session session = null;
4234    
4235                            try {
4236                                    session = openSession();
4237    
4238                                    StringBundler query = new StringBundler(2);
4239    
4240                                    query.append(_SQL_COUNT_IGIMAGE_WHERE);
4241    
4242                                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
4243    
4244                                    String sql = query.toString();
4245    
4246                                    Query q = session.createQuery(sql);
4247    
4248                                    QueryPos qPos = QueryPos.getInstance(q);
4249    
4250                                    qPos.add(groupId);
4251    
4252                                    count = (Long)q.uniqueResult();
4253                            }
4254                            catch (Exception e) {
4255                                    throw processException(e);
4256                            }
4257                            finally {
4258                                    if (count == null) {
4259                                            count = Long.valueOf(0);
4260                                    }
4261    
4262                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
4263                                            finderArgs, count);
4264    
4265                                    closeSession(session);
4266                            }
4267                    }
4268    
4269                    return count.intValue();
4270            }
4271    
4272            /**
4273             * Filters by the user's permissions and counts all the i g images where groupId = &#63;.
4274             *
4275             * @param groupId the group id to search with
4276             * @return the number of matching i g images that the user has permission to view
4277             * @throws SystemException if a system exception occurred
4278             */
4279            public int filterCountByGroupId(long groupId) throws SystemException {
4280                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4281                            return countByGroupId(groupId);
4282                    }
4283    
4284                    Session session = null;
4285    
4286                    try {
4287                            session = openSession();
4288    
4289                            StringBundler query = new StringBundler(2);
4290    
4291                            query.append(_FILTER_SQL_COUNT_IGIMAGE_WHERE);
4292    
4293                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
4294    
4295                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4296                                            IGImage.class.getName(), _FILTER_COLUMN_PK,
4297                                            _FILTER_COLUMN_USERID, groupId);
4298    
4299                            SQLQuery q = session.createSQLQuery(sql);
4300    
4301                            q.addScalar(COUNT_COLUMN_NAME,
4302                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
4303    
4304                            QueryPos qPos = QueryPos.getInstance(q);
4305    
4306                            qPos.add(groupId);
4307    
4308                            Long count = (Long)q.uniqueResult();
4309    
4310                            return count.intValue();
4311                    }
4312                    catch (Exception e) {
4313                            throw processException(e);
4314                    }
4315                    finally {
4316                            closeSession(session);
4317                    }
4318            }
4319    
4320            /**
4321             * Counts all the i g images where smallImageId = &#63;.
4322             *
4323             * @param smallImageId the small image id to search with
4324             * @return the number of matching i g images
4325             * @throws SystemException if a system exception occurred
4326             */
4327            public int countBySmallImageId(long smallImageId) throws SystemException {
4328                    Object[] finderArgs = new Object[] { smallImageId };
4329    
4330                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_SMALLIMAGEID,
4331                                    finderArgs, this);
4332    
4333                    if (count == null) {
4334                            Session session = null;
4335    
4336                            try {
4337                                    session = openSession();
4338    
4339                                    StringBundler query = new StringBundler(2);
4340    
4341                                    query.append(_SQL_COUNT_IGIMAGE_WHERE);
4342    
4343                                    query.append(_FINDER_COLUMN_SMALLIMAGEID_SMALLIMAGEID_2);
4344    
4345                                    String sql = query.toString();
4346    
4347                                    Query q = session.createQuery(sql);
4348    
4349                                    QueryPos qPos = QueryPos.getInstance(q);
4350    
4351                                    qPos.add(smallImageId);
4352    
4353                                    count = (Long)q.uniqueResult();
4354                            }
4355                            catch (Exception e) {
4356                                    throw processException(e);
4357                            }
4358                            finally {
4359                                    if (count == null) {
4360                                            count = Long.valueOf(0);
4361                                    }
4362    
4363                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_SMALLIMAGEID,
4364                                            finderArgs, count);
4365    
4366                                    closeSession(session);
4367                            }
4368                    }
4369    
4370                    return count.intValue();
4371            }
4372    
4373            /**
4374             * Counts all the i g images where largeImageId = &#63;.
4375             *
4376             * @param largeImageId the large image id to search with
4377             * @return the number of matching i g images
4378             * @throws SystemException if a system exception occurred
4379             */
4380            public int countByLargeImageId(long largeImageId) throws SystemException {
4381                    Object[] finderArgs = new Object[] { largeImageId };
4382    
4383                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_LARGEIMAGEID,
4384                                    finderArgs, this);
4385    
4386                    if (count == null) {
4387                            Session session = null;
4388    
4389                            try {
4390                                    session = openSession();
4391    
4392                                    StringBundler query = new StringBundler(2);
4393    
4394                                    query.append(_SQL_COUNT_IGIMAGE_WHERE);
4395    
4396                                    query.append(_FINDER_COLUMN_LARGEIMAGEID_LARGEIMAGEID_2);
4397    
4398                                    String sql = query.toString();
4399    
4400                                    Query q = session.createQuery(sql);
4401    
4402                                    QueryPos qPos = QueryPos.getInstance(q);
4403    
4404                                    qPos.add(largeImageId);
4405    
4406                                    count = (Long)q.uniqueResult();
4407                            }
4408                            catch (Exception e) {
4409                                    throw processException(e);
4410                            }
4411                            finally {
4412                                    if (count == null) {
4413                                            count = Long.valueOf(0);
4414                                    }
4415    
4416                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_LARGEIMAGEID,
4417                                            finderArgs, count);
4418    
4419                                    closeSession(session);
4420                            }
4421                    }
4422    
4423                    return count.intValue();
4424            }
4425    
4426            /**
4427             * Counts all the i g images where custom1ImageId = &#63;.
4428             *
4429             * @param custom1ImageId the custom1 image id to search with
4430             * @return the number of matching i g images
4431             * @throws SystemException if a system exception occurred
4432             */
4433            public int countByCustom1ImageId(long custom1ImageId)
4434                    throws SystemException {
4435                    Object[] finderArgs = new Object[] { custom1ImageId };
4436    
4437                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_CUSTOM1IMAGEID,
4438                                    finderArgs, this);
4439    
4440                    if (count == null) {
4441                            Session session = null;
4442    
4443                            try {
4444                                    session = openSession();
4445    
4446                                    StringBundler query = new StringBundler(2);
4447    
4448                                    query.append(_SQL_COUNT_IGIMAGE_WHERE);
4449    
4450                                    query.append(_FINDER_COLUMN_CUSTOM1IMAGEID_CUSTOM1IMAGEID_2);
4451    
4452                                    String sql = query.toString();
4453    
4454                                    Query q = session.createQuery(sql);
4455    
4456                                    QueryPos qPos = QueryPos.getInstance(q);
4457    
4458                                    qPos.add(custom1ImageId);
4459    
4460                                    count = (Long)q.uniqueResult();
4461                            }
4462                            catch (Exception e) {
4463                                    throw processException(e);
4464                            }
4465                            finally {
4466                                    if (count == null) {
4467                                            count = Long.valueOf(0);
4468                                    }
4469    
4470                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_CUSTOM1IMAGEID,
4471                                            finderArgs, count);
4472    
4473                                    closeSession(session);
4474                            }
4475                    }
4476    
4477                    return count.intValue();
4478            }
4479    
4480            /**
4481             * Counts all the i g images where custom2ImageId = &#63;.
4482             *
4483             * @param custom2ImageId the custom2 image id to search with
4484             * @return the number of matching i g images
4485             * @throws SystemException if a system exception occurred
4486             */
4487            public int countByCustom2ImageId(long custom2ImageId)
4488                    throws SystemException {
4489                    Object[] finderArgs = new Object[] { custom2ImageId };
4490    
4491                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_CUSTOM2IMAGEID,
4492                                    finderArgs, this);
4493    
4494                    if (count == null) {
4495                            Session session = null;
4496    
4497                            try {
4498                                    session = openSession();
4499    
4500                                    StringBundler query = new StringBundler(2);
4501    
4502                                    query.append(_SQL_COUNT_IGIMAGE_WHERE);
4503    
4504                                    query.append(_FINDER_COLUMN_CUSTOM2IMAGEID_CUSTOM2IMAGEID_2);
4505    
4506                                    String sql = query.toString();
4507    
4508                                    Query q = session.createQuery(sql);
4509    
4510                                    QueryPos qPos = QueryPos.getInstance(q);
4511    
4512                                    qPos.add(custom2ImageId);
4513    
4514                                    count = (Long)q.uniqueResult();
4515                            }
4516                            catch (Exception e) {
4517                                    throw processException(e);
4518                            }
4519                            finally {
4520                                    if (count == null) {
4521                                            count = Long.valueOf(0);
4522                                    }
4523    
4524                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_CUSTOM2IMAGEID,
4525                                            finderArgs, count);
4526    
4527                                    closeSession(session);
4528                            }
4529                    }
4530    
4531                    return count.intValue();
4532            }
4533    
4534            /**
4535             * Counts all the i g images where groupId = &#63; and userId = &#63;.
4536             *
4537             * @param groupId the group id to search with
4538             * @param userId the user id to search with
4539             * @return the number of matching i g images
4540             * @throws SystemException if a system exception occurred
4541             */
4542            public int countByG_U(long groupId, long userId) throws SystemException {
4543                    Object[] finderArgs = new Object[] { groupId, userId };
4544    
4545                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_U,
4546                                    finderArgs, this);
4547    
4548                    if (count == null) {
4549                            Session session = null;
4550    
4551                            try {
4552                                    session = openSession();
4553    
4554                                    StringBundler query = new StringBundler(3);
4555    
4556                                    query.append(_SQL_COUNT_IGIMAGE_WHERE);
4557    
4558                                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
4559    
4560                                    query.append(_FINDER_COLUMN_G_U_USERID_2);
4561    
4562                                    String sql = query.toString();
4563    
4564                                    Query q = session.createQuery(sql);
4565    
4566                                    QueryPos qPos = QueryPos.getInstance(q);
4567    
4568                                    qPos.add(groupId);
4569    
4570                                    qPos.add(userId);
4571    
4572                                    count = (Long)q.uniqueResult();
4573                            }
4574                            catch (Exception e) {
4575                                    throw processException(e);
4576                            }
4577                            finally {
4578                                    if (count == null) {
4579                                            count = Long.valueOf(0);
4580                                    }
4581    
4582                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_U, finderArgs,
4583                                            count);
4584    
4585                                    closeSession(session);
4586                            }
4587                    }
4588    
4589                    return count.intValue();
4590            }
4591    
4592            /**
4593             * Filters by the user's permissions and counts all the i g images where groupId = &#63; and userId = &#63;.
4594             *
4595             * @param groupId the group id to search with
4596             * @param userId the user id to search with
4597             * @return the number of matching i g images that the user has permission to view
4598             * @throws SystemException if a system exception occurred
4599             */
4600            public int filterCountByG_U(long groupId, long userId)
4601                    throws SystemException {
4602                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4603                            return countByG_U(groupId, userId);
4604                    }
4605    
4606                    Session session = null;
4607    
4608                    try {
4609                            session = openSession();
4610    
4611                            StringBundler query = new StringBundler(3);
4612    
4613                            query.append(_FILTER_SQL_COUNT_IGIMAGE_WHERE);
4614    
4615                            query.append(_FINDER_COLUMN_G_U_GROUPID_2);
4616    
4617                            query.append(_FINDER_COLUMN_G_U_USERID_2);
4618    
4619                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4620                                            IGImage.class.getName(), _FILTER_COLUMN_PK,
4621                                            _FILTER_COLUMN_USERID, groupId);
4622    
4623                            SQLQuery q = session.createSQLQuery(sql);
4624    
4625                            q.addScalar(COUNT_COLUMN_NAME,
4626                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
4627    
4628                            QueryPos qPos = QueryPos.getInstance(q);
4629    
4630                            qPos.add(groupId);
4631    
4632                            qPos.add(userId);
4633    
4634                            Long count = (Long)q.uniqueResult();
4635    
4636                            return count.intValue();
4637                    }
4638                    catch (Exception e) {
4639                            throw processException(e);
4640                    }
4641                    finally {
4642                            closeSession(session);
4643                    }
4644            }
4645    
4646            /**
4647             * Counts all the i g images where groupId = &#63; and folderId = &#63;.
4648             *
4649             * @param groupId the group id to search with
4650             * @param folderId the folder id to search with
4651             * @return the number of matching i g images
4652             * @throws SystemException if a system exception occurred
4653             */
4654            public int countByG_F(long groupId, long folderId)
4655                    throws SystemException {
4656                    Object[] finderArgs = new Object[] { groupId, folderId };
4657    
4658                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_F,
4659                                    finderArgs, this);
4660    
4661                    if (count == null) {
4662                            Session session = null;
4663    
4664                            try {
4665                                    session = openSession();
4666    
4667                                    StringBundler query = new StringBundler(3);
4668    
4669                                    query.append(_SQL_COUNT_IGIMAGE_WHERE);
4670    
4671                                    query.append(_FINDER_COLUMN_G_F_GROUPID_2);
4672    
4673                                    query.append(_FINDER_COLUMN_G_F_FOLDERID_2);
4674    
4675                                    String sql = query.toString();
4676    
4677                                    Query q = session.createQuery(sql);
4678    
4679                                    QueryPos qPos = QueryPos.getInstance(q);
4680    
4681                                    qPos.add(groupId);
4682    
4683                                    qPos.add(folderId);
4684    
4685                                    count = (Long)q.uniqueResult();
4686                            }
4687                            catch (Exception e) {
4688                                    throw processException(e);
4689                            }
4690                            finally {
4691                                    if (count == null) {
4692                                            count = Long.valueOf(0);
4693                                    }
4694    
4695                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_F, finderArgs,
4696                                            count);
4697    
4698                                    closeSession(session);
4699                            }
4700                    }
4701    
4702                    return count.intValue();
4703            }
4704    
4705            /**
4706             * Counts all the i g images where groupId = &#63; and folderId = any &#63;.
4707             *
4708             * @param groupId the group id to search with
4709             * @param folderIds the folder ids to search with
4710             * @return the number of matching i g images
4711             * @throws SystemException if a system exception occurred
4712             */
4713            public int countByG_F(long groupId, long[] folderIds)
4714                    throws SystemException {
4715                    Object[] finderArgs = new Object[] { groupId, StringUtil.merge(folderIds) };
4716    
4717                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_F,
4718                                    finderArgs, this);
4719    
4720                    if (count == null) {
4721                            Session session = null;
4722    
4723                            try {
4724                                    session = openSession();
4725    
4726                                    StringBundler query = new StringBundler();
4727    
4728                                    query.append(_SQL_COUNT_IGIMAGE_WHERE);
4729    
4730                                    boolean conjunctionable = false;
4731    
4732                                    if (conjunctionable) {
4733                                            query.append(WHERE_AND);
4734                                    }
4735    
4736                                    query.append(_FINDER_COLUMN_G_F_GROUPID_5);
4737    
4738                                    conjunctionable = true;
4739    
4740                                    if ((folderIds == null) || (folderIds.length > 0)) {
4741                                            if (conjunctionable) {
4742                                                    query.append(WHERE_AND);
4743                                            }
4744    
4745                                            query.append(StringPool.OPEN_PARENTHESIS);
4746    
4747                                            for (int i = 0; i < folderIds.length; i++) {
4748                                                    query.append(_FINDER_COLUMN_G_F_FOLDERID_5);
4749    
4750                                                    if ((i + 1) < folderIds.length) {
4751                                                            query.append(WHERE_OR);
4752                                                    }
4753                                            }
4754    
4755                                            query.append(StringPool.CLOSE_PARENTHESIS);
4756    
4757                                            conjunctionable = true;
4758                                    }
4759    
4760                                    String sql = query.toString();
4761    
4762                                    Query q = session.createQuery(sql);
4763    
4764                                    QueryPos qPos = QueryPos.getInstance(q);
4765    
4766                                    qPos.add(groupId);
4767    
4768                                    if (folderIds != null) {
4769                                            qPos.add(folderIds);
4770                                    }
4771    
4772                                    count = (Long)q.uniqueResult();
4773                            }
4774                            catch (Exception e) {
4775                                    throw processException(e);
4776                            }
4777                            finally {
4778                                    if (count == null) {
4779                                            count = Long.valueOf(0);
4780                                    }
4781    
4782                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_F, finderArgs,
4783                                            count);
4784    
4785                                    closeSession(session);
4786                            }
4787                    }
4788    
4789                    return count.intValue();
4790            }
4791    
4792            /**
4793             * Filters by the user's permissions and counts all the i g images where groupId = &#63; and folderId = &#63;.
4794             *
4795             * @param groupId the group id to search with
4796             * @param folderId the folder id to search with
4797             * @return the number of matching i g images that the user has permission to view
4798             * @throws SystemException if a system exception occurred
4799             */
4800            public int filterCountByG_F(long groupId, long folderId)
4801                    throws SystemException {
4802                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4803                            return countByG_F(groupId, folderId);
4804                    }
4805    
4806                    Session session = null;
4807    
4808                    try {
4809                            session = openSession();
4810    
4811                            StringBundler query = new StringBundler(3);
4812    
4813                            query.append(_FILTER_SQL_COUNT_IGIMAGE_WHERE);
4814    
4815                            query.append(_FINDER_COLUMN_G_F_GROUPID_2);
4816    
4817                            query.append(_FINDER_COLUMN_G_F_FOLDERID_2);
4818    
4819                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4820                                            IGImage.class.getName(), _FILTER_COLUMN_PK,
4821                                            _FILTER_COLUMN_USERID, groupId);
4822    
4823                            SQLQuery q = session.createSQLQuery(sql);
4824    
4825                            q.addScalar(COUNT_COLUMN_NAME,
4826                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
4827    
4828                            QueryPos qPos = QueryPos.getInstance(q);
4829    
4830                            qPos.add(groupId);
4831    
4832                            qPos.add(folderId);
4833    
4834                            Long count = (Long)q.uniqueResult();
4835    
4836                            return count.intValue();
4837                    }
4838                    catch (Exception e) {
4839                            throw processException(e);
4840                    }
4841                    finally {
4842                            closeSession(session);
4843                    }
4844            }
4845    
4846            /**
4847             * Filters by the user's permissions and counts all the i g images where groupId = &#63; and folderId = any &#63;.
4848             *
4849             * @param groupId the group id to search with
4850             * @param folderIds the folder ids to search with
4851             * @return the number of matching i g images that the user has permission to view
4852             * @throws SystemException if a system exception occurred
4853             */
4854            public int filterCountByG_F(long groupId, long[] folderIds)
4855                    throws SystemException {
4856                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4857                            return countByG_F(groupId, folderIds);
4858                    }
4859    
4860                    Session session = null;
4861    
4862                    try {
4863                            session = openSession();
4864    
4865                            StringBundler query = new StringBundler();
4866    
4867                            query.append(_FILTER_SQL_COUNT_IGIMAGE_WHERE);
4868    
4869                            boolean conjunctionable = false;
4870    
4871                            if (conjunctionable) {
4872                                    query.append(WHERE_AND);
4873                            }
4874    
4875                            query.append(_FINDER_COLUMN_G_F_GROUPID_5);
4876    
4877                            conjunctionable = true;
4878    
4879                            if ((folderIds == null) || (folderIds.length > 0)) {
4880                                    if (conjunctionable) {
4881                                            query.append(WHERE_AND);
4882                                    }
4883    
4884                                    query.append(StringPool.OPEN_PARENTHESIS);
4885    
4886                                    for (int i = 0; i < folderIds.length; i++) {
4887                                            query.append(_FINDER_COLUMN_G_F_FOLDERID_5);
4888    
4889                                            if ((i + 1) < folderIds.length) {
4890                                                    query.append(WHERE_OR);
4891                                            }
4892                                    }
4893    
4894                                    query.append(StringPool.CLOSE_PARENTHESIS);
4895    
4896                                    conjunctionable = true;
4897                            }
4898    
4899                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4900                                            IGImage.class.getName(), _FILTER_COLUMN_PK,
4901                                            _FILTER_COLUMN_USERID, groupId);
4902    
4903                            SQLQuery q = session.createSQLQuery(sql);
4904    
4905                            q.addScalar(COUNT_COLUMN_NAME,
4906                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
4907    
4908                            QueryPos qPos = QueryPos.getInstance(q);
4909    
4910                            qPos.add(groupId);
4911    
4912                            if (folderIds != null) {
4913                                    qPos.add(folderIds);
4914                            }
4915    
4916                            Long count = (Long)q.uniqueResult();
4917    
4918                            return count.intValue();
4919                    }
4920                    catch (Exception e) {
4921                            throw processException(e);
4922                    }
4923                    finally {
4924                            closeSession(session);
4925                    }
4926            }
4927    
4928            /**
4929             * Counts all the i g images where groupId = &#63; and folderId = &#63; and name = &#63;.
4930             *
4931             * @param groupId the group id to search with
4932             * @param folderId the folder id to search with
4933             * @param name the name to search with
4934             * @return the number of matching i g images
4935             * @throws SystemException if a system exception occurred
4936             */
4937            public int countByG_F_N(long groupId, long folderId, String name)
4938                    throws SystemException {
4939                    Object[] finderArgs = new Object[] { groupId, folderId, name };
4940    
4941                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_F_N,
4942                                    finderArgs, this);
4943    
4944                    if (count == null) {
4945                            Session session = null;
4946    
4947                            try {
4948                                    session = openSession();
4949    
4950                                    StringBundler query = new StringBundler(4);
4951    
4952                                    query.append(_SQL_COUNT_IGIMAGE_WHERE);
4953    
4954                                    query.append(_FINDER_COLUMN_G_F_N_GROUPID_2);
4955    
4956                                    query.append(_FINDER_COLUMN_G_F_N_FOLDERID_2);
4957    
4958                                    if (name == null) {
4959                                            query.append(_FINDER_COLUMN_G_F_N_NAME_1);
4960                                    }
4961                                    else {
4962                                            if (name.equals(StringPool.BLANK)) {
4963                                                    query.append(_FINDER_COLUMN_G_F_N_NAME_3);
4964                                            }
4965                                            else {
4966                                                    query.append(_FINDER_COLUMN_G_F_N_NAME_2);
4967                                            }
4968                                    }
4969    
4970                                    String sql = query.toString();
4971    
4972                                    Query q = session.createQuery(sql);
4973    
4974                                    QueryPos qPos = QueryPos.getInstance(q);
4975    
4976                                    qPos.add(groupId);
4977    
4978                                    qPos.add(folderId);
4979    
4980                                    if (name != null) {
4981                                            qPos.add(name);
4982                                    }
4983    
4984                                    count = (Long)q.uniqueResult();
4985                            }
4986                            catch (Exception e) {
4987                                    throw processException(e);
4988                            }
4989                            finally {
4990                                    if (count == null) {
4991                                            count = Long.valueOf(0);
4992                                    }
4993    
4994                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_F_N,
4995                                            finderArgs, count);
4996    
4997                                    closeSession(session);
4998                            }
4999                    }
5000    
5001                    return count.intValue();
5002            }
5003    
5004            /**
5005             * Filters by the user's permissions and counts all the i g images where groupId = &#63; and folderId = &#63; and name = &#63;.
5006             *
5007             * @param groupId the group id to search with
5008             * @param folderId the folder id to search with
5009             * @param name the name to search with
5010             * @return the number of matching i g images that the user has permission to view
5011             * @throws SystemException if a system exception occurred
5012             */
5013            public int filterCountByG_F_N(long groupId, long folderId, String name)
5014                    throws SystemException {
5015                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5016                            return countByG_F_N(groupId, folderId, name);
5017                    }
5018    
5019                    Session session = null;
5020    
5021                    try {
5022                            session = openSession();
5023    
5024                            StringBundler query = new StringBundler(4);
5025    
5026                            query.append(_FILTER_SQL_COUNT_IGIMAGE_WHERE);
5027    
5028                            query.append(_FINDER_COLUMN_G_F_N_GROUPID_2);
5029    
5030                            query.append(_FINDER_COLUMN_G_F_N_FOLDERID_2);
5031    
5032                            if (name == null) {
5033                                    query.append(_FINDER_COLUMN_G_F_N_NAME_1);
5034                            }
5035                            else {
5036                                    if (name.equals(StringPool.BLANK)) {
5037                                            query.append(_FINDER_COLUMN_G_F_N_NAME_3);
5038                                    }
5039                                    else {
5040                                            query.append(_FINDER_COLUMN_G_F_N_NAME_2);
5041                                    }
5042                            }
5043    
5044                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5045                                            IGImage.class.getName(), _FILTER_COLUMN_PK,
5046                                            _FILTER_COLUMN_USERID, groupId);
5047    
5048                            SQLQuery q = session.createSQLQuery(sql);
5049    
5050                            q.addScalar(COUNT_COLUMN_NAME,
5051                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
5052    
5053                            QueryPos qPos = QueryPos.getInstance(q);
5054    
5055                            qPos.add(groupId);
5056    
5057                            qPos.add(folderId);
5058    
5059                            if (name != null) {
5060                                    qPos.add(name);
5061                            }
5062    
5063                            Long count = (Long)q.uniqueResult();
5064    
5065                            return count.intValue();
5066                    }
5067                    catch (Exception e) {
5068                            throw processException(e);
5069                    }
5070                    finally {
5071                            closeSession(session);
5072                    }
5073            }
5074    
5075            /**
5076             * Counts all the i g images.
5077             *
5078             * @return the number of i g images
5079             * @throws SystemException if a system exception occurred
5080             */
5081            public int countAll() throws SystemException {
5082                    Object[] finderArgs = new Object[0];
5083    
5084                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
5085                                    finderArgs, this);
5086    
5087                    if (count == null) {
5088                            Session session = null;
5089    
5090                            try {
5091                                    session = openSession();
5092    
5093                                    Query q = session.createQuery(_SQL_COUNT_IGIMAGE);
5094    
5095                                    count = (Long)q.uniqueResult();
5096                            }
5097                            catch (Exception e) {
5098                                    throw processException(e);
5099                            }
5100                            finally {
5101                                    if (count == null) {
5102                                            count = Long.valueOf(0);
5103                                    }
5104    
5105                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
5106                                            count);
5107    
5108                                    closeSession(session);
5109                            }
5110                    }
5111    
5112                    return count.intValue();
5113            }
5114    
5115            /**
5116             * Initializes the i g image persistence.
5117             */
5118            public void afterPropertiesSet() {
5119                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
5120                                            com.liferay.portal.util.PropsUtil.get(
5121                                                    "value.object.listener.com.liferay.portlet.imagegallery.model.IGImage")));
5122    
5123                    if (listenerClassNames.length > 0) {
5124                            try {
5125                                    List<ModelListener<IGImage>> listenersList = new ArrayList<ModelListener<IGImage>>();
5126    
5127                                    for (String listenerClassName : listenerClassNames) {
5128                                            listenersList.add((ModelListener<IGImage>)InstanceFactory.newInstance(
5129                                                            listenerClassName));
5130                                    }
5131    
5132                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
5133                            }
5134                            catch (Exception e) {
5135                                    _log.error(e);
5136                            }
5137                    }
5138            }
5139    
5140            @BeanReference(type = IGFolderPersistence.class)
5141            protected IGFolderPersistence igFolderPersistence;
5142            @BeanReference(type = IGImagePersistence.class)
5143            protected IGImagePersistence igImagePersistence;
5144            @BeanReference(type = ImagePersistence.class)
5145            protected ImagePersistence imagePersistence;
5146            @BeanReference(type = ResourcePersistence.class)
5147            protected ResourcePersistence resourcePersistence;
5148            @BeanReference(type = UserPersistence.class)
5149            protected UserPersistence userPersistence;
5150            @BeanReference(type = AssetCategoryPersistence.class)
5151            protected AssetCategoryPersistence assetCategoryPersistence;
5152            @BeanReference(type = AssetEntryPersistence.class)
5153            protected AssetEntryPersistence assetEntryPersistence;
5154            @BeanReference(type = AssetTagPersistence.class)
5155            protected AssetTagPersistence assetTagPersistence;
5156            @BeanReference(type = ExpandoValuePersistence.class)
5157            protected ExpandoValuePersistence expandoValuePersistence;
5158            @BeanReference(type = SocialActivityPersistence.class)
5159            protected SocialActivityPersistence socialActivityPersistence;
5160            private static final String _SQL_SELECT_IGIMAGE = "SELECT igImage FROM IGImage igImage";
5161            private static final String _SQL_SELECT_IGIMAGE_WHERE = "SELECT igImage FROM IGImage igImage WHERE ";
5162            private static final String _SQL_COUNT_IGIMAGE = "SELECT COUNT(igImage) FROM IGImage igImage";
5163            private static final String _SQL_COUNT_IGIMAGE_WHERE = "SELECT COUNT(igImage) FROM IGImage igImage WHERE ";
5164            private static final String _FINDER_COLUMN_UUID_UUID_1 = "igImage.uuid IS NULL";
5165            private static final String _FINDER_COLUMN_UUID_UUID_2 = "igImage.uuid = ?";
5166            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(igImage.uuid IS NULL OR igImage.uuid = ?)";
5167            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "igImage.uuid IS NULL AND ";
5168            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "igImage.uuid = ? AND ";
5169            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(igImage.uuid IS NULL OR igImage.uuid = ?) AND ";
5170            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "igImage.groupId = ?";
5171            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "igImage.groupId = ?";
5172            private static final String _FINDER_COLUMN_SMALLIMAGEID_SMALLIMAGEID_2 = "igImage.smallImageId = ?";
5173            private static final String _FINDER_COLUMN_LARGEIMAGEID_LARGEIMAGEID_2 = "igImage.largeImageId = ?";
5174            private static final String _FINDER_COLUMN_CUSTOM1IMAGEID_CUSTOM1IMAGEID_2 = "igImage.custom1ImageId = ?";
5175            private static final String _FINDER_COLUMN_CUSTOM2IMAGEID_CUSTOM2IMAGEID_2 = "igImage.custom2ImageId = ?";
5176            private static final String _FINDER_COLUMN_G_U_GROUPID_2 = "igImage.groupId = ? AND ";
5177            private static final String _FINDER_COLUMN_G_U_USERID_2 = "igImage.userId = ?";
5178            private static final String _FINDER_COLUMN_G_F_GROUPID_2 = "igImage.groupId = ? AND ";
5179            private static final String _FINDER_COLUMN_G_F_GROUPID_5 = "(" +
5180                    _removeConjunction(_FINDER_COLUMN_G_F_GROUPID_2) + ")";
5181            private static final String _FINDER_COLUMN_G_F_FOLDERID_2 = "igImage.folderId = ?";
5182            private static final String _FINDER_COLUMN_G_F_FOLDERID_5 = "(" +
5183                    _removeConjunction(_FINDER_COLUMN_G_F_FOLDERID_2) + ")";
5184            private static final String _FINDER_COLUMN_G_F_N_GROUPID_2 = "igImage.groupId = ? AND ";
5185            private static final String _FINDER_COLUMN_G_F_N_FOLDERID_2 = "igImage.folderId = ? AND ";
5186            private static final String _FINDER_COLUMN_G_F_N_NAME_1 = "igImage.name IS NULL";
5187            private static final String _FINDER_COLUMN_G_F_N_NAME_2 = "igImage.name = ?";
5188            private static final String _FINDER_COLUMN_G_F_N_NAME_3 = "(igImage.name IS NULL OR igImage.name = ?)";
5189    
5190            private static String _removeConjunction(String sql) {
5191                    int pos = sql.indexOf(" AND ");
5192    
5193                    if (pos != -1) {
5194                            sql = sql.substring(0, pos);
5195                    }
5196    
5197                    return sql;
5198            }
5199    
5200            private static final String _FILTER_SQL_SELECT_IGIMAGE_WHERE = "SELECT DISTINCT {igImage.*} FROM IGImage igImage WHERE ";
5201            private static final String _FILTER_SQL_COUNT_IGIMAGE_WHERE = "SELECT COUNT(DISTINCT igImage.imageId) AS COUNT_VALUE FROM IGImage igImage WHERE ";
5202            private static final String _FILTER_COLUMN_PK = "igImage.imageId";
5203            private static final String _FILTER_COLUMN_USERID = "igImage.userId";
5204            private static final String _FILTER_ENTITY_ALIAS = "igImage";
5205            private static final String _ORDER_BY_ENTITY_ALIAS = "igImage.";
5206            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No IGImage exists with the primary key ";
5207            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No IGImage exists with the key {";
5208            private static Log _log = LogFactoryUtil.getLog(IGImagePersistenceImpl.class);
5209    }