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