001    /**
002     * Copyright (c) 2000-2012 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.documentlibrary.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.kernel.bean.BeanReference;
019    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.jdbc.MappingSqlQuery;
021    import com.liferay.portal.kernel.dao.jdbc.MappingSqlQueryFactoryUtil;
022    import com.liferay.portal.kernel.dao.jdbc.RowMapper;
023    import com.liferay.portal.kernel.dao.jdbc.SqlUpdate;
024    import com.liferay.portal.kernel.dao.jdbc.SqlUpdateFactoryUtil;
025    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
026    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
027    import com.liferay.portal.kernel.dao.orm.FinderPath;
028    import com.liferay.portal.kernel.dao.orm.Query;
029    import com.liferay.portal.kernel.dao.orm.QueryPos;
030    import com.liferay.portal.kernel.dao.orm.QueryUtil;
031    import com.liferay.portal.kernel.dao.orm.SQLQuery;
032    import com.liferay.portal.kernel.dao.orm.Session;
033    import com.liferay.portal.kernel.exception.SystemException;
034    import com.liferay.portal.kernel.log.Log;
035    import com.liferay.portal.kernel.log.LogFactoryUtil;
036    import com.liferay.portal.kernel.util.GetterUtil;
037    import com.liferay.portal.kernel.util.InstanceFactory;
038    import com.liferay.portal.kernel.util.OrderByComparator;
039    import com.liferay.portal.kernel.util.SetUtil;
040    import com.liferay.portal.kernel.util.StringBundler;
041    import com.liferay.portal.kernel.util.StringPool;
042    import com.liferay.portal.kernel.util.StringUtil;
043    import com.liferay.portal.kernel.util.Validator;
044    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
045    import com.liferay.portal.model.CacheModel;
046    import com.liferay.portal.model.ModelListener;
047    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
048    import com.liferay.portal.service.persistence.BatchSessionUtil;
049    import com.liferay.portal.service.persistence.GroupPersistence;
050    import com.liferay.portal.service.persistence.LockPersistence;
051    import com.liferay.portal.service.persistence.ResourcePersistence;
052    import com.liferay.portal.service.persistence.UserPersistence;
053    import com.liferay.portal.service.persistence.WebDAVPropsPersistence;
054    import com.liferay.portal.service.persistence.WorkflowDefinitionLinkPersistence;
055    import com.liferay.portal.service.persistence.WorkflowInstanceLinkPersistence;
056    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
057    
058    import com.liferay.portlet.documentlibrary.NoSuchFolderException;
059    import com.liferay.portlet.documentlibrary.model.DLFolder;
060    import com.liferay.portlet.documentlibrary.model.impl.DLFolderImpl;
061    import com.liferay.portlet.documentlibrary.model.impl.DLFolderModelImpl;
062    import com.liferay.portlet.expando.service.persistence.ExpandoValuePersistence;
063    
064    import java.io.Serializable;
065    
066    import java.util.ArrayList;
067    import java.util.Collections;
068    import java.util.List;
069    import java.util.Set;
070    
071    /**
072     * The persistence implementation for the document library folder service.
073     *
074     * <p>
075     * Caching information and settings can be found in <code>portal.properties</code>
076     * </p>
077     *
078     * @author Brian Wing Shun Chan
079     * @see DLFolderPersistence
080     * @see DLFolderUtil
081     * @generated
082     */
083    public class DLFolderPersistenceImpl extends BasePersistenceImpl<DLFolder>
084            implements DLFolderPersistence {
085            /*
086             * NOTE FOR DEVELOPERS:
087             *
088             * Never modify or reference this class directly. Always use {@link DLFolderUtil} to access the document library folder persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
089             */
090            public static final String FINDER_CLASS_NAME_ENTITY = DLFolderImpl.class.getName();
091            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
092                    ".List1";
093            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
094                    ".List2";
095            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
096                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
097                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
098                            new String[] {
099                                    String.class.getName(),
100                                    
101                            "java.lang.Integer", "java.lang.Integer",
102                                    "com.liferay.portal.kernel.util.OrderByComparator"
103                            });
104            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
105                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
106                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
107                            new String[] { String.class.getName() },
108                            DLFolderModelImpl.UUID_COLUMN_BITMASK);
109            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
110                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
111                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
112                            new String[] { String.class.getName() });
113            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
114                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
115                            FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
116                            new String[] { String.class.getName(), Long.class.getName() },
117                            DLFolderModelImpl.UUID_COLUMN_BITMASK |
118                            DLFolderModelImpl.GROUPID_COLUMN_BITMASK);
119            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
120                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
121                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
122                            new String[] { String.class.getName(), Long.class.getName() });
123            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
124                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
125                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
126                            new String[] {
127                                    Long.class.getName(),
128                                    
129                            "java.lang.Integer", "java.lang.Integer",
130                                    "com.liferay.portal.kernel.util.OrderByComparator"
131                            });
132            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
133                    new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
134                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
135                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
136                            new String[] { Long.class.getName() },
137                            DLFolderModelImpl.GROUPID_COLUMN_BITMASK);
138            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
139                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
140                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
141                            new String[] { Long.class.getName() });
142            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
143                    new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
144                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
145                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
146                            new String[] {
147                                    Long.class.getName(),
148                                    
149                            "java.lang.Integer", "java.lang.Integer",
150                                    "com.liferay.portal.kernel.util.OrderByComparator"
151                            });
152            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
153                    new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
154                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
155                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
156                            new String[] { Long.class.getName() },
157                            DLFolderModelImpl.COMPANYID_COLUMN_BITMASK);
158            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
159                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
160                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
161                            new String[] { Long.class.getName() });
162            public static final FinderPath FINDER_PATH_FETCH_BY_REPOSITORYID = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
163                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
164                            FINDER_CLASS_NAME_ENTITY, "fetchByRepositoryId",
165                            new String[] { Long.class.getName() },
166                            DLFolderModelImpl.REPOSITORYID_COLUMN_BITMASK);
167            public static final FinderPath FINDER_PATH_COUNT_BY_REPOSITORYID = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
168                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
169                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByRepositoryId",
170                            new String[] { Long.class.getName() });
171            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
172                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
173                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_P",
174                            new String[] {
175                                    Long.class.getName(), Long.class.getName(),
176                                    
177                            "java.lang.Integer", "java.lang.Integer",
178                                    "com.liferay.portal.kernel.util.OrderByComparator"
179                            });
180            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
181                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
182                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_P",
183                            new String[] { Long.class.getName(), Long.class.getName() },
184                            DLFolderModelImpl.GROUPID_COLUMN_BITMASK |
185                            DLFolderModelImpl.PARENTFOLDERID_COLUMN_BITMASK);
186            public static final FinderPath FINDER_PATH_COUNT_BY_G_P = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
187                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
188                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P",
189                            new String[] { Long.class.getName(), Long.class.getName() });
190            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_P_N = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
191                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
192                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByP_N",
193                            new String[] {
194                                    Long.class.getName(), String.class.getName(),
195                                    
196                            "java.lang.Integer", "java.lang.Integer",
197                                    "com.liferay.portal.kernel.util.OrderByComparator"
198                            });
199            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_N = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
200                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
201                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByP_N",
202                            new String[] { Long.class.getName(), String.class.getName() },
203                            DLFolderModelImpl.PARENTFOLDERID_COLUMN_BITMASK |
204                            DLFolderModelImpl.NAME_COLUMN_BITMASK);
205            public static final FinderPath FINDER_PATH_COUNT_BY_P_N = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
206                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
207                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByP_N",
208                            new String[] { Long.class.getName(), String.class.getName() });
209            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_M = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
210                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
211                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_P_M",
212                            new String[] {
213                                    Long.class.getName(), Long.class.getName(),
214                                    Boolean.class.getName(),
215                                    
216                            "java.lang.Integer", "java.lang.Integer",
217                                    "com.liferay.portal.kernel.util.OrderByComparator"
218                            });
219            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_M = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
220                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
221                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_P_M",
222                            new String[] {
223                                    Long.class.getName(), Long.class.getName(),
224                                    Boolean.class.getName()
225                            },
226                            DLFolderModelImpl.GROUPID_COLUMN_BITMASK |
227                            DLFolderModelImpl.PARENTFOLDERID_COLUMN_BITMASK |
228                            DLFolderModelImpl.MOUNTPOINT_COLUMN_BITMASK);
229            public static final FinderPath FINDER_PATH_COUNT_BY_G_P_M = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
230                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
231                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P_M",
232                            new String[] {
233                                    Long.class.getName(), Long.class.getName(),
234                                    Boolean.class.getName()
235                            });
236            public static final FinderPath FINDER_PATH_FETCH_BY_G_P_N = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
237                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
238                            FINDER_CLASS_NAME_ENTITY, "fetchByG_P_N",
239                            new String[] {
240                                    Long.class.getName(), Long.class.getName(),
241                                    String.class.getName()
242                            },
243                            DLFolderModelImpl.GROUPID_COLUMN_BITMASK |
244                            DLFolderModelImpl.PARENTFOLDERID_COLUMN_BITMASK |
245                            DLFolderModelImpl.NAME_COLUMN_BITMASK);
246            public static final FinderPath FINDER_PATH_COUNT_BY_G_P_N = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
247                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
248                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P_N",
249                            new String[] {
250                                    Long.class.getName(), Long.class.getName(),
251                                    String.class.getName()
252                            });
253            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
254                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
255                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
256            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
257                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
258                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
259            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
260                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
261                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
262    
263            /**
264             * Caches the document library folder in the entity cache if it is enabled.
265             *
266             * @param dlFolder the document library folder
267             */
268            public void cacheResult(DLFolder dlFolder) {
269                    EntityCacheUtil.putResult(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
270                            DLFolderImpl.class, dlFolder.getPrimaryKey(), dlFolder);
271    
272                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
273                            new Object[] { dlFolder.getUuid(), Long.valueOf(
274                                            dlFolder.getGroupId()) }, dlFolder);
275    
276                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_REPOSITORYID,
277                            new Object[] { Long.valueOf(dlFolder.getRepositoryId()) }, dlFolder);
278    
279                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_N,
280                            new Object[] {
281                                    Long.valueOf(dlFolder.getGroupId()),
282                                    Long.valueOf(dlFolder.getParentFolderId()),
283                                    
284                            dlFolder.getName()
285                            }, dlFolder);
286    
287                    dlFolder.resetOriginalValues();
288            }
289    
290            /**
291             * Caches the document library folders in the entity cache if it is enabled.
292             *
293             * @param dlFolders the document library folders
294             */
295            public void cacheResult(List<DLFolder> dlFolders) {
296                    for (DLFolder dlFolder : dlFolders) {
297                            if (EntityCacheUtil.getResult(
298                                                    DLFolderModelImpl.ENTITY_CACHE_ENABLED,
299                                                    DLFolderImpl.class, dlFolder.getPrimaryKey()) == null) {
300                                    cacheResult(dlFolder);
301                            }
302                            else {
303                                    dlFolder.resetOriginalValues();
304                            }
305                    }
306            }
307    
308            /**
309             * Clears the cache for all document library folders.
310             *
311             * <p>
312             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
313             * </p>
314             */
315            @Override
316            public void clearCache() {
317                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
318                            CacheRegistryUtil.clear(DLFolderImpl.class.getName());
319                    }
320    
321                    EntityCacheUtil.clearCache(DLFolderImpl.class.getName());
322    
323                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
324                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
325                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
326            }
327    
328            /**
329             * Clears the cache for the document library folder.
330             *
331             * <p>
332             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
333             * </p>
334             */
335            @Override
336            public void clearCache(DLFolder dlFolder) {
337                    EntityCacheUtil.removeResult(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
338                            DLFolderImpl.class, dlFolder.getPrimaryKey());
339    
340                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
341                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
342    
343                    clearUniqueFindersCache(dlFolder);
344            }
345    
346            @Override
347            public void clearCache(List<DLFolder> dlFolders) {
348                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
349                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
350    
351                    for (DLFolder dlFolder : dlFolders) {
352                            EntityCacheUtil.removeResult(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
353                                    DLFolderImpl.class, dlFolder.getPrimaryKey());
354    
355                            clearUniqueFindersCache(dlFolder);
356                    }
357            }
358    
359            protected void clearUniqueFindersCache(DLFolder dlFolder) {
360                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
361                            new Object[] { dlFolder.getUuid(), Long.valueOf(
362                                            dlFolder.getGroupId()) });
363    
364                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_REPOSITORYID,
365                            new Object[] { Long.valueOf(dlFolder.getRepositoryId()) });
366    
367                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P_N,
368                            new Object[] {
369                                    Long.valueOf(dlFolder.getGroupId()),
370                                    Long.valueOf(dlFolder.getParentFolderId()),
371                                    
372                            dlFolder.getName()
373                            });
374            }
375    
376            /**
377             * Creates a new document library folder with the primary key. Does not add the document library folder to the database.
378             *
379             * @param folderId the primary key for the new document library folder
380             * @return the new document library folder
381             */
382            public DLFolder create(long folderId) {
383                    DLFolder dlFolder = new DLFolderImpl();
384    
385                    dlFolder.setNew(true);
386                    dlFolder.setPrimaryKey(folderId);
387    
388                    String uuid = PortalUUIDUtil.generate();
389    
390                    dlFolder.setUuid(uuid);
391    
392                    return dlFolder;
393            }
394    
395            /**
396             * Removes the document library folder with the primary key from the database. Also notifies the appropriate model listeners.
397             *
398             * @param folderId the primary key of the document library folder
399             * @return the document library folder that was removed
400             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
401             * @throws SystemException if a system exception occurred
402             */
403            public DLFolder remove(long folderId)
404                    throws NoSuchFolderException, SystemException {
405                    return remove(Long.valueOf(folderId));
406            }
407    
408            /**
409             * Removes the document library folder with the primary key from the database. Also notifies the appropriate model listeners.
410             *
411             * @param primaryKey the primary key of the document library folder
412             * @return the document library folder that was removed
413             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
414             * @throws SystemException if a system exception occurred
415             */
416            @Override
417            public DLFolder remove(Serializable primaryKey)
418                    throws NoSuchFolderException, SystemException {
419                    Session session = null;
420    
421                    try {
422                            session = openSession();
423    
424                            DLFolder dlFolder = (DLFolder)session.get(DLFolderImpl.class,
425                                            primaryKey);
426    
427                            if (dlFolder == null) {
428                                    if (_log.isWarnEnabled()) {
429                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
430                                    }
431    
432                                    throw new NoSuchFolderException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
433                                            primaryKey);
434                            }
435    
436                            return remove(dlFolder);
437                    }
438                    catch (NoSuchFolderException nsee) {
439                            throw nsee;
440                    }
441                    catch (Exception e) {
442                            throw processException(e);
443                    }
444                    finally {
445                            closeSession(session);
446                    }
447            }
448    
449            @Override
450            protected DLFolder removeImpl(DLFolder dlFolder) throws SystemException {
451                    dlFolder = toUnwrappedModel(dlFolder);
452    
453                    try {
454                            clearDLFileEntryTypes.clear(dlFolder.getPrimaryKey());
455                    }
456                    catch (Exception e) {
457                            throw processException(e);
458                    }
459                    finally {
460                            FinderCacheUtil.clearCache(DLFolderModelImpl.MAPPING_TABLE_DLFILEENTRYTYPES_DLFOLDERS_NAME);
461                    }
462    
463                    Session session = null;
464    
465                    try {
466                            session = openSession();
467    
468                            BatchSessionUtil.delete(session, dlFolder);
469                    }
470                    catch (Exception e) {
471                            throw processException(e);
472                    }
473                    finally {
474                            closeSession(session);
475                    }
476    
477                    clearCache(dlFolder);
478    
479                    return dlFolder;
480            }
481    
482            @Override
483            public DLFolder updateImpl(
484                    com.liferay.portlet.documentlibrary.model.DLFolder dlFolder,
485                    boolean merge) throws SystemException {
486                    dlFolder = toUnwrappedModel(dlFolder);
487    
488                    boolean isNew = dlFolder.isNew();
489    
490                    DLFolderModelImpl dlFolderModelImpl = (DLFolderModelImpl)dlFolder;
491    
492                    if (Validator.isNull(dlFolder.getUuid())) {
493                            String uuid = PortalUUIDUtil.generate();
494    
495                            dlFolder.setUuid(uuid);
496                    }
497    
498                    Session session = null;
499    
500                    try {
501                            session = openSession();
502    
503                            BatchSessionUtil.update(session, dlFolder, merge);
504    
505                            dlFolder.setNew(false);
506                    }
507                    catch (Exception e) {
508                            throw processException(e);
509                    }
510                    finally {
511                            closeSession(session);
512                    }
513    
514                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
515    
516                    if (isNew || !DLFolderModelImpl.COLUMN_BITMASK_ENABLED) {
517                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
518                    }
519    
520                    else {
521                            if ((dlFolderModelImpl.getColumnBitmask() &
522                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
523                                    Object[] args = new Object[] { dlFolderModelImpl.getOriginalUuid() };
524    
525                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
526                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
527                                            args);
528    
529                                    args = new Object[] { dlFolderModelImpl.getUuid() };
530    
531                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
532                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
533                                            args);
534                            }
535    
536                            if ((dlFolderModelImpl.getColumnBitmask() &
537                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
538                                    Object[] args = new Object[] {
539                                                    Long.valueOf(dlFolderModelImpl.getOriginalGroupId())
540                                            };
541    
542                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
543                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
544                                            args);
545    
546                                    args = new Object[] { Long.valueOf(dlFolderModelImpl.getGroupId()) };
547    
548                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
549                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
550                                            args);
551                            }
552    
553                            if ((dlFolderModelImpl.getColumnBitmask() &
554                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
555                                    Object[] args = new Object[] {
556                                                    Long.valueOf(dlFolderModelImpl.getOriginalCompanyId())
557                                            };
558    
559                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
560                                            args);
561                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
562                                            args);
563    
564                                    args = new Object[] {
565                                                    Long.valueOf(dlFolderModelImpl.getCompanyId())
566                                            };
567    
568                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
569                                            args);
570                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
571                                            args);
572                            }
573    
574                            if ((dlFolderModelImpl.getColumnBitmask() &
575                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P.getColumnBitmask()) != 0) {
576                                    Object[] args = new Object[] {
577                                                    Long.valueOf(dlFolderModelImpl.getOriginalGroupId()),
578                                                    Long.valueOf(dlFolderModelImpl.getOriginalParentFolderId())
579                                            };
580    
581                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P, args);
582                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P,
583                                            args);
584    
585                                    args = new Object[] {
586                                                    Long.valueOf(dlFolderModelImpl.getGroupId()),
587                                                    Long.valueOf(dlFolderModelImpl.getParentFolderId())
588                                            };
589    
590                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P, args);
591                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P,
592                                            args);
593                            }
594    
595                            if ((dlFolderModelImpl.getColumnBitmask() &
596                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_N.getColumnBitmask()) != 0) {
597                                    Object[] args = new Object[] {
598                                                    Long.valueOf(dlFolderModelImpl.getOriginalParentFolderId()),
599                                                    
600                                                    dlFolderModelImpl.getOriginalName()
601                                            };
602    
603                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_P_N, args);
604                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_N,
605                                            args);
606    
607                                    args = new Object[] {
608                                                    Long.valueOf(dlFolderModelImpl.getParentFolderId()),
609                                                    
610                                                    dlFolderModelImpl.getName()
611                                            };
612    
613                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_P_N, args);
614                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_N,
615                                            args);
616                            }
617    
618                            if ((dlFolderModelImpl.getColumnBitmask() &
619                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_M.getColumnBitmask()) != 0) {
620                                    Object[] args = new Object[] {
621                                                    Long.valueOf(dlFolderModelImpl.getOriginalGroupId()),
622                                                    Long.valueOf(dlFolderModelImpl.getOriginalParentFolderId()),
623                                                    Boolean.valueOf(dlFolderModelImpl.getOriginalMountPoint())
624                                            };
625    
626                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_M, args);
627                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_M,
628                                            args);
629    
630                                    args = new Object[] {
631                                                    Long.valueOf(dlFolderModelImpl.getGroupId()),
632                                                    Long.valueOf(dlFolderModelImpl.getParentFolderId()),
633                                                    Boolean.valueOf(dlFolderModelImpl.getMountPoint())
634                                            };
635    
636                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_M, args);
637                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_M,
638                                            args);
639                            }
640                    }
641    
642                    EntityCacheUtil.putResult(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
643                            DLFolderImpl.class, dlFolder.getPrimaryKey(), dlFolder);
644    
645                    if (isNew) {
646                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
647                                    new Object[] {
648                                            dlFolder.getUuid(), Long.valueOf(dlFolder.getGroupId())
649                                    }, dlFolder);
650    
651                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_REPOSITORYID,
652                                    new Object[] { Long.valueOf(dlFolder.getRepositoryId()) },
653                                    dlFolder);
654    
655                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_N,
656                                    new Object[] {
657                                            Long.valueOf(dlFolder.getGroupId()),
658                                            Long.valueOf(dlFolder.getParentFolderId()),
659                                            
660                                    dlFolder.getName()
661                                    }, dlFolder);
662                    }
663                    else {
664                            if ((dlFolderModelImpl.getColumnBitmask() &
665                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
666                                    Object[] args = new Object[] {
667                                                    dlFolderModelImpl.getOriginalUuid(),
668                                                    Long.valueOf(dlFolderModelImpl.getOriginalGroupId())
669                                            };
670    
671                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
672    
673                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
674    
675                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
676                                            new Object[] {
677                                                    dlFolder.getUuid(), Long.valueOf(dlFolder.getGroupId())
678                                            }, dlFolder);
679                            }
680    
681                            if ((dlFolderModelImpl.getColumnBitmask() &
682                                            FINDER_PATH_FETCH_BY_REPOSITORYID.getColumnBitmask()) != 0) {
683                                    Object[] args = new Object[] {
684                                                    Long.valueOf(dlFolderModelImpl.getOriginalRepositoryId())
685                                            };
686    
687                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_REPOSITORYID,
688                                            args);
689    
690                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_REPOSITORYID,
691                                            args);
692    
693                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_REPOSITORYID,
694                                            new Object[] { Long.valueOf(dlFolder.getRepositoryId()) },
695                                            dlFolder);
696                            }
697    
698                            if ((dlFolderModelImpl.getColumnBitmask() &
699                                            FINDER_PATH_FETCH_BY_G_P_N.getColumnBitmask()) != 0) {
700                                    Object[] args = new Object[] {
701                                                    Long.valueOf(dlFolderModelImpl.getOriginalGroupId()),
702                                                    Long.valueOf(dlFolderModelImpl.getOriginalParentFolderId()),
703                                                    
704                                                    dlFolderModelImpl.getOriginalName()
705                                            };
706    
707                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_N, args);
708    
709                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P_N, args);
710    
711                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_N,
712                                            new Object[] {
713                                                    Long.valueOf(dlFolder.getGroupId()),
714                                                    Long.valueOf(dlFolder.getParentFolderId()),
715                                                    
716                                            dlFolder.getName()
717                                            }, dlFolder);
718                            }
719                    }
720    
721                    return dlFolder;
722            }
723    
724            protected DLFolder toUnwrappedModel(DLFolder dlFolder) {
725                    if (dlFolder instanceof DLFolderImpl) {
726                            return dlFolder;
727                    }
728    
729                    DLFolderImpl dlFolderImpl = new DLFolderImpl();
730    
731                    dlFolderImpl.setNew(dlFolder.isNew());
732                    dlFolderImpl.setPrimaryKey(dlFolder.getPrimaryKey());
733    
734                    dlFolderImpl.setUuid(dlFolder.getUuid());
735                    dlFolderImpl.setFolderId(dlFolder.getFolderId());
736                    dlFolderImpl.setGroupId(dlFolder.getGroupId());
737                    dlFolderImpl.setCompanyId(dlFolder.getCompanyId());
738                    dlFolderImpl.setUserId(dlFolder.getUserId());
739                    dlFolderImpl.setUserName(dlFolder.getUserName());
740                    dlFolderImpl.setCreateDate(dlFolder.getCreateDate());
741                    dlFolderImpl.setModifiedDate(dlFolder.getModifiedDate());
742                    dlFolderImpl.setRepositoryId(dlFolder.getRepositoryId());
743                    dlFolderImpl.setMountPoint(dlFolder.isMountPoint());
744                    dlFolderImpl.setParentFolderId(dlFolder.getParentFolderId());
745                    dlFolderImpl.setName(dlFolder.getName());
746                    dlFolderImpl.setDescription(dlFolder.getDescription());
747                    dlFolderImpl.setLastPostDate(dlFolder.getLastPostDate());
748                    dlFolderImpl.setDefaultFileEntryTypeId(dlFolder.getDefaultFileEntryTypeId());
749                    dlFolderImpl.setOverrideFileEntryTypes(dlFolder.isOverrideFileEntryTypes());
750    
751                    return dlFolderImpl;
752            }
753    
754            /**
755             * Returns the document library folder with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
756             *
757             * @param primaryKey the primary key of the document library folder
758             * @return the document library folder
759             * @throws com.liferay.portal.NoSuchModelException if a document library folder with the primary key could not be found
760             * @throws SystemException if a system exception occurred
761             */
762            @Override
763            public DLFolder findByPrimaryKey(Serializable primaryKey)
764                    throws NoSuchModelException, SystemException {
765                    return findByPrimaryKey(((Long)primaryKey).longValue());
766            }
767    
768            /**
769             * Returns the document library folder with the primary key or throws a {@link com.liferay.portlet.documentlibrary.NoSuchFolderException} if it could not be found.
770             *
771             * @param folderId the primary key of the document library folder
772             * @return the document library folder
773             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
774             * @throws SystemException if a system exception occurred
775             */
776            public DLFolder findByPrimaryKey(long folderId)
777                    throws NoSuchFolderException, SystemException {
778                    DLFolder dlFolder = fetchByPrimaryKey(folderId);
779    
780                    if (dlFolder == null) {
781                            if (_log.isWarnEnabled()) {
782                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + folderId);
783                            }
784    
785                            throw new NoSuchFolderException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
786                                    folderId);
787                    }
788    
789                    return dlFolder;
790            }
791    
792            /**
793             * Returns the document library folder with the primary key or returns <code>null</code> if it could not be found.
794             *
795             * @param primaryKey the primary key of the document library folder
796             * @return the document library folder, or <code>null</code> if a document library folder with the primary key could not be found
797             * @throws SystemException if a system exception occurred
798             */
799            @Override
800            public DLFolder fetchByPrimaryKey(Serializable primaryKey)
801                    throws SystemException {
802                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
803            }
804    
805            /**
806             * Returns the document library folder with the primary key or returns <code>null</code> if it could not be found.
807             *
808             * @param folderId the primary key of the document library folder
809             * @return the document library folder, or <code>null</code> if a document library folder with the primary key could not be found
810             * @throws SystemException if a system exception occurred
811             */
812            public DLFolder fetchByPrimaryKey(long folderId) throws SystemException {
813                    DLFolder dlFolder = (DLFolder)EntityCacheUtil.getResult(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
814                                    DLFolderImpl.class, folderId);
815    
816                    if (dlFolder == _nullDLFolder) {
817                            return null;
818                    }
819    
820                    if (dlFolder == null) {
821                            Session session = null;
822    
823                            boolean hasException = false;
824    
825                            try {
826                                    session = openSession();
827    
828                                    dlFolder = (DLFolder)session.get(DLFolderImpl.class,
829                                                    Long.valueOf(folderId));
830                            }
831                            catch (Exception e) {
832                                    hasException = true;
833    
834                                    throw processException(e);
835                            }
836                            finally {
837                                    if (dlFolder != null) {
838                                            cacheResult(dlFolder);
839                                    }
840                                    else if (!hasException) {
841                                            EntityCacheUtil.putResult(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
842                                                    DLFolderImpl.class, folderId, _nullDLFolder);
843                                    }
844    
845                                    closeSession(session);
846                            }
847                    }
848    
849                    return dlFolder;
850            }
851    
852            /**
853             * Returns all the document library folders where uuid = &#63;.
854             *
855             * @param uuid the uuid
856             * @return the matching document library folders
857             * @throws SystemException if a system exception occurred
858             */
859            public List<DLFolder> findByUuid(String uuid) throws SystemException {
860                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
861            }
862    
863            /**
864             * Returns a range of all the document library folders where uuid = &#63;.
865             *
866             * <p>
867             * 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.
868             * </p>
869             *
870             * @param uuid the uuid
871             * @param start the lower bound of the range of document library folders
872             * @param end the upper bound of the range of document library folders (not inclusive)
873             * @return the range of matching document library folders
874             * @throws SystemException if a system exception occurred
875             */
876            public List<DLFolder> findByUuid(String uuid, int start, int end)
877                    throws SystemException {
878                    return findByUuid(uuid, start, end, null);
879            }
880    
881            /**
882             * Returns an ordered range of all the document library folders where uuid = &#63;.
883             *
884             * <p>
885             * 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.
886             * </p>
887             *
888             * @param uuid the uuid
889             * @param start the lower bound of the range of document library folders
890             * @param end the upper bound of the range of document library folders (not inclusive)
891             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
892             * @return the ordered range of matching document library folders
893             * @throws SystemException if a system exception occurred
894             */
895            public List<DLFolder> findByUuid(String uuid, int start, int end,
896                    OrderByComparator orderByComparator) throws SystemException {
897                    FinderPath finderPath = null;
898                    Object[] finderArgs = null;
899    
900                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
901                                    (orderByComparator == null)) {
902                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
903                            finderArgs = new Object[] { uuid };
904                    }
905                    else {
906                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
907                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
908                    }
909    
910                    List<DLFolder> list = (List<DLFolder>)FinderCacheUtil.getResult(finderPath,
911                                    finderArgs, this);
912    
913                    if ((list != null) && !list.isEmpty()) {
914                            for (DLFolder dlFolder : list) {
915                                    if (!Validator.equals(uuid, dlFolder.getUuid())) {
916                                            list = null;
917    
918                                            break;
919                                    }
920                            }
921                    }
922    
923                    if (list == null) {
924                            StringBundler query = null;
925    
926                            if (orderByComparator != null) {
927                                    query = new StringBundler(3 +
928                                                    (orderByComparator.getOrderByFields().length * 3));
929                            }
930                            else {
931                                    query = new StringBundler(3);
932                            }
933    
934                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
935    
936                            if (uuid == null) {
937                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
938                            }
939                            else {
940                                    if (uuid.equals(StringPool.BLANK)) {
941                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
942                                    }
943                                    else {
944                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
945                                    }
946                            }
947    
948                            if (orderByComparator != null) {
949                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
950                                            orderByComparator);
951                            }
952    
953                            else {
954                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
955                            }
956    
957                            String sql = query.toString();
958    
959                            Session session = null;
960    
961                            try {
962                                    session = openSession();
963    
964                                    Query q = session.createQuery(sql);
965    
966                                    QueryPos qPos = QueryPos.getInstance(q);
967    
968                                    if (uuid != null) {
969                                            qPos.add(uuid);
970                                    }
971    
972                                    list = (List<DLFolder>)QueryUtil.list(q, getDialect(), start,
973                                                    end);
974                            }
975                            catch (Exception e) {
976                                    throw processException(e);
977                            }
978                            finally {
979                                    if (list == null) {
980                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
981                                    }
982                                    else {
983                                            cacheResult(list);
984    
985                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
986                                    }
987    
988                                    closeSession(session);
989                            }
990                    }
991    
992                    return list;
993            }
994    
995            /**
996             * Returns the first document library folder in the ordered set where uuid = &#63;.
997             *
998             * @param uuid the uuid
999             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1000             * @return the first matching document library folder
1001             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
1002             * @throws SystemException if a system exception occurred
1003             */
1004            public DLFolder findByUuid_First(String uuid,
1005                    OrderByComparator orderByComparator)
1006                    throws NoSuchFolderException, SystemException {
1007                    DLFolder dlFolder = fetchByUuid_First(uuid, orderByComparator);
1008    
1009                    if (dlFolder != null) {
1010                            return dlFolder;
1011                    }
1012    
1013                    StringBundler msg = new StringBundler(4);
1014    
1015                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1016    
1017                    msg.append("uuid=");
1018                    msg.append(uuid);
1019    
1020                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1021    
1022                    throw new NoSuchFolderException(msg.toString());
1023            }
1024    
1025            /**
1026             * Returns the first document library folder in the ordered set where uuid = &#63;.
1027             *
1028             * @param uuid the uuid
1029             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1030             * @return the first matching document library folder, or <code>null</code> if a matching document library folder could not be found
1031             * @throws SystemException if a system exception occurred
1032             */
1033            public DLFolder fetchByUuid_First(String uuid,
1034                    OrderByComparator orderByComparator) throws SystemException {
1035                    List<DLFolder> list = findByUuid(uuid, 0, 1, orderByComparator);
1036    
1037                    if (!list.isEmpty()) {
1038                            return list.get(0);
1039                    }
1040    
1041                    return null;
1042            }
1043    
1044            /**
1045             * Returns the last document library folder in the ordered set where uuid = &#63;.
1046             *
1047             * @param uuid the uuid
1048             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1049             * @return the last matching document library folder
1050             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
1051             * @throws SystemException if a system exception occurred
1052             */
1053            public DLFolder findByUuid_Last(String uuid,
1054                    OrderByComparator orderByComparator)
1055                    throws NoSuchFolderException, SystemException {
1056                    DLFolder dlFolder = fetchByUuid_Last(uuid, orderByComparator);
1057    
1058                    if (dlFolder != null) {
1059                            return dlFolder;
1060                    }
1061    
1062                    StringBundler msg = new StringBundler(4);
1063    
1064                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1065    
1066                    msg.append("uuid=");
1067                    msg.append(uuid);
1068    
1069                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1070    
1071                    throw new NoSuchFolderException(msg.toString());
1072            }
1073    
1074            /**
1075             * Returns the last document library folder in the ordered set where uuid = &#63;.
1076             *
1077             * @param uuid the uuid
1078             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1079             * @return the last matching document library folder, or <code>null</code> if a matching document library folder could not be found
1080             * @throws SystemException if a system exception occurred
1081             */
1082            public DLFolder fetchByUuid_Last(String uuid,
1083                    OrderByComparator orderByComparator) throws SystemException {
1084                    int count = countByUuid(uuid);
1085    
1086                    List<DLFolder> list = findByUuid(uuid, count - 1, count,
1087                                    orderByComparator);
1088    
1089                    if (!list.isEmpty()) {
1090                            return list.get(0);
1091                    }
1092    
1093                    return null;
1094            }
1095    
1096            /**
1097             * Returns the document library folders before and after the current document library folder in the ordered set where uuid = &#63;.
1098             *
1099             * @param folderId the primary key of the current document library folder
1100             * @param uuid the uuid
1101             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1102             * @return the previous, current, and next document library folder
1103             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
1104             * @throws SystemException if a system exception occurred
1105             */
1106            public DLFolder[] findByUuid_PrevAndNext(long folderId, String uuid,
1107                    OrderByComparator orderByComparator)
1108                    throws NoSuchFolderException, SystemException {
1109                    DLFolder dlFolder = findByPrimaryKey(folderId);
1110    
1111                    Session session = null;
1112    
1113                    try {
1114                            session = openSession();
1115    
1116                            DLFolder[] array = new DLFolderImpl[3];
1117    
1118                            array[0] = getByUuid_PrevAndNext(session, dlFolder, uuid,
1119                                            orderByComparator, true);
1120    
1121                            array[1] = dlFolder;
1122    
1123                            array[2] = getByUuid_PrevAndNext(session, dlFolder, uuid,
1124                                            orderByComparator, false);
1125    
1126                            return array;
1127                    }
1128                    catch (Exception e) {
1129                            throw processException(e);
1130                    }
1131                    finally {
1132                            closeSession(session);
1133                    }
1134            }
1135    
1136            protected DLFolder getByUuid_PrevAndNext(Session session,
1137                    DLFolder dlFolder, String uuid, OrderByComparator orderByComparator,
1138                    boolean previous) {
1139                    StringBundler query = null;
1140    
1141                    if (orderByComparator != null) {
1142                            query = new StringBundler(6 +
1143                                            (orderByComparator.getOrderByFields().length * 6));
1144                    }
1145                    else {
1146                            query = new StringBundler(3);
1147                    }
1148    
1149                    query.append(_SQL_SELECT_DLFOLDER_WHERE);
1150    
1151                    if (uuid == null) {
1152                            query.append(_FINDER_COLUMN_UUID_UUID_1);
1153                    }
1154                    else {
1155                            if (uuid.equals(StringPool.BLANK)) {
1156                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
1157                            }
1158                            else {
1159                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
1160                            }
1161                    }
1162    
1163                    if (orderByComparator != null) {
1164                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1165    
1166                            if (orderByConditionFields.length > 0) {
1167                                    query.append(WHERE_AND);
1168                            }
1169    
1170                            for (int i = 0; i < orderByConditionFields.length; i++) {
1171                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1172                                    query.append(orderByConditionFields[i]);
1173    
1174                                    if ((i + 1) < orderByConditionFields.length) {
1175                                            if (orderByComparator.isAscending() ^ previous) {
1176                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1177                                            }
1178                                            else {
1179                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1180                                            }
1181                                    }
1182                                    else {
1183                                            if (orderByComparator.isAscending() ^ previous) {
1184                                                    query.append(WHERE_GREATER_THAN);
1185                                            }
1186                                            else {
1187                                                    query.append(WHERE_LESSER_THAN);
1188                                            }
1189                                    }
1190                            }
1191    
1192                            query.append(ORDER_BY_CLAUSE);
1193    
1194                            String[] orderByFields = orderByComparator.getOrderByFields();
1195    
1196                            for (int i = 0; i < orderByFields.length; i++) {
1197                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1198                                    query.append(orderByFields[i]);
1199    
1200                                    if ((i + 1) < orderByFields.length) {
1201                                            if (orderByComparator.isAscending() ^ previous) {
1202                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1203                                            }
1204                                            else {
1205                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1206                                            }
1207                                    }
1208                                    else {
1209                                            if (orderByComparator.isAscending() ^ previous) {
1210                                                    query.append(ORDER_BY_ASC);
1211                                            }
1212                                            else {
1213                                                    query.append(ORDER_BY_DESC);
1214                                            }
1215                                    }
1216                            }
1217                    }
1218    
1219                    else {
1220                            query.append(DLFolderModelImpl.ORDER_BY_JPQL);
1221                    }
1222    
1223                    String sql = query.toString();
1224    
1225                    Query q = session.createQuery(sql);
1226    
1227                    q.setFirstResult(0);
1228                    q.setMaxResults(2);
1229    
1230                    QueryPos qPos = QueryPos.getInstance(q);
1231    
1232                    if (uuid != null) {
1233                            qPos.add(uuid);
1234                    }
1235    
1236                    if (orderByComparator != null) {
1237                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
1238    
1239                            for (Object value : values) {
1240                                    qPos.add(value);
1241                            }
1242                    }
1243    
1244                    List<DLFolder> list = q.list();
1245    
1246                    if (list.size() == 2) {
1247                            return list.get(1);
1248                    }
1249                    else {
1250                            return null;
1251                    }
1252            }
1253    
1254            /**
1255             * Returns the document library folder where uuid = &#63; and groupId = &#63; or throws a {@link com.liferay.portlet.documentlibrary.NoSuchFolderException} if it could not be found.
1256             *
1257             * @param uuid the uuid
1258             * @param groupId the group ID
1259             * @return the matching document library folder
1260             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
1261             * @throws SystemException if a system exception occurred
1262             */
1263            public DLFolder findByUUID_G(String uuid, long groupId)
1264                    throws NoSuchFolderException, SystemException {
1265                    DLFolder dlFolder = fetchByUUID_G(uuid, groupId);
1266    
1267                    if (dlFolder == null) {
1268                            StringBundler msg = new StringBundler(6);
1269    
1270                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1271    
1272                            msg.append("uuid=");
1273                            msg.append(uuid);
1274    
1275                            msg.append(", groupId=");
1276                            msg.append(groupId);
1277    
1278                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1279    
1280                            if (_log.isWarnEnabled()) {
1281                                    _log.warn(msg.toString());
1282                            }
1283    
1284                            throw new NoSuchFolderException(msg.toString());
1285                    }
1286    
1287                    return dlFolder;
1288            }
1289    
1290            /**
1291             * Returns the document library folder where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
1292             *
1293             * @param uuid the uuid
1294             * @param groupId the group ID
1295             * @return the matching document library folder, or <code>null</code> if a matching document library folder could not be found
1296             * @throws SystemException if a system exception occurred
1297             */
1298            public DLFolder fetchByUUID_G(String uuid, long groupId)
1299                    throws SystemException {
1300                    return fetchByUUID_G(uuid, groupId, true);
1301            }
1302    
1303            /**
1304             * Returns the document library folder where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
1305             *
1306             * @param uuid the uuid
1307             * @param groupId the group ID
1308             * @param retrieveFromCache whether to use the finder cache
1309             * @return the matching document library folder, or <code>null</code> if a matching document library folder could not be found
1310             * @throws SystemException if a system exception occurred
1311             */
1312            public DLFolder fetchByUUID_G(String uuid, long groupId,
1313                    boolean retrieveFromCache) throws SystemException {
1314                    Object[] finderArgs = new Object[] { uuid, groupId };
1315    
1316                    Object result = null;
1317    
1318                    if (retrieveFromCache) {
1319                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
1320                                            finderArgs, this);
1321                    }
1322    
1323                    if (result instanceof DLFolder) {
1324                            DLFolder dlFolder = (DLFolder)result;
1325    
1326                            if (!Validator.equals(uuid, dlFolder.getUuid()) ||
1327                                            (groupId != dlFolder.getGroupId())) {
1328                                    result = null;
1329                            }
1330                    }
1331    
1332                    if (result == null) {
1333                            StringBundler query = new StringBundler(4);
1334    
1335                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
1336    
1337                            if (uuid == null) {
1338                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
1339                            }
1340                            else {
1341                                    if (uuid.equals(StringPool.BLANK)) {
1342                                            query.append(_FINDER_COLUMN_UUID_G_UUID_3);
1343                                    }
1344                                    else {
1345                                            query.append(_FINDER_COLUMN_UUID_G_UUID_2);
1346                                    }
1347                            }
1348    
1349                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
1350    
1351                            query.append(DLFolderModelImpl.ORDER_BY_JPQL);
1352    
1353                            String sql = query.toString();
1354    
1355                            Session session = null;
1356    
1357                            try {
1358                                    session = openSession();
1359    
1360                                    Query q = session.createQuery(sql);
1361    
1362                                    QueryPos qPos = QueryPos.getInstance(q);
1363    
1364                                    if (uuid != null) {
1365                                            qPos.add(uuid);
1366                                    }
1367    
1368                                    qPos.add(groupId);
1369    
1370                                    List<DLFolder> list = q.list();
1371    
1372                                    result = list;
1373    
1374                                    DLFolder dlFolder = null;
1375    
1376                                    if (list.isEmpty()) {
1377                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1378                                                    finderArgs, list);
1379                                    }
1380                                    else {
1381                                            dlFolder = list.get(0);
1382    
1383                                            cacheResult(dlFolder);
1384    
1385                                            if ((dlFolder.getUuid() == null) ||
1386                                                            !dlFolder.getUuid().equals(uuid) ||
1387                                                            (dlFolder.getGroupId() != groupId)) {
1388                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1389                                                            finderArgs, dlFolder);
1390                                            }
1391                                    }
1392    
1393                                    return dlFolder;
1394                            }
1395                            catch (Exception e) {
1396                                    throw processException(e);
1397                            }
1398                            finally {
1399                                    if (result == null) {
1400                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
1401                                                    finderArgs);
1402                                    }
1403    
1404                                    closeSession(session);
1405                            }
1406                    }
1407                    else {
1408                            if (result instanceof List<?>) {
1409                                    return null;
1410                            }
1411                            else {
1412                                    return (DLFolder)result;
1413                            }
1414                    }
1415            }
1416    
1417            /**
1418             * Returns all the document library folders where groupId = &#63;.
1419             *
1420             * @param groupId the group ID
1421             * @return the matching document library folders
1422             * @throws SystemException if a system exception occurred
1423             */
1424            public List<DLFolder> findByGroupId(long groupId) throws SystemException {
1425                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1426            }
1427    
1428            /**
1429             * Returns a range of all the document library folders where groupId = &#63;.
1430             *
1431             * <p>
1432             * 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.
1433             * </p>
1434             *
1435             * @param groupId the group ID
1436             * @param start the lower bound of the range of document library folders
1437             * @param end the upper bound of the range of document library folders (not inclusive)
1438             * @return the range of matching document library folders
1439             * @throws SystemException if a system exception occurred
1440             */
1441            public List<DLFolder> findByGroupId(long groupId, int start, int end)
1442                    throws SystemException {
1443                    return findByGroupId(groupId, start, end, null);
1444            }
1445    
1446            /**
1447             * Returns an ordered range of all the document library folders where groupId = &#63;.
1448             *
1449             * <p>
1450             * 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.
1451             * </p>
1452             *
1453             * @param groupId the group ID
1454             * @param start the lower bound of the range of document library folders
1455             * @param end the upper bound of the range of document library folders (not inclusive)
1456             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1457             * @return the ordered range of matching document library folders
1458             * @throws SystemException if a system exception occurred
1459             */
1460            public List<DLFolder> findByGroupId(long groupId, int start, int end,
1461                    OrderByComparator orderByComparator) throws SystemException {
1462                    FinderPath finderPath = null;
1463                    Object[] finderArgs = null;
1464    
1465                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1466                                    (orderByComparator == null)) {
1467                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1468                            finderArgs = new Object[] { groupId };
1469                    }
1470                    else {
1471                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1472                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
1473                    }
1474    
1475                    List<DLFolder> list = (List<DLFolder>)FinderCacheUtil.getResult(finderPath,
1476                                    finderArgs, this);
1477    
1478                    if ((list != null) && !list.isEmpty()) {
1479                            for (DLFolder dlFolder : list) {
1480                                    if ((groupId != dlFolder.getGroupId())) {
1481                                            list = null;
1482    
1483                                            break;
1484                                    }
1485                            }
1486                    }
1487    
1488                    if (list == null) {
1489                            StringBundler query = null;
1490    
1491                            if (orderByComparator != null) {
1492                                    query = new StringBundler(3 +
1493                                                    (orderByComparator.getOrderByFields().length * 3));
1494                            }
1495                            else {
1496                                    query = new StringBundler(3);
1497                            }
1498    
1499                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
1500    
1501                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1502    
1503                            if (orderByComparator != null) {
1504                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1505                                            orderByComparator);
1506                            }
1507    
1508                            else {
1509                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
1510                            }
1511    
1512                            String sql = query.toString();
1513    
1514                            Session session = null;
1515    
1516                            try {
1517                                    session = openSession();
1518    
1519                                    Query q = session.createQuery(sql);
1520    
1521                                    QueryPos qPos = QueryPos.getInstance(q);
1522    
1523                                    qPos.add(groupId);
1524    
1525                                    list = (List<DLFolder>)QueryUtil.list(q, getDialect(), start,
1526                                                    end);
1527                            }
1528                            catch (Exception e) {
1529                                    throw processException(e);
1530                            }
1531                            finally {
1532                                    if (list == null) {
1533                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1534                                    }
1535                                    else {
1536                                            cacheResult(list);
1537    
1538                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1539                                    }
1540    
1541                                    closeSession(session);
1542                            }
1543                    }
1544    
1545                    return list;
1546            }
1547    
1548            /**
1549             * Returns the first document library folder in the ordered set where groupId = &#63;.
1550             *
1551             * @param groupId the group ID
1552             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1553             * @return the first matching document library folder
1554             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
1555             * @throws SystemException if a system exception occurred
1556             */
1557            public DLFolder findByGroupId_First(long groupId,
1558                    OrderByComparator orderByComparator)
1559                    throws NoSuchFolderException, SystemException {
1560                    DLFolder dlFolder = fetchByGroupId_First(groupId, orderByComparator);
1561    
1562                    if (dlFolder != null) {
1563                            return dlFolder;
1564                    }
1565    
1566                    StringBundler msg = new StringBundler(4);
1567    
1568                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1569    
1570                    msg.append("groupId=");
1571                    msg.append(groupId);
1572    
1573                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1574    
1575                    throw new NoSuchFolderException(msg.toString());
1576            }
1577    
1578            /**
1579             * Returns the first document library folder in the ordered set where groupId = &#63;.
1580             *
1581             * @param groupId the group ID
1582             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1583             * @return the first matching document library folder, or <code>null</code> if a matching document library folder could not be found
1584             * @throws SystemException if a system exception occurred
1585             */
1586            public DLFolder fetchByGroupId_First(long groupId,
1587                    OrderByComparator orderByComparator) throws SystemException {
1588                    List<DLFolder> list = findByGroupId(groupId, 0, 1, orderByComparator);
1589    
1590                    if (!list.isEmpty()) {
1591                            return list.get(0);
1592                    }
1593    
1594                    return null;
1595            }
1596    
1597            /**
1598             * Returns the last document library folder in the ordered set where groupId = &#63;.
1599             *
1600             * @param groupId the group ID
1601             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1602             * @return the last matching document library folder
1603             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
1604             * @throws SystemException if a system exception occurred
1605             */
1606            public DLFolder findByGroupId_Last(long groupId,
1607                    OrderByComparator orderByComparator)
1608                    throws NoSuchFolderException, SystemException {
1609                    DLFolder dlFolder = fetchByGroupId_Last(groupId, orderByComparator);
1610    
1611                    if (dlFolder != null) {
1612                            return dlFolder;
1613                    }
1614    
1615                    StringBundler msg = new StringBundler(4);
1616    
1617                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1618    
1619                    msg.append("groupId=");
1620                    msg.append(groupId);
1621    
1622                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1623    
1624                    throw new NoSuchFolderException(msg.toString());
1625            }
1626    
1627            /**
1628             * Returns the last document library folder in the ordered set where groupId = &#63;.
1629             *
1630             * @param groupId the group ID
1631             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1632             * @return the last matching document library folder, or <code>null</code> if a matching document library folder could not be found
1633             * @throws SystemException if a system exception occurred
1634             */
1635            public DLFolder fetchByGroupId_Last(long groupId,
1636                    OrderByComparator orderByComparator) throws SystemException {
1637                    int count = countByGroupId(groupId);
1638    
1639                    List<DLFolder> list = findByGroupId(groupId, count - 1, count,
1640                                    orderByComparator);
1641    
1642                    if (!list.isEmpty()) {
1643                            return list.get(0);
1644                    }
1645    
1646                    return null;
1647            }
1648    
1649            /**
1650             * Returns the document library folders before and after the current document library folder in the ordered set where groupId = &#63;.
1651             *
1652             * @param folderId the primary key of the current document library folder
1653             * @param groupId the group ID
1654             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1655             * @return the previous, current, and next document library folder
1656             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
1657             * @throws SystemException if a system exception occurred
1658             */
1659            public DLFolder[] findByGroupId_PrevAndNext(long folderId, long groupId,
1660                    OrderByComparator orderByComparator)
1661                    throws NoSuchFolderException, SystemException {
1662                    DLFolder dlFolder = findByPrimaryKey(folderId);
1663    
1664                    Session session = null;
1665    
1666                    try {
1667                            session = openSession();
1668    
1669                            DLFolder[] array = new DLFolderImpl[3];
1670    
1671                            array[0] = getByGroupId_PrevAndNext(session, dlFolder, groupId,
1672                                            orderByComparator, true);
1673    
1674                            array[1] = dlFolder;
1675    
1676                            array[2] = getByGroupId_PrevAndNext(session, dlFolder, groupId,
1677                                            orderByComparator, false);
1678    
1679                            return array;
1680                    }
1681                    catch (Exception e) {
1682                            throw processException(e);
1683                    }
1684                    finally {
1685                            closeSession(session);
1686                    }
1687            }
1688    
1689            protected DLFolder getByGroupId_PrevAndNext(Session session,
1690                    DLFolder dlFolder, long groupId, OrderByComparator orderByComparator,
1691                    boolean previous) {
1692                    StringBundler query = null;
1693    
1694                    if (orderByComparator != null) {
1695                            query = new StringBundler(6 +
1696                                            (orderByComparator.getOrderByFields().length * 6));
1697                    }
1698                    else {
1699                            query = new StringBundler(3);
1700                    }
1701    
1702                    query.append(_SQL_SELECT_DLFOLDER_WHERE);
1703    
1704                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1705    
1706                    if (orderByComparator != null) {
1707                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1708    
1709                            if (orderByConditionFields.length > 0) {
1710                                    query.append(WHERE_AND);
1711                            }
1712    
1713                            for (int i = 0; i < orderByConditionFields.length; i++) {
1714                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1715                                    query.append(orderByConditionFields[i]);
1716    
1717                                    if ((i + 1) < orderByConditionFields.length) {
1718                                            if (orderByComparator.isAscending() ^ previous) {
1719                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1720                                            }
1721                                            else {
1722                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1723                                            }
1724                                    }
1725                                    else {
1726                                            if (orderByComparator.isAscending() ^ previous) {
1727                                                    query.append(WHERE_GREATER_THAN);
1728                                            }
1729                                            else {
1730                                                    query.append(WHERE_LESSER_THAN);
1731                                            }
1732                                    }
1733                            }
1734    
1735                            query.append(ORDER_BY_CLAUSE);
1736    
1737                            String[] orderByFields = orderByComparator.getOrderByFields();
1738    
1739                            for (int i = 0; i < orderByFields.length; i++) {
1740                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1741                                    query.append(orderByFields[i]);
1742    
1743                                    if ((i + 1) < orderByFields.length) {
1744                                            if (orderByComparator.isAscending() ^ previous) {
1745                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1746                                            }
1747                                            else {
1748                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1749                                            }
1750                                    }
1751                                    else {
1752                                            if (orderByComparator.isAscending() ^ previous) {
1753                                                    query.append(ORDER_BY_ASC);
1754                                            }
1755                                            else {
1756                                                    query.append(ORDER_BY_DESC);
1757                                            }
1758                                    }
1759                            }
1760                    }
1761    
1762                    else {
1763                            query.append(DLFolderModelImpl.ORDER_BY_JPQL);
1764                    }
1765    
1766                    String sql = query.toString();
1767    
1768                    Query q = session.createQuery(sql);
1769    
1770                    q.setFirstResult(0);
1771                    q.setMaxResults(2);
1772    
1773                    QueryPos qPos = QueryPos.getInstance(q);
1774    
1775                    qPos.add(groupId);
1776    
1777                    if (orderByComparator != null) {
1778                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
1779    
1780                            for (Object value : values) {
1781                                    qPos.add(value);
1782                            }
1783                    }
1784    
1785                    List<DLFolder> list = q.list();
1786    
1787                    if (list.size() == 2) {
1788                            return list.get(1);
1789                    }
1790                    else {
1791                            return null;
1792                    }
1793            }
1794    
1795            /**
1796             * Returns all the document library folders that the user has permission to view where groupId = &#63;.
1797             *
1798             * @param groupId the group ID
1799             * @return the matching document library folders that the user has permission to view
1800             * @throws SystemException if a system exception occurred
1801             */
1802            public List<DLFolder> filterFindByGroupId(long groupId)
1803                    throws SystemException {
1804                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1805                            QueryUtil.ALL_POS, null);
1806            }
1807    
1808            /**
1809             * Returns a range of all the document library folders that the user has permission to view where groupId = &#63;.
1810             *
1811             * <p>
1812             * 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.
1813             * </p>
1814             *
1815             * @param groupId the group ID
1816             * @param start the lower bound of the range of document library folders
1817             * @param end the upper bound of the range of document library folders (not inclusive)
1818             * @return the range of matching document library folders that the user has permission to view
1819             * @throws SystemException if a system exception occurred
1820             */
1821            public List<DLFolder> filterFindByGroupId(long groupId, int start, int end)
1822                    throws SystemException {
1823                    return filterFindByGroupId(groupId, start, end, null);
1824            }
1825    
1826            /**
1827             * Returns an ordered range of all the document library folders that the user has permissions to view where groupId = &#63;.
1828             *
1829             * <p>
1830             * 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.
1831             * </p>
1832             *
1833             * @param groupId the group ID
1834             * @param start the lower bound of the range of document library folders
1835             * @param end the upper bound of the range of document library folders (not inclusive)
1836             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1837             * @return the ordered range of matching document library folders that the user has permission to view
1838             * @throws SystemException if a system exception occurred
1839             */
1840            public List<DLFolder> filterFindByGroupId(long groupId, int start, int end,
1841                    OrderByComparator orderByComparator) throws SystemException {
1842                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1843                            return findByGroupId(groupId, start, end, orderByComparator);
1844                    }
1845    
1846                    StringBundler query = null;
1847    
1848                    if (orderByComparator != null) {
1849                            query = new StringBundler(3 +
1850                                            (orderByComparator.getOrderByFields().length * 3));
1851                    }
1852                    else {
1853                            query = new StringBundler(3);
1854                    }
1855    
1856                    if (getDB().isSupportsInlineDistinct()) {
1857                            query.append(_FILTER_SQL_SELECT_DLFOLDER_WHERE);
1858                    }
1859                    else {
1860                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1);
1861                    }
1862    
1863                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1864    
1865                    if (!getDB().isSupportsInlineDistinct()) {
1866                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2);
1867                    }
1868    
1869                    if (orderByComparator != null) {
1870                            if (getDB().isSupportsInlineDistinct()) {
1871                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1872                                            orderByComparator);
1873                            }
1874                            else {
1875                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1876                                            orderByComparator);
1877                            }
1878                    }
1879    
1880                    else {
1881                            if (getDB().isSupportsInlineDistinct()) {
1882                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
1883                            }
1884                            else {
1885                                    query.append(DLFolderModelImpl.ORDER_BY_SQL);
1886                            }
1887                    }
1888    
1889                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1890                                    DLFolder.class.getName(),
1891                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1892    
1893                    Session session = null;
1894    
1895                    try {
1896                            session = openSession();
1897    
1898                            SQLQuery q = session.createSQLQuery(sql);
1899    
1900                            if (getDB().isSupportsInlineDistinct()) {
1901                                    q.addEntity(_FILTER_ENTITY_ALIAS, DLFolderImpl.class);
1902                            }
1903                            else {
1904                                    q.addEntity(_FILTER_ENTITY_TABLE, DLFolderImpl.class);
1905                            }
1906    
1907                            QueryPos qPos = QueryPos.getInstance(q);
1908    
1909                            qPos.add(groupId);
1910    
1911                            return (List<DLFolder>)QueryUtil.list(q, getDialect(), start, end);
1912                    }
1913                    catch (Exception e) {
1914                            throw processException(e);
1915                    }
1916                    finally {
1917                            closeSession(session);
1918                    }
1919            }
1920    
1921            /**
1922             * Returns the document library folders before and after the current document library folder in the ordered set of document library folders that the user has permission to view where groupId = &#63;.
1923             *
1924             * @param folderId the primary key of the current document library folder
1925             * @param groupId the group ID
1926             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1927             * @return the previous, current, and next document library folder
1928             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
1929             * @throws SystemException if a system exception occurred
1930             */
1931            public DLFolder[] filterFindByGroupId_PrevAndNext(long folderId,
1932                    long groupId, OrderByComparator orderByComparator)
1933                    throws NoSuchFolderException, SystemException {
1934                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1935                            return findByGroupId_PrevAndNext(folderId, groupId,
1936                                    orderByComparator);
1937                    }
1938    
1939                    DLFolder dlFolder = findByPrimaryKey(folderId);
1940    
1941                    Session session = null;
1942    
1943                    try {
1944                            session = openSession();
1945    
1946                            DLFolder[] array = new DLFolderImpl[3];
1947    
1948                            array[0] = filterGetByGroupId_PrevAndNext(session, dlFolder,
1949                                            groupId, orderByComparator, true);
1950    
1951                            array[1] = dlFolder;
1952    
1953                            array[2] = filterGetByGroupId_PrevAndNext(session, dlFolder,
1954                                            groupId, orderByComparator, false);
1955    
1956                            return array;
1957                    }
1958                    catch (Exception e) {
1959                            throw processException(e);
1960                    }
1961                    finally {
1962                            closeSession(session);
1963                    }
1964            }
1965    
1966            protected DLFolder filterGetByGroupId_PrevAndNext(Session session,
1967                    DLFolder dlFolder, long groupId, OrderByComparator orderByComparator,
1968                    boolean previous) {
1969                    StringBundler query = null;
1970    
1971                    if (orderByComparator != null) {
1972                            query = new StringBundler(6 +
1973                                            (orderByComparator.getOrderByFields().length * 6));
1974                    }
1975                    else {
1976                            query = new StringBundler(3);
1977                    }
1978    
1979                    if (getDB().isSupportsInlineDistinct()) {
1980                            query.append(_FILTER_SQL_SELECT_DLFOLDER_WHERE);
1981                    }
1982                    else {
1983                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1);
1984                    }
1985    
1986                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1987    
1988                    if (!getDB().isSupportsInlineDistinct()) {
1989                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2);
1990                    }
1991    
1992                    if (orderByComparator != null) {
1993                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1994    
1995                            if (orderByConditionFields.length > 0) {
1996                                    query.append(WHERE_AND);
1997                            }
1998    
1999                            for (int i = 0; i < orderByConditionFields.length; i++) {
2000                                    if (getDB().isSupportsInlineDistinct()) {
2001                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2002                                    }
2003                                    else {
2004                                            query.append(_ORDER_BY_ENTITY_TABLE);
2005                                    }
2006    
2007                                    query.append(orderByConditionFields[i]);
2008    
2009                                    if ((i + 1) < orderByConditionFields.length) {
2010                                            if (orderByComparator.isAscending() ^ previous) {
2011                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2012                                            }
2013                                            else {
2014                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2015                                            }
2016                                    }
2017                                    else {
2018                                            if (orderByComparator.isAscending() ^ previous) {
2019                                                    query.append(WHERE_GREATER_THAN);
2020                                            }
2021                                            else {
2022                                                    query.append(WHERE_LESSER_THAN);
2023                                            }
2024                                    }
2025                            }
2026    
2027                            query.append(ORDER_BY_CLAUSE);
2028    
2029                            String[] orderByFields = orderByComparator.getOrderByFields();
2030    
2031                            for (int i = 0; i < orderByFields.length; i++) {
2032                                    if (getDB().isSupportsInlineDistinct()) {
2033                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2034                                    }
2035                                    else {
2036                                            query.append(_ORDER_BY_ENTITY_TABLE);
2037                                    }
2038    
2039                                    query.append(orderByFields[i]);
2040    
2041                                    if ((i + 1) < orderByFields.length) {
2042                                            if (orderByComparator.isAscending() ^ previous) {
2043                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2044                                            }
2045                                            else {
2046                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2047                                            }
2048                                    }
2049                                    else {
2050                                            if (orderByComparator.isAscending() ^ previous) {
2051                                                    query.append(ORDER_BY_ASC);
2052                                            }
2053                                            else {
2054                                                    query.append(ORDER_BY_DESC);
2055                                            }
2056                                    }
2057                            }
2058                    }
2059    
2060                    else {
2061                            if (getDB().isSupportsInlineDistinct()) {
2062                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
2063                            }
2064                            else {
2065                                    query.append(DLFolderModelImpl.ORDER_BY_SQL);
2066                            }
2067                    }
2068    
2069                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2070                                    DLFolder.class.getName(),
2071                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2072    
2073                    SQLQuery q = session.createSQLQuery(sql);
2074    
2075                    q.setFirstResult(0);
2076                    q.setMaxResults(2);
2077    
2078                    if (getDB().isSupportsInlineDistinct()) {
2079                            q.addEntity(_FILTER_ENTITY_ALIAS, DLFolderImpl.class);
2080                    }
2081                    else {
2082                            q.addEntity(_FILTER_ENTITY_TABLE, DLFolderImpl.class);
2083                    }
2084    
2085                    QueryPos qPos = QueryPos.getInstance(q);
2086    
2087                    qPos.add(groupId);
2088    
2089                    if (orderByComparator != null) {
2090                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
2091    
2092                            for (Object value : values) {
2093                                    qPos.add(value);
2094                            }
2095                    }
2096    
2097                    List<DLFolder> list = q.list();
2098    
2099                    if (list.size() == 2) {
2100                            return list.get(1);
2101                    }
2102                    else {
2103                            return null;
2104                    }
2105            }
2106    
2107            /**
2108             * Returns all the document library folders where companyId = &#63;.
2109             *
2110             * @param companyId the company ID
2111             * @return the matching document library folders
2112             * @throws SystemException if a system exception occurred
2113             */
2114            public List<DLFolder> findByCompanyId(long companyId)
2115                    throws SystemException {
2116                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2117                            null);
2118            }
2119    
2120            /**
2121             * Returns a range of all the document library folders where companyId = &#63;.
2122             *
2123             * <p>
2124             * 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.
2125             * </p>
2126             *
2127             * @param companyId the company ID
2128             * @param start the lower bound of the range of document library folders
2129             * @param end the upper bound of the range of document library folders (not inclusive)
2130             * @return the range of matching document library folders
2131             * @throws SystemException if a system exception occurred
2132             */
2133            public List<DLFolder> findByCompanyId(long companyId, int start, int end)
2134                    throws SystemException {
2135                    return findByCompanyId(companyId, start, end, null);
2136            }
2137    
2138            /**
2139             * Returns an ordered range of all the document library folders where companyId = &#63;.
2140             *
2141             * <p>
2142             * 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.
2143             * </p>
2144             *
2145             * @param companyId the company ID
2146             * @param start the lower bound of the range of document library folders
2147             * @param end the upper bound of the range of document library folders (not inclusive)
2148             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2149             * @return the ordered range of matching document library folders
2150             * @throws SystemException if a system exception occurred
2151             */
2152            public List<DLFolder> findByCompanyId(long companyId, int start, int end,
2153                    OrderByComparator orderByComparator) throws SystemException {
2154                    FinderPath finderPath = null;
2155                    Object[] finderArgs = null;
2156    
2157                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2158                                    (orderByComparator == null)) {
2159                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
2160                            finderArgs = new Object[] { companyId };
2161                    }
2162                    else {
2163                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
2164                            finderArgs = new Object[] { companyId, start, end, orderByComparator };
2165                    }
2166    
2167                    List<DLFolder> list = (List<DLFolder>)FinderCacheUtil.getResult(finderPath,
2168                                    finderArgs, this);
2169    
2170                    if ((list != null) && !list.isEmpty()) {
2171                            for (DLFolder dlFolder : list) {
2172                                    if ((companyId != dlFolder.getCompanyId())) {
2173                                            list = null;
2174    
2175                                            break;
2176                                    }
2177                            }
2178                    }
2179    
2180                    if (list == null) {
2181                            StringBundler query = null;
2182    
2183                            if (orderByComparator != null) {
2184                                    query = new StringBundler(3 +
2185                                                    (orderByComparator.getOrderByFields().length * 3));
2186                            }
2187                            else {
2188                                    query = new StringBundler(3);
2189                            }
2190    
2191                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
2192    
2193                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2194    
2195                            if (orderByComparator != null) {
2196                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2197                                            orderByComparator);
2198                            }
2199    
2200                            else {
2201                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
2202                            }
2203    
2204                            String sql = query.toString();
2205    
2206                            Session session = null;
2207    
2208                            try {
2209                                    session = openSession();
2210    
2211                                    Query q = session.createQuery(sql);
2212    
2213                                    QueryPos qPos = QueryPos.getInstance(q);
2214    
2215                                    qPos.add(companyId);
2216    
2217                                    list = (List<DLFolder>)QueryUtil.list(q, getDialect(), start,
2218                                                    end);
2219                            }
2220                            catch (Exception e) {
2221                                    throw processException(e);
2222                            }
2223                            finally {
2224                                    if (list == null) {
2225                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
2226                                    }
2227                                    else {
2228                                            cacheResult(list);
2229    
2230                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
2231                                    }
2232    
2233                                    closeSession(session);
2234                            }
2235                    }
2236    
2237                    return list;
2238            }
2239    
2240            /**
2241             * Returns the first document library folder in the ordered set where companyId = &#63;.
2242             *
2243             * @param companyId the company ID
2244             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2245             * @return the first matching document library folder
2246             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
2247             * @throws SystemException if a system exception occurred
2248             */
2249            public DLFolder findByCompanyId_First(long companyId,
2250                    OrderByComparator orderByComparator)
2251                    throws NoSuchFolderException, SystemException {
2252                    DLFolder dlFolder = fetchByCompanyId_First(companyId, orderByComparator);
2253    
2254                    if (dlFolder != null) {
2255                            return dlFolder;
2256                    }
2257    
2258                    StringBundler msg = new StringBundler(4);
2259    
2260                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2261    
2262                    msg.append("companyId=");
2263                    msg.append(companyId);
2264    
2265                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2266    
2267                    throw new NoSuchFolderException(msg.toString());
2268            }
2269    
2270            /**
2271             * Returns the first document library folder in the ordered set where companyId = &#63;.
2272             *
2273             * @param companyId the company ID
2274             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2275             * @return the first matching document library folder, or <code>null</code> if a matching document library folder could not be found
2276             * @throws SystemException if a system exception occurred
2277             */
2278            public DLFolder fetchByCompanyId_First(long companyId,
2279                    OrderByComparator orderByComparator) throws SystemException {
2280                    List<DLFolder> list = findByCompanyId(companyId, 0, 1, orderByComparator);
2281    
2282                    if (!list.isEmpty()) {
2283                            return list.get(0);
2284                    }
2285    
2286                    return null;
2287            }
2288    
2289            /**
2290             * Returns the last document library folder in the ordered set where companyId = &#63;.
2291             *
2292             * @param companyId the company ID
2293             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2294             * @return the last matching document library folder
2295             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
2296             * @throws SystemException if a system exception occurred
2297             */
2298            public DLFolder findByCompanyId_Last(long companyId,
2299                    OrderByComparator orderByComparator)
2300                    throws NoSuchFolderException, SystemException {
2301                    DLFolder dlFolder = fetchByCompanyId_Last(companyId, orderByComparator);
2302    
2303                    if (dlFolder != null) {
2304                            return dlFolder;
2305                    }
2306    
2307                    StringBundler msg = new StringBundler(4);
2308    
2309                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2310    
2311                    msg.append("companyId=");
2312                    msg.append(companyId);
2313    
2314                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2315    
2316                    throw new NoSuchFolderException(msg.toString());
2317            }
2318    
2319            /**
2320             * Returns the last document library folder in the ordered set where companyId = &#63;.
2321             *
2322             * @param companyId the company ID
2323             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2324             * @return the last matching document library folder, or <code>null</code> if a matching document library folder could not be found
2325             * @throws SystemException if a system exception occurred
2326             */
2327            public DLFolder fetchByCompanyId_Last(long companyId,
2328                    OrderByComparator orderByComparator) throws SystemException {
2329                    int count = countByCompanyId(companyId);
2330    
2331                    List<DLFolder> list = findByCompanyId(companyId, count - 1, count,
2332                                    orderByComparator);
2333    
2334                    if (!list.isEmpty()) {
2335                            return list.get(0);
2336                    }
2337    
2338                    return null;
2339            }
2340    
2341            /**
2342             * Returns the document library folders before and after the current document library folder in the ordered set where companyId = &#63;.
2343             *
2344             * @param folderId the primary key of the current document library folder
2345             * @param companyId the company ID
2346             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2347             * @return the previous, current, and next document library folder
2348             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
2349             * @throws SystemException if a system exception occurred
2350             */
2351            public DLFolder[] findByCompanyId_PrevAndNext(long folderId,
2352                    long companyId, OrderByComparator orderByComparator)
2353                    throws NoSuchFolderException, SystemException {
2354                    DLFolder dlFolder = findByPrimaryKey(folderId);
2355    
2356                    Session session = null;
2357    
2358                    try {
2359                            session = openSession();
2360    
2361                            DLFolder[] array = new DLFolderImpl[3];
2362    
2363                            array[0] = getByCompanyId_PrevAndNext(session, dlFolder, companyId,
2364                                            orderByComparator, true);
2365    
2366                            array[1] = dlFolder;
2367    
2368                            array[2] = getByCompanyId_PrevAndNext(session, dlFolder, companyId,
2369                                            orderByComparator, false);
2370    
2371                            return array;
2372                    }
2373                    catch (Exception e) {
2374                            throw processException(e);
2375                    }
2376                    finally {
2377                            closeSession(session);
2378                    }
2379            }
2380    
2381            protected DLFolder getByCompanyId_PrevAndNext(Session session,
2382                    DLFolder dlFolder, long companyId, OrderByComparator orderByComparator,
2383                    boolean previous) {
2384                    StringBundler query = null;
2385    
2386                    if (orderByComparator != null) {
2387                            query = new StringBundler(6 +
2388                                            (orderByComparator.getOrderByFields().length * 6));
2389                    }
2390                    else {
2391                            query = new StringBundler(3);
2392                    }
2393    
2394                    query.append(_SQL_SELECT_DLFOLDER_WHERE);
2395    
2396                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2397    
2398                    if (orderByComparator != null) {
2399                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2400    
2401                            if (orderByConditionFields.length > 0) {
2402                                    query.append(WHERE_AND);
2403                            }
2404    
2405                            for (int i = 0; i < orderByConditionFields.length; i++) {
2406                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2407                                    query.append(orderByConditionFields[i]);
2408    
2409                                    if ((i + 1) < orderByConditionFields.length) {
2410                                            if (orderByComparator.isAscending() ^ previous) {
2411                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2412                                            }
2413                                            else {
2414                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2415                                            }
2416                                    }
2417                                    else {
2418                                            if (orderByComparator.isAscending() ^ previous) {
2419                                                    query.append(WHERE_GREATER_THAN);
2420                                            }
2421                                            else {
2422                                                    query.append(WHERE_LESSER_THAN);
2423                                            }
2424                                    }
2425                            }
2426    
2427                            query.append(ORDER_BY_CLAUSE);
2428    
2429                            String[] orderByFields = orderByComparator.getOrderByFields();
2430    
2431                            for (int i = 0; i < orderByFields.length; i++) {
2432                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2433                                    query.append(orderByFields[i]);
2434    
2435                                    if ((i + 1) < orderByFields.length) {
2436                                            if (orderByComparator.isAscending() ^ previous) {
2437                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2438                                            }
2439                                            else {
2440                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2441                                            }
2442                                    }
2443                                    else {
2444                                            if (orderByComparator.isAscending() ^ previous) {
2445                                                    query.append(ORDER_BY_ASC);
2446                                            }
2447                                            else {
2448                                                    query.append(ORDER_BY_DESC);
2449                                            }
2450                                    }
2451                            }
2452                    }
2453    
2454                    else {
2455                            query.append(DLFolderModelImpl.ORDER_BY_JPQL);
2456                    }
2457    
2458                    String sql = query.toString();
2459    
2460                    Query q = session.createQuery(sql);
2461    
2462                    q.setFirstResult(0);
2463                    q.setMaxResults(2);
2464    
2465                    QueryPos qPos = QueryPos.getInstance(q);
2466    
2467                    qPos.add(companyId);
2468    
2469                    if (orderByComparator != null) {
2470                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
2471    
2472                            for (Object value : values) {
2473                                    qPos.add(value);
2474                            }
2475                    }
2476    
2477                    List<DLFolder> list = q.list();
2478    
2479                    if (list.size() == 2) {
2480                            return list.get(1);
2481                    }
2482                    else {
2483                            return null;
2484                    }
2485            }
2486    
2487            /**
2488             * Returns the document library folder where repositoryId = &#63; or throws a {@link com.liferay.portlet.documentlibrary.NoSuchFolderException} if it could not be found.
2489             *
2490             * @param repositoryId the repository ID
2491             * @return the matching document library folder
2492             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
2493             * @throws SystemException if a system exception occurred
2494             */
2495            public DLFolder findByRepositoryId(long repositoryId)
2496                    throws NoSuchFolderException, SystemException {
2497                    DLFolder dlFolder = fetchByRepositoryId(repositoryId);
2498    
2499                    if (dlFolder == null) {
2500                            StringBundler msg = new StringBundler(4);
2501    
2502                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2503    
2504                            msg.append("repositoryId=");
2505                            msg.append(repositoryId);
2506    
2507                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2508    
2509                            if (_log.isWarnEnabled()) {
2510                                    _log.warn(msg.toString());
2511                            }
2512    
2513                            throw new NoSuchFolderException(msg.toString());
2514                    }
2515    
2516                    return dlFolder;
2517            }
2518    
2519            /**
2520             * Returns the document library folder where repositoryId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
2521             *
2522             * @param repositoryId the repository ID
2523             * @return the matching document library folder, or <code>null</code> if a matching document library folder could not be found
2524             * @throws SystemException if a system exception occurred
2525             */
2526            public DLFolder fetchByRepositoryId(long repositoryId)
2527                    throws SystemException {
2528                    return fetchByRepositoryId(repositoryId, true);
2529            }
2530    
2531            /**
2532             * Returns the document library folder where repositoryId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
2533             *
2534             * @param repositoryId the repository ID
2535             * @param retrieveFromCache whether to use the finder cache
2536             * @return the matching document library folder, or <code>null</code> if a matching document library folder could not be found
2537             * @throws SystemException if a system exception occurred
2538             */
2539            public DLFolder fetchByRepositoryId(long repositoryId,
2540                    boolean retrieveFromCache) throws SystemException {
2541                    Object[] finderArgs = new Object[] { repositoryId };
2542    
2543                    Object result = null;
2544    
2545                    if (retrieveFromCache) {
2546                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_REPOSITORYID,
2547                                            finderArgs, this);
2548                    }
2549    
2550                    if (result instanceof DLFolder) {
2551                            DLFolder dlFolder = (DLFolder)result;
2552    
2553                            if ((repositoryId != dlFolder.getRepositoryId())) {
2554                                    result = null;
2555                            }
2556                    }
2557    
2558                    if (result == null) {
2559                            StringBundler query = new StringBundler(3);
2560    
2561                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
2562    
2563                            query.append(_FINDER_COLUMN_REPOSITORYID_REPOSITORYID_2);
2564    
2565                            query.append(DLFolderModelImpl.ORDER_BY_JPQL);
2566    
2567                            String sql = query.toString();
2568    
2569                            Session session = null;
2570    
2571                            try {
2572                                    session = openSession();
2573    
2574                                    Query q = session.createQuery(sql);
2575    
2576                                    QueryPos qPos = QueryPos.getInstance(q);
2577    
2578                                    qPos.add(repositoryId);
2579    
2580                                    List<DLFolder> list = q.list();
2581    
2582                                    result = list;
2583    
2584                                    DLFolder dlFolder = null;
2585    
2586                                    if (list.isEmpty()) {
2587                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_REPOSITORYID,
2588                                                    finderArgs, list);
2589                                    }
2590                                    else {
2591                                            dlFolder = list.get(0);
2592    
2593                                            cacheResult(dlFolder);
2594    
2595                                            if ((dlFolder.getRepositoryId() != repositoryId)) {
2596                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_REPOSITORYID,
2597                                                            finderArgs, dlFolder);
2598                                            }
2599                                    }
2600    
2601                                    return dlFolder;
2602                            }
2603                            catch (Exception e) {
2604                                    throw processException(e);
2605                            }
2606                            finally {
2607                                    if (result == null) {
2608                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_REPOSITORYID,
2609                                                    finderArgs);
2610                                    }
2611    
2612                                    closeSession(session);
2613                            }
2614                    }
2615                    else {
2616                            if (result instanceof List<?>) {
2617                                    return null;
2618                            }
2619                            else {
2620                                    return (DLFolder)result;
2621                            }
2622                    }
2623            }
2624    
2625            /**
2626             * Returns all the document library folders where groupId = &#63; and parentFolderId = &#63;.
2627             *
2628             * @param groupId the group ID
2629             * @param parentFolderId the parent folder ID
2630             * @return the matching document library folders
2631             * @throws SystemException if a system exception occurred
2632             */
2633            public List<DLFolder> findByG_P(long groupId, long parentFolderId)
2634                    throws SystemException {
2635                    return findByG_P(groupId, parentFolderId, QueryUtil.ALL_POS,
2636                            QueryUtil.ALL_POS, null);
2637            }
2638    
2639            /**
2640             * Returns a range of all the document library folders where groupId = &#63; and parentFolderId = &#63;.
2641             *
2642             * <p>
2643             * 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.
2644             * </p>
2645             *
2646             * @param groupId the group ID
2647             * @param parentFolderId the parent folder ID
2648             * @param start the lower bound of the range of document library folders
2649             * @param end the upper bound of the range of document library folders (not inclusive)
2650             * @return the range of matching document library folders
2651             * @throws SystemException if a system exception occurred
2652             */
2653            public List<DLFolder> findByG_P(long groupId, long parentFolderId,
2654                    int start, int end) throws SystemException {
2655                    return findByG_P(groupId, parentFolderId, start, end, null);
2656            }
2657    
2658            /**
2659             * Returns an ordered range of all the document library folders where groupId = &#63; and parentFolderId = &#63;.
2660             *
2661             * <p>
2662             * 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.
2663             * </p>
2664             *
2665             * @param groupId the group ID
2666             * @param parentFolderId the parent folder ID
2667             * @param start the lower bound of the range of document library folders
2668             * @param end the upper bound of the range of document library folders (not inclusive)
2669             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2670             * @return the ordered range of matching document library folders
2671             * @throws SystemException if a system exception occurred
2672             */
2673            public List<DLFolder> findByG_P(long groupId, long parentFolderId,
2674                    int start, int end, OrderByComparator orderByComparator)
2675                    throws SystemException {
2676                    FinderPath finderPath = null;
2677                    Object[] finderArgs = null;
2678    
2679                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2680                                    (orderByComparator == null)) {
2681                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P;
2682                            finderArgs = new Object[] { groupId, parentFolderId };
2683                    }
2684                    else {
2685                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P;
2686                            finderArgs = new Object[] {
2687                                            groupId, parentFolderId,
2688                                            
2689                                            start, end, orderByComparator
2690                                    };
2691                    }
2692    
2693                    List<DLFolder> list = (List<DLFolder>)FinderCacheUtil.getResult(finderPath,
2694                                    finderArgs, this);
2695    
2696                    if ((list != null) && !list.isEmpty()) {
2697                            for (DLFolder dlFolder : list) {
2698                                    if ((groupId != dlFolder.getGroupId()) ||
2699                                                    (parentFolderId != dlFolder.getParentFolderId())) {
2700                                            list = null;
2701    
2702                                            break;
2703                                    }
2704                            }
2705                    }
2706    
2707                    if (list == null) {
2708                            StringBundler query = null;
2709    
2710                            if (orderByComparator != null) {
2711                                    query = new StringBundler(4 +
2712                                                    (orderByComparator.getOrderByFields().length * 3));
2713                            }
2714                            else {
2715                                    query = new StringBundler(4);
2716                            }
2717    
2718                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
2719    
2720                            query.append(_FINDER_COLUMN_G_P_GROUPID_2);
2721    
2722                            query.append(_FINDER_COLUMN_G_P_PARENTFOLDERID_2);
2723    
2724                            if (orderByComparator != null) {
2725                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2726                                            orderByComparator);
2727                            }
2728    
2729                            else {
2730                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
2731                            }
2732    
2733                            String sql = query.toString();
2734    
2735                            Session session = null;
2736    
2737                            try {
2738                                    session = openSession();
2739    
2740                                    Query q = session.createQuery(sql);
2741    
2742                                    QueryPos qPos = QueryPos.getInstance(q);
2743    
2744                                    qPos.add(groupId);
2745    
2746                                    qPos.add(parentFolderId);
2747    
2748                                    list = (List<DLFolder>)QueryUtil.list(q, getDialect(), start,
2749                                                    end);
2750                            }
2751                            catch (Exception e) {
2752                                    throw processException(e);
2753                            }
2754                            finally {
2755                                    if (list == null) {
2756                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
2757                                    }
2758                                    else {
2759                                            cacheResult(list);
2760    
2761                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
2762                                    }
2763    
2764                                    closeSession(session);
2765                            }
2766                    }
2767    
2768                    return list;
2769            }
2770    
2771            /**
2772             * Returns the first document library folder in the ordered set where groupId = &#63; and parentFolderId = &#63;.
2773             *
2774             * @param groupId the group ID
2775             * @param parentFolderId the parent folder ID
2776             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2777             * @return the first matching document library folder
2778             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
2779             * @throws SystemException if a system exception occurred
2780             */
2781            public DLFolder findByG_P_First(long groupId, long parentFolderId,
2782                    OrderByComparator orderByComparator)
2783                    throws NoSuchFolderException, SystemException {
2784                    DLFolder dlFolder = fetchByG_P_First(groupId, parentFolderId,
2785                                    orderByComparator);
2786    
2787                    if (dlFolder != null) {
2788                            return dlFolder;
2789                    }
2790    
2791                    StringBundler msg = new StringBundler(6);
2792    
2793                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2794    
2795                    msg.append("groupId=");
2796                    msg.append(groupId);
2797    
2798                    msg.append(", parentFolderId=");
2799                    msg.append(parentFolderId);
2800    
2801                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2802    
2803                    throw new NoSuchFolderException(msg.toString());
2804            }
2805    
2806            /**
2807             * Returns the first document library folder in the ordered set where groupId = &#63; and parentFolderId = &#63;.
2808             *
2809             * @param groupId the group ID
2810             * @param parentFolderId the parent folder ID
2811             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2812             * @return the first matching document library folder, or <code>null</code> if a matching document library folder could not be found
2813             * @throws SystemException if a system exception occurred
2814             */
2815            public DLFolder fetchByG_P_First(long groupId, long parentFolderId,
2816                    OrderByComparator orderByComparator) throws SystemException {
2817                    List<DLFolder> list = findByG_P(groupId, parentFolderId, 0, 1,
2818                                    orderByComparator);
2819    
2820                    if (!list.isEmpty()) {
2821                            return list.get(0);
2822                    }
2823    
2824                    return null;
2825            }
2826    
2827            /**
2828             * Returns the last document library folder in the ordered set where groupId = &#63; and parentFolderId = &#63;.
2829             *
2830             * @param groupId the group ID
2831             * @param parentFolderId the parent folder ID
2832             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2833             * @return the last matching document library folder
2834             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
2835             * @throws SystemException if a system exception occurred
2836             */
2837            public DLFolder findByG_P_Last(long groupId, long parentFolderId,
2838                    OrderByComparator orderByComparator)
2839                    throws NoSuchFolderException, SystemException {
2840                    DLFolder dlFolder = fetchByG_P_Last(groupId, parentFolderId,
2841                                    orderByComparator);
2842    
2843                    if (dlFolder != null) {
2844                            return dlFolder;
2845                    }
2846    
2847                    StringBundler msg = new StringBundler(6);
2848    
2849                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2850    
2851                    msg.append("groupId=");
2852                    msg.append(groupId);
2853    
2854                    msg.append(", parentFolderId=");
2855                    msg.append(parentFolderId);
2856    
2857                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2858    
2859                    throw new NoSuchFolderException(msg.toString());
2860            }
2861    
2862            /**
2863             * Returns the last document library folder in the ordered set where groupId = &#63; and parentFolderId = &#63;.
2864             *
2865             * @param groupId the group ID
2866             * @param parentFolderId the parent folder ID
2867             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2868             * @return the last matching document library folder, or <code>null</code> if a matching document library folder could not be found
2869             * @throws SystemException if a system exception occurred
2870             */
2871            public DLFolder fetchByG_P_Last(long groupId, long parentFolderId,
2872                    OrderByComparator orderByComparator) throws SystemException {
2873                    int count = countByG_P(groupId, parentFolderId);
2874    
2875                    List<DLFolder> list = findByG_P(groupId, parentFolderId, count - 1,
2876                                    count, orderByComparator);
2877    
2878                    if (!list.isEmpty()) {
2879                            return list.get(0);
2880                    }
2881    
2882                    return null;
2883            }
2884    
2885            /**
2886             * Returns the document library folders before and after the current document library folder in the ordered set where groupId = &#63; and parentFolderId = &#63;.
2887             *
2888             * @param folderId the primary key of the current document library folder
2889             * @param groupId the group ID
2890             * @param parentFolderId the parent folder ID
2891             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2892             * @return the previous, current, and next document library folder
2893             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
2894             * @throws SystemException if a system exception occurred
2895             */
2896            public DLFolder[] findByG_P_PrevAndNext(long folderId, long groupId,
2897                    long parentFolderId, OrderByComparator orderByComparator)
2898                    throws NoSuchFolderException, SystemException {
2899                    DLFolder dlFolder = findByPrimaryKey(folderId);
2900    
2901                    Session session = null;
2902    
2903                    try {
2904                            session = openSession();
2905    
2906                            DLFolder[] array = new DLFolderImpl[3];
2907    
2908                            array[0] = getByG_P_PrevAndNext(session, dlFolder, groupId,
2909                                            parentFolderId, orderByComparator, true);
2910    
2911                            array[1] = dlFolder;
2912    
2913                            array[2] = getByG_P_PrevAndNext(session, dlFolder, groupId,
2914                                            parentFolderId, orderByComparator, false);
2915    
2916                            return array;
2917                    }
2918                    catch (Exception e) {
2919                            throw processException(e);
2920                    }
2921                    finally {
2922                            closeSession(session);
2923                    }
2924            }
2925    
2926            protected DLFolder getByG_P_PrevAndNext(Session session, DLFolder dlFolder,
2927                    long groupId, long parentFolderId, OrderByComparator orderByComparator,
2928                    boolean previous) {
2929                    StringBundler query = null;
2930    
2931                    if (orderByComparator != null) {
2932                            query = new StringBundler(6 +
2933                                            (orderByComparator.getOrderByFields().length * 6));
2934                    }
2935                    else {
2936                            query = new StringBundler(3);
2937                    }
2938    
2939                    query.append(_SQL_SELECT_DLFOLDER_WHERE);
2940    
2941                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
2942    
2943                    query.append(_FINDER_COLUMN_G_P_PARENTFOLDERID_2);
2944    
2945                    if (orderByComparator != null) {
2946                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2947    
2948                            if (orderByConditionFields.length > 0) {
2949                                    query.append(WHERE_AND);
2950                            }
2951    
2952                            for (int i = 0; i < orderByConditionFields.length; i++) {
2953                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2954                                    query.append(orderByConditionFields[i]);
2955    
2956                                    if ((i + 1) < orderByConditionFields.length) {
2957                                            if (orderByComparator.isAscending() ^ previous) {
2958                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2959                                            }
2960                                            else {
2961                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2962                                            }
2963                                    }
2964                                    else {
2965                                            if (orderByComparator.isAscending() ^ previous) {
2966                                                    query.append(WHERE_GREATER_THAN);
2967                                            }
2968                                            else {
2969                                                    query.append(WHERE_LESSER_THAN);
2970                                            }
2971                                    }
2972                            }
2973    
2974                            query.append(ORDER_BY_CLAUSE);
2975    
2976                            String[] orderByFields = orderByComparator.getOrderByFields();
2977    
2978                            for (int i = 0; i < orderByFields.length; i++) {
2979                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2980                                    query.append(orderByFields[i]);
2981    
2982                                    if ((i + 1) < orderByFields.length) {
2983                                            if (orderByComparator.isAscending() ^ previous) {
2984                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2985                                            }
2986                                            else {
2987                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2988                                            }
2989                                    }
2990                                    else {
2991                                            if (orderByComparator.isAscending() ^ previous) {
2992                                                    query.append(ORDER_BY_ASC);
2993                                            }
2994                                            else {
2995                                                    query.append(ORDER_BY_DESC);
2996                                            }
2997                                    }
2998                            }
2999                    }
3000    
3001                    else {
3002                            query.append(DLFolderModelImpl.ORDER_BY_JPQL);
3003                    }
3004    
3005                    String sql = query.toString();
3006    
3007                    Query q = session.createQuery(sql);
3008    
3009                    q.setFirstResult(0);
3010                    q.setMaxResults(2);
3011    
3012                    QueryPos qPos = QueryPos.getInstance(q);
3013    
3014                    qPos.add(groupId);
3015    
3016                    qPos.add(parentFolderId);
3017    
3018                    if (orderByComparator != null) {
3019                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
3020    
3021                            for (Object value : values) {
3022                                    qPos.add(value);
3023                            }
3024                    }
3025    
3026                    List<DLFolder> list = q.list();
3027    
3028                    if (list.size() == 2) {
3029                            return list.get(1);
3030                    }
3031                    else {
3032                            return null;
3033                    }
3034            }
3035    
3036            /**
3037             * Returns all the document library folders that the user has permission to view where groupId = &#63; and parentFolderId = &#63;.
3038             *
3039             * @param groupId the group ID
3040             * @param parentFolderId the parent folder ID
3041             * @return the matching document library folders that the user has permission to view
3042             * @throws SystemException if a system exception occurred
3043             */
3044            public List<DLFolder> filterFindByG_P(long groupId, long parentFolderId)
3045                    throws SystemException {
3046                    return filterFindByG_P(groupId, parentFolderId, QueryUtil.ALL_POS,
3047                            QueryUtil.ALL_POS, null);
3048            }
3049    
3050            /**
3051             * Returns a range of all the document library folders that the user has permission to view where groupId = &#63; and parentFolderId = &#63;.
3052             *
3053             * <p>
3054             * 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.
3055             * </p>
3056             *
3057             * @param groupId the group ID
3058             * @param parentFolderId the parent folder ID
3059             * @param start the lower bound of the range of document library folders
3060             * @param end the upper bound of the range of document library folders (not inclusive)
3061             * @return the range of matching document library folders that the user has permission to view
3062             * @throws SystemException if a system exception occurred
3063             */
3064            public List<DLFolder> filterFindByG_P(long groupId, long parentFolderId,
3065                    int start, int end) throws SystemException {
3066                    return filterFindByG_P(groupId, parentFolderId, start, end, null);
3067            }
3068    
3069            /**
3070             * Returns an ordered range of all the document library folders that the user has permissions to view where groupId = &#63; and parentFolderId = &#63;.
3071             *
3072             * <p>
3073             * 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.
3074             * </p>
3075             *
3076             * @param groupId the group ID
3077             * @param parentFolderId the parent folder ID
3078             * @param start the lower bound of the range of document library folders
3079             * @param end the upper bound of the range of document library folders (not inclusive)
3080             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3081             * @return the ordered range of matching document library folders that the user has permission to view
3082             * @throws SystemException if a system exception occurred
3083             */
3084            public List<DLFolder> filterFindByG_P(long groupId, long parentFolderId,
3085                    int start, int end, OrderByComparator orderByComparator)
3086                    throws SystemException {
3087                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3088                            return findByG_P(groupId, parentFolderId, start, end,
3089                                    orderByComparator);
3090                    }
3091    
3092                    StringBundler query = null;
3093    
3094                    if (orderByComparator != null) {
3095                            query = new StringBundler(4 +
3096                                            (orderByComparator.getOrderByFields().length * 3));
3097                    }
3098                    else {
3099                            query = new StringBundler(4);
3100                    }
3101    
3102                    if (getDB().isSupportsInlineDistinct()) {
3103                            query.append(_FILTER_SQL_SELECT_DLFOLDER_WHERE);
3104                    }
3105                    else {
3106                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1);
3107                    }
3108    
3109                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
3110    
3111                    query.append(_FINDER_COLUMN_G_P_PARENTFOLDERID_2);
3112    
3113                    if (!getDB().isSupportsInlineDistinct()) {
3114                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2);
3115                    }
3116    
3117                    if (orderByComparator != null) {
3118                            if (getDB().isSupportsInlineDistinct()) {
3119                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3120                                            orderByComparator);
3121                            }
3122                            else {
3123                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3124                                            orderByComparator);
3125                            }
3126                    }
3127    
3128                    else {
3129                            if (getDB().isSupportsInlineDistinct()) {
3130                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
3131                            }
3132                            else {
3133                                    query.append(DLFolderModelImpl.ORDER_BY_SQL);
3134                            }
3135                    }
3136    
3137                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3138                                    DLFolder.class.getName(),
3139                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3140    
3141                    Session session = null;
3142    
3143                    try {
3144                            session = openSession();
3145    
3146                            SQLQuery q = session.createSQLQuery(sql);
3147    
3148                            if (getDB().isSupportsInlineDistinct()) {
3149                                    q.addEntity(_FILTER_ENTITY_ALIAS, DLFolderImpl.class);
3150                            }
3151                            else {
3152                                    q.addEntity(_FILTER_ENTITY_TABLE, DLFolderImpl.class);
3153                            }
3154    
3155                            QueryPos qPos = QueryPos.getInstance(q);
3156    
3157                            qPos.add(groupId);
3158    
3159                            qPos.add(parentFolderId);
3160    
3161                            return (List<DLFolder>)QueryUtil.list(q, getDialect(), start, end);
3162                    }
3163                    catch (Exception e) {
3164                            throw processException(e);
3165                    }
3166                    finally {
3167                            closeSession(session);
3168                    }
3169            }
3170    
3171            /**
3172             * Returns the document library folders before and after the current document library folder in the ordered set of document library folders that the user has permission to view where groupId = &#63; and parentFolderId = &#63;.
3173             *
3174             * @param folderId the primary key of the current document library folder
3175             * @param groupId the group ID
3176             * @param parentFolderId the parent folder ID
3177             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3178             * @return the previous, current, and next document library folder
3179             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
3180             * @throws SystemException if a system exception occurred
3181             */
3182            public DLFolder[] filterFindByG_P_PrevAndNext(long folderId, long groupId,
3183                    long parentFolderId, OrderByComparator orderByComparator)
3184                    throws NoSuchFolderException, SystemException {
3185                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3186                            return findByG_P_PrevAndNext(folderId, groupId, parentFolderId,
3187                                    orderByComparator);
3188                    }
3189    
3190                    DLFolder dlFolder = findByPrimaryKey(folderId);
3191    
3192                    Session session = null;
3193    
3194                    try {
3195                            session = openSession();
3196    
3197                            DLFolder[] array = new DLFolderImpl[3];
3198    
3199                            array[0] = filterGetByG_P_PrevAndNext(session, dlFolder, groupId,
3200                                            parentFolderId, orderByComparator, true);
3201    
3202                            array[1] = dlFolder;
3203    
3204                            array[2] = filterGetByG_P_PrevAndNext(session, dlFolder, groupId,
3205                                            parentFolderId, orderByComparator, false);
3206    
3207                            return array;
3208                    }
3209                    catch (Exception e) {
3210                            throw processException(e);
3211                    }
3212                    finally {
3213                            closeSession(session);
3214                    }
3215            }
3216    
3217            protected DLFolder filterGetByG_P_PrevAndNext(Session session,
3218                    DLFolder dlFolder, long groupId, long parentFolderId,
3219                    OrderByComparator orderByComparator, boolean previous) {
3220                    StringBundler query = null;
3221    
3222                    if (orderByComparator != null) {
3223                            query = new StringBundler(6 +
3224                                            (orderByComparator.getOrderByFields().length * 6));
3225                    }
3226                    else {
3227                            query = new StringBundler(3);
3228                    }
3229    
3230                    if (getDB().isSupportsInlineDistinct()) {
3231                            query.append(_FILTER_SQL_SELECT_DLFOLDER_WHERE);
3232                    }
3233                    else {
3234                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1);
3235                    }
3236    
3237                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
3238    
3239                    query.append(_FINDER_COLUMN_G_P_PARENTFOLDERID_2);
3240    
3241                    if (!getDB().isSupportsInlineDistinct()) {
3242                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2);
3243                    }
3244    
3245                    if (orderByComparator != null) {
3246                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3247    
3248                            if (orderByConditionFields.length > 0) {
3249                                    query.append(WHERE_AND);
3250                            }
3251    
3252                            for (int i = 0; i < orderByConditionFields.length; i++) {
3253                                    if (getDB().isSupportsInlineDistinct()) {
3254                                            query.append(_ORDER_BY_ENTITY_ALIAS);
3255                                    }
3256                                    else {
3257                                            query.append(_ORDER_BY_ENTITY_TABLE);
3258                                    }
3259    
3260                                    query.append(orderByConditionFields[i]);
3261    
3262                                    if ((i + 1) < orderByConditionFields.length) {
3263                                            if (orderByComparator.isAscending() ^ previous) {
3264                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3265                                            }
3266                                            else {
3267                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3268                                            }
3269                                    }
3270                                    else {
3271                                            if (orderByComparator.isAscending() ^ previous) {
3272                                                    query.append(WHERE_GREATER_THAN);
3273                                            }
3274                                            else {
3275                                                    query.append(WHERE_LESSER_THAN);
3276                                            }
3277                                    }
3278                            }
3279    
3280                            query.append(ORDER_BY_CLAUSE);
3281    
3282                            String[] orderByFields = orderByComparator.getOrderByFields();
3283    
3284                            for (int i = 0; i < orderByFields.length; i++) {
3285                                    if (getDB().isSupportsInlineDistinct()) {
3286                                            query.append(_ORDER_BY_ENTITY_ALIAS);
3287                                    }
3288                                    else {
3289                                            query.append(_ORDER_BY_ENTITY_TABLE);
3290                                    }
3291    
3292                                    query.append(orderByFields[i]);
3293    
3294                                    if ((i + 1) < orderByFields.length) {
3295                                            if (orderByComparator.isAscending() ^ previous) {
3296                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3297                                            }
3298                                            else {
3299                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3300                                            }
3301                                    }
3302                                    else {
3303                                            if (orderByComparator.isAscending() ^ previous) {
3304                                                    query.append(ORDER_BY_ASC);
3305                                            }
3306                                            else {
3307                                                    query.append(ORDER_BY_DESC);
3308                                            }
3309                                    }
3310                            }
3311                    }
3312    
3313                    else {
3314                            if (getDB().isSupportsInlineDistinct()) {
3315                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
3316                            }
3317                            else {
3318                                    query.append(DLFolderModelImpl.ORDER_BY_SQL);
3319                            }
3320                    }
3321    
3322                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3323                                    DLFolder.class.getName(),
3324                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3325    
3326                    SQLQuery q = session.createSQLQuery(sql);
3327    
3328                    q.setFirstResult(0);
3329                    q.setMaxResults(2);
3330    
3331                    if (getDB().isSupportsInlineDistinct()) {
3332                            q.addEntity(_FILTER_ENTITY_ALIAS, DLFolderImpl.class);
3333                    }
3334                    else {
3335                            q.addEntity(_FILTER_ENTITY_TABLE, DLFolderImpl.class);
3336                    }
3337    
3338                    QueryPos qPos = QueryPos.getInstance(q);
3339    
3340                    qPos.add(groupId);
3341    
3342                    qPos.add(parentFolderId);
3343    
3344                    if (orderByComparator != null) {
3345                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
3346    
3347                            for (Object value : values) {
3348                                    qPos.add(value);
3349                            }
3350                    }
3351    
3352                    List<DLFolder> list = q.list();
3353    
3354                    if (list.size() == 2) {
3355                            return list.get(1);
3356                    }
3357                    else {
3358                            return null;
3359                    }
3360            }
3361    
3362            /**
3363             * Returns all the document library folders where parentFolderId = &#63; and name = &#63;.
3364             *
3365             * @param parentFolderId the parent folder ID
3366             * @param name the name
3367             * @return the matching document library folders
3368             * @throws SystemException if a system exception occurred
3369             */
3370            public List<DLFolder> findByP_N(long parentFolderId, String name)
3371                    throws SystemException {
3372                    return findByP_N(parentFolderId, name, QueryUtil.ALL_POS,
3373                            QueryUtil.ALL_POS, null);
3374            }
3375    
3376            /**
3377             * Returns a range of all the document library folders where parentFolderId = &#63; and name = &#63;.
3378             *
3379             * <p>
3380             * 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.
3381             * </p>
3382             *
3383             * @param parentFolderId the parent folder ID
3384             * @param name the name
3385             * @param start the lower bound of the range of document library folders
3386             * @param end the upper bound of the range of document library folders (not inclusive)
3387             * @return the range of matching document library folders
3388             * @throws SystemException if a system exception occurred
3389             */
3390            public List<DLFolder> findByP_N(long parentFolderId, String name,
3391                    int start, int end) throws SystemException {
3392                    return findByP_N(parentFolderId, name, start, end, null);
3393            }
3394    
3395            /**
3396             * Returns an ordered range of all the document library folders where parentFolderId = &#63; and name = &#63;.
3397             *
3398             * <p>
3399             * 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.
3400             * </p>
3401             *
3402             * @param parentFolderId the parent folder ID
3403             * @param name the name
3404             * @param start the lower bound of the range of document library folders
3405             * @param end the upper bound of the range of document library folders (not inclusive)
3406             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3407             * @return the ordered range of matching document library folders
3408             * @throws SystemException if a system exception occurred
3409             */
3410            public List<DLFolder> findByP_N(long parentFolderId, String name,
3411                    int start, int end, OrderByComparator orderByComparator)
3412                    throws SystemException {
3413                    FinderPath finderPath = null;
3414                    Object[] finderArgs = null;
3415    
3416                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3417                                    (orderByComparator == null)) {
3418                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_N;
3419                            finderArgs = new Object[] { parentFolderId, name };
3420                    }
3421                    else {
3422                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_P_N;
3423                            finderArgs = new Object[] {
3424                                            parentFolderId, name,
3425                                            
3426                                            start, end, orderByComparator
3427                                    };
3428                    }
3429    
3430                    List<DLFolder> list = (List<DLFolder>)FinderCacheUtil.getResult(finderPath,
3431                                    finderArgs, this);
3432    
3433                    if ((list != null) && !list.isEmpty()) {
3434                            for (DLFolder dlFolder : list) {
3435                                    if ((parentFolderId != dlFolder.getParentFolderId()) ||
3436                                                    !Validator.equals(name, dlFolder.getName())) {
3437                                            list = null;
3438    
3439                                            break;
3440                                    }
3441                            }
3442                    }
3443    
3444                    if (list == null) {
3445                            StringBundler query = null;
3446    
3447                            if (orderByComparator != null) {
3448                                    query = new StringBundler(4 +
3449                                                    (orderByComparator.getOrderByFields().length * 3));
3450                            }
3451                            else {
3452                                    query = new StringBundler(4);
3453                            }
3454    
3455                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
3456    
3457                            query.append(_FINDER_COLUMN_P_N_PARENTFOLDERID_2);
3458    
3459                            if (name == null) {
3460                                    query.append(_FINDER_COLUMN_P_N_NAME_1);
3461                            }
3462                            else {
3463                                    if (name.equals(StringPool.BLANK)) {
3464                                            query.append(_FINDER_COLUMN_P_N_NAME_3);
3465                                    }
3466                                    else {
3467                                            query.append(_FINDER_COLUMN_P_N_NAME_2);
3468                                    }
3469                            }
3470    
3471                            if (orderByComparator != null) {
3472                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3473                                            orderByComparator);
3474                            }
3475    
3476                            else {
3477                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
3478                            }
3479    
3480                            String sql = query.toString();
3481    
3482                            Session session = null;
3483    
3484                            try {
3485                                    session = openSession();
3486    
3487                                    Query q = session.createQuery(sql);
3488    
3489                                    QueryPos qPos = QueryPos.getInstance(q);
3490    
3491                                    qPos.add(parentFolderId);
3492    
3493                                    if (name != null) {
3494                                            qPos.add(name);
3495                                    }
3496    
3497                                    list = (List<DLFolder>)QueryUtil.list(q, getDialect(), start,
3498                                                    end);
3499                            }
3500                            catch (Exception e) {
3501                                    throw processException(e);
3502                            }
3503                            finally {
3504                                    if (list == null) {
3505                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
3506                                    }
3507                                    else {
3508                                            cacheResult(list);
3509    
3510                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
3511                                    }
3512    
3513                                    closeSession(session);
3514                            }
3515                    }
3516    
3517                    return list;
3518            }
3519    
3520            /**
3521             * Returns the first document library folder in the ordered set where parentFolderId = &#63; and name = &#63;.
3522             *
3523             * @param parentFolderId the parent folder ID
3524             * @param name the name
3525             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3526             * @return the first matching document library folder
3527             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
3528             * @throws SystemException if a system exception occurred
3529             */
3530            public DLFolder findByP_N_First(long parentFolderId, String name,
3531                    OrderByComparator orderByComparator)
3532                    throws NoSuchFolderException, SystemException {
3533                    DLFolder dlFolder = fetchByP_N_First(parentFolderId, name,
3534                                    orderByComparator);
3535    
3536                    if (dlFolder != null) {
3537                            return dlFolder;
3538                    }
3539    
3540                    StringBundler msg = new StringBundler(6);
3541    
3542                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3543    
3544                    msg.append("parentFolderId=");
3545                    msg.append(parentFolderId);
3546    
3547                    msg.append(", name=");
3548                    msg.append(name);
3549    
3550                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3551    
3552                    throw new NoSuchFolderException(msg.toString());
3553            }
3554    
3555            /**
3556             * Returns the first document library folder in the ordered set where parentFolderId = &#63; and name = &#63;.
3557             *
3558             * @param parentFolderId the parent folder ID
3559             * @param name the name
3560             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3561             * @return the first matching document library folder, or <code>null</code> if a matching document library folder could not be found
3562             * @throws SystemException if a system exception occurred
3563             */
3564            public DLFolder fetchByP_N_First(long parentFolderId, String name,
3565                    OrderByComparator orderByComparator) throws SystemException {
3566                    List<DLFolder> list = findByP_N(parentFolderId, name, 0, 1,
3567                                    orderByComparator);
3568    
3569                    if (!list.isEmpty()) {
3570                            return list.get(0);
3571                    }
3572    
3573                    return null;
3574            }
3575    
3576            /**
3577             * Returns the last document library folder in the ordered set where parentFolderId = &#63; and name = &#63;.
3578             *
3579             * @param parentFolderId the parent folder ID
3580             * @param name the name
3581             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3582             * @return the last matching document library folder
3583             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
3584             * @throws SystemException if a system exception occurred
3585             */
3586            public DLFolder findByP_N_Last(long parentFolderId, String name,
3587                    OrderByComparator orderByComparator)
3588                    throws NoSuchFolderException, SystemException {
3589                    DLFolder dlFolder = fetchByP_N_Last(parentFolderId, name,
3590                                    orderByComparator);
3591    
3592                    if (dlFolder != null) {
3593                            return dlFolder;
3594                    }
3595    
3596                    StringBundler msg = new StringBundler(6);
3597    
3598                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3599    
3600                    msg.append("parentFolderId=");
3601                    msg.append(parentFolderId);
3602    
3603                    msg.append(", name=");
3604                    msg.append(name);
3605    
3606                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3607    
3608                    throw new NoSuchFolderException(msg.toString());
3609            }
3610    
3611            /**
3612             * Returns the last document library folder in the ordered set where parentFolderId = &#63; and name = &#63;.
3613             *
3614             * @param parentFolderId the parent folder ID
3615             * @param name the name
3616             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3617             * @return the last matching document library folder, or <code>null</code> if a matching document library folder could not be found
3618             * @throws SystemException if a system exception occurred
3619             */
3620            public DLFolder fetchByP_N_Last(long parentFolderId, String name,
3621                    OrderByComparator orderByComparator) throws SystemException {
3622                    int count = countByP_N(parentFolderId, name);
3623    
3624                    List<DLFolder> list = findByP_N(parentFolderId, name, count - 1, count,
3625                                    orderByComparator);
3626    
3627                    if (!list.isEmpty()) {
3628                            return list.get(0);
3629                    }
3630    
3631                    return null;
3632            }
3633    
3634            /**
3635             * Returns the document library folders before and after the current document library folder in the ordered set where parentFolderId = &#63; and name = &#63;.
3636             *
3637             * @param folderId the primary key of the current document library folder
3638             * @param parentFolderId the parent folder ID
3639             * @param name the name
3640             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3641             * @return the previous, current, and next document library folder
3642             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
3643             * @throws SystemException if a system exception occurred
3644             */
3645            public DLFolder[] findByP_N_PrevAndNext(long folderId, long parentFolderId,
3646                    String name, OrderByComparator orderByComparator)
3647                    throws NoSuchFolderException, SystemException {
3648                    DLFolder dlFolder = findByPrimaryKey(folderId);
3649    
3650                    Session session = null;
3651    
3652                    try {
3653                            session = openSession();
3654    
3655                            DLFolder[] array = new DLFolderImpl[3];
3656    
3657                            array[0] = getByP_N_PrevAndNext(session, dlFolder, parentFolderId,
3658                                            name, orderByComparator, true);
3659    
3660                            array[1] = dlFolder;
3661    
3662                            array[2] = getByP_N_PrevAndNext(session, dlFolder, parentFolderId,
3663                                            name, orderByComparator, false);
3664    
3665                            return array;
3666                    }
3667                    catch (Exception e) {
3668                            throw processException(e);
3669                    }
3670                    finally {
3671                            closeSession(session);
3672                    }
3673            }
3674    
3675            protected DLFolder getByP_N_PrevAndNext(Session session, DLFolder dlFolder,
3676                    long parentFolderId, String name, OrderByComparator orderByComparator,
3677                    boolean previous) {
3678                    StringBundler query = null;
3679    
3680                    if (orderByComparator != null) {
3681                            query = new StringBundler(6 +
3682                                            (orderByComparator.getOrderByFields().length * 6));
3683                    }
3684                    else {
3685                            query = new StringBundler(3);
3686                    }
3687    
3688                    query.append(_SQL_SELECT_DLFOLDER_WHERE);
3689    
3690                    query.append(_FINDER_COLUMN_P_N_PARENTFOLDERID_2);
3691    
3692                    if (name == null) {
3693                            query.append(_FINDER_COLUMN_P_N_NAME_1);
3694                    }
3695                    else {
3696                            if (name.equals(StringPool.BLANK)) {
3697                                    query.append(_FINDER_COLUMN_P_N_NAME_3);
3698                            }
3699                            else {
3700                                    query.append(_FINDER_COLUMN_P_N_NAME_2);
3701                            }
3702                    }
3703    
3704                    if (orderByComparator != null) {
3705                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3706    
3707                            if (orderByConditionFields.length > 0) {
3708                                    query.append(WHERE_AND);
3709                            }
3710    
3711                            for (int i = 0; i < orderByConditionFields.length; i++) {
3712                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3713                                    query.append(orderByConditionFields[i]);
3714    
3715                                    if ((i + 1) < orderByConditionFields.length) {
3716                                            if (orderByComparator.isAscending() ^ previous) {
3717                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3718                                            }
3719                                            else {
3720                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3721                                            }
3722                                    }
3723                                    else {
3724                                            if (orderByComparator.isAscending() ^ previous) {
3725                                                    query.append(WHERE_GREATER_THAN);
3726                                            }
3727                                            else {
3728                                                    query.append(WHERE_LESSER_THAN);
3729                                            }
3730                                    }
3731                            }
3732    
3733                            query.append(ORDER_BY_CLAUSE);
3734    
3735                            String[] orderByFields = orderByComparator.getOrderByFields();
3736    
3737                            for (int i = 0; i < orderByFields.length; i++) {
3738                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3739                                    query.append(orderByFields[i]);
3740    
3741                                    if ((i + 1) < orderByFields.length) {
3742                                            if (orderByComparator.isAscending() ^ previous) {
3743                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3744                                            }
3745                                            else {
3746                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3747                                            }
3748                                    }
3749                                    else {
3750                                            if (orderByComparator.isAscending() ^ previous) {
3751                                                    query.append(ORDER_BY_ASC);
3752                                            }
3753                                            else {
3754                                                    query.append(ORDER_BY_DESC);
3755                                            }
3756                                    }
3757                            }
3758                    }
3759    
3760                    else {
3761                            query.append(DLFolderModelImpl.ORDER_BY_JPQL);
3762                    }
3763    
3764                    String sql = query.toString();
3765    
3766                    Query q = session.createQuery(sql);
3767    
3768                    q.setFirstResult(0);
3769                    q.setMaxResults(2);
3770    
3771                    QueryPos qPos = QueryPos.getInstance(q);
3772    
3773                    qPos.add(parentFolderId);
3774    
3775                    if (name != null) {
3776                            qPos.add(name);
3777                    }
3778    
3779                    if (orderByComparator != null) {
3780                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
3781    
3782                            for (Object value : values) {
3783                                    qPos.add(value);
3784                            }
3785                    }
3786    
3787                    List<DLFolder> list = q.list();
3788    
3789                    if (list.size() == 2) {
3790                            return list.get(1);
3791                    }
3792                    else {
3793                            return null;
3794                    }
3795            }
3796    
3797            /**
3798             * Returns all the document library folders where groupId = &#63; and parentFolderId = &#63; and mountPoint = &#63;.
3799             *
3800             * @param groupId the group ID
3801             * @param parentFolderId the parent folder ID
3802             * @param mountPoint the mount point
3803             * @return the matching document library folders
3804             * @throws SystemException if a system exception occurred
3805             */
3806            public List<DLFolder> findByG_P_M(long groupId, long parentFolderId,
3807                    boolean mountPoint) throws SystemException {
3808                    return findByG_P_M(groupId, parentFolderId, mountPoint,
3809                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3810            }
3811    
3812            /**
3813             * Returns a range of all the document library folders where groupId = &#63; and parentFolderId = &#63; and mountPoint = &#63;.
3814             *
3815             * <p>
3816             * 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.
3817             * </p>
3818             *
3819             * @param groupId the group ID
3820             * @param parentFolderId the parent folder ID
3821             * @param mountPoint the mount point
3822             * @param start the lower bound of the range of document library folders
3823             * @param end the upper bound of the range of document library folders (not inclusive)
3824             * @return the range of matching document library folders
3825             * @throws SystemException if a system exception occurred
3826             */
3827            public List<DLFolder> findByG_P_M(long groupId, long parentFolderId,
3828                    boolean mountPoint, int start, int end) throws SystemException {
3829                    return findByG_P_M(groupId, parentFolderId, mountPoint, start, end, null);
3830            }
3831    
3832            /**
3833             * Returns an ordered range of all the document library folders where groupId = &#63; and parentFolderId = &#63; and mountPoint = &#63;.
3834             *
3835             * <p>
3836             * 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.
3837             * </p>
3838             *
3839             * @param groupId the group ID
3840             * @param parentFolderId the parent folder ID
3841             * @param mountPoint the mount point
3842             * @param start the lower bound of the range of document library folders
3843             * @param end the upper bound of the range of document library folders (not inclusive)
3844             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3845             * @return the ordered range of matching document library folders
3846             * @throws SystemException if a system exception occurred
3847             */
3848            public List<DLFolder> findByG_P_M(long groupId, long parentFolderId,
3849                    boolean mountPoint, int start, int end,
3850                    OrderByComparator orderByComparator) throws SystemException {
3851                    FinderPath finderPath = null;
3852                    Object[] finderArgs = null;
3853    
3854                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3855                                    (orderByComparator == null)) {
3856                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_M;
3857                            finderArgs = new Object[] { groupId, parentFolderId, mountPoint };
3858                    }
3859                    else {
3860                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_M;
3861                            finderArgs = new Object[] {
3862                                            groupId, parentFolderId, mountPoint,
3863                                            
3864                                            start, end, orderByComparator
3865                                    };
3866                    }
3867    
3868                    List<DLFolder> list = (List<DLFolder>)FinderCacheUtil.getResult(finderPath,
3869                                    finderArgs, this);
3870    
3871                    if ((list != null) && !list.isEmpty()) {
3872                            for (DLFolder dlFolder : list) {
3873                                    if ((groupId != dlFolder.getGroupId()) ||
3874                                                    (parentFolderId != dlFolder.getParentFolderId()) ||
3875                                                    (mountPoint != dlFolder.getMountPoint())) {
3876                                            list = null;
3877    
3878                                            break;
3879                                    }
3880                            }
3881                    }
3882    
3883                    if (list == null) {
3884                            StringBundler query = null;
3885    
3886                            if (orderByComparator != null) {
3887                                    query = new StringBundler(5 +
3888                                                    (orderByComparator.getOrderByFields().length * 3));
3889                            }
3890                            else {
3891                                    query = new StringBundler(5);
3892                            }
3893    
3894                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
3895    
3896                            query.append(_FINDER_COLUMN_G_P_M_GROUPID_2);
3897    
3898                            query.append(_FINDER_COLUMN_G_P_M_PARENTFOLDERID_2);
3899    
3900                            query.append(_FINDER_COLUMN_G_P_M_MOUNTPOINT_2);
3901    
3902                            if (orderByComparator != null) {
3903                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3904                                            orderByComparator);
3905                            }
3906    
3907                            else {
3908                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
3909                            }
3910    
3911                            String sql = query.toString();
3912    
3913                            Session session = null;
3914    
3915                            try {
3916                                    session = openSession();
3917    
3918                                    Query q = session.createQuery(sql);
3919    
3920                                    QueryPos qPos = QueryPos.getInstance(q);
3921    
3922                                    qPos.add(groupId);
3923    
3924                                    qPos.add(parentFolderId);
3925    
3926                                    qPos.add(mountPoint);
3927    
3928                                    list = (List<DLFolder>)QueryUtil.list(q, getDialect(), start,
3929                                                    end);
3930                            }
3931                            catch (Exception e) {
3932                                    throw processException(e);
3933                            }
3934                            finally {
3935                                    if (list == null) {
3936                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
3937                                    }
3938                                    else {
3939                                            cacheResult(list);
3940    
3941                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
3942                                    }
3943    
3944                                    closeSession(session);
3945                            }
3946                    }
3947    
3948                    return list;
3949            }
3950    
3951            /**
3952             * Returns the first document library folder in the ordered set where groupId = &#63; and parentFolderId = &#63; and mountPoint = &#63;.
3953             *
3954             * @param groupId the group ID
3955             * @param parentFolderId the parent folder ID
3956             * @param mountPoint the mount point
3957             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3958             * @return the first matching document library folder
3959             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
3960             * @throws SystemException if a system exception occurred
3961             */
3962            public DLFolder findByG_P_M_First(long groupId, long parentFolderId,
3963                    boolean mountPoint, OrderByComparator orderByComparator)
3964                    throws NoSuchFolderException, SystemException {
3965                    DLFolder dlFolder = fetchByG_P_M_First(groupId, parentFolderId,
3966                                    mountPoint, orderByComparator);
3967    
3968                    if (dlFolder != null) {
3969                            return dlFolder;
3970                    }
3971    
3972                    StringBundler msg = new StringBundler(8);
3973    
3974                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3975    
3976                    msg.append("groupId=");
3977                    msg.append(groupId);
3978    
3979                    msg.append(", parentFolderId=");
3980                    msg.append(parentFolderId);
3981    
3982                    msg.append(", mountPoint=");
3983                    msg.append(mountPoint);
3984    
3985                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3986    
3987                    throw new NoSuchFolderException(msg.toString());
3988            }
3989    
3990            /**
3991             * Returns the first document library folder in the ordered set where groupId = &#63; and parentFolderId = &#63; and mountPoint = &#63;.
3992             *
3993             * @param groupId the group ID
3994             * @param parentFolderId the parent folder ID
3995             * @param mountPoint the mount point
3996             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3997             * @return the first matching document library folder, or <code>null</code> if a matching document library folder could not be found
3998             * @throws SystemException if a system exception occurred
3999             */
4000            public DLFolder fetchByG_P_M_First(long groupId, long parentFolderId,
4001                    boolean mountPoint, OrderByComparator orderByComparator)
4002                    throws SystemException {
4003                    List<DLFolder> list = findByG_P_M(groupId, parentFolderId, mountPoint,
4004                                    0, 1, orderByComparator);
4005    
4006                    if (!list.isEmpty()) {
4007                            return list.get(0);
4008                    }
4009    
4010                    return null;
4011            }
4012    
4013            /**
4014             * Returns the last document library folder in the ordered set where groupId = &#63; and parentFolderId = &#63; and mountPoint = &#63;.
4015             *
4016             * @param groupId the group ID
4017             * @param parentFolderId the parent folder ID
4018             * @param mountPoint the mount point
4019             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4020             * @return the last matching document library folder
4021             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
4022             * @throws SystemException if a system exception occurred
4023             */
4024            public DLFolder findByG_P_M_Last(long groupId, long parentFolderId,
4025                    boolean mountPoint, OrderByComparator orderByComparator)
4026                    throws NoSuchFolderException, SystemException {
4027                    DLFolder dlFolder = fetchByG_P_M_Last(groupId, parentFolderId,
4028                                    mountPoint, orderByComparator);
4029    
4030                    if (dlFolder != null) {
4031                            return dlFolder;
4032                    }
4033    
4034                    StringBundler msg = new StringBundler(8);
4035    
4036                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4037    
4038                    msg.append("groupId=");
4039                    msg.append(groupId);
4040    
4041                    msg.append(", parentFolderId=");
4042                    msg.append(parentFolderId);
4043    
4044                    msg.append(", mountPoint=");
4045                    msg.append(mountPoint);
4046    
4047                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4048    
4049                    throw new NoSuchFolderException(msg.toString());
4050            }
4051    
4052            /**
4053             * Returns the last document library folder in the ordered set where groupId = &#63; and parentFolderId = &#63; and mountPoint = &#63;.
4054             *
4055             * @param groupId the group ID
4056             * @param parentFolderId the parent folder ID
4057             * @param mountPoint the mount point
4058             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4059             * @return the last matching document library folder, or <code>null</code> if a matching document library folder could not be found
4060             * @throws SystemException if a system exception occurred
4061             */
4062            public DLFolder fetchByG_P_M_Last(long groupId, long parentFolderId,
4063                    boolean mountPoint, OrderByComparator orderByComparator)
4064                    throws SystemException {
4065                    int count = countByG_P_M(groupId, parentFolderId, mountPoint);
4066    
4067                    List<DLFolder> list = findByG_P_M(groupId, parentFolderId, mountPoint,
4068                                    count - 1, count, orderByComparator);
4069    
4070                    if (!list.isEmpty()) {
4071                            return list.get(0);
4072                    }
4073    
4074                    return null;
4075            }
4076    
4077            /**
4078             * Returns the document library folders before and after the current document library folder in the ordered set where groupId = &#63; and parentFolderId = &#63; and mountPoint = &#63;.
4079             *
4080             * @param folderId the primary key of the current document library folder
4081             * @param groupId the group ID
4082             * @param parentFolderId the parent folder ID
4083             * @param mountPoint the mount point
4084             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4085             * @return the previous, current, and next document library folder
4086             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
4087             * @throws SystemException if a system exception occurred
4088             */
4089            public DLFolder[] findByG_P_M_PrevAndNext(long folderId, long groupId,
4090                    long parentFolderId, boolean mountPoint,
4091                    OrderByComparator orderByComparator)
4092                    throws NoSuchFolderException, SystemException {
4093                    DLFolder dlFolder = findByPrimaryKey(folderId);
4094    
4095                    Session session = null;
4096    
4097                    try {
4098                            session = openSession();
4099    
4100                            DLFolder[] array = new DLFolderImpl[3];
4101    
4102                            array[0] = getByG_P_M_PrevAndNext(session, dlFolder, groupId,
4103                                            parentFolderId, mountPoint, orderByComparator, true);
4104    
4105                            array[1] = dlFolder;
4106    
4107                            array[2] = getByG_P_M_PrevAndNext(session, dlFolder, groupId,
4108                                            parentFolderId, mountPoint, orderByComparator, false);
4109    
4110                            return array;
4111                    }
4112                    catch (Exception e) {
4113                            throw processException(e);
4114                    }
4115                    finally {
4116                            closeSession(session);
4117                    }
4118            }
4119    
4120            protected DLFolder getByG_P_M_PrevAndNext(Session session,
4121                    DLFolder dlFolder, long groupId, long parentFolderId,
4122                    boolean mountPoint, OrderByComparator orderByComparator,
4123                    boolean previous) {
4124                    StringBundler query = null;
4125    
4126                    if (orderByComparator != null) {
4127                            query = new StringBundler(6 +
4128                                            (orderByComparator.getOrderByFields().length * 6));
4129                    }
4130                    else {
4131                            query = new StringBundler(3);
4132                    }
4133    
4134                    query.append(_SQL_SELECT_DLFOLDER_WHERE);
4135    
4136                    query.append(_FINDER_COLUMN_G_P_M_GROUPID_2);
4137    
4138                    query.append(_FINDER_COLUMN_G_P_M_PARENTFOLDERID_2);
4139    
4140                    query.append(_FINDER_COLUMN_G_P_M_MOUNTPOINT_2);
4141    
4142                    if (orderByComparator != null) {
4143                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4144    
4145                            if (orderByConditionFields.length > 0) {
4146                                    query.append(WHERE_AND);
4147                            }
4148    
4149                            for (int i = 0; i < orderByConditionFields.length; i++) {
4150                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4151                                    query.append(orderByConditionFields[i]);
4152    
4153                                    if ((i + 1) < orderByConditionFields.length) {
4154                                            if (orderByComparator.isAscending() ^ previous) {
4155                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4156                                            }
4157                                            else {
4158                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4159                                            }
4160                                    }
4161                                    else {
4162                                            if (orderByComparator.isAscending() ^ previous) {
4163                                                    query.append(WHERE_GREATER_THAN);
4164                                            }
4165                                            else {
4166                                                    query.append(WHERE_LESSER_THAN);
4167                                            }
4168                                    }
4169                            }
4170    
4171                            query.append(ORDER_BY_CLAUSE);
4172    
4173                            String[] orderByFields = orderByComparator.getOrderByFields();
4174    
4175                            for (int i = 0; i < orderByFields.length; i++) {
4176                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4177                                    query.append(orderByFields[i]);
4178    
4179                                    if ((i + 1) < orderByFields.length) {
4180                                            if (orderByComparator.isAscending() ^ previous) {
4181                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4182                                            }
4183                                            else {
4184                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4185                                            }
4186                                    }
4187                                    else {
4188                                            if (orderByComparator.isAscending() ^ previous) {
4189                                                    query.append(ORDER_BY_ASC);
4190                                            }
4191                                            else {
4192                                                    query.append(ORDER_BY_DESC);
4193                                            }
4194                                    }
4195                            }
4196                    }
4197    
4198                    else {
4199                            query.append(DLFolderModelImpl.ORDER_BY_JPQL);
4200                    }
4201    
4202                    String sql = query.toString();
4203    
4204                    Query q = session.createQuery(sql);
4205    
4206                    q.setFirstResult(0);
4207                    q.setMaxResults(2);
4208    
4209                    QueryPos qPos = QueryPos.getInstance(q);
4210    
4211                    qPos.add(groupId);
4212    
4213                    qPos.add(parentFolderId);
4214    
4215                    qPos.add(mountPoint);
4216    
4217                    if (orderByComparator != null) {
4218                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
4219    
4220                            for (Object value : values) {
4221                                    qPos.add(value);
4222                            }
4223                    }
4224    
4225                    List<DLFolder> list = q.list();
4226    
4227                    if (list.size() == 2) {
4228                            return list.get(1);
4229                    }
4230                    else {
4231                            return null;
4232                    }
4233            }
4234    
4235            /**
4236             * Returns all the document library folders that the user has permission to view where groupId = &#63; and parentFolderId = &#63; and mountPoint = &#63;.
4237             *
4238             * @param groupId the group ID
4239             * @param parentFolderId the parent folder ID
4240             * @param mountPoint the mount point
4241             * @return the matching document library folders that the user has permission to view
4242             * @throws SystemException if a system exception occurred
4243             */
4244            public List<DLFolder> filterFindByG_P_M(long groupId, long parentFolderId,
4245                    boolean mountPoint) throws SystemException {
4246                    return filterFindByG_P_M(groupId, parentFolderId, mountPoint,
4247                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
4248            }
4249    
4250            /**
4251             * Returns a range of all the document library folders that the user has permission to view where groupId = &#63; and parentFolderId = &#63; and mountPoint = &#63;.
4252             *
4253             * <p>
4254             * 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.
4255             * </p>
4256             *
4257             * @param groupId the group ID
4258             * @param parentFolderId the parent folder ID
4259             * @param mountPoint the mount point
4260             * @param start the lower bound of the range of document library folders
4261             * @param end the upper bound of the range of document library folders (not inclusive)
4262             * @return the range of matching document library folders that the user has permission to view
4263             * @throws SystemException if a system exception occurred
4264             */
4265            public List<DLFolder> filterFindByG_P_M(long groupId, long parentFolderId,
4266                    boolean mountPoint, int start, int end) throws SystemException {
4267                    return filterFindByG_P_M(groupId, parentFolderId, mountPoint, start,
4268                            end, null);
4269            }
4270    
4271            /**
4272             * Returns an ordered range of all the document library folders that the user has permissions to view where groupId = &#63; and parentFolderId = &#63; and mountPoint = &#63;.
4273             *
4274             * <p>
4275             * 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.
4276             * </p>
4277             *
4278             * @param groupId the group ID
4279             * @param parentFolderId the parent folder ID
4280             * @param mountPoint the mount point
4281             * @param start the lower bound of the range of document library folders
4282             * @param end the upper bound of the range of document library folders (not inclusive)
4283             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4284             * @return the ordered range of matching document library folders that the user has permission to view
4285             * @throws SystemException if a system exception occurred
4286             */
4287            public List<DLFolder> filterFindByG_P_M(long groupId, long parentFolderId,
4288                    boolean mountPoint, int start, int end,
4289                    OrderByComparator orderByComparator) throws SystemException {
4290                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4291                            return findByG_P_M(groupId, parentFolderId, mountPoint, start, end,
4292                                    orderByComparator);
4293                    }
4294    
4295                    StringBundler query = null;
4296    
4297                    if (orderByComparator != null) {
4298                            query = new StringBundler(5 +
4299                                            (orderByComparator.getOrderByFields().length * 3));
4300                    }
4301                    else {
4302                            query = new StringBundler(5);
4303                    }
4304    
4305                    if (getDB().isSupportsInlineDistinct()) {
4306                            query.append(_FILTER_SQL_SELECT_DLFOLDER_WHERE);
4307                    }
4308                    else {
4309                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1);
4310                    }
4311    
4312                    query.append(_FINDER_COLUMN_G_P_M_GROUPID_2);
4313    
4314                    query.append(_FINDER_COLUMN_G_P_M_PARENTFOLDERID_2);
4315    
4316                    query.append(_FINDER_COLUMN_G_P_M_MOUNTPOINT_2);
4317    
4318                    if (!getDB().isSupportsInlineDistinct()) {
4319                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2);
4320                    }
4321    
4322                    if (orderByComparator != null) {
4323                            if (getDB().isSupportsInlineDistinct()) {
4324                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4325                                            orderByComparator);
4326                            }
4327                            else {
4328                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
4329                                            orderByComparator);
4330                            }
4331                    }
4332    
4333                    else {
4334                            if (getDB().isSupportsInlineDistinct()) {
4335                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
4336                            }
4337                            else {
4338                                    query.append(DLFolderModelImpl.ORDER_BY_SQL);
4339                            }
4340                    }
4341    
4342                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4343                                    DLFolder.class.getName(),
4344                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4345    
4346                    Session session = null;
4347    
4348                    try {
4349                            session = openSession();
4350    
4351                            SQLQuery q = session.createSQLQuery(sql);
4352    
4353                            if (getDB().isSupportsInlineDistinct()) {
4354                                    q.addEntity(_FILTER_ENTITY_ALIAS, DLFolderImpl.class);
4355                            }
4356                            else {
4357                                    q.addEntity(_FILTER_ENTITY_TABLE, DLFolderImpl.class);
4358                            }
4359    
4360                            QueryPos qPos = QueryPos.getInstance(q);
4361    
4362                            qPos.add(groupId);
4363    
4364                            qPos.add(parentFolderId);
4365    
4366                            qPos.add(mountPoint);
4367    
4368                            return (List<DLFolder>)QueryUtil.list(q, getDialect(), start, end);
4369                    }
4370                    catch (Exception e) {
4371                            throw processException(e);
4372                    }
4373                    finally {
4374                            closeSession(session);
4375                    }
4376            }
4377    
4378            /**
4379             * Returns the document library folders before and after the current document library folder in the ordered set of document library folders that the user has permission to view where groupId = &#63; and parentFolderId = &#63; and mountPoint = &#63;.
4380             *
4381             * @param folderId the primary key of the current document library folder
4382             * @param groupId the group ID
4383             * @param parentFolderId the parent folder ID
4384             * @param mountPoint the mount point
4385             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4386             * @return the previous, current, and next document library folder
4387             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
4388             * @throws SystemException if a system exception occurred
4389             */
4390            public DLFolder[] filterFindByG_P_M_PrevAndNext(long folderId,
4391                    long groupId, long parentFolderId, boolean mountPoint,
4392                    OrderByComparator orderByComparator)
4393                    throws NoSuchFolderException, SystemException {
4394                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4395                            return findByG_P_M_PrevAndNext(folderId, groupId, parentFolderId,
4396                                    mountPoint, orderByComparator);
4397                    }
4398    
4399                    DLFolder dlFolder = findByPrimaryKey(folderId);
4400    
4401                    Session session = null;
4402    
4403                    try {
4404                            session = openSession();
4405    
4406                            DLFolder[] array = new DLFolderImpl[3];
4407    
4408                            array[0] = filterGetByG_P_M_PrevAndNext(session, dlFolder, groupId,
4409                                            parentFolderId, mountPoint, orderByComparator, true);
4410    
4411                            array[1] = dlFolder;
4412    
4413                            array[2] = filterGetByG_P_M_PrevAndNext(session, dlFolder, groupId,
4414                                            parentFolderId, mountPoint, orderByComparator, false);
4415    
4416                            return array;
4417                    }
4418                    catch (Exception e) {
4419                            throw processException(e);
4420                    }
4421                    finally {
4422                            closeSession(session);
4423                    }
4424            }
4425    
4426            protected DLFolder filterGetByG_P_M_PrevAndNext(Session session,
4427                    DLFolder dlFolder, long groupId, long parentFolderId,
4428                    boolean mountPoint, OrderByComparator orderByComparator,
4429                    boolean previous) {
4430                    StringBundler query = null;
4431    
4432                    if (orderByComparator != null) {
4433                            query = new StringBundler(6 +
4434                                            (orderByComparator.getOrderByFields().length * 6));
4435                    }
4436                    else {
4437                            query = new StringBundler(3);
4438                    }
4439    
4440                    if (getDB().isSupportsInlineDistinct()) {
4441                            query.append(_FILTER_SQL_SELECT_DLFOLDER_WHERE);
4442                    }
4443                    else {
4444                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1);
4445                    }
4446    
4447                    query.append(_FINDER_COLUMN_G_P_M_GROUPID_2);
4448    
4449                    query.append(_FINDER_COLUMN_G_P_M_PARENTFOLDERID_2);
4450    
4451                    query.append(_FINDER_COLUMN_G_P_M_MOUNTPOINT_2);
4452    
4453                    if (!getDB().isSupportsInlineDistinct()) {
4454                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2);
4455                    }
4456    
4457                    if (orderByComparator != null) {
4458                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4459    
4460                            if (orderByConditionFields.length > 0) {
4461                                    query.append(WHERE_AND);
4462                            }
4463    
4464                            for (int i = 0; i < orderByConditionFields.length; i++) {
4465                                    if (getDB().isSupportsInlineDistinct()) {
4466                                            query.append(_ORDER_BY_ENTITY_ALIAS);
4467                                    }
4468                                    else {
4469                                            query.append(_ORDER_BY_ENTITY_TABLE);
4470                                    }
4471    
4472                                    query.append(orderByConditionFields[i]);
4473    
4474                                    if ((i + 1) < orderByConditionFields.length) {
4475                                            if (orderByComparator.isAscending() ^ previous) {
4476                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4477                                            }
4478                                            else {
4479                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4480                                            }
4481                                    }
4482                                    else {
4483                                            if (orderByComparator.isAscending() ^ previous) {
4484                                                    query.append(WHERE_GREATER_THAN);
4485                                            }
4486                                            else {
4487                                                    query.append(WHERE_LESSER_THAN);
4488                                            }
4489                                    }
4490                            }
4491    
4492                            query.append(ORDER_BY_CLAUSE);
4493    
4494                            String[] orderByFields = orderByComparator.getOrderByFields();
4495    
4496                            for (int i = 0; i < orderByFields.length; i++) {
4497                                    if (getDB().isSupportsInlineDistinct()) {
4498                                            query.append(_ORDER_BY_ENTITY_ALIAS);
4499                                    }
4500                                    else {
4501                                            query.append(_ORDER_BY_ENTITY_TABLE);
4502                                    }
4503    
4504                                    query.append(orderByFields[i]);
4505    
4506                                    if ((i + 1) < orderByFields.length) {
4507                                            if (orderByComparator.isAscending() ^ previous) {
4508                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4509                                            }
4510                                            else {
4511                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4512                                            }
4513                                    }
4514                                    else {
4515                                            if (orderByComparator.isAscending() ^ previous) {
4516                                                    query.append(ORDER_BY_ASC);
4517                                            }
4518                                            else {
4519                                                    query.append(ORDER_BY_DESC);
4520                                            }
4521                                    }
4522                            }
4523                    }
4524    
4525                    else {
4526                            if (getDB().isSupportsInlineDistinct()) {
4527                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
4528                            }
4529                            else {
4530                                    query.append(DLFolderModelImpl.ORDER_BY_SQL);
4531                            }
4532                    }
4533    
4534                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4535                                    DLFolder.class.getName(),
4536                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4537    
4538                    SQLQuery q = session.createSQLQuery(sql);
4539    
4540                    q.setFirstResult(0);
4541                    q.setMaxResults(2);
4542    
4543                    if (getDB().isSupportsInlineDistinct()) {
4544                            q.addEntity(_FILTER_ENTITY_ALIAS, DLFolderImpl.class);
4545                    }
4546                    else {
4547                            q.addEntity(_FILTER_ENTITY_TABLE, DLFolderImpl.class);
4548                    }
4549    
4550                    QueryPos qPos = QueryPos.getInstance(q);
4551    
4552                    qPos.add(groupId);
4553    
4554                    qPos.add(parentFolderId);
4555    
4556                    qPos.add(mountPoint);
4557    
4558                    if (orderByComparator != null) {
4559                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
4560    
4561                            for (Object value : values) {
4562                                    qPos.add(value);
4563                            }
4564                    }
4565    
4566                    List<DLFolder> list = q.list();
4567    
4568                    if (list.size() == 2) {
4569                            return list.get(1);
4570                    }
4571                    else {
4572                            return null;
4573                    }
4574            }
4575    
4576            /**
4577             * Returns the document library folder where groupId = &#63; and parentFolderId = &#63; and name = &#63; or throws a {@link com.liferay.portlet.documentlibrary.NoSuchFolderException} if it could not be found.
4578             *
4579             * @param groupId the group ID
4580             * @param parentFolderId the parent folder ID
4581             * @param name the name
4582             * @return the matching document library folder
4583             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
4584             * @throws SystemException if a system exception occurred
4585             */
4586            public DLFolder findByG_P_N(long groupId, long parentFolderId, String name)
4587                    throws NoSuchFolderException, SystemException {
4588                    DLFolder dlFolder = fetchByG_P_N(groupId, parentFolderId, name);
4589    
4590                    if (dlFolder == null) {
4591                            StringBundler msg = new StringBundler(8);
4592    
4593                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4594    
4595                            msg.append("groupId=");
4596                            msg.append(groupId);
4597    
4598                            msg.append(", parentFolderId=");
4599                            msg.append(parentFolderId);
4600    
4601                            msg.append(", name=");
4602                            msg.append(name);
4603    
4604                            msg.append(StringPool.CLOSE_CURLY_BRACE);
4605    
4606                            if (_log.isWarnEnabled()) {
4607                                    _log.warn(msg.toString());
4608                            }
4609    
4610                            throw new NoSuchFolderException(msg.toString());
4611                    }
4612    
4613                    return dlFolder;
4614            }
4615    
4616            /**
4617             * Returns the document library 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.
4618             *
4619             * @param groupId the group ID
4620             * @param parentFolderId the parent folder ID
4621             * @param name the name
4622             * @return the matching document library folder, or <code>null</code> if a matching document library folder could not be found
4623             * @throws SystemException if a system exception occurred
4624             */
4625            public DLFolder fetchByG_P_N(long groupId, long parentFolderId, String name)
4626                    throws SystemException {
4627                    return fetchByG_P_N(groupId, parentFolderId, name, true);
4628            }
4629    
4630            /**
4631             * Returns the document library 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.
4632             *
4633             * @param groupId the group ID
4634             * @param parentFolderId the parent folder ID
4635             * @param name the name
4636             * @param retrieveFromCache whether to use the finder cache
4637             * @return the matching document library folder, or <code>null</code> if a matching document library folder could not be found
4638             * @throws SystemException if a system exception occurred
4639             */
4640            public DLFolder fetchByG_P_N(long groupId, long parentFolderId,
4641                    String name, boolean retrieveFromCache) throws SystemException {
4642                    Object[] finderArgs = new Object[] { groupId, parentFolderId, name };
4643    
4644                    Object result = null;
4645    
4646                    if (retrieveFromCache) {
4647                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_P_N,
4648                                            finderArgs, this);
4649                    }
4650    
4651                    if (result instanceof DLFolder) {
4652                            DLFolder dlFolder = (DLFolder)result;
4653    
4654                            if ((groupId != dlFolder.getGroupId()) ||
4655                                            (parentFolderId != dlFolder.getParentFolderId()) ||
4656                                            !Validator.equals(name, dlFolder.getName())) {
4657                                    result = null;
4658                            }
4659                    }
4660    
4661                    if (result == null) {
4662                            StringBundler query = new StringBundler(5);
4663    
4664                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
4665    
4666                            query.append(_FINDER_COLUMN_G_P_N_GROUPID_2);
4667    
4668                            query.append(_FINDER_COLUMN_G_P_N_PARENTFOLDERID_2);
4669    
4670                            if (name == null) {
4671                                    query.append(_FINDER_COLUMN_G_P_N_NAME_1);
4672                            }
4673                            else {
4674                                    if (name.equals(StringPool.BLANK)) {
4675                                            query.append(_FINDER_COLUMN_G_P_N_NAME_3);
4676                                    }
4677                                    else {
4678                                            query.append(_FINDER_COLUMN_G_P_N_NAME_2);
4679                                    }
4680                            }
4681    
4682                            query.append(DLFolderModelImpl.ORDER_BY_JPQL);
4683    
4684                            String sql = query.toString();
4685    
4686                            Session session = null;
4687    
4688                            try {
4689                                    session = openSession();
4690    
4691                                    Query q = session.createQuery(sql);
4692    
4693                                    QueryPos qPos = QueryPos.getInstance(q);
4694    
4695                                    qPos.add(groupId);
4696    
4697                                    qPos.add(parentFolderId);
4698    
4699                                    if (name != null) {
4700                                            qPos.add(name);
4701                                    }
4702    
4703                                    List<DLFolder> list = q.list();
4704    
4705                                    result = list;
4706    
4707                                    DLFolder dlFolder = null;
4708    
4709                                    if (list.isEmpty()) {
4710                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_N,
4711                                                    finderArgs, list);
4712                                    }
4713                                    else {
4714                                            dlFolder = list.get(0);
4715    
4716                                            cacheResult(dlFolder);
4717    
4718                                            if ((dlFolder.getGroupId() != groupId) ||
4719                                                            (dlFolder.getParentFolderId() != parentFolderId) ||
4720                                                            (dlFolder.getName() == null) ||
4721                                                            !dlFolder.getName().equals(name)) {
4722                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_N,
4723                                                            finderArgs, dlFolder);
4724                                            }
4725                                    }
4726    
4727                                    return dlFolder;
4728                            }
4729                            catch (Exception e) {
4730                                    throw processException(e);
4731                            }
4732                            finally {
4733                                    if (result == null) {
4734                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P_N,
4735                                                    finderArgs);
4736                                    }
4737    
4738                                    closeSession(session);
4739                            }
4740                    }
4741                    else {
4742                            if (result instanceof List<?>) {
4743                                    return null;
4744                            }
4745                            else {
4746                                    return (DLFolder)result;
4747                            }
4748                    }
4749            }
4750    
4751            /**
4752             * Returns all the document library folders.
4753             *
4754             * @return the document library folders
4755             * @throws SystemException if a system exception occurred
4756             */
4757            public List<DLFolder> findAll() throws SystemException {
4758                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
4759            }
4760    
4761            /**
4762             * Returns a range of all the document library folders.
4763             *
4764             * <p>
4765             * 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.
4766             * </p>
4767             *
4768             * @param start the lower bound of the range of document library folders
4769             * @param end the upper bound of the range of document library folders (not inclusive)
4770             * @return the range of document library folders
4771             * @throws SystemException if a system exception occurred
4772             */
4773            public List<DLFolder> findAll(int start, int end) throws SystemException {
4774                    return findAll(start, end, null);
4775            }
4776    
4777            /**
4778             * Returns an ordered range of all the document library folders.
4779             *
4780             * <p>
4781             * 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.
4782             * </p>
4783             *
4784             * @param start the lower bound of the range of document library folders
4785             * @param end the upper bound of the range of document library folders (not inclusive)
4786             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4787             * @return the ordered range of document library folders
4788             * @throws SystemException if a system exception occurred
4789             */
4790            public List<DLFolder> findAll(int start, int end,
4791                    OrderByComparator orderByComparator) throws SystemException {
4792                    FinderPath finderPath = null;
4793                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
4794    
4795                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4796                                    (orderByComparator == null)) {
4797                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
4798                            finderArgs = FINDER_ARGS_EMPTY;
4799                    }
4800                    else {
4801                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
4802                            finderArgs = new Object[] { start, end, orderByComparator };
4803                    }
4804    
4805                    List<DLFolder> list = (List<DLFolder>)FinderCacheUtil.getResult(finderPath,
4806                                    finderArgs, this);
4807    
4808                    if (list == null) {
4809                            StringBundler query = null;
4810                            String sql = null;
4811    
4812                            if (orderByComparator != null) {
4813                                    query = new StringBundler(2 +
4814                                                    (orderByComparator.getOrderByFields().length * 3));
4815    
4816                                    query.append(_SQL_SELECT_DLFOLDER);
4817    
4818                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4819                                            orderByComparator);
4820    
4821                                    sql = query.toString();
4822                            }
4823                            else {
4824                                    sql = _SQL_SELECT_DLFOLDER.concat(DLFolderModelImpl.ORDER_BY_JPQL);
4825                            }
4826    
4827                            Session session = null;
4828    
4829                            try {
4830                                    session = openSession();
4831    
4832                                    Query q = session.createQuery(sql);
4833    
4834                                    if (orderByComparator == null) {
4835                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
4836                                                            start, end, false);
4837    
4838                                            Collections.sort(list);
4839                                    }
4840                                    else {
4841                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
4842                                                            start, end);
4843                                    }
4844                            }
4845                            catch (Exception e) {
4846                                    throw processException(e);
4847                            }
4848                            finally {
4849                                    if (list == null) {
4850                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
4851                                    }
4852                                    else {
4853                                            cacheResult(list);
4854    
4855                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
4856                                    }
4857    
4858                                    closeSession(session);
4859                            }
4860                    }
4861    
4862                    return list;
4863            }
4864    
4865            /**
4866             * Removes all the document library folders where uuid = &#63; from the database.
4867             *
4868             * @param uuid the uuid
4869             * @throws SystemException if a system exception occurred
4870             */
4871            public void removeByUuid(String uuid) throws SystemException {
4872                    for (DLFolder dlFolder : findByUuid(uuid)) {
4873                            remove(dlFolder);
4874                    }
4875            }
4876    
4877            /**
4878             * Removes the document library folder where uuid = &#63; and groupId = &#63; from the database.
4879             *
4880             * @param uuid the uuid
4881             * @param groupId the group ID
4882             * @return the document library folder that was removed
4883             * @throws SystemException if a system exception occurred
4884             */
4885            public DLFolder removeByUUID_G(String uuid, long groupId)
4886                    throws NoSuchFolderException, SystemException {
4887                    DLFolder dlFolder = findByUUID_G(uuid, groupId);
4888    
4889                    return remove(dlFolder);
4890            }
4891    
4892            /**
4893             * Removes all the document library folders where groupId = &#63; from the database.
4894             *
4895             * @param groupId the group ID
4896             * @throws SystemException if a system exception occurred
4897             */
4898            public void removeByGroupId(long groupId) throws SystemException {
4899                    for (DLFolder dlFolder : findByGroupId(groupId)) {
4900                            remove(dlFolder);
4901                    }
4902            }
4903    
4904            /**
4905             * Removes all the document library folders where companyId = &#63; from the database.
4906             *
4907             * @param companyId the company ID
4908             * @throws SystemException if a system exception occurred
4909             */
4910            public void removeByCompanyId(long companyId) throws SystemException {
4911                    for (DLFolder dlFolder : findByCompanyId(companyId)) {
4912                            remove(dlFolder);
4913                    }
4914            }
4915    
4916            /**
4917             * Removes the document library folder where repositoryId = &#63; from the database.
4918             *
4919             * @param repositoryId the repository ID
4920             * @return the document library folder that was removed
4921             * @throws SystemException if a system exception occurred
4922             */
4923            public DLFolder removeByRepositoryId(long repositoryId)
4924                    throws NoSuchFolderException, SystemException {
4925                    DLFolder dlFolder = findByRepositoryId(repositoryId);
4926    
4927                    return remove(dlFolder);
4928            }
4929    
4930            /**
4931             * Removes all the document library folders where groupId = &#63; and parentFolderId = &#63; from the database.
4932             *
4933             * @param groupId the group ID
4934             * @param parentFolderId the parent folder ID
4935             * @throws SystemException if a system exception occurred
4936             */
4937            public void removeByG_P(long groupId, long parentFolderId)
4938                    throws SystemException {
4939                    for (DLFolder dlFolder : findByG_P(groupId, parentFolderId)) {
4940                            remove(dlFolder);
4941                    }
4942            }
4943    
4944            /**
4945             * Removes all the document library folders where parentFolderId = &#63; and name = &#63; from the database.
4946             *
4947             * @param parentFolderId the parent folder ID
4948             * @param name the name
4949             * @throws SystemException if a system exception occurred
4950             */
4951            public void removeByP_N(long parentFolderId, String name)
4952                    throws SystemException {
4953                    for (DLFolder dlFolder : findByP_N(parentFolderId, name)) {
4954                            remove(dlFolder);
4955                    }
4956            }
4957    
4958            /**
4959             * Removes all the document library folders where groupId = &#63; and parentFolderId = &#63; and mountPoint = &#63; from the database.
4960             *
4961             * @param groupId the group ID
4962             * @param parentFolderId the parent folder ID
4963             * @param mountPoint the mount point
4964             * @throws SystemException if a system exception occurred
4965             */
4966            public void removeByG_P_M(long groupId, long parentFolderId,
4967                    boolean mountPoint) throws SystemException {
4968                    for (DLFolder dlFolder : findByG_P_M(groupId, parentFolderId, mountPoint)) {
4969                            remove(dlFolder);
4970                    }
4971            }
4972    
4973            /**
4974             * Removes the document library folder where groupId = &#63; and parentFolderId = &#63; and name = &#63; from the database.
4975             *
4976             * @param groupId the group ID
4977             * @param parentFolderId the parent folder ID
4978             * @param name the name
4979             * @return the document library folder that was removed
4980             * @throws SystemException if a system exception occurred
4981             */
4982            public DLFolder removeByG_P_N(long groupId, long parentFolderId, String name)
4983                    throws NoSuchFolderException, SystemException {
4984                    DLFolder dlFolder = findByG_P_N(groupId, parentFolderId, name);
4985    
4986                    return remove(dlFolder);
4987            }
4988    
4989            /**
4990             * Removes all the document library folders from the database.
4991             *
4992             * @throws SystemException if a system exception occurred
4993             */
4994            public void removeAll() throws SystemException {
4995                    for (DLFolder dlFolder : findAll()) {
4996                            remove(dlFolder);
4997                    }
4998            }
4999    
5000            /**
5001             * Returns the number of document library folders where uuid = &#63;.
5002             *
5003             * @param uuid the uuid
5004             * @return the number of matching document library folders
5005             * @throws SystemException if a system exception occurred
5006             */
5007            public int countByUuid(String uuid) throws SystemException {
5008                    Object[] finderArgs = new Object[] { uuid };
5009    
5010                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
5011                                    finderArgs, this);
5012    
5013                    if (count == null) {
5014                            StringBundler query = new StringBundler(2);
5015    
5016                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
5017    
5018                            if (uuid == null) {
5019                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
5020                            }
5021                            else {
5022                                    if (uuid.equals(StringPool.BLANK)) {
5023                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
5024                                    }
5025                                    else {
5026                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
5027                                    }
5028                            }
5029    
5030                            String sql = query.toString();
5031    
5032                            Session session = null;
5033    
5034                            try {
5035                                    session = openSession();
5036    
5037                                    Query q = session.createQuery(sql);
5038    
5039                                    QueryPos qPos = QueryPos.getInstance(q);
5040    
5041                                    if (uuid != null) {
5042                                            qPos.add(uuid);
5043                                    }
5044    
5045                                    count = (Long)q.uniqueResult();
5046                            }
5047                            catch (Exception e) {
5048                                    throw processException(e);
5049                            }
5050                            finally {
5051                                    if (count == null) {
5052                                            count = Long.valueOf(0);
5053                                    }
5054    
5055                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
5056                                            finderArgs, count);
5057    
5058                                    closeSession(session);
5059                            }
5060                    }
5061    
5062                    return count.intValue();
5063            }
5064    
5065            /**
5066             * Returns the number of document library folders where uuid = &#63; and groupId = &#63;.
5067             *
5068             * @param uuid the uuid
5069             * @param groupId the group ID
5070             * @return the number of matching document library folders
5071             * @throws SystemException if a system exception occurred
5072             */
5073            public int countByUUID_G(String uuid, long groupId)
5074                    throws SystemException {
5075                    Object[] finderArgs = new Object[] { uuid, groupId };
5076    
5077                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
5078                                    finderArgs, this);
5079    
5080                    if (count == null) {
5081                            StringBundler query = new StringBundler(3);
5082    
5083                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
5084    
5085                            if (uuid == null) {
5086                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
5087                            }
5088                            else {
5089                                    if (uuid.equals(StringPool.BLANK)) {
5090                                            query.append(_FINDER_COLUMN_UUID_G_UUID_3);
5091                                    }
5092                                    else {
5093                                            query.append(_FINDER_COLUMN_UUID_G_UUID_2);
5094                                    }
5095                            }
5096    
5097                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
5098    
5099                            String sql = query.toString();
5100    
5101                            Session session = null;
5102    
5103                            try {
5104                                    session = openSession();
5105    
5106                                    Query q = session.createQuery(sql);
5107    
5108                                    QueryPos qPos = QueryPos.getInstance(q);
5109    
5110                                    if (uuid != null) {
5111                                            qPos.add(uuid);
5112                                    }
5113    
5114                                    qPos.add(groupId);
5115    
5116                                    count = (Long)q.uniqueResult();
5117                            }
5118                            catch (Exception e) {
5119                                    throw processException(e);
5120                            }
5121                            finally {
5122                                    if (count == null) {
5123                                            count = Long.valueOf(0);
5124                                    }
5125    
5126                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
5127                                            finderArgs, count);
5128    
5129                                    closeSession(session);
5130                            }
5131                    }
5132    
5133                    return count.intValue();
5134            }
5135    
5136            /**
5137             * Returns the number of document library folders where groupId = &#63;.
5138             *
5139             * @param groupId the group ID
5140             * @return the number of matching document library folders
5141             * @throws SystemException if a system exception occurred
5142             */
5143            public int countByGroupId(long groupId) throws SystemException {
5144                    Object[] finderArgs = new Object[] { groupId };
5145    
5146                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
5147                                    finderArgs, this);
5148    
5149                    if (count == null) {
5150                            StringBundler query = new StringBundler(2);
5151    
5152                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
5153    
5154                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
5155    
5156                            String sql = query.toString();
5157    
5158                            Session session = null;
5159    
5160                            try {
5161                                    session = openSession();
5162    
5163                                    Query q = session.createQuery(sql);
5164    
5165                                    QueryPos qPos = QueryPos.getInstance(q);
5166    
5167                                    qPos.add(groupId);
5168    
5169                                    count = (Long)q.uniqueResult();
5170                            }
5171                            catch (Exception e) {
5172                                    throw processException(e);
5173                            }
5174                            finally {
5175                                    if (count == null) {
5176                                            count = Long.valueOf(0);
5177                                    }
5178    
5179                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
5180                                            finderArgs, count);
5181    
5182                                    closeSession(session);
5183                            }
5184                    }
5185    
5186                    return count.intValue();
5187            }
5188    
5189            /**
5190             * Returns the number of document library folders that the user has permission to view where groupId = &#63;.
5191             *
5192             * @param groupId the group ID
5193             * @return the number of matching document library folders that the user has permission to view
5194             * @throws SystemException if a system exception occurred
5195             */
5196            public int filterCountByGroupId(long groupId) throws SystemException {
5197                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5198                            return countByGroupId(groupId);
5199                    }
5200    
5201                    StringBundler query = new StringBundler(2);
5202    
5203                    query.append(_FILTER_SQL_COUNT_DLFOLDER_WHERE);
5204    
5205                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
5206    
5207                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5208                                    DLFolder.class.getName(),
5209                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5210    
5211                    Session session = null;
5212    
5213                    try {
5214                            session = openSession();
5215    
5216                            SQLQuery q = session.createSQLQuery(sql);
5217    
5218                            q.addScalar(COUNT_COLUMN_NAME,
5219                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
5220    
5221                            QueryPos qPos = QueryPos.getInstance(q);
5222    
5223                            qPos.add(groupId);
5224    
5225                            Long count = (Long)q.uniqueResult();
5226    
5227                            return count.intValue();
5228                    }
5229                    catch (Exception e) {
5230                            throw processException(e);
5231                    }
5232                    finally {
5233                            closeSession(session);
5234                    }
5235            }
5236    
5237            /**
5238             * Returns the number of document library folders where companyId = &#63;.
5239             *
5240             * @param companyId the company ID
5241             * @return the number of matching document library folders
5242             * @throws SystemException if a system exception occurred
5243             */
5244            public int countByCompanyId(long companyId) throws SystemException {
5245                    Object[] finderArgs = new Object[] { companyId };
5246    
5247                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
5248                                    finderArgs, this);
5249    
5250                    if (count == null) {
5251                            StringBundler query = new StringBundler(2);
5252    
5253                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
5254    
5255                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
5256    
5257                            String sql = query.toString();
5258    
5259                            Session session = null;
5260    
5261                            try {
5262                                    session = openSession();
5263    
5264                                    Query q = session.createQuery(sql);
5265    
5266                                    QueryPos qPos = QueryPos.getInstance(q);
5267    
5268                                    qPos.add(companyId);
5269    
5270                                    count = (Long)q.uniqueResult();
5271                            }
5272                            catch (Exception e) {
5273                                    throw processException(e);
5274                            }
5275                            finally {
5276                                    if (count == null) {
5277                                            count = Long.valueOf(0);
5278                                    }
5279    
5280                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
5281                                            finderArgs, count);
5282    
5283                                    closeSession(session);
5284                            }
5285                    }
5286    
5287                    return count.intValue();
5288            }
5289    
5290            /**
5291             * Returns the number of document library folders where repositoryId = &#63;.
5292             *
5293             * @param repositoryId the repository ID
5294             * @return the number of matching document library folders
5295             * @throws SystemException if a system exception occurred
5296             */
5297            public int countByRepositoryId(long repositoryId) throws SystemException {
5298                    Object[] finderArgs = new Object[] { repositoryId };
5299    
5300                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_REPOSITORYID,
5301                                    finderArgs, this);
5302    
5303                    if (count == null) {
5304                            StringBundler query = new StringBundler(2);
5305    
5306                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
5307    
5308                            query.append(_FINDER_COLUMN_REPOSITORYID_REPOSITORYID_2);
5309    
5310                            String sql = query.toString();
5311    
5312                            Session session = null;
5313    
5314                            try {
5315                                    session = openSession();
5316    
5317                                    Query q = session.createQuery(sql);
5318    
5319                                    QueryPos qPos = QueryPos.getInstance(q);
5320    
5321                                    qPos.add(repositoryId);
5322    
5323                                    count = (Long)q.uniqueResult();
5324                            }
5325                            catch (Exception e) {
5326                                    throw processException(e);
5327                            }
5328                            finally {
5329                                    if (count == null) {
5330                                            count = Long.valueOf(0);
5331                                    }
5332    
5333                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_REPOSITORYID,
5334                                            finderArgs, count);
5335    
5336                                    closeSession(session);
5337                            }
5338                    }
5339    
5340                    return count.intValue();
5341            }
5342    
5343            /**
5344             * Returns the number of document library folders where groupId = &#63; and parentFolderId = &#63;.
5345             *
5346             * @param groupId the group ID
5347             * @param parentFolderId the parent folder ID
5348             * @return the number of matching document library folders
5349             * @throws SystemException if a system exception occurred
5350             */
5351            public int countByG_P(long groupId, long parentFolderId)
5352                    throws SystemException {
5353                    Object[] finderArgs = new Object[] { groupId, parentFolderId };
5354    
5355                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_P,
5356                                    finderArgs, this);
5357    
5358                    if (count == null) {
5359                            StringBundler query = new StringBundler(3);
5360    
5361                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
5362    
5363                            query.append(_FINDER_COLUMN_G_P_GROUPID_2);
5364    
5365                            query.append(_FINDER_COLUMN_G_P_PARENTFOLDERID_2);
5366    
5367                            String sql = query.toString();
5368    
5369                            Session session = null;
5370    
5371                            try {
5372                                    session = openSession();
5373    
5374                                    Query q = session.createQuery(sql);
5375    
5376                                    QueryPos qPos = QueryPos.getInstance(q);
5377    
5378                                    qPos.add(groupId);
5379    
5380                                    qPos.add(parentFolderId);
5381    
5382                                    count = (Long)q.uniqueResult();
5383                            }
5384                            catch (Exception e) {
5385                                    throw processException(e);
5386                            }
5387                            finally {
5388                                    if (count == null) {
5389                                            count = Long.valueOf(0);
5390                                    }
5391    
5392                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_P, finderArgs,
5393                                            count);
5394    
5395                                    closeSession(session);
5396                            }
5397                    }
5398    
5399                    return count.intValue();
5400            }
5401    
5402            /**
5403             * Returns the number of document library folders that the user has permission to view where groupId = &#63; and parentFolderId = &#63;.
5404             *
5405             * @param groupId the group ID
5406             * @param parentFolderId the parent folder ID
5407             * @return the number of matching document library folders that the user has permission to view
5408             * @throws SystemException if a system exception occurred
5409             */
5410            public int filterCountByG_P(long groupId, long parentFolderId)
5411                    throws SystemException {
5412                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5413                            return countByG_P(groupId, parentFolderId);
5414                    }
5415    
5416                    StringBundler query = new StringBundler(3);
5417    
5418                    query.append(_FILTER_SQL_COUNT_DLFOLDER_WHERE);
5419    
5420                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
5421    
5422                    query.append(_FINDER_COLUMN_G_P_PARENTFOLDERID_2);
5423    
5424                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5425                                    DLFolder.class.getName(),
5426                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5427    
5428                    Session session = null;
5429    
5430                    try {
5431                            session = openSession();
5432    
5433                            SQLQuery q = session.createSQLQuery(sql);
5434    
5435                            q.addScalar(COUNT_COLUMN_NAME,
5436                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
5437    
5438                            QueryPos qPos = QueryPos.getInstance(q);
5439    
5440                            qPos.add(groupId);
5441    
5442                            qPos.add(parentFolderId);
5443    
5444                            Long count = (Long)q.uniqueResult();
5445    
5446                            return count.intValue();
5447                    }
5448                    catch (Exception e) {
5449                            throw processException(e);
5450                    }
5451                    finally {
5452                            closeSession(session);
5453                    }
5454            }
5455    
5456            /**
5457             * Returns the number of document library folders where parentFolderId = &#63; and name = &#63;.
5458             *
5459             * @param parentFolderId the parent folder ID
5460             * @param name the name
5461             * @return the number of matching document library folders
5462             * @throws SystemException if a system exception occurred
5463             */
5464            public int countByP_N(long parentFolderId, String name)
5465                    throws SystemException {
5466                    Object[] finderArgs = new Object[] { parentFolderId, name };
5467    
5468                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_P_N,
5469                                    finderArgs, this);
5470    
5471                    if (count == null) {
5472                            StringBundler query = new StringBundler(3);
5473    
5474                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
5475    
5476                            query.append(_FINDER_COLUMN_P_N_PARENTFOLDERID_2);
5477    
5478                            if (name == null) {
5479                                    query.append(_FINDER_COLUMN_P_N_NAME_1);
5480                            }
5481                            else {
5482                                    if (name.equals(StringPool.BLANK)) {
5483                                            query.append(_FINDER_COLUMN_P_N_NAME_3);
5484                                    }
5485                                    else {
5486                                            query.append(_FINDER_COLUMN_P_N_NAME_2);
5487                                    }
5488                            }
5489    
5490                            String sql = query.toString();
5491    
5492                            Session session = null;
5493    
5494                            try {
5495                                    session = openSession();
5496    
5497                                    Query q = session.createQuery(sql);
5498    
5499                                    QueryPos qPos = QueryPos.getInstance(q);
5500    
5501                                    qPos.add(parentFolderId);
5502    
5503                                    if (name != null) {
5504                                            qPos.add(name);
5505                                    }
5506    
5507                                    count = (Long)q.uniqueResult();
5508                            }
5509                            catch (Exception e) {
5510                                    throw processException(e);
5511                            }
5512                            finally {
5513                                    if (count == null) {
5514                                            count = Long.valueOf(0);
5515                                    }
5516    
5517                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_P_N, finderArgs,
5518                                            count);
5519    
5520                                    closeSession(session);
5521                            }
5522                    }
5523    
5524                    return count.intValue();
5525            }
5526    
5527            /**
5528             * Returns the number of document library folders where groupId = &#63; and parentFolderId = &#63; and mountPoint = &#63;.
5529             *
5530             * @param groupId the group ID
5531             * @param parentFolderId the parent folder ID
5532             * @param mountPoint the mount point
5533             * @return the number of matching document library folders
5534             * @throws SystemException if a system exception occurred
5535             */
5536            public int countByG_P_M(long groupId, long parentFolderId,
5537                    boolean mountPoint) throws SystemException {
5538                    Object[] finderArgs = new Object[] { groupId, parentFolderId, mountPoint };
5539    
5540                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_P_M,
5541                                    finderArgs, this);
5542    
5543                    if (count == null) {
5544                            StringBundler query = new StringBundler(4);
5545    
5546                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
5547    
5548                            query.append(_FINDER_COLUMN_G_P_M_GROUPID_2);
5549    
5550                            query.append(_FINDER_COLUMN_G_P_M_PARENTFOLDERID_2);
5551    
5552                            query.append(_FINDER_COLUMN_G_P_M_MOUNTPOINT_2);
5553    
5554                            String sql = query.toString();
5555    
5556                            Session session = null;
5557    
5558                            try {
5559                                    session = openSession();
5560    
5561                                    Query q = session.createQuery(sql);
5562    
5563                                    QueryPos qPos = QueryPos.getInstance(q);
5564    
5565                                    qPos.add(groupId);
5566    
5567                                    qPos.add(parentFolderId);
5568    
5569                                    qPos.add(mountPoint);
5570    
5571                                    count = (Long)q.uniqueResult();
5572                            }
5573                            catch (Exception e) {
5574                                    throw processException(e);
5575                            }
5576                            finally {
5577                                    if (count == null) {
5578                                            count = Long.valueOf(0);
5579                                    }
5580    
5581                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_P_M,
5582                                            finderArgs, count);
5583    
5584                                    closeSession(session);
5585                            }
5586                    }
5587    
5588                    return count.intValue();
5589            }
5590    
5591            /**
5592             * Returns the number of document library folders that the user has permission to view where groupId = &#63; and parentFolderId = &#63; and mountPoint = &#63;.
5593             *
5594             * @param groupId the group ID
5595             * @param parentFolderId the parent folder ID
5596             * @param mountPoint the mount point
5597             * @return the number of matching document library folders that the user has permission to view
5598             * @throws SystemException if a system exception occurred
5599             */
5600            public int filterCountByG_P_M(long groupId, long parentFolderId,
5601                    boolean mountPoint) throws SystemException {
5602                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5603                            return countByG_P_M(groupId, parentFolderId, mountPoint);
5604                    }
5605    
5606                    StringBundler query = new StringBundler(4);
5607    
5608                    query.append(_FILTER_SQL_COUNT_DLFOLDER_WHERE);
5609    
5610                    query.append(_FINDER_COLUMN_G_P_M_GROUPID_2);
5611    
5612                    query.append(_FINDER_COLUMN_G_P_M_PARENTFOLDERID_2);
5613    
5614                    query.append(_FINDER_COLUMN_G_P_M_MOUNTPOINT_2);
5615    
5616                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5617                                    DLFolder.class.getName(),
5618                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5619    
5620                    Session session = null;
5621    
5622                    try {
5623                            session = openSession();
5624    
5625                            SQLQuery q = session.createSQLQuery(sql);
5626    
5627                            q.addScalar(COUNT_COLUMN_NAME,
5628                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
5629    
5630                            QueryPos qPos = QueryPos.getInstance(q);
5631    
5632                            qPos.add(groupId);
5633    
5634                            qPos.add(parentFolderId);
5635    
5636                            qPos.add(mountPoint);
5637    
5638                            Long count = (Long)q.uniqueResult();
5639    
5640                            return count.intValue();
5641                    }
5642                    catch (Exception e) {
5643                            throw processException(e);
5644                    }
5645                    finally {
5646                            closeSession(session);
5647                    }
5648            }
5649    
5650            /**
5651             * Returns the number of document library folders where groupId = &#63; and parentFolderId = &#63; and name = &#63;.
5652             *
5653             * @param groupId the group ID
5654             * @param parentFolderId the parent folder ID
5655             * @param name the name
5656             * @return the number of matching document library folders
5657             * @throws SystemException if a system exception occurred
5658             */
5659            public int countByG_P_N(long groupId, long parentFolderId, String name)
5660                    throws SystemException {
5661                    Object[] finderArgs = new Object[] { groupId, parentFolderId, name };
5662    
5663                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_P_N,
5664                                    finderArgs, this);
5665    
5666                    if (count == null) {
5667                            StringBundler query = new StringBundler(4);
5668    
5669                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
5670    
5671                            query.append(_FINDER_COLUMN_G_P_N_GROUPID_2);
5672    
5673                            query.append(_FINDER_COLUMN_G_P_N_PARENTFOLDERID_2);
5674    
5675                            if (name == null) {
5676                                    query.append(_FINDER_COLUMN_G_P_N_NAME_1);
5677                            }
5678                            else {
5679                                    if (name.equals(StringPool.BLANK)) {
5680                                            query.append(_FINDER_COLUMN_G_P_N_NAME_3);
5681                                    }
5682                                    else {
5683                                            query.append(_FINDER_COLUMN_G_P_N_NAME_2);
5684                                    }
5685                            }
5686    
5687                            String sql = query.toString();
5688    
5689                            Session session = null;
5690    
5691                            try {
5692                                    session = openSession();
5693    
5694                                    Query q = session.createQuery(sql);
5695    
5696                                    QueryPos qPos = QueryPos.getInstance(q);
5697    
5698                                    qPos.add(groupId);
5699    
5700                                    qPos.add(parentFolderId);
5701    
5702                                    if (name != null) {
5703                                            qPos.add(name);
5704                                    }
5705    
5706                                    count = (Long)q.uniqueResult();
5707                            }
5708                            catch (Exception e) {
5709                                    throw processException(e);
5710                            }
5711                            finally {
5712                                    if (count == null) {
5713                                            count = Long.valueOf(0);
5714                                    }
5715    
5716                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_P_N,
5717                                            finderArgs, count);
5718    
5719                                    closeSession(session);
5720                            }
5721                    }
5722    
5723                    return count.intValue();
5724            }
5725    
5726            /**
5727             * Returns the number of document library folders.
5728             *
5729             * @return the number of document library folders
5730             * @throws SystemException if a system exception occurred
5731             */
5732            public int countAll() throws SystemException {
5733                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
5734                                    FINDER_ARGS_EMPTY, this);
5735    
5736                    if (count == null) {
5737                            Session session = null;
5738    
5739                            try {
5740                                    session = openSession();
5741    
5742                                    Query q = session.createQuery(_SQL_COUNT_DLFOLDER);
5743    
5744                                    count = (Long)q.uniqueResult();
5745                            }
5746                            catch (Exception e) {
5747                                    throw processException(e);
5748                            }
5749                            finally {
5750                                    if (count == null) {
5751                                            count = Long.valueOf(0);
5752                                    }
5753    
5754                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
5755                                            FINDER_ARGS_EMPTY, count);
5756    
5757                                    closeSession(session);
5758                            }
5759                    }
5760    
5761                    return count.intValue();
5762            }
5763    
5764            /**
5765             * Returns all the document library file entry types associated with the document library folder.
5766             *
5767             * @param pk the primary key of the document library folder
5768             * @return the document library file entry types associated with the document library folder
5769             * @throws SystemException if a system exception occurred
5770             */
5771            public List<com.liferay.portlet.documentlibrary.model.DLFileEntryType> getDLFileEntryTypes(
5772                    long pk) throws SystemException {
5773                    return getDLFileEntryTypes(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
5774            }
5775    
5776            /**
5777             * Returns a range of all the document library file entry types associated with the document library folder.
5778             *
5779             * <p>
5780             * 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.
5781             * </p>
5782             *
5783             * @param pk the primary key of the document library folder
5784             * @param start the lower bound of the range of document library folders
5785             * @param end the upper bound of the range of document library folders (not inclusive)
5786             * @return the range of document library file entry types associated with the document library folder
5787             * @throws SystemException if a system exception occurred
5788             */
5789            public List<com.liferay.portlet.documentlibrary.model.DLFileEntryType> getDLFileEntryTypes(
5790                    long pk, int start, int end) throws SystemException {
5791                    return getDLFileEntryTypes(pk, start, end, null);
5792            }
5793    
5794            public static final FinderPath FINDER_PATH_GET_DLFILEENTRYTYPES = new FinderPath(com.liferay.portlet.documentlibrary.model.impl.DLFileEntryTypeModelImpl.ENTITY_CACHE_ENABLED,
5795                            DLFolderModelImpl.FINDER_CACHE_ENABLED_DLFILEENTRYTYPES_DLFOLDERS,
5796                            com.liferay.portlet.documentlibrary.model.impl.DLFileEntryTypeImpl.class,
5797                            DLFolderModelImpl.MAPPING_TABLE_DLFILEENTRYTYPES_DLFOLDERS_NAME,
5798                            "getDLFileEntryTypes",
5799                            new String[] {
5800                                    Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
5801                                    "com.liferay.portal.kernel.util.OrderByComparator"
5802                            });
5803    
5804            static {
5805                    FINDER_PATH_GET_DLFILEENTRYTYPES.setCacheKeyGeneratorCacheName(null);
5806            }
5807    
5808            /**
5809             * Returns an ordered range of all the document library file entry types associated with the document library folder.
5810             *
5811             * <p>
5812             * 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.
5813             * </p>
5814             *
5815             * @param pk the primary key of the document library folder
5816             * @param start the lower bound of the range of document library folders
5817             * @param end the upper bound of the range of document library folders (not inclusive)
5818             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5819             * @return the ordered range of document library file entry types associated with the document library folder
5820             * @throws SystemException if a system exception occurred
5821             */
5822            public List<com.liferay.portlet.documentlibrary.model.DLFileEntryType> getDLFileEntryTypes(
5823                    long pk, int start, int end, OrderByComparator orderByComparator)
5824                    throws SystemException {
5825                    Object[] finderArgs = new Object[] { pk, start, end, orderByComparator };
5826    
5827                    List<com.liferay.portlet.documentlibrary.model.DLFileEntryType> list = (List<com.liferay.portlet.documentlibrary.model.DLFileEntryType>)FinderCacheUtil.getResult(FINDER_PATH_GET_DLFILEENTRYTYPES,
5828                                    finderArgs, this);
5829    
5830                    if (list == null) {
5831                            Session session = null;
5832    
5833                            try {
5834                                    session = openSession();
5835    
5836                                    String sql = null;
5837    
5838                                    if (orderByComparator != null) {
5839                                            sql = _SQL_GETDLFILEENTRYTYPES.concat(ORDER_BY_CLAUSE)
5840                                                                                                      .concat(orderByComparator.getOrderBy());
5841                                    }
5842                                    else {
5843                                            sql = _SQL_GETDLFILEENTRYTYPES;
5844                                    }
5845    
5846                                    SQLQuery q = session.createSQLQuery(sql);
5847    
5848                                    q.addEntity("DLFileEntryType",
5849                                            com.liferay.portlet.documentlibrary.model.impl.DLFileEntryTypeImpl.class);
5850    
5851                                    QueryPos qPos = QueryPos.getInstance(q);
5852    
5853                                    qPos.add(pk);
5854    
5855                                    list = (List<com.liferay.portlet.documentlibrary.model.DLFileEntryType>)QueryUtil.list(q,
5856                                                    getDialect(), start, end);
5857                            }
5858                            catch (Exception e) {
5859                                    throw processException(e);
5860                            }
5861                            finally {
5862                                    if (list == null) {
5863                                            FinderCacheUtil.removeResult(FINDER_PATH_GET_DLFILEENTRYTYPES,
5864                                                    finderArgs);
5865                                    }
5866                                    else {
5867                                            dlFileEntryTypePersistence.cacheResult(list);
5868    
5869                                            FinderCacheUtil.putResult(FINDER_PATH_GET_DLFILEENTRYTYPES,
5870                                                    finderArgs, list);
5871                                    }
5872    
5873                                    closeSession(session);
5874                            }
5875                    }
5876    
5877                    return list;
5878            }
5879    
5880            public static final FinderPath FINDER_PATH_GET_DLFILEENTRYTYPES_SIZE = new FinderPath(com.liferay.portlet.documentlibrary.model.impl.DLFileEntryTypeModelImpl.ENTITY_CACHE_ENABLED,
5881                            DLFolderModelImpl.FINDER_CACHE_ENABLED_DLFILEENTRYTYPES_DLFOLDERS,
5882                            Long.class,
5883                            DLFolderModelImpl.MAPPING_TABLE_DLFILEENTRYTYPES_DLFOLDERS_NAME,
5884                            "getDLFileEntryTypesSize", new String[] { Long.class.getName() });
5885    
5886            static {
5887                    FINDER_PATH_GET_DLFILEENTRYTYPES_SIZE.setCacheKeyGeneratorCacheName(null);
5888            }
5889    
5890            /**
5891             * Returns the number of document library file entry types associated with the document library folder.
5892             *
5893             * @param pk the primary key of the document library folder
5894             * @return the number of document library file entry types associated with the document library folder
5895             * @throws SystemException if a system exception occurred
5896             */
5897            public int getDLFileEntryTypesSize(long pk) throws SystemException {
5898                    Object[] finderArgs = new Object[] { pk };
5899    
5900                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_DLFILEENTRYTYPES_SIZE,
5901                                    finderArgs, this);
5902    
5903                    if (count == null) {
5904                            Session session = null;
5905    
5906                            try {
5907                                    session = openSession();
5908    
5909                                    SQLQuery q = session.createSQLQuery(_SQL_GETDLFILEENTRYTYPESSIZE);
5910    
5911                                    q.addScalar(COUNT_COLUMN_NAME,
5912                                            com.liferay.portal.kernel.dao.orm.Type.LONG);
5913    
5914                                    QueryPos qPos = QueryPos.getInstance(q);
5915    
5916                                    qPos.add(pk);
5917    
5918                                    count = (Long)q.uniqueResult();
5919                            }
5920                            catch (Exception e) {
5921                                    throw processException(e);
5922                            }
5923                            finally {
5924                                    if (count == null) {
5925                                            count = Long.valueOf(0);
5926                                    }
5927    
5928                                    FinderCacheUtil.putResult(FINDER_PATH_GET_DLFILEENTRYTYPES_SIZE,
5929                                            finderArgs, count);
5930    
5931                                    closeSession(session);
5932                            }
5933                    }
5934    
5935                    return count.intValue();
5936            }
5937    
5938            public static final FinderPath FINDER_PATH_CONTAINS_DLFILEENTRYTYPE = new FinderPath(com.liferay.portlet.documentlibrary.model.impl.DLFileEntryTypeModelImpl.ENTITY_CACHE_ENABLED,
5939                            DLFolderModelImpl.FINDER_CACHE_ENABLED_DLFILEENTRYTYPES_DLFOLDERS,
5940                            Boolean.class,
5941                            DLFolderModelImpl.MAPPING_TABLE_DLFILEENTRYTYPES_DLFOLDERS_NAME,
5942                            "containsDLFileEntryType",
5943                            new String[] { Long.class.getName(), Long.class.getName() });
5944    
5945            /**
5946             * Returns <code>true</code> if the document library file entry type is associated with the document library folder.
5947             *
5948             * @param pk the primary key of the document library folder
5949             * @param dlFileEntryTypePK the primary key of the document library file entry type
5950             * @return <code>true</code> if the document library file entry type is associated with the document library folder; <code>false</code> otherwise
5951             * @throws SystemException if a system exception occurred
5952             */
5953            public boolean containsDLFileEntryType(long pk, long dlFileEntryTypePK)
5954                    throws SystemException {
5955                    Object[] finderArgs = new Object[] { pk, dlFileEntryTypePK };
5956    
5957                    Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_DLFILEENTRYTYPE,
5958                                    finderArgs, this);
5959    
5960                    if (value == null) {
5961                            try {
5962                                    value = Boolean.valueOf(containsDLFileEntryType.contains(pk,
5963                                                            dlFileEntryTypePK));
5964                            }
5965                            catch (Exception e) {
5966                                    throw processException(e);
5967                            }
5968                            finally {
5969                                    if (value == null) {
5970                                            value = Boolean.FALSE;
5971                                    }
5972    
5973                                    FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_DLFILEENTRYTYPE,
5974                                            finderArgs, value);
5975                            }
5976                    }
5977    
5978                    return value.booleanValue();
5979            }
5980    
5981            /**
5982             * Returns <code>true</code> if the document library folder has any document library file entry types associated with it.
5983             *
5984             * @param pk the primary key of the document library folder to check for associations with document library file entry types
5985             * @return <code>true</code> if the document library folder has any document library file entry types associated with it; <code>false</code> otherwise
5986             * @throws SystemException if a system exception occurred
5987             */
5988            public boolean containsDLFileEntryTypes(long pk) throws SystemException {
5989                    if (getDLFileEntryTypesSize(pk) > 0) {
5990                            return true;
5991                    }
5992                    else {
5993                            return false;
5994                    }
5995            }
5996    
5997            /**
5998             * Adds an association between the document library folder and the document library file entry type. Also notifies the appropriate model listeners and clears the mapping table finder cache.
5999             *
6000             * @param pk the primary key of the document library folder
6001             * @param dlFileEntryTypePK the primary key of the document library file entry type
6002             * @throws SystemException if a system exception occurred
6003             */
6004            public void addDLFileEntryType(long pk, long dlFileEntryTypePK)
6005                    throws SystemException {
6006                    try {
6007                            addDLFileEntryType.add(pk, dlFileEntryTypePK);
6008                    }
6009                    catch (Exception e) {
6010                            throw processException(e);
6011                    }
6012                    finally {
6013                            FinderCacheUtil.clearCache(DLFolderModelImpl.MAPPING_TABLE_DLFILEENTRYTYPES_DLFOLDERS_NAME);
6014                    }
6015            }
6016    
6017            /**
6018             * Adds an association between the document library folder and the document library file entry type. Also notifies the appropriate model listeners and clears the mapping table finder cache.
6019             *
6020             * @param pk the primary key of the document library folder
6021             * @param dlFileEntryType the document library file entry type
6022             * @throws SystemException if a system exception occurred
6023             */
6024            public void addDLFileEntryType(long pk,
6025                    com.liferay.portlet.documentlibrary.model.DLFileEntryType dlFileEntryType)
6026                    throws SystemException {
6027                    try {
6028                            addDLFileEntryType.add(pk, dlFileEntryType.getPrimaryKey());
6029                    }
6030                    catch (Exception e) {
6031                            throw processException(e);
6032                    }
6033                    finally {
6034                            FinderCacheUtil.clearCache(DLFolderModelImpl.MAPPING_TABLE_DLFILEENTRYTYPES_DLFOLDERS_NAME);
6035                    }
6036            }
6037    
6038            /**
6039             * Adds an association between the document library folder and the document library file entry types. Also notifies the appropriate model listeners and clears the mapping table finder cache.
6040             *
6041             * @param pk the primary key of the document library folder
6042             * @param dlFileEntryTypePKs the primary keys of the document library file entry types
6043             * @throws SystemException if a system exception occurred
6044             */
6045            public void addDLFileEntryTypes(long pk, long[] dlFileEntryTypePKs)
6046                    throws SystemException {
6047                    try {
6048                            for (long dlFileEntryTypePK : dlFileEntryTypePKs) {
6049                                    addDLFileEntryType.add(pk, dlFileEntryTypePK);
6050                            }
6051                    }
6052                    catch (Exception e) {
6053                            throw processException(e);
6054                    }
6055                    finally {
6056                            FinderCacheUtil.clearCache(DLFolderModelImpl.MAPPING_TABLE_DLFILEENTRYTYPES_DLFOLDERS_NAME);
6057                    }
6058            }
6059    
6060            /**
6061             * Adds an association between the document library folder and the document library file entry types. Also notifies the appropriate model listeners and clears the mapping table finder cache.
6062             *
6063             * @param pk the primary key of the document library folder
6064             * @param dlFileEntryTypes the document library file entry types
6065             * @throws SystemException if a system exception occurred
6066             */
6067            public void addDLFileEntryTypes(long pk,
6068                    List<com.liferay.portlet.documentlibrary.model.DLFileEntryType> dlFileEntryTypes)
6069                    throws SystemException {
6070                    try {
6071                            for (com.liferay.portlet.documentlibrary.model.DLFileEntryType dlFileEntryType : dlFileEntryTypes) {
6072                                    addDLFileEntryType.add(pk, dlFileEntryType.getPrimaryKey());
6073                            }
6074                    }
6075                    catch (Exception e) {
6076                            throw processException(e);
6077                    }
6078                    finally {
6079                            FinderCacheUtil.clearCache(DLFolderModelImpl.MAPPING_TABLE_DLFILEENTRYTYPES_DLFOLDERS_NAME);
6080                    }
6081            }
6082    
6083            /**
6084             * Clears all associations between the document library folder and its document library file entry types. Also notifies the appropriate model listeners and clears the mapping table finder cache.
6085             *
6086             * @param pk the primary key of the document library folder to clear the associated document library file entry types from
6087             * @throws SystemException if a system exception occurred
6088             */
6089            public void clearDLFileEntryTypes(long pk) throws SystemException {
6090                    try {
6091                            clearDLFileEntryTypes.clear(pk);
6092                    }
6093                    catch (Exception e) {
6094                            throw processException(e);
6095                    }
6096                    finally {
6097                            FinderCacheUtil.clearCache(DLFolderModelImpl.MAPPING_TABLE_DLFILEENTRYTYPES_DLFOLDERS_NAME);
6098                    }
6099            }
6100    
6101            /**
6102             * Removes the association between the document library folder and the document library file entry type. Also notifies the appropriate model listeners and clears the mapping table finder cache.
6103             *
6104             * @param pk the primary key of the document library folder
6105             * @param dlFileEntryTypePK the primary key of the document library file entry type
6106             * @throws SystemException if a system exception occurred
6107             */
6108            public void removeDLFileEntryType(long pk, long dlFileEntryTypePK)
6109                    throws SystemException {
6110                    try {
6111                            removeDLFileEntryType.remove(pk, dlFileEntryTypePK);
6112                    }
6113                    catch (Exception e) {
6114                            throw processException(e);
6115                    }
6116                    finally {
6117                            FinderCacheUtil.clearCache(DLFolderModelImpl.MAPPING_TABLE_DLFILEENTRYTYPES_DLFOLDERS_NAME);
6118                    }
6119            }
6120    
6121            /**
6122             * Removes the association between the document library folder and the document library file entry type. Also notifies the appropriate model listeners and clears the mapping table finder cache.
6123             *
6124             * @param pk the primary key of the document library folder
6125             * @param dlFileEntryType the document library file entry type
6126             * @throws SystemException if a system exception occurred
6127             */
6128            public void removeDLFileEntryType(long pk,
6129                    com.liferay.portlet.documentlibrary.model.DLFileEntryType dlFileEntryType)
6130                    throws SystemException {
6131                    try {
6132                            removeDLFileEntryType.remove(pk, dlFileEntryType.getPrimaryKey());
6133                    }
6134                    catch (Exception e) {
6135                            throw processException(e);
6136                    }
6137                    finally {
6138                            FinderCacheUtil.clearCache(DLFolderModelImpl.MAPPING_TABLE_DLFILEENTRYTYPES_DLFOLDERS_NAME);
6139                    }
6140            }
6141    
6142            /**
6143             * Removes the association between the document library folder and the document library file entry types. Also notifies the appropriate model listeners and clears the mapping table finder cache.
6144             *
6145             * @param pk the primary key of the document library folder
6146             * @param dlFileEntryTypePKs the primary keys of the document library file entry types
6147             * @throws SystemException if a system exception occurred
6148             */
6149            public void removeDLFileEntryTypes(long pk, long[] dlFileEntryTypePKs)
6150                    throws SystemException {
6151                    try {
6152                            for (long dlFileEntryTypePK : dlFileEntryTypePKs) {
6153                                    removeDLFileEntryType.remove(pk, dlFileEntryTypePK);
6154                            }
6155                    }
6156                    catch (Exception e) {
6157                            throw processException(e);
6158                    }
6159                    finally {
6160                            FinderCacheUtil.clearCache(DLFolderModelImpl.MAPPING_TABLE_DLFILEENTRYTYPES_DLFOLDERS_NAME);
6161                    }
6162            }
6163    
6164            /**
6165             * Removes the association between the document library folder and the document library file entry types. Also notifies the appropriate model listeners and clears the mapping table finder cache.
6166             *
6167             * @param pk the primary key of the document library folder
6168             * @param dlFileEntryTypes the document library file entry types
6169             * @throws SystemException if a system exception occurred
6170             */
6171            public void removeDLFileEntryTypes(long pk,
6172                    List<com.liferay.portlet.documentlibrary.model.DLFileEntryType> dlFileEntryTypes)
6173                    throws SystemException {
6174                    try {
6175                            for (com.liferay.portlet.documentlibrary.model.DLFileEntryType dlFileEntryType : dlFileEntryTypes) {
6176                                    removeDLFileEntryType.remove(pk, dlFileEntryType.getPrimaryKey());
6177                            }
6178                    }
6179                    catch (Exception e) {
6180                            throw processException(e);
6181                    }
6182                    finally {
6183                            FinderCacheUtil.clearCache(DLFolderModelImpl.MAPPING_TABLE_DLFILEENTRYTYPES_DLFOLDERS_NAME);
6184                    }
6185            }
6186    
6187            /**
6188             * Sets the document library file entry types associated with the document library folder, removing and adding associations as necessary. Also notifies the appropriate model listeners and clears the mapping table finder cache.
6189             *
6190             * @param pk the primary key of the document library folder
6191             * @param dlFileEntryTypePKs the primary keys of the document library file entry types to be associated with the document library folder
6192             * @throws SystemException if a system exception occurred
6193             */
6194            public void setDLFileEntryTypes(long pk, long[] dlFileEntryTypePKs)
6195                    throws SystemException {
6196                    try {
6197                            Set<Long> dlFileEntryTypePKSet = SetUtil.fromArray(dlFileEntryTypePKs);
6198    
6199                            List<com.liferay.portlet.documentlibrary.model.DLFileEntryType> dlFileEntryTypes =
6200                                    getDLFileEntryTypes(pk);
6201    
6202                            for (com.liferay.portlet.documentlibrary.model.DLFileEntryType dlFileEntryType : dlFileEntryTypes) {
6203                                    if (!dlFileEntryTypePKSet.remove(
6204                                                            dlFileEntryType.getPrimaryKey())) {
6205                                            removeDLFileEntryType.remove(pk,
6206                                                    dlFileEntryType.getPrimaryKey());
6207                                    }
6208                            }
6209    
6210                            for (Long dlFileEntryTypePK : dlFileEntryTypePKSet) {
6211                                    addDLFileEntryType.add(pk, dlFileEntryTypePK);
6212                            }
6213                    }
6214                    catch (Exception e) {
6215                            throw processException(e);
6216                    }
6217                    finally {
6218                            FinderCacheUtil.clearCache(DLFolderModelImpl.MAPPING_TABLE_DLFILEENTRYTYPES_DLFOLDERS_NAME);
6219                    }
6220            }
6221    
6222            /**
6223             * Sets the document library file entry types associated with the document library folder, removing and adding associations as necessary. Also notifies the appropriate model listeners and clears the mapping table finder cache.
6224             *
6225             * @param pk the primary key of the document library folder
6226             * @param dlFileEntryTypes the document library file entry types to be associated with the document library folder
6227             * @throws SystemException if a system exception occurred
6228             */
6229            public void setDLFileEntryTypes(long pk,
6230                    List<com.liferay.portlet.documentlibrary.model.DLFileEntryType> dlFileEntryTypes)
6231                    throws SystemException {
6232                    try {
6233                            long[] dlFileEntryTypePKs = new long[dlFileEntryTypes.size()];
6234    
6235                            for (int i = 0; i < dlFileEntryTypes.size(); i++) {
6236                                    com.liferay.portlet.documentlibrary.model.DLFileEntryType dlFileEntryType =
6237                                            dlFileEntryTypes.get(i);
6238    
6239                                    dlFileEntryTypePKs[i] = dlFileEntryType.getPrimaryKey();
6240                            }
6241    
6242                            setDLFileEntryTypes(pk, dlFileEntryTypePKs);
6243                    }
6244                    catch (Exception e) {
6245                            throw processException(e);
6246                    }
6247                    finally {
6248                            FinderCacheUtil.clearCache(DLFolderModelImpl.MAPPING_TABLE_DLFILEENTRYTYPES_DLFOLDERS_NAME);
6249                    }
6250            }
6251    
6252            /**
6253             * Initializes the document library folder persistence.
6254             */
6255            public void afterPropertiesSet() {
6256                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
6257                                            com.liferay.portal.util.PropsUtil.get(
6258                                                    "value.object.listener.com.liferay.portlet.documentlibrary.model.DLFolder")));
6259    
6260                    if (listenerClassNames.length > 0) {
6261                            try {
6262                                    List<ModelListener<DLFolder>> listenersList = new ArrayList<ModelListener<DLFolder>>();
6263    
6264                                    for (String listenerClassName : listenerClassNames) {
6265                                            listenersList.add((ModelListener<DLFolder>)InstanceFactory.newInstance(
6266                                                            listenerClassName));
6267                                    }
6268    
6269                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
6270                            }
6271                            catch (Exception e) {
6272                                    _log.error(e);
6273                            }
6274                    }
6275    
6276                    containsDLFileEntryType = new ContainsDLFileEntryType();
6277    
6278                    addDLFileEntryType = new AddDLFileEntryType();
6279                    clearDLFileEntryTypes = new ClearDLFileEntryTypes();
6280                    removeDLFileEntryType = new RemoveDLFileEntryType();
6281            }
6282    
6283            public void destroy() {
6284                    EntityCacheUtil.removeCache(DLFolderImpl.class.getName());
6285                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
6286                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
6287            }
6288    
6289            @BeanReference(type = DLContentPersistence.class)
6290            protected DLContentPersistence dlContentPersistence;
6291            @BeanReference(type = DLFileEntryPersistence.class)
6292            protected DLFileEntryPersistence dlFileEntryPersistence;
6293            @BeanReference(type = DLFileEntryMetadataPersistence.class)
6294            protected DLFileEntryMetadataPersistence dlFileEntryMetadataPersistence;
6295            @BeanReference(type = DLFileEntryTypePersistence.class)
6296            protected DLFileEntryTypePersistence dlFileEntryTypePersistence;
6297            @BeanReference(type = DLFileRankPersistence.class)
6298            protected DLFileRankPersistence dlFileRankPersistence;
6299            @BeanReference(type = DLFileShortcutPersistence.class)
6300            protected DLFileShortcutPersistence dlFileShortcutPersistence;
6301            @BeanReference(type = DLFileVersionPersistence.class)
6302            protected DLFileVersionPersistence dlFileVersionPersistence;
6303            @BeanReference(type = DLFolderPersistence.class)
6304            protected DLFolderPersistence dlFolderPersistence;
6305            @BeanReference(type = DLSyncPersistence.class)
6306            protected DLSyncPersistence dlSyncPersistence;
6307            @BeanReference(type = GroupPersistence.class)
6308            protected GroupPersistence groupPersistence;
6309            @BeanReference(type = LockPersistence.class)
6310            protected LockPersistence lockPersistence;
6311            @BeanReference(type = ResourcePersistence.class)
6312            protected ResourcePersistence resourcePersistence;
6313            @BeanReference(type = UserPersistence.class)
6314            protected UserPersistence userPersistence;
6315            @BeanReference(type = WebDAVPropsPersistence.class)
6316            protected WebDAVPropsPersistence webDAVPropsPersistence;
6317            @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
6318            protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
6319            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
6320            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
6321            @BeanReference(type = ExpandoValuePersistence.class)
6322            protected ExpandoValuePersistence expandoValuePersistence;
6323            protected ContainsDLFileEntryType containsDLFileEntryType;
6324            protected AddDLFileEntryType addDLFileEntryType;
6325            protected ClearDLFileEntryTypes clearDLFileEntryTypes;
6326            protected RemoveDLFileEntryType removeDLFileEntryType;
6327    
6328            protected class ContainsDLFileEntryType {
6329                    protected ContainsDLFileEntryType() {
6330                            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
6331                                            _SQL_CONTAINSDLFILEENTRYTYPE,
6332                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT },
6333                                            RowMapper.COUNT);
6334                    }
6335    
6336                    protected boolean contains(long folderId, long fileEntryTypeId) {
6337                            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
6338                                                    new Long(folderId), new Long(fileEntryTypeId)
6339                                            });
6340    
6341                            if (results.size() > 0) {
6342                                    Integer count = results.get(0);
6343    
6344                                    if (count.intValue() > 0) {
6345                                            return true;
6346                                    }
6347                            }
6348    
6349                            return false;
6350                    }
6351    
6352                    private MappingSqlQuery<Integer> _mappingSqlQuery;
6353            }
6354    
6355            protected class AddDLFileEntryType {
6356                    protected AddDLFileEntryType() {
6357                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
6358                                            "INSERT INTO DLFileEntryTypes_DLFolders (folderId, fileEntryTypeId) VALUES (?, ?)",
6359                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
6360                    }
6361    
6362                    protected void add(long folderId, long fileEntryTypeId)
6363                            throws SystemException {
6364                            if (!containsDLFileEntryType.contains(folderId, fileEntryTypeId)) {
6365                                    ModelListener<com.liferay.portlet.documentlibrary.model.DLFileEntryType>[] dlFileEntryTypeListeners =
6366                                            dlFileEntryTypePersistence.getListeners();
6367    
6368                                    for (ModelListener<DLFolder> listener : listeners) {
6369                                            listener.onBeforeAddAssociation(folderId,
6370                                                    com.liferay.portlet.documentlibrary.model.DLFileEntryType.class.getName(),
6371                                                    fileEntryTypeId);
6372                                    }
6373    
6374                                    for (ModelListener<com.liferay.portlet.documentlibrary.model.DLFileEntryType> listener : dlFileEntryTypeListeners) {
6375                                            listener.onBeforeAddAssociation(fileEntryTypeId,
6376                                                    DLFolder.class.getName(), folderId);
6377                                    }
6378    
6379                                    _sqlUpdate.update(new Object[] {
6380                                                    new Long(folderId), new Long(fileEntryTypeId)
6381                                            });
6382    
6383                                    for (ModelListener<DLFolder> listener : listeners) {
6384                                            listener.onAfterAddAssociation(folderId,
6385                                                    com.liferay.portlet.documentlibrary.model.DLFileEntryType.class.getName(),
6386                                                    fileEntryTypeId);
6387                                    }
6388    
6389                                    for (ModelListener<com.liferay.portlet.documentlibrary.model.DLFileEntryType> listener : dlFileEntryTypeListeners) {
6390                                            listener.onAfterAddAssociation(fileEntryTypeId,
6391                                                    DLFolder.class.getName(), folderId);
6392                                    }
6393                            }
6394                    }
6395    
6396                    private SqlUpdate _sqlUpdate;
6397            }
6398    
6399            protected class ClearDLFileEntryTypes {
6400                    protected ClearDLFileEntryTypes() {
6401                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
6402                                            "DELETE FROM DLFileEntryTypes_DLFolders WHERE folderId = ?",
6403                                            new int[] { java.sql.Types.BIGINT });
6404                    }
6405    
6406                    protected void clear(long folderId) throws SystemException {
6407                            ModelListener<com.liferay.portlet.documentlibrary.model.DLFileEntryType>[] dlFileEntryTypeListeners =
6408                                    dlFileEntryTypePersistence.getListeners();
6409    
6410                            List<com.liferay.portlet.documentlibrary.model.DLFileEntryType> dlFileEntryTypes =
6411                                    null;
6412    
6413                            if ((listeners.length > 0) ||
6414                                            (dlFileEntryTypeListeners.length > 0)) {
6415                                    dlFileEntryTypes = getDLFileEntryTypes(folderId);
6416    
6417                                    for (com.liferay.portlet.documentlibrary.model.DLFileEntryType dlFileEntryType : dlFileEntryTypes) {
6418                                            for (ModelListener<DLFolder> listener : listeners) {
6419                                                    listener.onBeforeRemoveAssociation(folderId,
6420                                                            com.liferay.portlet.documentlibrary.model.DLFileEntryType.class.getName(),
6421                                                            dlFileEntryType.getPrimaryKey());
6422                                            }
6423    
6424                                            for (ModelListener<com.liferay.portlet.documentlibrary.model.DLFileEntryType> listener : dlFileEntryTypeListeners) {
6425                                                    listener.onBeforeRemoveAssociation(dlFileEntryType.getPrimaryKey(),
6426                                                            DLFolder.class.getName(), folderId);
6427                                            }
6428                                    }
6429                            }
6430    
6431                            _sqlUpdate.update(new Object[] { new Long(folderId) });
6432    
6433                            if ((listeners.length > 0) ||
6434                                            (dlFileEntryTypeListeners.length > 0)) {
6435                                    for (com.liferay.portlet.documentlibrary.model.DLFileEntryType dlFileEntryType : dlFileEntryTypes) {
6436                                            for (ModelListener<DLFolder> listener : listeners) {
6437                                                    listener.onAfterRemoveAssociation(folderId,
6438                                                            com.liferay.portlet.documentlibrary.model.DLFileEntryType.class.getName(),
6439                                                            dlFileEntryType.getPrimaryKey());
6440                                            }
6441    
6442                                            for (ModelListener<com.liferay.portlet.documentlibrary.model.DLFileEntryType> listener : dlFileEntryTypeListeners) {
6443                                                    listener.onAfterRemoveAssociation(dlFileEntryType.getPrimaryKey(),
6444                                                            DLFolder.class.getName(), folderId);
6445                                            }
6446                                    }
6447                            }
6448                    }
6449    
6450                    private SqlUpdate _sqlUpdate;
6451            }
6452    
6453            protected class RemoveDLFileEntryType {
6454                    protected RemoveDLFileEntryType() {
6455                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
6456                                            "DELETE FROM DLFileEntryTypes_DLFolders WHERE folderId = ? AND fileEntryTypeId = ?",
6457                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
6458                    }
6459    
6460                    protected void remove(long folderId, long fileEntryTypeId)
6461                            throws SystemException {
6462                            if (containsDLFileEntryType.contains(folderId, fileEntryTypeId)) {
6463                                    ModelListener<com.liferay.portlet.documentlibrary.model.DLFileEntryType>[] dlFileEntryTypeListeners =
6464                                            dlFileEntryTypePersistence.getListeners();
6465    
6466                                    for (ModelListener<DLFolder> listener : listeners) {
6467                                            listener.onBeforeRemoveAssociation(folderId,
6468                                                    com.liferay.portlet.documentlibrary.model.DLFileEntryType.class.getName(),
6469                                                    fileEntryTypeId);
6470                                    }
6471    
6472                                    for (ModelListener<com.liferay.portlet.documentlibrary.model.DLFileEntryType> listener : dlFileEntryTypeListeners) {
6473                                            listener.onBeforeRemoveAssociation(fileEntryTypeId,
6474                                                    DLFolder.class.getName(), folderId);
6475                                    }
6476    
6477                                    _sqlUpdate.update(new Object[] {
6478                                                    new Long(folderId), new Long(fileEntryTypeId)
6479                                            });
6480    
6481                                    for (ModelListener<DLFolder> listener : listeners) {
6482                                            listener.onAfterRemoveAssociation(folderId,
6483                                                    com.liferay.portlet.documentlibrary.model.DLFileEntryType.class.getName(),
6484                                                    fileEntryTypeId);
6485                                    }
6486    
6487                                    for (ModelListener<com.liferay.portlet.documentlibrary.model.DLFileEntryType> listener : dlFileEntryTypeListeners) {
6488                                            listener.onAfterRemoveAssociation(fileEntryTypeId,
6489                                                    DLFolder.class.getName(), folderId);
6490                                    }
6491                            }
6492                    }
6493    
6494                    private SqlUpdate _sqlUpdate;
6495            }
6496    
6497            private static final String _SQL_SELECT_DLFOLDER = "SELECT dlFolder FROM DLFolder dlFolder";
6498            private static final String _SQL_SELECT_DLFOLDER_WHERE = "SELECT dlFolder FROM DLFolder dlFolder WHERE ";
6499            private static final String _SQL_COUNT_DLFOLDER = "SELECT COUNT(dlFolder) FROM DLFolder dlFolder";
6500            private static final String _SQL_COUNT_DLFOLDER_WHERE = "SELECT COUNT(dlFolder) FROM DLFolder dlFolder WHERE ";
6501            private static final String _SQL_GETDLFILEENTRYTYPES = "SELECT {DLFileEntryType.*} FROM DLFileEntryType INNER JOIN DLFileEntryTypes_DLFolders ON (DLFileEntryTypes_DLFolders.fileEntryTypeId = DLFileEntryType.fileEntryTypeId) WHERE (DLFileEntryTypes_DLFolders.folderId = ?)";
6502            private static final String _SQL_GETDLFILEENTRYTYPESSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM DLFileEntryTypes_DLFolders WHERE folderId = ?";
6503            private static final String _SQL_CONTAINSDLFILEENTRYTYPE = "SELECT COUNT(*) AS COUNT_VALUE FROM DLFileEntryTypes_DLFolders WHERE folderId = ? AND fileEntryTypeId = ?";
6504            private static final String _FINDER_COLUMN_UUID_UUID_1 = "dlFolder.uuid IS NULL";
6505            private static final String _FINDER_COLUMN_UUID_UUID_2 = "dlFolder.uuid = ?";
6506            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(dlFolder.uuid IS NULL OR dlFolder.uuid = ?)";
6507            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "dlFolder.uuid IS NULL AND ";
6508            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "dlFolder.uuid = ? AND ";
6509            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(dlFolder.uuid IS NULL OR dlFolder.uuid = ?) AND ";
6510            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "dlFolder.groupId = ?";
6511            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "dlFolder.groupId = ?";
6512            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "dlFolder.companyId = ?";
6513            private static final String _FINDER_COLUMN_REPOSITORYID_REPOSITORYID_2 = "dlFolder.repositoryId = ?";
6514            private static final String _FINDER_COLUMN_G_P_GROUPID_2 = "dlFolder.groupId = ? AND ";
6515            private static final String _FINDER_COLUMN_G_P_PARENTFOLDERID_2 = "dlFolder.parentFolderId = ?";
6516            private static final String _FINDER_COLUMN_P_N_PARENTFOLDERID_2 = "dlFolder.parentFolderId = ? AND ";
6517            private static final String _FINDER_COLUMN_P_N_NAME_1 = "dlFolder.name IS NULL";
6518            private static final String _FINDER_COLUMN_P_N_NAME_2 = "dlFolder.name = ?";
6519            private static final String _FINDER_COLUMN_P_N_NAME_3 = "(dlFolder.name IS NULL OR dlFolder.name = ?)";
6520            private static final String _FINDER_COLUMN_G_P_M_GROUPID_2 = "dlFolder.groupId = ? AND ";
6521            private static final String _FINDER_COLUMN_G_P_M_PARENTFOLDERID_2 = "dlFolder.parentFolderId = ? AND ";
6522            private static final String _FINDER_COLUMN_G_P_M_MOUNTPOINT_2 = "dlFolder.mountPoint = ?";
6523            private static final String _FINDER_COLUMN_G_P_N_GROUPID_2 = "dlFolder.groupId = ? AND ";
6524            private static final String _FINDER_COLUMN_G_P_N_PARENTFOLDERID_2 = "dlFolder.parentFolderId = ? AND ";
6525            private static final String _FINDER_COLUMN_G_P_N_NAME_1 = "dlFolder.name IS NULL";
6526            private static final String _FINDER_COLUMN_G_P_N_NAME_2 = "dlFolder.name = ?";
6527            private static final String _FINDER_COLUMN_G_P_N_NAME_3 = "(dlFolder.name IS NULL OR dlFolder.name = ?)";
6528            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "dlFolder.folderId";
6529            private static final String _FILTER_SQL_SELECT_DLFOLDER_WHERE = "SELECT DISTINCT {dlFolder.*} FROM DLFolder dlFolder WHERE ";
6530            private static final String _FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1 =
6531                    "SELECT {DLFolder.*} FROM (SELECT DISTINCT dlFolder.folderId FROM DLFolder dlFolder WHERE ";
6532            private static final String _FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2 =
6533                    ") TEMP_TABLE INNER JOIN DLFolder ON TEMP_TABLE.folderId = DLFolder.folderId";
6534            private static final String _FILTER_SQL_COUNT_DLFOLDER_WHERE = "SELECT COUNT(DISTINCT dlFolder.folderId) AS COUNT_VALUE FROM DLFolder dlFolder WHERE ";
6535            private static final String _FILTER_ENTITY_ALIAS = "dlFolder";
6536            private static final String _FILTER_ENTITY_TABLE = "DLFolder";
6537            private static final String _ORDER_BY_ENTITY_ALIAS = "dlFolder.";
6538            private static final String _ORDER_BY_ENTITY_TABLE = "DLFolder.";
6539            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No DLFolder exists with the primary key ";
6540            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No DLFolder exists with the key {";
6541            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
6542            private static Log _log = LogFactoryUtil.getLog(DLFolderPersistenceImpl.class);
6543            private static DLFolder _nullDLFolder = new DLFolderImpl() {
6544                            @Override
6545                            public Object clone() {
6546                                    return this;
6547                            }
6548    
6549                            @Override
6550                            public CacheModel<DLFolder> toCacheModel() {
6551                                    return _nullDLFolderCacheModel;
6552                            }
6553                    };
6554    
6555            private static CacheModel<DLFolder> _nullDLFolderCacheModel = new CacheModel<DLFolder>() {
6556                            public DLFolder toEntityModel() {
6557                                    return _nullDLFolder;
6558                            }
6559                    };
6560    }