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