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