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