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