001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.documentlibrary.service.persistence.impl;
016    
017    import aQute.bnd.annotation.ProviderType;
018    
019    import com.liferay.portal.kernel.bean.BeanReference;
020    import com.liferay.portal.kernel.dao.orm.EntityCache;
021    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderCache;
023    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
024    import com.liferay.portal.kernel.dao.orm.FinderPath;
025    import com.liferay.portal.kernel.dao.orm.Query;
026    import com.liferay.portal.kernel.dao.orm.QueryPos;
027    import com.liferay.portal.kernel.dao.orm.QueryUtil;
028    import com.liferay.portal.kernel.dao.orm.SQLQuery;
029    import com.liferay.portal.kernel.dao.orm.Session;
030    import com.liferay.portal.kernel.log.Log;
031    import com.liferay.portal.kernel.log.LogFactoryUtil;
032    import com.liferay.portal.kernel.security.permission.InlineSQLHelperUtil;
033    import com.liferay.portal.kernel.util.CharPool;
034    import com.liferay.portal.kernel.util.OrderByComparator;
035    import com.liferay.portal.kernel.util.SetUtil;
036    import com.liferay.portal.kernel.util.StringBundler;
037    import com.liferay.portal.kernel.util.StringPool;
038    import com.liferay.portal.kernel.util.StringUtil;
039    import com.liferay.portal.kernel.util.Validator;
040    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
041    import com.liferay.portal.model.CacheModel;
042    import com.liferay.portal.service.ServiceContext;
043    import com.liferay.portal.service.ServiceContextThreadLocal;
044    import com.liferay.portal.service.persistence.CompanyProvider;
045    import com.liferay.portal.service.persistence.CompanyProviderWrapper;
046    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
047    import com.liferay.portal.service.persistence.impl.TableMapper;
048    import com.liferay.portal.service.persistence.impl.TableMapperFactory;
049    
050    import com.liferay.portlet.documentlibrary.exception.NoSuchFolderException;
051    import com.liferay.portlet.documentlibrary.model.DLFolder;
052    import com.liferay.portlet.documentlibrary.model.impl.DLFolderImpl;
053    import com.liferay.portlet.documentlibrary.model.impl.DLFolderModelImpl;
054    import com.liferay.portlet.documentlibrary.service.persistence.DLFileEntryTypePersistence;
055    import com.liferay.portlet.documentlibrary.service.persistence.DLFolderPersistence;
056    
057    import java.io.Serializable;
058    
059    import java.util.Collections;
060    import java.util.Date;
061    import java.util.HashMap;
062    import java.util.HashSet;
063    import java.util.Iterator;
064    import java.util.List;
065    import java.util.Map;
066    import java.util.Set;
067    
068    /**
069     * The persistence implementation for the document library folder service.
070     *
071     * <p>
072     * Caching information and settings can be found in <code>portal.properties</code>
073     * </p>
074     *
075     * @author Brian Wing Shun Chan
076     * @see DLFolderPersistence
077     * @see com.liferay.portlet.documentlibrary.service.persistence.DLFolderUtil
078     * @generated
079     */
080    @ProviderType
081    public class DLFolderPersistenceImpl extends BasePersistenceImpl<DLFolder>
082            implements DLFolderPersistence {
083            /*
084             * NOTE FOR DEVELOPERS:
085             *
086             * 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.
087             */
088            public static final String FINDER_CLASS_NAME_ENTITY = DLFolderImpl.class.getName();
089            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
090                    ".List1";
091            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
092                    ".List2";
093            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
094                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
095                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
096            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
097                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
098                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
099            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
100                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
101                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
102            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
103                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
104                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
105                            new String[] {
106                                    String.class.getName(),
107                                    
108                            Integer.class.getName(), Integer.class.getName(),
109                                    OrderByComparator.class.getName()
110                            });
111            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
112                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
113                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
114                            new String[] { String.class.getName() },
115                            DLFolderModelImpl.UUID_COLUMN_BITMASK |
116                            DLFolderModelImpl.PARENTFOLDERID_COLUMN_BITMASK |
117                            DLFolderModelImpl.NAME_COLUMN_BITMASK);
118            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
119                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
120                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
121                            new String[] { String.class.getName() });
122    
123            /**
124             * Returns all the document library folders where uuid = &#63;.
125             *
126             * @param uuid the uuid
127             * @return the matching document library folders
128             */
129            @Override
130            public List<DLFolder> findByUuid(String uuid) {
131                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
132            }
133    
134            /**
135             * Returns a range of all the document library folders where uuid = &#63;.
136             *
137             * <p>
138             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
139             * </p>
140             *
141             * @param uuid the uuid
142             * @param start the lower bound of the range of document library folders
143             * @param end the upper bound of the range of document library folders (not inclusive)
144             * @return the range of matching document library folders
145             */
146            @Override
147            public List<DLFolder> findByUuid(String uuid, int start, int end) {
148                    return findByUuid(uuid, start, end, null);
149            }
150    
151            /**
152             * Returns an ordered range of all the document library folders where uuid = &#63;.
153             *
154             * <p>
155             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
156             * </p>
157             *
158             * @param uuid the uuid
159             * @param start the lower bound of the range of document library folders
160             * @param end the upper bound of the range of document library folders (not inclusive)
161             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
162             * @return the ordered range of matching document library folders
163             */
164            @Override
165            public List<DLFolder> findByUuid(String uuid, int start, int end,
166                    OrderByComparator<DLFolder> orderByComparator) {
167                    return findByUuid(uuid, start, end, orderByComparator, true);
168            }
169    
170            /**
171             * Returns an ordered range of all the document library folders where uuid = &#63;.
172             *
173             * <p>
174             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
175             * </p>
176             *
177             * @param uuid the uuid
178             * @param start the lower bound of the range of document library folders
179             * @param end the upper bound of the range of document library folders (not inclusive)
180             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
181             * @param retrieveFromCache whether to retrieve from the finder cache
182             * @return the ordered range of matching document library folders
183             */
184            @Override
185            public List<DLFolder> findByUuid(String uuid, int start, int end,
186                    OrderByComparator<DLFolder> orderByComparator, boolean retrieveFromCache) {
187                    boolean pagination = true;
188                    FinderPath finderPath = null;
189                    Object[] finderArgs = null;
190    
191                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
192                                    (orderByComparator == null)) {
193                            pagination = false;
194                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
195                            finderArgs = new Object[] { uuid };
196                    }
197                    else {
198                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
199                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
200                    }
201    
202                    List<DLFolder> list = null;
203    
204                    if (retrieveFromCache) {
205                            list = (List<DLFolder>)finderCache.getResult(finderPath,
206                                            finderArgs, this);
207    
208                            if ((list != null) && !list.isEmpty()) {
209                                    for (DLFolder dlFolder : list) {
210                                            if (!Validator.equals(uuid, dlFolder.getUuid())) {
211                                                    list = null;
212    
213                                                    break;
214                                            }
215                                    }
216                            }
217                    }
218    
219                    if (list == null) {
220                            StringBundler query = null;
221    
222                            if (orderByComparator != null) {
223                                    query = new StringBundler(3 +
224                                                    (orderByComparator.getOrderByFields().length * 2));
225                            }
226                            else {
227                                    query = new StringBundler(3);
228                            }
229    
230                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
231    
232                            boolean bindUuid = false;
233    
234                            if (uuid == null) {
235                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
236                            }
237                            else if (uuid.equals(StringPool.BLANK)) {
238                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
239                            }
240                            else {
241                                    bindUuid = true;
242    
243                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
244                            }
245    
246                            if (orderByComparator != null) {
247                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
248                                            orderByComparator);
249                            }
250                            else
251                             if (pagination) {
252                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
253                            }
254    
255                            String sql = query.toString();
256    
257                            Session session = null;
258    
259                            try {
260                                    session = openSession();
261    
262                                    Query q = session.createQuery(sql);
263    
264                                    QueryPos qPos = QueryPos.getInstance(q);
265    
266                                    if (bindUuid) {
267                                            qPos.add(uuid);
268                                    }
269    
270                                    if (!pagination) {
271                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
272                                                            start, end, false);
273    
274                                            Collections.sort(list);
275    
276                                            list = Collections.unmodifiableList(list);
277                                    }
278                                    else {
279                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
280                                                            start, end);
281                                    }
282    
283                                    cacheResult(list);
284    
285                                    finderCache.putResult(finderPath, finderArgs, list);
286                            }
287                            catch (Exception e) {
288                                    finderCache.removeResult(finderPath, finderArgs);
289    
290                                    throw processException(e);
291                            }
292                            finally {
293                                    closeSession(session);
294                            }
295                    }
296    
297                    return list;
298            }
299    
300            /**
301             * Returns the first document library folder in the ordered set where uuid = &#63;.
302             *
303             * @param uuid the uuid
304             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
305             * @return the first matching document library folder
306             * @throws NoSuchFolderException if a matching document library folder could not be found
307             */
308            @Override
309            public DLFolder findByUuid_First(String uuid,
310                    OrderByComparator<DLFolder> orderByComparator)
311                    throws NoSuchFolderException {
312                    DLFolder dlFolder = fetchByUuid_First(uuid, orderByComparator);
313    
314                    if (dlFolder != null) {
315                            return dlFolder;
316                    }
317    
318                    StringBundler msg = new StringBundler(4);
319    
320                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
321    
322                    msg.append("uuid=");
323                    msg.append(uuid);
324    
325                    msg.append(StringPool.CLOSE_CURLY_BRACE);
326    
327                    throw new NoSuchFolderException(msg.toString());
328            }
329    
330            /**
331             * Returns the first document library folder in the ordered set where uuid = &#63;.
332             *
333             * @param uuid the uuid
334             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
335             * @return the first matching document library folder, or <code>null</code> if a matching document library folder could not be found
336             */
337            @Override
338            public DLFolder fetchByUuid_First(String uuid,
339                    OrderByComparator<DLFolder> orderByComparator) {
340                    List<DLFolder> list = findByUuid(uuid, 0, 1, orderByComparator);
341    
342                    if (!list.isEmpty()) {
343                            return list.get(0);
344                    }
345    
346                    return null;
347            }
348    
349            /**
350             * Returns the last document library folder in the ordered set where uuid = &#63;.
351             *
352             * @param uuid the uuid
353             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
354             * @return the last matching document library folder
355             * @throws NoSuchFolderException if a matching document library folder could not be found
356             */
357            @Override
358            public DLFolder findByUuid_Last(String uuid,
359                    OrderByComparator<DLFolder> orderByComparator)
360                    throws NoSuchFolderException {
361                    DLFolder dlFolder = fetchByUuid_Last(uuid, orderByComparator);
362    
363                    if (dlFolder != null) {
364                            return dlFolder;
365                    }
366    
367                    StringBundler msg = new StringBundler(4);
368    
369                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
370    
371                    msg.append("uuid=");
372                    msg.append(uuid);
373    
374                    msg.append(StringPool.CLOSE_CURLY_BRACE);
375    
376                    throw new NoSuchFolderException(msg.toString());
377            }
378    
379            /**
380             * Returns the last document library folder in the ordered set where uuid = &#63;.
381             *
382             * @param uuid the uuid
383             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
384             * @return the last matching document library folder, or <code>null</code> if a matching document library folder could not be found
385             */
386            @Override
387            public DLFolder fetchByUuid_Last(String uuid,
388                    OrderByComparator<DLFolder> orderByComparator) {
389                    int count = countByUuid(uuid);
390    
391                    if (count == 0) {
392                            return null;
393                    }
394    
395                    List<DLFolder> list = findByUuid(uuid, count - 1, count,
396                                    orderByComparator);
397    
398                    if (!list.isEmpty()) {
399                            return list.get(0);
400                    }
401    
402                    return null;
403            }
404    
405            /**
406             * Returns the document library folders before and after the current document library folder in the ordered set where uuid = &#63;.
407             *
408             * @param folderId the primary key of the current document library folder
409             * @param uuid the uuid
410             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
411             * @return the previous, current, and next document library folder
412             * @throws NoSuchFolderException if a document library folder with the primary key could not be found
413             */
414            @Override
415            public DLFolder[] findByUuid_PrevAndNext(long folderId, String uuid,
416                    OrderByComparator<DLFolder> orderByComparator)
417                    throws NoSuchFolderException {
418                    DLFolder dlFolder = findByPrimaryKey(folderId);
419    
420                    Session session = null;
421    
422                    try {
423                            session = openSession();
424    
425                            DLFolder[] array = new DLFolderImpl[3];
426    
427                            array[0] = getByUuid_PrevAndNext(session, dlFolder, uuid,
428                                            orderByComparator, true);
429    
430                            array[1] = dlFolder;
431    
432                            array[2] = getByUuid_PrevAndNext(session, dlFolder, uuid,
433                                            orderByComparator, false);
434    
435                            return array;
436                    }
437                    catch (Exception e) {
438                            throw processException(e);
439                    }
440                    finally {
441                            closeSession(session);
442                    }
443            }
444    
445            protected DLFolder getByUuid_PrevAndNext(Session session,
446                    DLFolder dlFolder, String uuid,
447                    OrderByComparator<DLFolder> orderByComparator, boolean previous) {
448                    StringBundler query = null;
449    
450                    if (orderByComparator != null) {
451                            query = new StringBundler(4 +
452                                            (orderByComparator.getOrderByConditionFields().length * 3) +
453                                            (orderByComparator.getOrderByFields().length * 3));
454                    }
455                    else {
456                            query = new StringBundler(3);
457                    }
458    
459                    query.append(_SQL_SELECT_DLFOLDER_WHERE);
460    
461                    boolean bindUuid = false;
462    
463                    if (uuid == null) {
464                            query.append(_FINDER_COLUMN_UUID_UUID_1);
465                    }
466                    else if (uuid.equals(StringPool.BLANK)) {
467                            query.append(_FINDER_COLUMN_UUID_UUID_3);
468                    }
469                    else {
470                            bindUuid = true;
471    
472                            query.append(_FINDER_COLUMN_UUID_UUID_2);
473                    }
474    
475                    if (orderByComparator != null) {
476                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
477    
478                            if (orderByConditionFields.length > 0) {
479                                    query.append(WHERE_AND);
480                            }
481    
482                            for (int i = 0; i < orderByConditionFields.length; i++) {
483                                    query.append(_ORDER_BY_ENTITY_ALIAS);
484                                    query.append(orderByConditionFields[i]);
485    
486                                    if ((i + 1) < orderByConditionFields.length) {
487                                            if (orderByComparator.isAscending() ^ previous) {
488                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
489                                            }
490                                            else {
491                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
492                                            }
493                                    }
494                                    else {
495                                            if (orderByComparator.isAscending() ^ previous) {
496                                                    query.append(WHERE_GREATER_THAN);
497                                            }
498                                            else {
499                                                    query.append(WHERE_LESSER_THAN);
500                                            }
501                                    }
502                            }
503    
504                            query.append(ORDER_BY_CLAUSE);
505    
506                            String[] orderByFields = orderByComparator.getOrderByFields();
507    
508                            for (int i = 0; i < orderByFields.length; i++) {
509                                    query.append(_ORDER_BY_ENTITY_ALIAS);
510                                    query.append(orderByFields[i]);
511    
512                                    if ((i + 1) < orderByFields.length) {
513                                            if (orderByComparator.isAscending() ^ previous) {
514                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
515                                            }
516                                            else {
517                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
518                                            }
519                                    }
520                                    else {
521                                            if (orderByComparator.isAscending() ^ previous) {
522                                                    query.append(ORDER_BY_ASC);
523                                            }
524                                            else {
525                                                    query.append(ORDER_BY_DESC);
526                                            }
527                                    }
528                            }
529                    }
530                    else {
531                            query.append(DLFolderModelImpl.ORDER_BY_JPQL);
532                    }
533    
534                    String sql = query.toString();
535    
536                    Query q = session.createQuery(sql);
537    
538                    q.setFirstResult(0);
539                    q.setMaxResults(2);
540    
541                    QueryPos qPos = QueryPos.getInstance(q);
542    
543                    if (bindUuid) {
544                            qPos.add(uuid);
545                    }
546    
547                    if (orderByComparator != null) {
548                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
549    
550                            for (Object value : values) {
551                                    qPos.add(value);
552                            }
553                    }
554    
555                    List<DLFolder> list = q.list();
556    
557                    if (list.size() == 2) {
558                            return list.get(1);
559                    }
560                    else {
561                            return null;
562                    }
563            }
564    
565            /**
566             * Removes all the document library folders where uuid = &#63; from the database.
567             *
568             * @param uuid the uuid
569             */
570            @Override
571            public void removeByUuid(String uuid) {
572                    for (DLFolder dlFolder : findByUuid(uuid, QueryUtil.ALL_POS,
573                                    QueryUtil.ALL_POS, null)) {
574                            remove(dlFolder);
575                    }
576            }
577    
578            /**
579             * Returns the number of document library folders where uuid = &#63;.
580             *
581             * @param uuid the uuid
582             * @return the number of matching document library folders
583             */
584            @Override
585            public int countByUuid(String uuid) {
586                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
587    
588                    Object[] finderArgs = new Object[] { uuid };
589    
590                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
591    
592                    if (count == null) {
593                            StringBundler query = new StringBundler(2);
594    
595                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
596    
597                            boolean bindUuid = false;
598    
599                            if (uuid == null) {
600                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
601                            }
602                            else if (uuid.equals(StringPool.BLANK)) {
603                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
604                            }
605                            else {
606                                    bindUuid = true;
607    
608                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
609                            }
610    
611                            String sql = query.toString();
612    
613                            Session session = null;
614    
615                            try {
616                                    session = openSession();
617    
618                                    Query q = session.createQuery(sql);
619    
620                                    QueryPos qPos = QueryPos.getInstance(q);
621    
622                                    if (bindUuid) {
623                                            qPos.add(uuid);
624                                    }
625    
626                                    count = (Long)q.uniqueResult();
627    
628                                    finderCache.putResult(finderPath, finderArgs, count);
629                            }
630                            catch (Exception e) {
631                                    finderCache.removeResult(finderPath, finderArgs);
632    
633                                    throw processException(e);
634                            }
635                            finally {
636                                    closeSession(session);
637                            }
638                    }
639    
640                    return count.intValue();
641            }
642    
643            private static final String _FINDER_COLUMN_UUID_UUID_1 = "dlFolder.uuid IS NULL";
644            private static final String _FINDER_COLUMN_UUID_UUID_2 = "dlFolder.uuid = ?";
645            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(dlFolder.uuid IS NULL OR dlFolder.uuid = '')";
646            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
647                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
648                            FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
649                            new String[] { String.class.getName(), Long.class.getName() },
650                            DLFolderModelImpl.UUID_COLUMN_BITMASK |
651                            DLFolderModelImpl.GROUPID_COLUMN_BITMASK);
652            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
653                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
654                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
655                            new String[] { String.class.getName(), Long.class.getName() });
656    
657            /**
658             * Returns the document library folder where uuid = &#63; and groupId = &#63; or throws a {@link NoSuchFolderException} if it could not be found.
659             *
660             * @param uuid the uuid
661             * @param groupId the group ID
662             * @return the matching document library folder
663             * @throws NoSuchFolderException if a matching document library folder could not be found
664             */
665            @Override
666            public DLFolder findByUUID_G(String uuid, long groupId)
667                    throws NoSuchFolderException {
668                    DLFolder dlFolder = fetchByUUID_G(uuid, groupId);
669    
670                    if (dlFolder == null) {
671                            StringBundler msg = new StringBundler(6);
672    
673                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
674    
675                            msg.append("uuid=");
676                            msg.append(uuid);
677    
678                            msg.append(", groupId=");
679                            msg.append(groupId);
680    
681                            msg.append(StringPool.CLOSE_CURLY_BRACE);
682    
683                            if (_log.isWarnEnabled()) {
684                                    _log.warn(msg.toString());
685                            }
686    
687                            throw new NoSuchFolderException(msg.toString());
688                    }
689    
690                    return dlFolder;
691            }
692    
693            /**
694             * 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.
695             *
696             * @param uuid the uuid
697             * @param groupId the group ID
698             * @return the matching document library folder, or <code>null</code> if a matching document library folder could not be found
699             */
700            @Override
701            public DLFolder fetchByUUID_G(String uuid, long groupId) {
702                    return fetchByUUID_G(uuid, groupId, true);
703            }
704    
705            /**
706             * 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.
707             *
708             * @param uuid the uuid
709             * @param groupId the group ID
710             * @param retrieveFromCache whether to retrieve from the finder cache
711             * @return the matching document library folder, or <code>null</code> if a matching document library folder could not be found
712             */
713            @Override
714            public DLFolder fetchByUUID_G(String uuid, long groupId,
715                    boolean retrieveFromCache) {
716                    Object[] finderArgs = new Object[] { uuid, groupId };
717    
718                    Object result = null;
719    
720                    if (retrieveFromCache) {
721                            result = finderCache.getResult(FINDER_PATH_FETCH_BY_UUID_G,
722                                            finderArgs, this);
723                    }
724    
725                    if (result instanceof DLFolder) {
726                            DLFolder dlFolder = (DLFolder)result;
727    
728                            if (!Validator.equals(uuid, dlFolder.getUuid()) ||
729                                            (groupId != dlFolder.getGroupId())) {
730                                    result = null;
731                            }
732                    }
733    
734                    if (result == null) {
735                            StringBundler query = new StringBundler(4);
736    
737                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
738    
739                            boolean bindUuid = false;
740    
741                            if (uuid == null) {
742                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
743                            }
744                            else if (uuid.equals(StringPool.BLANK)) {
745                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
746                            }
747                            else {
748                                    bindUuid = true;
749    
750                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
751                            }
752    
753                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
754    
755                            String sql = query.toString();
756    
757                            Session session = null;
758    
759                            try {
760                                    session = openSession();
761    
762                                    Query q = session.createQuery(sql);
763    
764                                    QueryPos qPos = QueryPos.getInstance(q);
765    
766                                    if (bindUuid) {
767                                            qPos.add(uuid);
768                                    }
769    
770                                    qPos.add(groupId);
771    
772                                    List<DLFolder> list = q.list();
773    
774                                    if (list.isEmpty()) {
775                                            finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G,
776                                                    finderArgs, list);
777                                    }
778                                    else {
779                                            DLFolder dlFolder = list.get(0);
780    
781                                            result = dlFolder;
782    
783                                            cacheResult(dlFolder);
784    
785                                            if ((dlFolder.getUuid() == null) ||
786                                                            !dlFolder.getUuid().equals(uuid) ||
787                                                            (dlFolder.getGroupId() != groupId)) {
788                                                    finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G,
789                                                            finderArgs, dlFolder);
790                                            }
791                                    }
792                            }
793                            catch (Exception e) {
794                                    finderCache.removeResult(FINDER_PATH_FETCH_BY_UUID_G, finderArgs);
795    
796                                    throw processException(e);
797                            }
798                            finally {
799                                    closeSession(session);
800                            }
801                    }
802    
803                    if (result instanceof List<?>) {
804                            return null;
805                    }
806                    else {
807                            return (DLFolder)result;
808                    }
809            }
810    
811            /**
812             * Removes the document library folder where uuid = &#63; and groupId = &#63; from the database.
813             *
814             * @param uuid the uuid
815             * @param groupId the group ID
816             * @return the document library folder that was removed
817             */
818            @Override
819            public DLFolder removeByUUID_G(String uuid, long groupId)
820                    throws NoSuchFolderException {
821                    DLFolder dlFolder = findByUUID_G(uuid, groupId);
822    
823                    return remove(dlFolder);
824            }
825    
826            /**
827             * Returns the number of document library folders where uuid = &#63; and groupId = &#63;.
828             *
829             * @param uuid the uuid
830             * @param groupId the group ID
831             * @return the number of matching document library folders
832             */
833            @Override
834            public int countByUUID_G(String uuid, long groupId) {
835                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G;
836    
837                    Object[] finderArgs = new Object[] { uuid, groupId };
838    
839                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
840    
841                    if (count == null) {
842                            StringBundler query = new StringBundler(3);
843    
844                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
845    
846                            boolean bindUuid = false;
847    
848                            if (uuid == null) {
849                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
850                            }
851                            else if (uuid.equals(StringPool.BLANK)) {
852                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
853                            }
854                            else {
855                                    bindUuid = true;
856    
857                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
858                            }
859    
860                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
861    
862                            String sql = query.toString();
863    
864                            Session session = null;
865    
866                            try {
867                                    session = openSession();
868    
869                                    Query q = session.createQuery(sql);
870    
871                                    QueryPos qPos = QueryPos.getInstance(q);
872    
873                                    if (bindUuid) {
874                                            qPos.add(uuid);
875                                    }
876    
877                                    qPos.add(groupId);
878    
879                                    count = (Long)q.uniqueResult();
880    
881                                    finderCache.putResult(finderPath, finderArgs, count);
882                            }
883                            catch (Exception e) {
884                                    finderCache.removeResult(finderPath, finderArgs);
885    
886                                    throw processException(e);
887                            }
888                            finally {
889                                    closeSession(session);
890                            }
891                    }
892    
893                    return count.intValue();
894            }
895    
896            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "dlFolder.uuid IS NULL AND ";
897            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "dlFolder.uuid = ? AND ";
898            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(dlFolder.uuid IS NULL OR dlFolder.uuid = '') AND ";
899            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "dlFolder.groupId = ?";
900            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
901                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
902                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
903                            new String[] {
904                                    String.class.getName(), Long.class.getName(),
905                                    
906                            Integer.class.getName(), Integer.class.getName(),
907                                    OrderByComparator.class.getName()
908                            });
909            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
910                    new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
911                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
912                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
913                            new String[] { String.class.getName(), Long.class.getName() },
914                            DLFolderModelImpl.UUID_COLUMN_BITMASK |
915                            DLFolderModelImpl.COMPANYID_COLUMN_BITMASK |
916                            DLFolderModelImpl.PARENTFOLDERID_COLUMN_BITMASK |
917                            DLFolderModelImpl.NAME_COLUMN_BITMASK);
918            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
919                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
920                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
921                            new String[] { String.class.getName(), Long.class.getName() });
922    
923            /**
924             * Returns all the document library folders where uuid = &#63; and companyId = &#63;.
925             *
926             * @param uuid the uuid
927             * @param companyId the company ID
928             * @return the matching document library folders
929             */
930            @Override
931            public List<DLFolder> findByUuid_C(String uuid, long companyId) {
932                    return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
933                            QueryUtil.ALL_POS, null);
934            }
935    
936            /**
937             * Returns a range of all the document library folders where uuid = &#63; and companyId = &#63;.
938             *
939             * <p>
940             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
941             * </p>
942             *
943             * @param uuid the uuid
944             * @param companyId the company ID
945             * @param start the lower bound of the range of document library folders
946             * @param end the upper bound of the range of document library folders (not inclusive)
947             * @return the range of matching document library folders
948             */
949            @Override
950            public List<DLFolder> findByUuid_C(String uuid, long companyId, int start,
951                    int end) {
952                    return findByUuid_C(uuid, companyId, start, end, null);
953            }
954    
955            /**
956             * Returns an ordered range of all the document library folders where uuid = &#63; and companyId = &#63;.
957             *
958             * <p>
959             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
960             * </p>
961             *
962             * @param uuid the uuid
963             * @param companyId the company ID
964             * @param start the lower bound of the range of document library folders
965             * @param end the upper bound of the range of document library folders (not inclusive)
966             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
967             * @return the ordered range of matching document library folders
968             */
969            @Override
970            public List<DLFolder> findByUuid_C(String uuid, long companyId, int start,
971                    int end, OrderByComparator<DLFolder> orderByComparator) {
972                    return findByUuid_C(uuid, companyId, start, end, orderByComparator, true);
973            }
974    
975            /**
976             * Returns an ordered range of all the document library folders where uuid = &#63; and companyId = &#63;.
977             *
978             * <p>
979             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
980             * </p>
981             *
982             * @param uuid the uuid
983             * @param companyId the company ID
984             * @param start the lower bound of the range of document library folders
985             * @param end the upper bound of the range of document library folders (not inclusive)
986             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
987             * @param retrieveFromCache whether to retrieve from the finder cache
988             * @return the ordered range of matching document library folders
989             */
990            @Override
991            public List<DLFolder> findByUuid_C(String uuid, long companyId, int start,
992                    int end, OrderByComparator<DLFolder> orderByComparator,
993                    boolean retrieveFromCache) {
994                    boolean pagination = true;
995                    FinderPath finderPath = null;
996                    Object[] finderArgs = null;
997    
998                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
999                                    (orderByComparator == null)) {
1000                            pagination = false;
1001                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
1002                            finderArgs = new Object[] { uuid, companyId };
1003                    }
1004                    else {
1005                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
1006                            finderArgs = new Object[] {
1007                                            uuid, companyId,
1008                                            
1009                                            start, end, orderByComparator
1010                                    };
1011                    }
1012    
1013                    List<DLFolder> list = null;
1014    
1015                    if (retrieveFromCache) {
1016                            list = (List<DLFolder>)finderCache.getResult(finderPath,
1017                                            finderArgs, this);
1018    
1019                            if ((list != null) && !list.isEmpty()) {
1020                                    for (DLFolder dlFolder : list) {
1021                                            if (!Validator.equals(uuid, dlFolder.getUuid()) ||
1022                                                            (companyId != dlFolder.getCompanyId())) {
1023                                                    list = null;
1024    
1025                                                    break;
1026                                            }
1027                                    }
1028                            }
1029                    }
1030    
1031                    if (list == null) {
1032                            StringBundler query = null;
1033    
1034                            if (orderByComparator != null) {
1035                                    query = new StringBundler(4 +
1036                                                    (orderByComparator.getOrderByFields().length * 2));
1037                            }
1038                            else {
1039                                    query = new StringBundler(4);
1040                            }
1041    
1042                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
1043    
1044                            boolean bindUuid = false;
1045    
1046                            if (uuid == null) {
1047                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1048                            }
1049                            else if (uuid.equals(StringPool.BLANK)) {
1050                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1051                            }
1052                            else {
1053                                    bindUuid = true;
1054    
1055                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1056                            }
1057    
1058                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1059    
1060                            if (orderByComparator != null) {
1061                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1062                                            orderByComparator);
1063                            }
1064                            else
1065                             if (pagination) {
1066                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
1067                            }
1068    
1069                            String sql = query.toString();
1070    
1071                            Session session = null;
1072    
1073                            try {
1074                                    session = openSession();
1075    
1076                                    Query q = session.createQuery(sql);
1077    
1078                                    QueryPos qPos = QueryPos.getInstance(q);
1079    
1080                                    if (bindUuid) {
1081                                            qPos.add(uuid);
1082                                    }
1083    
1084                                    qPos.add(companyId);
1085    
1086                                    if (!pagination) {
1087                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
1088                                                            start, end, false);
1089    
1090                                            Collections.sort(list);
1091    
1092                                            list = Collections.unmodifiableList(list);
1093                                    }
1094                                    else {
1095                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
1096                                                            start, end);
1097                                    }
1098    
1099                                    cacheResult(list);
1100    
1101                                    finderCache.putResult(finderPath, finderArgs, list);
1102                            }
1103                            catch (Exception e) {
1104                                    finderCache.removeResult(finderPath, finderArgs);
1105    
1106                                    throw processException(e);
1107                            }
1108                            finally {
1109                                    closeSession(session);
1110                            }
1111                    }
1112    
1113                    return list;
1114            }
1115    
1116            /**
1117             * Returns the first document library folder in the ordered set where uuid = &#63; and companyId = &#63;.
1118             *
1119             * @param uuid the uuid
1120             * @param companyId the company ID
1121             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1122             * @return the first matching document library folder
1123             * @throws NoSuchFolderException if a matching document library folder could not be found
1124             */
1125            @Override
1126            public DLFolder findByUuid_C_First(String uuid, long companyId,
1127                    OrderByComparator<DLFolder> orderByComparator)
1128                    throws NoSuchFolderException {
1129                    DLFolder dlFolder = fetchByUuid_C_First(uuid, companyId,
1130                                    orderByComparator);
1131    
1132                    if (dlFolder != null) {
1133                            return dlFolder;
1134                    }
1135    
1136                    StringBundler msg = new StringBundler(6);
1137    
1138                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1139    
1140                    msg.append("uuid=");
1141                    msg.append(uuid);
1142    
1143                    msg.append(", companyId=");
1144                    msg.append(companyId);
1145    
1146                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1147    
1148                    throw new NoSuchFolderException(msg.toString());
1149            }
1150    
1151            /**
1152             * Returns the first document library folder in the ordered set where uuid = &#63; and companyId = &#63;.
1153             *
1154             * @param uuid the uuid
1155             * @param companyId the company ID
1156             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1157             * @return the first matching document library folder, or <code>null</code> if a matching document library folder could not be found
1158             */
1159            @Override
1160            public DLFolder fetchByUuid_C_First(String uuid, long companyId,
1161                    OrderByComparator<DLFolder> orderByComparator) {
1162                    List<DLFolder> list = findByUuid_C(uuid, companyId, 0, 1,
1163                                    orderByComparator);
1164    
1165                    if (!list.isEmpty()) {
1166                            return list.get(0);
1167                    }
1168    
1169                    return null;
1170            }
1171    
1172            /**
1173             * Returns the last document library folder in the ordered set where uuid = &#63; and companyId = &#63;.
1174             *
1175             * @param uuid the uuid
1176             * @param companyId the company ID
1177             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1178             * @return the last matching document library folder
1179             * @throws NoSuchFolderException if a matching document library folder could not be found
1180             */
1181            @Override
1182            public DLFolder findByUuid_C_Last(String uuid, long companyId,
1183                    OrderByComparator<DLFolder> orderByComparator)
1184                    throws NoSuchFolderException {
1185                    DLFolder dlFolder = fetchByUuid_C_Last(uuid, companyId,
1186                                    orderByComparator);
1187    
1188                    if (dlFolder != null) {
1189                            return dlFolder;
1190                    }
1191    
1192                    StringBundler msg = new StringBundler(6);
1193    
1194                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1195    
1196                    msg.append("uuid=");
1197                    msg.append(uuid);
1198    
1199                    msg.append(", companyId=");
1200                    msg.append(companyId);
1201    
1202                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1203    
1204                    throw new NoSuchFolderException(msg.toString());
1205            }
1206    
1207            /**
1208             * Returns the last document library folder in the ordered set where uuid = &#63; and companyId = &#63;.
1209             *
1210             * @param uuid the uuid
1211             * @param companyId the company ID
1212             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1213             * @return the last matching document library folder, or <code>null</code> if a matching document library folder could not be found
1214             */
1215            @Override
1216            public DLFolder fetchByUuid_C_Last(String uuid, long companyId,
1217                    OrderByComparator<DLFolder> orderByComparator) {
1218                    int count = countByUuid_C(uuid, companyId);
1219    
1220                    if (count == 0) {
1221                            return null;
1222                    }
1223    
1224                    List<DLFolder> list = findByUuid_C(uuid, companyId, count - 1, count,
1225                                    orderByComparator);
1226    
1227                    if (!list.isEmpty()) {
1228                            return list.get(0);
1229                    }
1230    
1231                    return null;
1232            }
1233    
1234            /**
1235             * Returns the document library folders before and after the current document library folder in the ordered set where uuid = &#63; and companyId = &#63;.
1236             *
1237             * @param folderId the primary key of the current document library folder
1238             * @param uuid the uuid
1239             * @param companyId the company ID
1240             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1241             * @return the previous, current, and next document library folder
1242             * @throws NoSuchFolderException if a document library folder with the primary key could not be found
1243             */
1244            @Override
1245            public DLFolder[] findByUuid_C_PrevAndNext(long folderId, String uuid,
1246                    long companyId, OrderByComparator<DLFolder> orderByComparator)
1247                    throws NoSuchFolderException {
1248                    DLFolder dlFolder = findByPrimaryKey(folderId);
1249    
1250                    Session session = null;
1251    
1252                    try {
1253                            session = openSession();
1254    
1255                            DLFolder[] array = new DLFolderImpl[3];
1256    
1257                            array[0] = getByUuid_C_PrevAndNext(session, dlFolder, uuid,
1258                                            companyId, orderByComparator, true);
1259    
1260                            array[1] = dlFolder;
1261    
1262                            array[2] = getByUuid_C_PrevAndNext(session, dlFolder, uuid,
1263                                            companyId, orderByComparator, false);
1264    
1265                            return array;
1266                    }
1267                    catch (Exception e) {
1268                            throw processException(e);
1269                    }
1270                    finally {
1271                            closeSession(session);
1272                    }
1273            }
1274    
1275            protected DLFolder getByUuid_C_PrevAndNext(Session session,
1276                    DLFolder dlFolder, String uuid, long companyId,
1277                    OrderByComparator<DLFolder> orderByComparator, boolean previous) {
1278                    StringBundler query = null;
1279    
1280                    if (orderByComparator != null) {
1281                            query = new StringBundler(5 +
1282                                            (orderByComparator.getOrderByConditionFields().length * 3) +
1283                                            (orderByComparator.getOrderByFields().length * 3));
1284                    }
1285                    else {
1286                            query = new StringBundler(4);
1287                    }
1288    
1289                    query.append(_SQL_SELECT_DLFOLDER_WHERE);
1290    
1291                    boolean bindUuid = false;
1292    
1293                    if (uuid == null) {
1294                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1295                    }
1296                    else if (uuid.equals(StringPool.BLANK)) {
1297                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1298                    }
1299                    else {
1300                            bindUuid = true;
1301    
1302                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1303                    }
1304    
1305                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1306    
1307                    if (orderByComparator != null) {
1308                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1309    
1310                            if (orderByConditionFields.length > 0) {
1311                                    query.append(WHERE_AND);
1312                            }
1313    
1314                            for (int i = 0; i < orderByConditionFields.length; i++) {
1315                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1316                                    query.append(orderByConditionFields[i]);
1317    
1318                                    if ((i + 1) < orderByConditionFields.length) {
1319                                            if (orderByComparator.isAscending() ^ previous) {
1320                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1321                                            }
1322                                            else {
1323                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1324                                            }
1325                                    }
1326                                    else {
1327                                            if (orderByComparator.isAscending() ^ previous) {
1328                                                    query.append(WHERE_GREATER_THAN);
1329                                            }
1330                                            else {
1331                                                    query.append(WHERE_LESSER_THAN);
1332                                            }
1333                                    }
1334                            }
1335    
1336                            query.append(ORDER_BY_CLAUSE);
1337    
1338                            String[] orderByFields = orderByComparator.getOrderByFields();
1339    
1340                            for (int i = 0; i < orderByFields.length; i++) {
1341                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1342                                    query.append(orderByFields[i]);
1343    
1344                                    if ((i + 1) < orderByFields.length) {
1345                                            if (orderByComparator.isAscending() ^ previous) {
1346                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1347                                            }
1348                                            else {
1349                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1350                                            }
1351                                    }
1352                                    else {
1353                                            if (orderByComparator.isAscending() ^ previous) {
1354                                                    query.append(ORDER_BY_ASC);
1355                                            }
1356                                            else {
1357                                                    query.append(ORDER_BY_DESC);
1358                                            }
1359                                    }
1360                            }
1361                    }
1362                    else {
1363                            query.append(DLFolderModelImpl.ORDER_BY_JPQL);
1364                    }
1365    
1366                    String sql = query.toString();
1367    
1368                    Query q = session.createQuery(sql);
1369    
1370                    q.setFirstResult(0);
1371                    q.setMaxResults(2);
1372    
1373                    QueryPos qPos = QueryPos.getInstance(q);
1374    
1375                    if (bindUuid) {
1376                            qPos.add(uuid);
1377                    }
1378    
1379                    qPos.add(companyId);
1380    
1381                    if (orderByComparator != null) {
1382                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
1383    
1384                            for (Object value : values) {
1385                                    qPos.add(value);
1386                            }
1387                    }
1388    
1389                    List<DLFolder> list = q.list();
1390    
1391                    if (list.size() == 2) {
1392                            return list.get(1);
1393                    }
1394                    else {
1395                            return null;
1396                    }
1397            }
1398    
1399            /**
1400             * Removes all the document library folders where uuid = &#63; and companyId = &#63; from the database.
1401             *
1402             * @param uuid the uuid
1403             * @param companyId the company ID
1404             */
1405            @Override
1406            public void removeByUuid_C(String uuid, long companyId) {
1407                    for (DLFolder dlFolder : findByUuid_C(uuid, companyId,
1408                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1409                            remove(dlFolder);
1410                    }
1411            }
1412    
1413            /**
1414             * Returns the number of document library folders where uuid = &#63; and companyId = &#63;.
1415             *
1416             * @param uuid the uuid
1417             * @param companyId the company ID
1418             * @return the number of matching document library folders
1419             */
1420            @Override
1421            public int countByUuid_C(String uuid, long companyId) {
1422                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1423    
1424                    Object[] finderArgs = new Object[] { uuid, companyId };
1425    
1426                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1427    
1428                    if (count == null) {
1429                            StringBundler query = new StringBundler(3);
1430    
1431                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
1432    
1433                            boolean bindUuid = false;
1434    
1435                            if (uuid == null) {
1436                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1437                            }
1438                            else if (uuid.equals(StringPool.BLANK)) {
1439                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1440                            }
1441                            else {
1442                                    bindUuid = true;
1443    
1444                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1445                            }
1446    
1447                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1448    
1449                            String sql = query.toString();
1450    
1451                            Session session = null;
1452    
1453                            try {
1454                                    session = openSession();
1455    
1456                                    Query q = session.createQuery(sql);
1457    
1458                                    QueryPos qPos = QueryPos.getInstance(q);
1459    
1460                                    if (bindUuid) {
1461                                            qPos.add(uuid);
1462                                    }
1463    
1464                                    qPos.add(companyId);
1465    
1466                                    count = (Long)q.uniqueResult();
1467    
1468                                    finderCache.putResult(finderPath, finderArgs, count);
1469                            }
1470                            catch (Exception e) {
1471                                    finderCache.removeResult(finderPath, finderArgs);
1472    
1473                                    throw processException(e);
1474                            }
1475                            finally {
1476                                    closeSession(session);
1477                            }
1478                    }
1479    
1480                    return count.intValue();
1481            }
1482    
1483            private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "dlFolder.uuid IS NULL AND ";
1484            private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "dlFolder.uuid = ? AND ";
1485            private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(dlFolder.uuid IS NULL OR dlFolder.uuid = '') AND ";
1486            private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "dlFolder.companyId = ?";
1487            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
1488                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
1489                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
1490                            new String[] {
1491                                    Long.class.getName(),
1492                                    
1493                            Integer.class.getName(), Integer.class.getName(),
1494                                    OrderByComparator.class.getName()
1495                            });
1496            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
1497                    new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
1498                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
1499                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
1500                            new String[] { Long.class.getName() },
1501                            DLFolderModelImpl.GROUPID_COLUMN_BITMASK |
1502                            DLFolderModelImpl.PARENTFOLDERID_COLUMN_BITMASK |
1503                            DLFolderModelImpl.NAME_COLUMN_BITMASK);
1504            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
1505                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
1506                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
1507                            new String[] { Long.class.getName() });
1508    
1509            /**
1510             * Returns all the document library folders where groupId = &#63;.
1511             *
1512             * @param groupId the group ID
1513             * @return the matching document library folders
1514             */
1515            @Override
1516            public List<DLFolder> findByGroupId(long groupId) {
1517                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1518            }
1519    
1520            /**
1521             * Returns a range of all the document library folders where groupId = &#63;.
1522             *
1523             * <p>
1524             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1525             * </p>
1526             *
1527             * @param groupId the group ID
1528             * @param start the lower bound of the range of document library folders
1529             * @param end the upper bound of the range of document library folders (not inclusive)
1530             * @return the range of matching document library folders
1531             */
1532            @Override
1533            public List<DLFolder> findByGroupId(long groupId, int start, int end) {
1534                    return findByGroupId(groupId, start, end, null);
1535            }
1536    
1537            /**
1538             * Returns an ordered range of all the document library folders where groupId = &#63;.
1539             *
1540             * <p>
1541             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1542             * </p>
1543             *
1544             * @param groupId the group ID
1545             * @param start the lower bound of the range of document library folders
1546             * @param end the upper bound of the range of document library folders (not inclusive)
1547             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1548             * @return the ordered range of matching document library folders
1549             */
1550            @Override
1551            public List<DLFolder> findByGroupId(long groupId, int start, int end,
1552                    OrderByComparator<DLFolder> orderByComparator) {
1553                    return findByGroupId(groupId, start, end, orderByComparator, true);
1554            }
1555    
1556            /**
1557             * Returns an ordered range of all the document library folders where groupId = &#63;.
1558             *
1559             * <p>
1560             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1561             * </p>
1562             *
1563             * @param groupId the group ID
1564             * @param start the lower bound of the range of document library folders
1565             * @param end the upper bound of the range of document library folders (not inclusive)
1566             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1567             * @param retrieveFromCache whether to retrieve from the finder cache
1568             * @return the ordered range of matching document library folders
1569             */
1570            @Override
1571            public List<DLFolder> findByGroupId(long groupId, int start, int end,
1572                    OrderByComparator<DLFolder> orderByComparator, boolean retrieveFromCache) {
1573                    boolean pagination = true;
1574                    FinderPath finderPath = null;
1575                    Object[] finderArgs = null;
1576    
1577                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1578                                    (orderByComparator == null)) {
1579                            pagination = false;
1580                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1581                            finderArgs = new Object[] { groupId };
1582                    }
1583                    else {
1584                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1585                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
1586                    }
1587    
1588                    List<DLFolder> list = null;
1589    
1590                    if (retrieveFromCache) {
1591                            list = (List<DLFolder>)finderCache.getResult(finderPath,
1592                                            finderArgs, this);
1593    
1594                            if ((list != null) && !list.isEmpty()) {
1595                                    for (DLFolder dlFolder : list) {
1596                                            if ((groupId != dlFolder.getGroupId())) {
1597                                                    list = null;
1598    
1599                                                    break;
1600                                            }
1601                                    }
1602                            }
1603                    }
1604    
1605                    if (list == null) {
1606                            StringBundler query = null;
1607    
1608                            if (orderByComparator != null) {
1609                                    query = new StringBundler(3 +
1610                                                    (orderByComparator.getOrderByFields().length * 2));
1611                            }
1612                            else {
1613                                    query = new StringBundler(3);
1614                            }
1615    
1616                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
1617    
1618                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1619    
1620                            if (orderByComparator != null) {
1621                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1622                                            orderByComparator);
1623                            }
1624                            else
1625                             if (pagination) {
1626                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
1627                            }
1628    
1629                            String sql = query.toString();
1630    
1631                            Session session = null;
1632    
1633                            try {
1634                                    session = openSession();
1635    
1636                                    Query q = session.createQuery(sql);
1637    
1638                                    QueryPos qPos = QueryPos.getInstance(q);
1639    
1640                                    qPos.add(groupId);
1641    
1642                                    if (!pagination) {
1643                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
1644                                                            start, end, false);
1645    
1646                                            Collections.sort(list);
1647    
1648                                            list = Collections.unmodifiableList(list);
1649                                    }
1650                                    else {
1651                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
1652                                                            start, end);
1653                                    }
1654    
1655                                    cacheResult(list);
1656    
1657                                    finderCache.putResult(finderPath, finderArgs, list);
1658                            }
1659                            catch (Exception e) {
1660                                    finderCache.removeResult(finderPath, finderArgs);
1661    
1662                                    throw processException(e);
1663                            }
1664                            finally {
1665                                    closeSession(session);
1666                            }
1667                    }
1668    
1669                    return list;
1670            }
1671    
1672            /**
1673             * Returns the first document library folder in the ordered set where groupId = &#63;.
1674             *
1675             * @param groupId the group ID
1676             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1677             * @return the first matching document library folder
1678             * @throws NoSuchFolderException if a matching document library folder could not be found
1679             */
1680            @Override
1681            public DLFolder findByGroupId_First(long groupId,
1682                    OrderByComparator<DLFolder> orderByComparator)
1683                    throws NoSuchFolderException {
1684                    DLFolder dlFolder = fetchByGroupId_First(groupId, orderByComparator);
1685    
1686                    if (dlFolder != null) {
1687                            return dlFolder;
1688                    }
1689    
1690                    StringBundler msg = new StringBundler(4);
1691    
1692                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1693    
1694                    msg.append("groupId=");
1695                    msg.append(groupId);
1696    
1697                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1698    
1699                    throw new NoSuchFolderException(msg.toString());
1700            }
1701    
1702            /**
1703             * Returns the first document library folder in the ordered set where groupId = &#63;.
1704             *
1705             * @param groupId the group ID
1706             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1707             * @return the first matching document library folder, or <code>null</code> if a matching document library folder could not be found
1708             */
1709            @Override
1710            public DLFolder fetchByGroupId_First(long groupId,
1711                    OrderByComparator<DLFolder> orderByComparator) {
1712                    List<DLFolder> list = findByGroupId(groupId, 0, 1, orderByComparator);
1713    
1714                    if (!list.isEmpty()) {
1715                            return list.get(0);
1716                    }
1717    
1718                    return null;
1719            }
1720    
1721            /**
1722             * Returns the last document library folder in the ordered set where groupId = &#63;.
1723             *
1724             * @param groupId the group ID
1725             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1726             * @return the last matching document library folder
1727             * @throws NoSuchFolderException if a matching document library folder could not be found
1728             */
1729            @Override
1730            public DLFolder findByGroupId_Last(long groupId,
1731                    OrderByComparator<DLFolder> orderByComparator)
1732                    throws NoSuchFolderException {
1733                    DLFolder dlFolder = fetchByGroupId_Last(groupId, orderByComparator);
1734    
1735                    if (dlFolder != null) {
1736                            return dlFolder;
1737                    }
1738    
1739                    StringBundler msg = new StringBundler(4);
1740    
1741                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1742    
1743                    msg.append("groupId=");
1744                    msg.append(groupId);
1745    
1746                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1747    
1748                    throw new NoSuchFolderException(msg.toString());
1749            }
1750    
1751            /**
1752             * Returns the last document library folder in the ordered set where groupId = &#63;.
1753             *
1754             * @param groupId the group ID
1755             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1756             * @return the last matching document library folder, or <code>null</code> if a matching document library folder could not be found
1757             */
1758            @Override
1759            public DLFolder fetchByGroupId_Last(long groupId,
1760                    OrderByComparator<DLFolder> orderByComparator) {
1761                    int count = countByGroupId(groupId);
1762    
1763                    if (count == 0) {
1764                            return null;
1765                    }
1766    
1767                    List<DLFolder> list = findByGroupId(groupId, count - 1, count,
1768                                    orderByComparator);
1769    
1770                    if (!list.isEmpty()) {
1771                            return list.get(0);
1772                    }
1773    
1774                    return null;
1775            }
1776    
1777            /**
1778             * Returns the document library folders before and after the current document library folder in the ordered set where groupId = &#63;.
1779             *
1780             * @param folderId the primary key of the current document library folder
1781             * @param groupId the group ID
1782             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1783             * @return the previous, current, and next document library folder
1784             * @throws NoSuchFolderException if a document library folder with the primary key could not be found
1785             */
1786            @Override
1787            public DLFolder[] findByGroupId_PrevAndNext(long folderId, long groupId,
1788                    OrderByComparator<DLFolder> orderByComparator)
1789                    throws NoSuchFolderException {
1790                    DLFolder dlFolder = findByPrimaryKey(folderId);
1791    
1792                    Session session = null;
1793    
1794                    try {
1795                            session = openSession();
1796    
1797                            DLFolder[] array = new DLFolderImpl[3];
1798    
1799                            array[0] = getByGroupId_PrevAndNext(session, dlFolder, groupId,
1800                                            orderByComparator, true);
1801    
1802                            array[1] = dlFolder;
1803    
1804                            array[2] = getByGroupId_PrevAndNext(session, dlFolder, groupId,
1805                                            orderByComparator, false);
1806    
1807                            return array;
1808                    }
1809                    catch (Exception e) {
1810                            throw processException(e);
1811                    }
1812                    finally {
1813                            closeSession(session);
1814                    }
1815            }
1816    
1817            protected DLFolder getByGroupId_PrevAndNext(Session session,
1818                    DLFolder dlFolder, long groupId,
1819                    OrderByComparator<DLFolder> orderByComparator, boolean previous) {
1820                    StringBundler query = null;
1821    
1822                    if (orderByComparator != null) {
1823                            query = new StringBundler(4 +
1824                                            (orderByComparator.getOrderByConditionFields().length * 3) +
1825                                            (orderByComparator.getOrderByFields().length * 3));
1826                    }
1827                    else {
1828                            query = new StringBundler(3);
1829                    }
1830    
1831                    query.append(_SQL_SELECT_DLFOLDER_WHERE);
1832    
1833                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1834    
1835                    if (orderByComparator != null) {
1836                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1837    
1838                            if (orderByConditionFields.length > 0) {
1839                                    query.append(WHERE_AND);
1840                            }
1841    
1842                            for (int i = 0; i < orderByConditionFields.length; i++) {
1843                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1844                                    query.append(orderByConditionFields[i]);
1845    
1846                                    if ((i + 1) < orderByConditionFields.length) {
1847                                            if (orderByComparator.isAscending() ^ previous) {
1848                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1849                                            }
1850                                            else {
1851                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1852                                            }
1853                                    }
1854                                    else {
1855                                            if (orderByComparator.isAscending() ^ previous) {
1856                                                    query.append(WHERE_GREATER_THAN);
1857                                            }
1858                                            else {
1859                                                    query.append(WHERE_LESSER_THAN);
1860                                            }
1861                                    }
1862                            }
1863    
1864                            query.append(ORDER_BY_CLAUSE);
1865    
1866                            String[] orderByFields = orderByComparator.getOrderByFields();
1867    
1868                            for (int i = 0; i < orderByFields.length; i++) {
1869                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1870                                    query.append(orderByFields[i]);
1871    
1872                                    if ((i + 1) < orderByFields.length) {
1873                                            if (orderByComparator.isAscending() ^ previous) {
1874                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1875                                            }
1876                                            else {
1877                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1878                                            }
1879                                    }
1880                                    else {
1881                                            if (orderByComparator.isAscending() ^ previous) {
1882                                                    query.append(ORDER_BY_ASC);
1883                                            }
1884                                            else {
1885                                                    query.append(ORDER_BY_DESC);
1886                                            }
1887                                    }
1888                            }
1889                    }
1890                    else {
1891                            query.append(DLFolderModelImpl.ORDER_BY_JPQL);
1892                    }
1893    
1894                    String sql = query.toString();
1895    
1896                    Query q = session.createQuery(sql);
1897    
1898                    q.setFirstResult(0);
1899                    q.setMaxResults(2);
1900    
1901                    QueryPos qPos = QueryPos.getInstance(q);
1902    
1903                    qPos.add(groupId);
1904    
1905                    if (orderByComparator != null) {
1906                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
1907    
1908                            for (Object value : values) {
1909                                    qPos.add(value);
1910                            }
1911                    }
1912    
1913                    List<DLFolder> list = q.list();
1914    
1915                    if (list.size() == 2) {
1916                            return list.get(1);
1917                    }
1918                    else {
1919                            return null;
1920                    }
1921            }
1922    
1923            /**
1924             * Returns all the document library folders that the user has permission to view where groupId = &#63;.
1925             *
1926             * @param groupId the group ID
1927             * @return the matching document library folders that the user has permission to view
1928             */
1929            @Override
1930            public List<DLFolder> filterFindByGroupId(long groupId) {
1931                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1932                            QueryUtil.ALL_POS, null);
1933            }
1934    
1935            /**
1936             * Returns a range of all the document library folders that the user has permission to view where groupId = &#63;.
1937             *
1938             * <p>
1939             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1940             * </p>
1941             *
1942             * @param groupId the group ID
1943             * @param start the lower bound of the range of document library folders
1944             * @param end the upper bound of the range of document library folders (not inclusive)
1945             * @return the range of matching document library folders that the user has permission to view
1946             */
1947            @Override
1948            public List<DLFolder> filterFindByGroupId(long groupId, int start, int end) {
1949                    return filterFindByGroupId(groupId, start, end, null);
1950            }
1951    
1952            /**
1953             * Returns an ordered range of all the document library folders that the user has permissions to view where groupId = &#63;.
1954             *
1955             * <p>
1956             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1957             * </p>
1958             *
1959             * @param groupId the group ID
1960             * @param start the lower bound of the range of document library folders
1961             * @param end the upper bound of the range of document library folders (not inclusive)
1962             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1963             * @return the ordered range of matching document library folders that the user has permission to view
1964             */
1965            @Override
1966            public List<DLFolder> filterFindByGroupId(long groupId, int start, int end,
1967                    OrderByComparator<DLFolder> orderByComparator) {
1968                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1969                            return findByGroupId(groupId, start, end, orderByComparator);
1970                    }
1971    
1972                    StringBundler query = null;
1973    
1974                    if (orderByComparator != null) {
1975                            query = new StringBundler(3 +
1976                                            (orderByComparator.getOrderByFields().length * 2));
1977                    }
1978                    else {
1979                            query = new StringBundler(4);
1980                    }
1981    
1982                    if (getDB().isSupportsInlineDistinct()) {
1983                            query.append(_FILTER_SQL_SELECT_DLFOLDER_WHERE);
1984                    }
1985                    else {
1986                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1);
1987                    }
1988    
1989                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1990    
1991                    if (!getDB().isSupportsInlineDistinct()) {
1992                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2);
1993                    }
1994    
1995                    if (orderByComparator != null) {
1996                            if (getDB().isSupportsInlineDistinct()) {
1997                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1998                                            orderByComparator, true);
1999                            }
2000                            else {
2001                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2002                                            orderByComparator, true);
2003                            }
2004                    }
2005                    else {
2006                            if (getDB().isSupportsInlineDistinct()) {
2007                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
2008                            }
2009                            else {
2010                                    query.append(DLFolderModelImpl.ORDER_BY_SQL);
2011                            }
2012                    }
2013    
2014                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2015                                    DLFolder.class.getName(),
2016                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2017    
2018                    Session session = null;
2019    
2020                    try {
2021                            session = openSession();
2022    
2023                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
2024    
2025                            if (getDB().isSupportsInlineDistinct()) {
2026                                    q.addEntity(_FILTER_ENTITY_ALIAS, DLFolderImpl.class);
2027                            }
2028                            else {
2029                                    q.addEntity(_FILTER_ENTITY_TABLE, DLFolderImpl.class);
2030                            }
2031    
2032                            QueryPos qPos = QueryPos.getInstance(q);
2033    
2034                            qPos.add(groupId);
2035    
2036                            return (List<DLFolder>)QueryUtil.list(q, getDialect(), start, end);
2037                    }
2038                    catch (Exception e) {
2039                            throw processException(e);
2040                    }
2041                    finally {
2042                            closeSession(session);
2043                    }
2044            }
2045    
2046            /**
2047             * 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;.
2048             *
2049             * @param folderId the primary key of the current document library folder
2050             * @param groupId the group ID
2051             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2052             * @return the previous, current, and next document library folder
2053             * @throws NoSuchFolderException if a document library folder with the primary key could not be found
2054             */
2055            @Override
2056            public DLFolder[] filterFindByGroupId_PrevAndNext(long folderId,
2057                    long groupId, OrderByComparator<DLFolder> orderByComparator)
2058                    throws NoSuchFolderException {
2059                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2060                            return findByGroupId_PrevAndNext(folderId, groupId,
2061                                    orderByComparator);
2062                    }
2063    
2064                    DLFolder dlFolder = findByPrimaryKey(folderId);
2065    
2066                    Session session = null;
2067    
2068                    try {
2069                            session = openSession();
2070    
2071                            DLFolder[] array = new DLFolderImpl[3];
2072    
2073                            array[0] = filterGetByGroupId_PrevAndNext(session, dlFolder,
2074                                            groupId, orderByComparator, true);
2075    
2076                            array[1] = dlFolder;
2077    
2078                            array[2] = filterGetByGroupId_PrevAndNext(session, dlFolder,
2079                                            groupId, orderByComparator, false);
2080    
2081                            return array;
2082                    }
2083                    catch (Exception e) {
2084                            throw processException(e);
2085                    }
2086                    finally {
2087                            closeSession(session);
2088                    }
2089            }
2090    
2091            protected DLFolder filterGetByGroupId_PrevAndNext(Session session,
2092                    DLFolder dlFolder, long groupId,
2093                    OrderByComparator<DLFolder> orderByComparator, boolean previous) {
2094                    StringBundler query = null;
2095    
2096                    if (orderByComparator != null) {
2097                            query = new StringBundler(5 +
2098                                            (orderByComparator.getOrderByConditionFields().length * 3) +
2099                                            (orderByComparator.getOrderByFields().length * 3));
2100                    }
2101                    else {
2102                            query = new StringBundler(4);
2103                    }
2104    
2105                    if (getDB().isSupportsInlineDistinct()) {
2106                            query.append(_FILTER_SQL_SELECT_DLFOLDER_WHERE);
2107                    }
2108                    else {
2109                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1);
2110                    }
2111    
2112                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2113    
2114                    if (!getDB().isSupportsInlineDistinct()) {
2115                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2);
2116                    }
2117    
2118                    if (orderByComparator != null) {
2119                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2120    
2121                            if (orderByConditionFields.length > 0) {
2122                                    query.append(WHERE_AND);
2123                            }
2124    
2125                            for (int i = 0; i < orderByConditionFields.length; i++) {
2126                                    if (getDB().isSupportsInlineDistinct()) {
2127                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2128                                    }
2129                                    else {
2130                                            query.append(_ORDER_BY_ENTITY_TABLE);
2131                                    }
2132    
2133                                    query.append(orderByConditionFields[i]);
2134    
2135                                    if ((i + 1) < orderByConditionFields.length) {
2136                                            if (orderByComparator.isAscending() ^ previous) {
2137                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2138                                            }
2139                                            else {
2140                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2141                                            }
2142                                    }
2143                                    else {
2144                                            if (orderByComparator.isAscending() ^ previous) {
2145                                                    query.append(WHERE_GREATER_THAN);
2146                                            }
2147                                            else {
2148                                                    query.append(WHERE_LESSER_THAN);
2149                                            }
2150                                    }
2151                            }
2152    
2153                            query.append(ORDER_BY_CLAUSE);
2154    
2155                            String[] orderByFields = orderByComparator.getOrderByFields();
2156    
2157                            for (int i = 0; i < orderByFields.length; i++) {
2158                                    if (getDB().isSupportsInlineDistinct()) {
2159                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2160                                    }
2161                                    else {
2162                                            query.append(_ORDER_BY_ENTITY_TABLE);
2163                                    }
2164    
2165                                    query.append(orderByFields[i]);
2166    
2167                                    if ((i + 1) < orderByFields.length) {
2168                                            if (orderByComparator.isAscending() ^ previous) {
2169                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2170                                            }
2171                                            else {
2172                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2173                                            }
2174                                    }
2175                                    else {
2176                                            if (orderByComparator.isAscending() ^ previous) {
2177                                                    query.append(ORDER_BY_ASC);
2178                                            }
2179                                            else {
2180                                                    query.append(ORDER_BY_DESC);
2181                                            }
2182                                    }
2183                            }
2184                    }
2185                    else {
2186                            if (getDB().isSupportsInlineDistinct()) {
2187                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
2188                            }
2189                            else {
2190                                    query.append(DLFolderModelImpl.ORDER_BY_SQL);
2191                            }
2192                    }
2193    
2194                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2195                                    DLFolder.class.getName(),
2196                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2197    
2198                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
2199    
2200                    q.setFirstResult(0);
2201                    q.setMaxResults(2);
2202    
2203                    if (getDB().isSupportsInlineDistinct()) {
2204                            q.addEntity(_FILTER_ENTITY_ALIAS, DLFolderImpl.class);
2205                    }
2206                    else {
2207                            q.addEntity(_FILTER_ENTITY_TABLE, DLFolderImpl.class);
2208                    }
2209    
2210                    QueryPos qPos = QueryPos.getInstance(q);
2211    
2212                    qPos.add(groupId);
2213    
2214                    if (orderByComparator != null) {
2215                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
2216    
2217                            for (Object value : values) {
2218                                    qPos.add(value);
2219                            }
2220                    }
2221    
2222                    List<DLFolder> list = q.list();
2223    
2224                    if (list.size() == 2) {
2225                            return list.get(1);
2226                    }
2227                    else {
2228                            return null;
2229                    }
2230            }
2231    
2232            /**
2233             * Removes all the document library folders where groupId = &#63; from the database.
2234             *
2235             * @param groupId the group ID
2236             */
2237            @Override
2238            public void removeByGroupId(long groupId) {
2239                    for (DLFolder dlFolder : findByGroupId(groupId, QueryUtil.ALL_POS,
2240                                    QueryUtil.ALL_POS, null)) {
2241                            remove(dlFolder);
2242                    }
2243            }
2244    
2245            /**
2246             * Returns the number of document library folders where groupId = &#63;.
2247             *
2248             * @param groupId the group ID
2249             * @return the number of matching document library folders
2250             */
2251            @Override
2252            public int countByGroupId(long groupId) {
2253                    FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
2254    
2255                    Object[] finderArgs = new Object[] { groupId };
2256    
2257                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
2258    
2259                    if (count == null) {
2260                            StringBundler query = new StringBundler(2);
2261    
2262                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
2263    
2264                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2265    
2266                            String sql = query.toString();
2267    
2268                            Session session = null;
2269    
2270                            try {
2271                                    session = openSession();
2272    
2273                                    Query q = session.createQuery(sql);
2274    
2275                                    QueryPos qPos = QueryPos.getInstance(q);
2276    
2277                                    qPos.add(groupId);
2278    
2279                                    count = (Long)q.uniqueResult();
2280    
2281                                    finderCache.putResult(finderPath, finderArgs, count);
2282                            }
2283                            catch (Exception e) {
2284                                    finderCache.removeResult(finderPath, finderArgs);
2285    
2286                                    throw processException(e);
2287                            }
2288                            finally {
2289                                    closeSession(session);
2290                            }
2291                    }
2292    
2293                    return count.intValue();
2294            }
2295    
2296            /**
2297             * Returns the number of document library folders that the user has permission to view where groupId = &#63;.
2298             *
2299             * @param groupId the group ID
2300             * @return the number of matching document library folders that the user has permission to view
2301             */
2302            @Override
2303            public int filterCountByGroupId(long groupId) {
2304                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2305                            return countByGroupId(groupId);
2306                    }
2307    
2308                    StringBundler query = new StringBundler(2);
2309    
2310                    query.append(_FILTER_SQL_COUNT_DLFOLDER_WHERE);
2311    
2312                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2313    
2314                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2315                                    DLFolder.class.getName(),
2316                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2317    
2318                    Session session = null;
2319    
2320                    try {
2321                            session = openSession();
2322    
2323                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
2324    
2325                            q.addScalar(COUNT_COLUMN_NAME,
2326                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
2327    
2328                            QueryPos qPos = QueryPos.getInstance(q);
2329    
2330                            qPos.add(groupId);
2331    
2332                            Long count = (Long)q.uniqueResult();
2333    
2334                            return count.intValue();
2335                    }
2336                    catch (Exception e) {
2337                            throw processException(e);
2338                    }
2339                    finally {
2340                            closeSession(session);
2341                    }
2342            }
2343    
2344            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "dlFolder.groupId = ?";
2345            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
2346                    new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
2347                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
2348                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
2349                            new String[] {
2350                                    Long.class.getName(),
2351                                    
2352                            Integer.class.getName(), Integer.class.getName(),
2353                                    OrderByComparator.class.getName()
2354                            });
2355            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
2356                    new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
2357                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
2358                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
2359                            new String[] { Long.class.getName() },
2360                            DLFolderModelImpl.COMPANYID_COLUMN_BITMASK |
2361                            DLFolderModelImpl.PARENTFOLDERID_COLUMN_BITMASK |
2362                            DLFolderModelImpl.NAME_COLUMN_BITMASK);
2363            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
2364                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
2365                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
2366                            new String[] { Long.class.getName() });
2367    
2368            /**
2369             * Returns all the document library folders where companyId = &#63;.
2370             *
2371             * @param companyId the company ID
2372             * @return the matching document library folders
2373             */
2374            @Override
2375            public List<DLFolder> findByCompanyId(long companyId) {
2376                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2377                            null);
2378            }
2379    
2380            /**
2381             * Returns a range of all the document library folders where companyId = &#63;.
2382             *
2383             * <p>
2384             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2385             * </p>
2386             *
2387             * @param companyId the company ID
2388             * @param start the lower bound of the range of document library folders
2389             * @param end the upper bound of the range of document library folders (not inclusive)
2390             * @return the range of matching document library folders
2391             */
2392            @Override
2393            public List<DLFolder> findByCompanyId(long companyId, int start, int end) {
2394                    return findByCompanyId(companyId, start, end, null);
2395            }
2396    
2397            /**
2398             * Returns an ordered range of all the document library folders where companyId = &#63;.
2399             *
2400             * <p>
2401             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2402             * </p>
2403             *
2404             * @param companyId the company ID
2405             * @param start the lower bound of the range of document library folders
2406             * @param end the upper bound of the range of document library folders (not inclusive)
2407             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2408             * @return the ordered range of matching document library folders
2409             */
2410            @Override
2411            public List<DLFolder> findByCompanyId(long companyId, int start, int end,
2412                    OrderByComparator<DLFolder> orderByComparator) {
2413                    return findByCompanyId(companyId, start, end, orderByComparator, true);
2414            }
2415    
2416            /**
2417             * Returns an ordered range of all the document library folders where companyId = &#63;.
2418             *
2419             * <p>
2420             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2421             * </p>
2422             *
2423             * @param companyId the company ID
2424             * @param start the lower bound of the range of document library folders
2425             * @param end the upper bound of the range of document library folders (not inclusive)
2426             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2427             * @param retrieveFromCache whether to retrieve from the finder cache
2428             * @return the ordered range of matching document library folders
2429             */
2430            @Override
2431            public List<DLFolder> findByCompanyId(long companyId, int start, int end,
2432                    OrderByComparator<DLFolder> orderByComparator, boolean retrieveFromCache) {
2433                    boolean pagination = true;
2434                    FinderPath finderPath = null;
2435                    Object[] finderArgs = null;
2436    
2437                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2438                                    (orderByComparator == null)) {
2439                            pagination = false;
2440                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
2441                            finderArgs = new Object[] { companyId };
2442                    }
2443                    else {
2444                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
2445                            finderArgs = new Object[] { companyId, start, end, orderByComparator };
2446                    }
2447    
2448                    List<DLFolder> list = null;
2449    
2450                    if (retrieveFromCache) {
2451                            list = (List<DLFolder>)finderCache.getResult(finderPath,
2452                                            finderArgs, this);
2453    
2454                            if ((list != null) && !list.isEmpty()) {
2455                                    for (DLFolder dlFolder : list) {
2456                                            if ((companyId != dlFolder.getCompanyId())) {
2457                                                    list = null;
2458    
2459                                                    break;
2460                                            }
2461                                    }
2462                            }
2463                    }
2464    
2465                    if (list == null) {
2466                            StringBundler query = null;
2467    
2468                            if (orderByComparator != null) {
2469                                    query = new StringBundler(3 +
2470                                                    (orderByComparator.getOrderByFields().length * 2));
2471                            }
2472                            else {
2473                                    query = new StringBundler(3);
2474                            }
2475    
2476                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
2477    
2478                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2479    
2480                            if (orderByComparator != null) {
2481                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2482                                            orderByComparator);
2483                            }
2484                            else
2485                             if (pagination) {
2486                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
2487                            }
2488    
2489                            String sql = query.toString();
2490    
2491                            Session session = null;
2492    
2493                            try {
2494                                    session = openSession();
2495    
2496                                    Query q = session.createQuery(sql);
2497    
2498                                    QueryPos qPos = QueryPos.getInstance(q);
2499    
2500                                    qPos.add(companyId);
2501    
2502                                    if (!pagination) {
2503                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
2504                                                            start, end, false);
2505    
2506                                            Collections.sort(list);
2507    
2508                                            list = Collections.unmodifiableList(list);
2509                                    }
2510                                    else {
2511                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
2512                                                            start, end);
2513                                    }
2514    
2515                                    cacheResult(list);
2516    
2517                                    finderCache.putResult(finderPath, finderArgs, list);
2518                            }
2519                            catch (Exception e) {
2520                                    finderCache.removeResult(finderPath, finderArgs);
2521    
2522                                    throw processException(e);
2523                            }
2524                            finally {
2525                                    closeSession(session);
2526                            }
2527                    }
2528    
2529                    return list;
2530            }
2531    
2532            /**
2533             * Returns the first document library folder in the ordered set where companyId = &#63;.
2534             *
2535             * @param companyId the company ID
2536             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2537             * @return the first matching document library folder
2538             * @throws NoSuchFolderException if a matching document library folder could not be found
2539             */
2540            @Override
2541            public DLFolder findByCompanyId_First(long companyId,
2542                    OrderByComparator<DLFolder> orderByComparator)
2543                    throws NoSuchFolderException {
2544                    DLFolder dlFolder = fetchByCompanyId_First(companyId, orderByComparator);
2545    
2546                    if (dlFolder != null) {
2547                            return dlFolder;
2548                    }
2549    
2550                    StringBundler msg = new StringBundler(4);
2551    
2552                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2553    
2554                    msg.append("companyId=");
2555                    msg.append(companyId);
2556    
2557                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2558    
2559                    throw new NoSuchFolderException(msg.toString());
2560            }
2561    
2562            /**
2563             * Returns the first document library folder in the ordered set where companyId = &#63;.
2564             *
2565             * @param companyId the company ID
2566             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2567             * @return the first matching document library folder, or <code>null</code> if a matching document library folder could not be found
2568             */
2569            @Override
2570            public DLFolder fetchByCompanyId_First(long companyId,
2571                    OrderByComparator<DLFolder> orderByComparator) {
2572                    List<DLFolder> list = findByCompanyId(companyId, 0, 1, orderByComparator);
2573    
2574                    if (!list.isEmpty()) {
2575                            return list.get(0);
2576                    }
2577    
2578                    return null;
2579            }
2580    
2581            /**
2582             * Returns the last document library folder in the ordered set where companyId = &#63;.
2583             *
2584             * @param companyId the company ID
2585             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2586             * @return the last matching document library folder
2587             * @throws NoSuchFolderException if a matching document library folder could not be found
2588             */
2589            @Override
2590            public DLFolder findByCompanyId_Last(long companyId,
2591                    OrderByComparator<DLFolder> orderByComparator)
2592                    throws NoSuchFolderException {
2593                    DLFolder dlFolder = fetchByCompanyId_Last(companyId, orderByComparator);
2594    
2595                    if (dlFolder != null) {
2596                            return dlFolder;
2597                    }
2598    
2599                    StringBundler msg = new StringBundler(4);
2600    
2601                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2602    
2603                    msg.append("companyId=");
2604                    msg.append(companyId);
2605    
2606                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2607    
2608                    throw new NoSuchFolderException(msg.toString());
2609            }
2610    
2611            /**
2612             * Returns the last document library folder in the ordered set where companyId = &#63;.
2613             *
2614             * @param companyId the company ID
2615             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2616             * @return the last matching document library folder, or <code>null</code> if a matching document library folder could not be found
2617             */
2618            @Override
2619            public DLFolder fetchByCompanyId_Last(long companyId,
2620                    OrderByComparator<DLFolder> orderByComparator) {
2621                    int count = countByCompanyId(companyId);
2622    
2623                    if (count == 0) {
2624                            return null;
2625                    }
2626    
2627                    List<DLFolder> list = findByCompanyId(companyId, count - 1, count,
2628                                    orderByComparator);
2629    
2630                    if (!list.isEmpty()) {
2631                            return list.get(0);
2632                    }
2633    
2634                    return null;
2635            }
2636    
2637            /**
2638             * Returns the document library folders before and after the current document library folder in the ordered set where companyId = &#63;.
2639             *
2640             * @param folderId the primary key of the current document library folder
2641             * @param companyId the company ID
2642             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2643             * @return the previous, current, and next document library folder
2644             * @throws NoSuchFolderException if a document library folder with the primary key could not be found
2645             */
2646            @Override
2647            public DLFolder[] findByCompanyId_PrevAndNext(long folderId,
2648                    long companyId, OrderByComparator<DLFolder> orderByComparator)
2649                    throws NoSuchFolderException {
2650                    DLFolder dlFolder = findByPrimaryKey(folderId);
2651    
2652                    Session session = null;
2653    
2654                    try {
2655                            session = openSession();
2656    
2657                            DLFolder[] array = new DLFolderImpl[3];
2658    
2659                            array[0] = getByCompanyId_PrevAndNext(session, dlFolder, companyId,
2660                                            orderByComparator, true);
2661    
2662                            array[1] = dlFolder;
2663    
2664                            array[2] = getByCompanyId_PrevAndNext(session, dlFolder, companyId,
2665                                            orderByComparator, false);
2666    
2667                            return array;
2668                    }
2669                    catch (Exception e) {
2670                            throw processException(e);
2671                    }
2672                    finally {
2673                            closeSession(session);
2674                    }
2675            }
2676    
2677            protected DLFolder getByCompanyId_PrevAndNext(Session session,
2678                    DLFolder dlFolder, long companyId,
2679                    OrderByComparator<DLFolder> orderByComparator, boolean previous) {
2680                    StringBundler query = null;
2681    
2682                    if (orderByComparator != null) {
2683                            query = new StringBundler(4 +
2684                                            (orderByComparator.getOrderByConditionFields().length * 3) +
2685                                            (orderByComparator.getOrderByFields().length * 3));
2686                    }
2687                    else {
2688                            query = new StringBundler(3);
2689                    }
2690    
2691                    query.append(_SQL_SELECT_DLFOLDER_WHERE);
2692    
2693                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2694    
2695                    if (orderByComparator != null) {
2696                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2697    
2698                            if (orderByConditionFields.length > 0) {
2699                                    query.append(WHERE_AND);
2700                            }
2701    
2702                            for (int i = 0; i < orderByConditionFields.length; i++) {
2703                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2704                                    query.append(orderByConditionFields[i]);
2705    
2706                                    if ((i + 1) < orderByConditionFields.length) {
2707                                            if (orderByComparator.isAscending() ^ previous) {
2708                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2709                                            }
2710                                            else {
2711                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2712                                            }
2713                                    }
2714                                    else {
2715                                            if (orderByComparator.isAscending() ^ previous) {
2716                                                    query.append(WHERE_GREATER_THAN);
2717                                            }
2718                                            else {
2719                                                    query.append(WHERE_LESSER_THAN);
2720                                            }
2721                                    }
2722                            }
2723    
2724                            query.append(ORDER_BY_CLAUSE);
2725    
2726                            String[] orderByFields = orderByComparator.getOrderByFields();
2727    
2728                            for (int i = 0; i < orderByFields.length; i++) {
2729                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2730                                    query.append(orderByFields[i]);
2731    
2732                                    if ((i + 1) < orderByFields.length) {
2733                                            if (orderByComparator.isAscending() ^ previous) {
2734                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2735                                            }
2736                                            else {
2737                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2738                                            }
2739                                    }
2740                                    else {
2741                                            if (orderByComparator.isAscending() ^ previous) {
2742                                                    query.append(ORDER_BY_ASC);
2743                                            }
2744                                            else {
2745                                                    query.append(ORDER_BY_DESC);
2746                                            }
2747                                    }
2748                            }
2749                    }
2750                    else {
2751                            query.append(DLFolderModelImpl.ORDER_BY_JPQL);
2752                    }
2753    
2754                    String sql = query.toString();
2755    
2756                    Query q = session.createQuery(sql);
2757    
2758                    q.setFirstResult(0);
2759                    q.setMaxResults(2);
2760    
2761                    QueryPos qPos = QueryPos.getInstance(q);
2762    
2763                    qPos.add(companyId);
2764    
2765                    if (orderByComparator != null) {
2766                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
2767    
2768                            for (Object value : values) {
2769                                    qPos.add(value);
2770                            }
2771                    }
2772    
2773                    List<DLFolder> list = q.list();
2774    
2775                    if (list.size() == 2) {
2776                            return list.get(1);
2777                    }
2778                    else {
2779                            return null;
2780                    }
2781            }
2782    
2783            /**
2784             * Removes all the document library folders where companyId = &#63; from the database.
2785             *
2786             * @param companyId the company ID
2787             */
2788            @Override
2789            public void removeByCompanyId(long companyId) {
2790                    for (DLFolder dlFolder : findByCompanyId(companyId, QueryUtil.ALL_POS,
2791                                    QueryUtil.ALL_POS, null)) {
2792                            remove(dlFolder);
2793                    }
2794            }
2795    
2796            /**
2797             * Returns the number of document library folders where companyId = &#63;.
2798             *
2799             * @param companyId the company ID
2800             * @return the number of matching document library folders
2801             */
2802            @Override
2803            public int countByCompanyId(long companyId) {
2804                    FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
2805    
2806                    Object[] finderArgs = new Object[] { companyId };
2807    
2808                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
2809    
2810                    if (count == null) {
2811                            StringBundler query = new StringBundler(2);
2812    
2813                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
2814    
2815                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2816    
2817                            String sql = query.toString();
2818    
2819                            Session session = null;
2820    
2821                            try {
2822                                    session = openSession();
2823    
2824                                    Query q = session.createQuery(sql);
2825    
2826                                    QueryPos qPos = QueryPos.getInstance(q);
2827    
2828                                    qPos.add(companyId);
2829    
2830                                    count = (Long)q.uniqueResult();
2831    
2832                                    finderCache.putResult(finderPath, finderArgs, count);
2833                            }
2834                            catch (Exception e) {
2835                                    finderCache.removeResult(finderPath, finderArgs);
2836    
2837                                    throw processException(e);
2838                            }
2839                            finally {
2840                                    closeSession(session);
2841                            }
2842                    }
2843    
2844                    return count.intValue();
2845            }
2846    
2847            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "dlFolder.companyId = ?";
2848            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_REPOSITORYID =
2849                    new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
2850                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
2851                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByRepositoryId",
2852                            new String[] {
2853                                    Long.class.getName(),
2854                                    
2855                            Integer.class.getName(), Integer.class.getName(),
2856                                    OrderByComparator.class.getName()
2857                            });
2858            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_REPOSITORYID =
2859                    new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
2860                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
2861                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByRepositoryId",
2862                            new String[] { Long.class.getName() },
2863                            DLFolderModelImpl.REPOSITORYID_COLUMN_BITMASK |
2864                            DLFolderModelImpl.PARENTFOLDERID_COLUMN_BITMASK |
2865                            DLFolderModelImpl.NAME_COLUMN_BITMASK);
2866            public static final FinderPath FINDER_PATH_COUNT_BY_REPOSITORYID = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
2867                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
2868                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByRepositoryId",
2869                            new String[] { Long.class.getName() });
2870    
2871            /**
2872             * Returns all the document library folders where repositoryId = &#63;.
2873             *
2874             * @param repositoryId the repository ID
2875             * @return the matching document library folders
2876             */
2877            @Override
2878            public List<DLFolder> findByRepositoryId(long repositoryId) {
2879                    return findByRepositoryId(repositoryId, QueryUtil.ALL_POS,
2880                            QueryUtil.ALL_POS, null);
2881            }
2882    
2883            /**
2884             * Returns a range of all the document library folders where repositoryId = &#63;.
2885             *
2886             * <p>
2887             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2888             * </p>
2889             *
2890             * @param repositoryId the repository ID
2891             * @param start the lower bound of the range of document library folders
2892             * @param end the upper bound of the range of document library folders (not inclusive)
2893             * @return the range of matching document library folders
2894             */
2895            @Override
2896            public List<DLFolder> findByRepositoryId(long repositoryId, int start,
2897                    int end) {
2898                    return findByRepositoryId(repositoryId, start, end, null);
2899            }
2900    
2901            /**
2902             * Returns an ordered range of all the document library folders where repositoryId = &#63;.
2903             *
2904             * <p>
2905             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2906             * </p>
2907             *
2908             * @param repositoryId the repository ID
2909             * @param start the lower bound of the range of document library folders
2910             * @param end the upper bound of the range of document library folders (not inclusive)
2911             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2912             * @return the ordered range of matching document library folders
2913             */
2914            @Override
2915            public List<DLFolder> findByRepositoryId(long repositoryId, int start,
2916                    int end, OrderByComparator<DLFolder> orderByComparator) {
2917                    return findByRepositoryId(repositoryId, start, end, orderByComparator,
2918                            true);
2919            }
2920    
2921            /**
2922             * Returns an ordered range of all the document library folders where repositoryId = &#63;.
2923             *
2924             * <p>
2925             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2926             * </p>
2927             *
2928             * @param repositoryId the repository ID
2929             * @param start the lower bound of the range of document library folders
2930             * @param end the upper bound of the range of document library folders (not inclusive)
2931             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2932             * @param retrieveFromCache whether to retrieve from the finder cache
2933             * @return the ordered range of matching document library folders
2934             */
2935            @Override
2936            public List<DLFolder> findByRepositoryId(long repositoryId, int start,
2937                    int end, OrderByComparator<DLFolder> orderByComparator,
2938                    boolean retrieveFromCache) {
2939                    boolean pagination = true;
2940                    FinderPath finderPath = null;
2941                    Object[] finderArgs = null;
2942    
2943                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2944                                    (orderByComparator == null)) {
2945                            pagination = false;
2946                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_REPOSITORYID;
2947                            finderArgs = new Object[] { repositoryId };
2948                    }
2949                    else {
2950                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_REPOSITORYID;
2951                            finderArgs = new Object[] {
2952                                            repositoryId,
2953                                            
2954                                            start, end, orderByComparator
2955                                    };
2956                    }
2957    
2958                    List<DLFolder> list = null;
2959    
2960                    if (retrieveFromCache) {
2961                            list = (List<DLFolder>)finderCache.getResult(finderPath,
2962                                            finderArgs, this);
2963    
2964                            if ((list != null) && !list.isEmpty()) {
2965                                    for (DLFolder dlFolder : list) {
2966                                            if ((repositoryId != dlFolder.getRepositoryId())) {
2967                                                    list = null;
2968    
2969                                                    break;
2970                                            }
2971                                    }
2972                            }
2973                    }
2974    
2975                    if (list == null) {
2976                            StringBundler query = null;
2977    
2978                            if (orderByComparator != null) {
2979                                    query = new StringBundler(3 +
2980                                                    (orderByComparator.getOrderByFields().length * 2));
2981                            }
2982                            else {
2983                                    query = new StringBundler(3);
2984                            }
2985    
2986                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
2987    
2988                            query.append(_FINDER_COLUMN_REPOSITORYID_REPOSITORYID_2);
2989    
2990                            if (orderByComparator != null) {
2991                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2992                                            orderByComparator);
2993                            }
2994                            else
2995                             if (pagination) {
2996                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
2997                            }
2998    
2999                            String sql = query.toString();
3000    
3001                            Session session = null;
3002    
3003                            try {
3004                                    session = openSession();
3005    
3006                                    Query q = session.createQuery(sql);
3007    
3008                                    QueryPos qPos = QueryPos.getInstance(q);
3009    
3010                                    qPos.add(repositoryId);
3011    
3012                                    if (!pagination) {
3013                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
3014                                                            start, end, false);
3015    
3016                                            Collections.sort(list);
3017    
3018                                            list = Collections.unmodifiableList(list);
3019                                    }
3020                                    else {
3021                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
3022                                                            start, end);
3023                                    }
3024    
3025                                    cacheResult(list);
3026    
3027                                    finderCache.putResult(finderPath, finderArgs, list);
3028                            }
3029                            catch (Exception e) {
3030                                    finderCache.removeResult(finderPath, finderArgs);
3031    
3032                                    throw processException(e);
3033                            }
3034                            finally {
3035                                    closeSession(session);
3036                            }
3037                    }
3038    
3039                    return list;
3040            }
3041    
3042            /**
3043             * Returns the first document library folder in the ordered set where repositoryId = &#63;.
3044             *
3045             * @param repositoryId the repository ID
3046             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3047             * @return the first matching document library folder
3048             * @throws NoSuchFolderException if a matching document library folder could not be found
3049             */
3050            @Override
3051            public DLFolder findByRepositoryId_First(long repositoryId,
3052                    OrderByComparator<DLFolder> orderByComparator)
3053                    throws NoSuchFolderException {
3054                    DLFolder dlFolder = fetchByRepositoryId_First(repositoryId,
3055                                    orderByComparator);
3056    
3057                    if (dlFolder != null) {
3058                            return dlFolder;
3059                    }
3060    
3061                    StringBundler msg = new StringBundler(4);
3062    
3063                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3064    
3065                    msg.append("repositoryId=");
3066                    msg.append(repositoryId);
3067    
3068                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3069    
3070                    throw new NoSuchFolderException(msg.toString());
3071            }
3072    
3073            /**
3074             * Returns the first document library folder in the ordered set where repositoryId = &#63;.
3075             *
3076             * @param repositoryId the repository ID
3077             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3078             * @return the first matching document library folder, or <code>null</code> if a matching document library folder could not be found
3079             */
3080            @Override
3081            public DLFolder fetchByRepositoryId_First(long repositoryId,
3082                    OrderByComparator<DLFolder> orderByComparator) {
3083                    List<DLFolder> list = findByRepositoryId(repositoryId, 0, 1,
3084                                    orderByComparator);
3085    
3086                    if (!list.isEmpty()) {
3087                            return list.get(0);
3088                    }
3089    
3090                    return null;
3091            }
3092    
3093            /**
3094             * Returns the last document library folder in the ordered set where repositoryId = &#63;.
3095             *
3096             * @param repositoryId the repository ID
3097             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3098             * @return the last matching document library folder
3099             * @throws NoSuchFolderException if a matching document library folder could not be found
3100             */
3101            @Override
3102            public DLFolder findByRepositoryId_Last(long repositoryId,
3103                    OrderByComparator<DLFolder> orderByComparator)
3104                    throws NoSuchFolderException {
3105                    DLFolder dlFolder = fetchByRepositoryId_Last(repositoryId,
3106                                    orderByComparator);
3107    
3108                    if (dlFolder != null) {
3109                            return dlFolder;
3110                    }
3111    
3112                    StringBundler msg = new StringBundler(4);
3113    
3114                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3115    
3116                    msg.append("repositoryId=");
3117                    msg.append(repositoryId);
3118    
3119                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3120    
3121                    throw new NoSuchFolderException(msg.toString());
3122            }
3123    
3124            /**
3125             * Returns the last document library folder in the ordered set where repositoryId = &#63;.
3126             *
3127             * @param repositoryId the repository ID
3128             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3129             * @return the last matching document library folder, or <code>null</code> if a matching document library folder could not be found
3130             */
3131            @Override
3132            public DLFolder fetchByRepositoryId_Last(long repositoryId,
3133                    OrderByComparator<DLFolder> orderByComparator) {
3134                    int count = countByRepositoryId(repositoryId);
3135    
3136                    if (count == 0) {
3137                            return null;
3138                    }
3139    
3140                    List<DLFolder> list = findByRepositoryId(repositoryId, count - 1,
3141                                    count, orderByComparator);
3142    
3143                    if (!list.isEmpty()) {
3144                            return list.get(0);
3145                    }
3146    
3147                    return null;
3148            }
3149    
3150            /**
3151             * Returns the document library folders before and after the current document library folder in the ordered set where repositoryId = &#63;.
3152             *
3153             * @param folderId the primary key of the current document library folder
3154             * @param repositoryId the repository ID
3155             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3156             * @return the previous, current, and next document library folder
3157             * @throws NoSuchFolderException if a document library folder with the primary key could not be found
3158             */
3159            @Override
3160            public DLFolder[] findByRepositoryId_PrevAndNext(long folderId,
3161                    long repositoryId, OrderByComparator<DLFolder> orderByComparator)
3162                    throws NoSuchFolderException {
3163                    DLFolder dlFolder = findByPrimaryKey(folderId);
3164    
3165                    Session session = null;
3166    
3167                    try {
3168                            session = openSession();
3169    
3170                            DLFolder[] array = new DLFolderImpl[3];
3171    
3172                            array[0] = getByRepositoryId_PrevAndNext(session, dlFolder,
3173                                            repositoryId, orderByComparator, true);
3174    
3175                            array[1] = dlFolder;
3176    
3177                            array[2] = getByRepositoryId_PrevAndNext(session, dlFolder,
3178                                            repositoryId, orderByComparator, false);
3179    
3180                            return array;
3181                    }
3182                    catch (Exception e) {
3183                            throw processException(e);
3184                    }
3185                    finally {
3186                            closeSession(session);
3187                    }
3188            }
3189    
3190            protected DLFolder getByRepositoryId_PrevAndNext(Session session,
3191                    DLFolder dlFolder, long repositoryId,
3192                    OrderByComparator<DLFolder> orderByComparator, boolean previous) {
3193                    StringBundler query = null;
3194    
3195                    if (orderByComparator != null) {
3196                            query = new StringBundler(4 +
3197                                            (orderByComparator.getOrderByConditionFields().length * 3) +
3198                                            (orderByComparator.getOrderByFields().length * 3));
3199                    }
3200                    else {
3201                            query = new StringBundler(3);
3202                    }
3203    
3204                    query.append(_SQL_SELECT_DLFOLDER_WHERE);
3205    
3206                    query.append(_FINDER_COLUMN_REPOSITORYID_REPOSITORYID_2);
3207    
3208                    if (orderByComparator != null) {
3209                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3210    
3211                            if (orderByConditionFields.length > 0) {
3212                                    query.append(WHERE_AND);
3213                            }
3214    
3215                            for (int i = 0; i < orderByConditionFields.length; i++) {
3216                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3217                                    query.append(orderByConditionFields[i]);
3218    
3219                                    if ((i + 1) < orderByConditionFields.length) {
3220                                            if (orderByComparator.isAscending() ^ previous) {
3221                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3222                                            }
3223                                            else {
3224                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3225                                            }
3226                                    }
3227                                    else {
3228                                            if (orderByComparator.isAscending() ^ previous) {
3229                                                    query.append(WHERE_GREATER_THAN);
3230                                            }
3231                                            else {
3232                                                    query.append(WHERE_LESSER_THAN);
3233                                            }
3234                                    }
3235                            }
3236    
3237                            query.append(ORDER_BY_CLAUSE);
3238    
3239                            String[] orderByFields = orderByComparator.getOrderByFields();
3240    
3241                            for (int i = 0; i < orderByFields.length; i++) {
3242                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3243                                    query.append(orderByFields[i]);
3244    
3245                                    if ((i + 1) < orderByFields.length) {
3246                                            if (orderByComparator.isAscending() ^ previous) {
3247                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3248                                            }
3249                                            else {
3250                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3251                                            }
3252                                    }
3253                                    else {
3254                                            if (orderByComparator.isAscending() ^ previous) {
3255                                                    query.append(ORDER_BY_ASC);
3256                                            }
3257                                            else {
3258                                                    query.append(ORDER_BY_DESC);
3259                                            }
3260                                    }
3261                            }
3262                    }
3263                    else {
3264                            query.append(DLFolderModelImpl.ORDER_BY_JPQL);
3265                    }
3266    
3267                    String sql = query.toString();
3268    
3269                    Query q = session.createQuery(sql);
3270    
3271                    q.setFirstResult(0);
3272                    q.setMaxResults(2);
3273    
3274                    QueryPos qPos = QueryPos.getInstance(q);
3275    
3276                    qPos.add(repositoryId);
3277    
3278                    if (orderByComparator != null) {
3279                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
3280    
3281                            for (Object value : values) {
3282                                    qPos.add(value);
3283                            }
3284                    }
3285    
3286                    List<DLFolder> list = q.list();
3287    
3288                    if (list.size() == 2) {
3289                            return list.get(1);
3290                    }
3291                    else {
3292                            return null;
3293                    }
3294            }
3295    
3296            /**
3297             * Removes all the document library folders where repositoryId = &#63; from the database.
3298             *
3299             * @param repositoryId the repository ID
3300             */
3301            @Override
3302            public void removeByRepositoryId(long repositoryId) {
3303                    for (DLFolder dlFolder : findByRepositoryId(repositoryId,
3304                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3305                            remove(dlFolder);
3306                    }
3307            }
3308    
3309            /**
3310             * Returns the number of document library folders where repositoryId = &#63;.
3311             *
3312             * @param repositoryId the repository ID
3313             * @return the number of matching document library folders
3314             */
3315            @Override
3316            public int countByRepositoryId(long repositoryId) {
3317                    FinderPath finderPath = FINDER_PATH_COUNT_BY_REPOSITORYID;
3318    
3319                    Object[] finderArgs = new Object[] { repositoryId };
3320    
3321                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
3322    
3323                    if (count == null) {
3324                            StringBundler query = new StringBundler(2);
3325    
3326                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
3327    
3328                            query.append(_FINDER_COLUMN_REPOSITORYID_REPOSITORYID_2);
3329    
3330                            String sql = query.toString();
3331    
3332                            Session session = null;
3333    
3334                            try {
3335                                    session = openSession();
3336    
3337                                    Query q = session.createQuery(sql);
3338    
3339                                    QueryPos qPos = QueryPos.getInstance(q);
3340    
3341                                    qPos.add(repositoryId);
3342    
3343                                    count = (Long)q.uniqueResult();
3344    
3345                                    finderCache.putResult(finderPath, finderArgs, count);
3346                            }
3347                            catch (Exception e) {
3348                                    finderCache.removeResult(finderPath, finderArgs);
3349    
3350                                    throw processException(e);
3351                            }
3352                            finally {
3353                                    closeSession(session);
3354                            }
3355                    }
3356    
3357                    return count.intValue();
3358            }
3359    
3360            private static final String _FINDER_COLUMN_REPOSITORYID_REPOSITORYID_2 = "dlFolder.repositoryId = ?";
3361            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
3362                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
3363                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_P",
3364                            new String[] {
3365                                    Long.class.getName(), Long.class.getName(),
3366                                    
3367                            Integer.class.getName(), Integer.class.getName(),
3368                                    OrderByComparator.class.getName()
3369                            });
3370            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
3371                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
3372                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_P",
3373                            new String[] { Long.class.getName(), Long.class.getName() },
3374                            DLFolderModelImpl.GROUPID_COLUMN_BITMASK |
3375                            DLFolderModelImpl.PARENTFOLDERID_COLUMN_BITMASK |
3376                            DLFolderModelImpl.NAME_COLUMN_BITMASK);
3377            public static final FinderPath FINDER_PATH_COUNT_BY_G_P = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
3378                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
3379                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P",
3380                            new String[] { Long.class.getName(), Long.class.getName() });
3381    
3382            /**
3383             * Returns all the document library folders where groupId = &#63; and parentFolderId = &#63;.
3384             *
3385             * @param groupId the group ID
3386             * @param parentFolderId the parent folder ID
3387             * @return the matching document library folders
3388             */
3389            @Override
3390            public List<DLFolder> findByG_P(long groupId, long parentFolderId) {
3391                    return findByG_P(groupId, parentFolderId, QueryUtil.ALL_POS,
3392                            QueryUtil.ALL_POS, null);
3393            }
3394    
3395            /**
3396             * Returns a range of all the document library folders where groupId = &#63; and parentFolderId = &#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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3400             * </p>
3401             *
3402             * @param groupId the group ID
3403             * @param parentFolderId the parent folder ID
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             * @return the range of matching document library folders
3407             */
3408            @Override
3409            public List<DLFolder> findByG_P(long groupId, long parentFolderId,
3410                    int start, int end) {
3411                    return findByG_P(groupId, parentFolderId, start, end, null);
3412            }
3413    
3414            /**
3415             * Returns an ordered range of all the document library folders where groupId = &#63; and parentFolderId = &#63;.
3416             *
3417             * <p>
3418             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3419             * </p>
3420             *
3421             * @param groupId the group ID
3422             * @param parentFolderId the parent folder ID
3423             * @param start the lower bound of the range of document library folders
3424             * @param end the upper bound of the range of document library folders (not inclusive)
3425             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3426             * @return the ordered range of matching document library folders
3427             */
3428            @Override
3429            public List<DLFolder> findByG_P(long groupId, long parentFolderId,
3430                    int start, int end, OrderByComparator<DLFolder> orderByComparator) {
3431                    return findByG_P(groupId, parentFolderId, start, end,
3432                            orderByComparator, true);
3433            }
3434    
3435            /**
3436             * Returns an ordered range of all the document library folders where groupId = &#63; and parentFolderId = &#63;.
3437             *
3438             * <p>
3439             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3440             * </p>
3441             *
3442             * @param groupId the group ID
3443             * @param parentFolderId the parent folder ID
3444             * @param start the lower bound of the range of document library folders
3445             * @param end the upper bound of the range of document library folders (not inclusive)
3446             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3447             * @param retrieveFromCache whether to retrieve from the finder cache
3448             * @return the ordered range of matching document library folders
3449             */
3450            @Override
3451            public List<DLFolder> findByG_P(long groupId, long parentFolderId,
3452                    int start, int end, OrderByComparator<DLFolder> orderByComparator,
3453                    boolean retrieveFromCache) {
3454                    boolean pagination = true;
3455                    FinderPath finderPath = null;
3456                    Object[] finderArgs = null;
3457    
3458                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3459                                    (orderByComparator == null)) {
3460                            pagination = false;
3461                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P;
3462                            finderArgs = new Object[] { groupId, parentFolderId };
3463                    }
3464                    else {
3465                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P;
3466                            finderArgs = new Object[] {
3467                                            groupId, parentFolderId,
3468                                            
3469                                            start, end, orderByComparator
3470                                    };
3471                    }
3472    
3473                    List<DLFolder> list = null;
3474    
3475                    if (retrieveFromCache) {
3476                            list = (List<DLFolder>)finderCache.getResult(finderPath,
3477                                            finderArgs, this);
3478    
3479                            if ((list != null) && !list.isEmpty()) {
3480                                    for (DLFolder dlFolder : list) {
3481                                            if ((groupId != dlFolder.getGroupId()) ||
3482                                                            (parentFolderId != dlFolder.getParentFolderId())) {
3483                                                    list = null;
3484    
3485                                                    break;
3486                                            }
3487                                    }
3488                            }
3489                    }
3490    
3491                    if (list == null) {
3492                            StringBundler query = null;
3493    
3494                            if (orderByComparator != null) {
3495                                    query = new StringBundler(4 +
3496                                                    (orderByComparator.getOrderByFields().length * 2));
3497                            }
3498                            else {
3499                                    query = new StringBundler(4);
3500                            }
3501    
3502                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
3503    
3504                            query.append(_FINDER_COLUMN_G_P_GROUPID_2);
3505    
3506                            query.append(_FINDER_COLUMN_G_P_PARENTFOLDERID_2);
3507    
3508                            if (orderByComparator != null) {
3509                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3510                                            orderByComparator);
3511                            }
3512                            else
3513                             if (pagination) {
3514                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
3515                            }
3516    
3517                            String sql = query.toString();
3518    
3519                            Session session = null;
3520    
3521                            try {
3522                                    session = openSession();
3523    
3524                                    Query q = session.createQuery(sql);
3525    
3526                                    QueryPos qPos = QueryPos.getInstance(q);
3527    
3528                                    qPos.add(groupId);
3529    
3530                                    qPos.add(parentFolderId);
3531    
3532                                    if (!pagination) {
3533                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
3534                                                            start, end, false);
3535    
3536                                            Collections.sort(list);
3537    
3538                                            list = Collections.unmodifiableList(list);
3539                                    }
3540                                    else {
3541                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
3542                                                            start, end);
3543                                    }
3544    
3545                                    cacheResult(list);
3546    
3547                                    finderCache.putResult(finderPath, finderArgs, list);
3548                            }
3549                            catch (Exception e) {
3550                                    finderCache.removeResult(finderPath, finderArgs);
3551    
3552                                    throw processException(e);
3553                            }
3554                            finally {
3555                                    closeSession(session);
3556                            }
3557                    }
3558    
3559                    return list;
3560            }
3561    
3562            /**
3563             * Returns the first document library folder in the ordered set where groupId = &#63; and parentFolderId = &#63;.
3564             *
3565             * @param groupId the group ID
3566             * @param parentFolderId the parent folder ID
3567             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3568             * @return the first matching document library folder
3569             * @throws NoSuchFolderException if a matching document library folder could not be found
3570             */
3571            @Override
3572            public DLFolder findByG_P_First(long groupId, long parentFolderId,
3573                    OrderByComparator<DLFolder> orderByComparator)
3574                    throws NoSuchFolderException {
3575                    DLFolder dlFolder = fetchByG_P_First(groupId, parentFolderId,
3576                                    orderByComparator);
3577    
3578                    if (dlFolder != null) {
3579                            return dlFolder;
3580                    }
3581    
3582                    StringBundler msg = new StringBundler(6);
3583    
3584                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3585    
3586                    msg.append("groupId=");
3587                    msg.append(groupId);
3588    
3589                    msg.append(", parentFolderId=");
3590                    msg.append(parentFolderId);
3591    
3592                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3593    
3594                    throw new NoSuchFolderException(msg.toString());
3595            }
3596    
3597            /**
3598             * Returns the first document library folder in the ordered set where groupId = &#63; and parentFolderId = &#63;.
3599             *
3600             * @param groupId the group ID
3601             * @param parentFolderId the parent folder ID
3602             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3603             * @return the first matching document library folder, or <code>null</code> if a matching document library folder could not be found
3604             */
3605            @Override
3606            public DLFolder fetchByG_P_First(long groupId, long parentFolderId,
3607                    OrderByComparator<DLFolder> orderByComparator) {
3608                    List<DLFolder> list = findByG_P(groupId, parentFolderId, 0, 1,
3609                                    orderByComparator);
3610    
3611                    if (!list.isEmpty()) {
3612                            return list.get(0);
3613                    }
3614    
3615                    return null;
3616            }
3617    
3618            /**
3619             * Returns the last document library folder in the ordered set where groupId = &#63; and parentFolderId = &#63;.
3620             *
3621             * @param groupId the group ID
3622             * @param parentFolderId the parent folder ID
3623             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3624             * @return the last matching document library folder
3625             * @throws NoSuchFolderException if a matching document library folder could not be found
3626             */
3627            @Override
3628            public DLFolder findByG_P_Last(long groupId, long parentFolderId,
3629                    OrderByComparator<DLFolder> orderByComparator)
3630                    throws NoSuchFolderException {
3631                    DLFolder dlFolder = fetchByG_P_Last(groupId, parentFolderId,
3632                                    orderByComparator);
3633    
3634                    if (dlFolder != null) {
3635                            return dlFolder;
3636                    }
3637    
3638                    StringBundler msg = new StringBundler(6);
3639    
3640                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3641    
3642                    msg.append("groupId=");
3643                    msg.append(groupId);
3644    
3645                    msg.append(", parentFolderId=");
3646                    msg.append(parentFolderId);
3647    
3648                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3649    
3650                    throw new NoSuchFolderException(msg.toString());
3651            }
3652    
3653            /**
3654             * Returns the last document library folder in the ordered set where groupId = &#63; and parentFolderId = &#63;.
3655             *
3656             * @param groupId the group ID
3657             * @param parentFolderId the parent folder ID
3658             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3659             * @return the last matching document library folder, or <code>null</code> if a matching document library folder could not be found
3660             */
3661            @Override
3662            public DLFolder fetchByG_P_Last(long groupId, long parentFolderId,
3663                    OrderByComparator<DLFolder> orderByComparator) {
3664                    int count = countByG_P(groupId, parentFolderId);
3665    
3666                    if (count == 0) {
3667                            return null;
3668                    }
3669    
3670                    List<DLFolder> list = findByG_P(groupId, parentFolderId, count - 1,
3671                                    count, orderByComparator);
3672    
3673                    if (!list.isEmpty()) {
3674                            return list.get(0);
3675                    }
3676    
3677                    return null;
3678            }
3679    
3680            /**
3681             * Returns the document library folders before and after the current document library folder in the ordered set where groupId = &#63; and parentFolderId = &#63;.
3682             *
3683             * @param folderId the primary key of the current document library folder
3684             * @param groupId the group ID
3685             * @param parentFolderId the parent folder ID
3686             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3687             * @return the previous, current, and next document library folder
3688             * @throws NoSuchFolderException if a document library folder with the primary key could not be found
3689             */
3690            @Override
3691            public DLFolder[] findByG_P_PrevAndNext(long folderId, long groupId,
3692                    long parentFolderId, OrderByComparator<DLFolder> orderByComparator)
3693                    throws NoSuchFolderException {
3694                    DLFolder dlFolder = findByPrimaryKey(folderId);
3695    
3696                    Session session = null;
3697    
3698                    try {
3699                            session = openSession();
3700    
3701                            DLFolder[] array = new DLFolderImpl[3];
3702    
3703                            array[0] = getByG_P_PrevAndNext(session, dlFolder, groupId,
3704                                            parentFolderId, orderByComparator, true);
3705    
3706                            array[1] = dlFolder;
3707    
3708                            array[2] = getByG_P_PrevAndNext(session, dlFolder, groupId,
3709                                            parentFolderId, orderByComparator, false);
3710    
3711                            return array;
3712                    }
3713                    catch (Exception e) {
3714                            throw processException(e);
3715                    }
3716                    finally {
3717                            closeSession(session);
3718                    }
3719            }
3720    
3721            protected DLFolder getByG_P_PrevAndNext(Session session, DLFolder dlFolder,
3722                    long groupId, long parentFolderId,
3723                    OrderByComparator<DLFolder> orderByComparator, boolean previous) {
3724                    StringBundler query = null;
3725    
3726                    if (orderByComparator != null) {
3727                            query = new StringBundler(5 +
3728                                            (orderByComparator.getOrderByConditionFields().length * 3) +
3729                                            (orderByComparator.getOrderByFields().length * 3));
3730                    }
3731                    else {
3732                            query = new StringBundler(4);
3733                    }
3734    
3735                    query.append(_SQL_SELECT_DLFOLDER_WHERE);
3736    
3737                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
3738    
3739                    query.append(_FINDER_COLUMN_G_P_PARENTFOLDERID_2);
3740    
3741                    if (orderByComparator != null) {
3742                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3743    
3744                            if (orderByConditionFields.length > 0) {
3745                                    query.append(WHERE_AND);
3746                            }
3747    
3748                            for (int i = 0; i < orderByConditionFields.length; i++) {
3749                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3750                                    query.append(orderByConditionFields[i]);
3751    
3752                                    if ((i + 1) < orderByConditionFields.length) {
3753                                            if (orderByComparator.isAscending() ^ previous) {
3754                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3755                                            }
3756                                            else {
3757                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3758                                            }
3759                                    }
3760                                    else {
3761                                            if (orderByComparator.isAscending() ^ previous) {
3762                                                    query.append(WHERE_GREATER_THAN);
3763                                            }
3764                                            else {
3765                                                    query.append(WHERE_LESSER_THAN);
3766                                            }
3767                                    }
3768                            }
3769    
3770                            query.append(ORDER_BY_CLAUSE);
3771    
3772                            String[] orderByFields = orderByComparator.getOrderByFields();
3773    
3774                            for (int i = 0; i < orderByFields.length; i++) {
3775                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3776                                    query.append(orderByFields[i]);
3777    
3778                                    if ((i + 1) < orderByFields.length) {
3779                                            if (orderByComparator.isAscending() ^ previous) {
3780                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3781                                            }
3782                                            else {
3783                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3784                                            }
3785                                    }
3786                                    else {
3787                                            if (orderByComparator.isAscending() ^ previous) {
3788                                                    query.append(ORDER_BY_ASC);
3789                                            }
3790                                            else {
3791                                                    query.append(ORDER_BY_DESC);
3792                                            }
3793                                    }
3794                            }
3795                    }
3796                    else {
3797                            query.append(DLFolderModelImpl.ORDER_BY_JPQL);
3798                    }
3799    
3800                    String sql = query.toString();
3801    
3802                    Query q = session.createQuery(sql);
3803    
3804                    q.setFirstResult(0);
3805                    q.setMaxResults(2);
3806    
3807                    QueryPos qPos = QueryPos.getInstance(q);
3808    
3809                    qPos.add(groupId);
3810    
3811                    qPos.add(parentFolderId);
3812    
3813                    if (orderByComparator != null) {
3814                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
3815    
3816                            for (Object value : values) {
3817                                    qPos.add(value);
3818                            }
3819                    }
3820    
3821                    List<DLFolder> list = q.list();
3822    
3823                    if (list.size() == 2) {
3824                            return list.get(1);
3825                    }
3826                    else {
3827                            return null;
3828                    }
3829            }
3830    
3831            /**
3832             * Returns all the document library folders that the user has permission to view where groupId = &#63; and parentFolderId = &#63;.
3833             *
3834             * @param groupId the group ID
3835             * @param parentFolderId the parent folder ID
3836             * @return the matching document library folders that the user has permission to view
3837             */
3838            @Override
3839            public List<DLFolder> filterFindByG_P(long groupId, long parentFolderId) {
3840                    return filterFindByG_P(groupId, parentFolderId, QueryUtil.ALL_POS,
3841                            QueryUtil.ALL_POS, null);
3842            }
3843    
3844            /**
3845             * Returns a range of all the document library folders that the user has permission to view where groupId = &#63; and parentFolderId = &#63;.
3846             *
3847             * <p>
3848             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3849             * </p>
3850             *
3851             * @param groupId the group ID
3852             * @param parentFolderId the parent folder ID
3853             * @param start the lower bound of the range of document library folders
3854             * @param end the upper bound of the range of document library folders (not inclusive)
3855             * @return the range of matching document library folders that the user has permission to view
3856             */
3857            @Override
3858            public List<DLFolder> filterFindByG_P(long groupId, long parentFolderId,
3859                    int start, int end) {
3860                    return filterFindByG_P(groupId, parentFolderId, start, end, null);
3861            }
3862    
3863            /**
3864             * Returns an ordered range of all the document library folders that the user has permissions to view where groupId = &#63; and parentFolderId = &#63;.
3865             *
3866             * <p>
3867             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3868             * </p>
3869             *
3870             * @param groupId the group ID
3871             * @param parentFolderId the parent folder ID
3872             * @param start the lower bound of the range of document library folders
3873             * @param end the upper bound of the range of document library folders (not inclusive)
3874             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3875             * @return the ordered range of matching document library folders that the user has permission to view
3876             */
3877            @Override
3878            public List<DLFolder> filterFindByG_P(long groupId, long parentFolderId,
3879                    int start, int end, OrderByComparator<DLFolder> orderByComparator) {
3880                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3881                            return findByG_P(groupId, parentFolderId, start, end,
3882                                    orderByComparator);
3883                    }
3884    
3885                    StringBundler query = null;
3886    
3887                    if (orderByComparator != null) {
3888                            query = new StringBundler(4 +
3889                                            (orderByComparator.getOrderByFields().length * 2));
3890                    }
3891                    else {
3892                            query = new StringBundler(5);
3893                    }
3894    
3895                    if (getDB().isSupportsInlineDistinct()) {
3896                            query.append(_FILTER_SQL_SELECT_DLFOLDER_WHERE);
3897                    }
3898                    else {
3899                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1);
3900                    }
3901    
3902                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
3903    
3904                    query.append(_FINDER_COLUMN_G_P_PARENTFOLDERID_2);
3905    
3906                    if (!getDB().isSupportsInlineDistinct()) {
3907                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2);
3908                    }
3909    
3910                    if (orderByComparator != null) {
3911                            if (getDB().isSupportsInlineDistinct()) {
3912                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3913                                            orderByComparator, true);
3914                            }
3915                            else {
3916                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3917                                            orderByComparator, true);
3918                            }
3919                    }
3920                    else {
3921                            if (getDB().isSupportsInlineDistinct()) {
3922                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
3923                            }
3924                            else {
3925                                    query.append(DLFolderModelImpl.ORDER_BY_SQL);
3926                            }
3927                    }
3928    
3929                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3930                                    DLFolder.class.getName(),
3931                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3932    
3933                    Session session = null;
3934    
3935                    try {
3936                            session = openSession();
3937    
3938                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
3939    
3940                            if (getDB().isSupportsInlineDistinct()) {
3941                                    q.addEntity(_FILTER_ENTITY_ALIAS, DLFolderImpl.class);
3942                            }
3943                            else {
3944                                    q.addEntity(_FILTER_ENTITY_TABLE, DLFolderImpl.class);
3945                            }
3946    
3947                            QueryPos qPos = QueryPos.getInstance(q);
3948    
3949                            qPos.add(groupId);
3950    
3951                            qPos.add(parentFolderId);
3952    
3953                            return (List<DLFolder>)QueryUtil.list(q, getDialect(), start, end);
3954                    }
3955                    catch (Exception e) {
3956                            throw processException(e);
3957                    }
3958                    finally {
3959                            closeSession(session);
3960                    }
3961            }
3962    
3963            /**
3964             * 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;.
3965             *
3966             * @param folderId the primary key of the current document library folder
3967             * @param groupId the group ID
3968             * @param parentFolderId the parent folder ID
3969             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3970             * @return the previous, current, and next document library folder
3971             * @throws NoSuchFolderException if a document library folder with the primary key could not be found
3972             */
3973            @Override
3974            public DLFolder[] filterFindByG_P_PrevAndNext(long folderId, long groupId,
3975                    long parentFolderId, OrderByComparator<DLFolder> orderByComparator)
3976                    throws NoSuchFolderException {
3977                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3978                            return findByG_P_PrevAndNext(folderId, groupId, parentFolderId,
3979                                    orderByComparator);
3980                    }
3981    
3982                    DLFolder dlFolder = findByPrimaryKey(folderId);
3983    
3984                    Session session = null;
3985    
3986                    try {
3987                            session = openSession();
3988    
3989                            DLFolder[] array = new DLFolderImpl[3];
3990    
3991                            array[0] = filterGetByG_P_PrevAndNext(session, dlFolder, groupId,
3992                                            parentFolderId, orderByComparator, true);
3993    
3994                            array[1] = dlFolder;
3995    
3996                            array[2] = filterGetByG_P_PrevAndNext(session, dlFolder, groupId,
3997                                            parentFolderId, orderByComparator, false);
3998    
3999                            return array;
4000                    }
4001                    catch (Exception e) {
4002                            throw processException(e);
4003                    }
4004                    finally {
4005                            closeSession(session);
4006                    }
4007            }
4008    
4009            protected DLFolder filterGetByG_P_PrevAndNext(Session session,
4010                    DLFolder dlFolder, long groupId, long parentFolderId,
4011                    OrderByComparator<DLFolder> orderByComparator, boolean previous) {
4012                    StringBundler query = null;
4013    
4014                    if (orderByComparator != null) {
4015                            query = new StringBundler(6 +
4016                                            (orderByComparator.getOrderByConditionFields().length * 3) +
4017                                            (orderByComparator.getOrderByFields().length * 3));
4018                    }
4019                    else {
4020                            query = new StringBundler(5);
4021                    }
4022    
4023                    if (getDB().isSupportsInlineDistinct()) {
4024                            query.append(_FILTER_SQL_SELECT_DLFOLDER_WHERE);
4025                    }
4026                    else {
4027                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1);
4028                    }
4029    
4030                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
4031    
4032                    query.append(_FINDER_COLUMN_G_P_PARENTFOLDERID_2);
4033    
4034                    if (!getDB().isSupportsInlineDistinct()) {
4035                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2);
4036                    }
4037    
4038                    if (orderByComparator != null) {
4039                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4040    
4041                            if (orderByConditionFields.length > 0) {
4042                                    query.append(WHERE_AND);
4043                            }
4044    
4045                            for (int i = 0; i < orderByConditionFields.length; i++) {
4046                                    if (getDB().isSupportsInlineDistinct()) {
4047                                            query.append(_ORDER_BY_ENTITY_ALIAS);
4048                                    }
4049                                    else {
4050                                            query.append(_ORDER_BY_ENTITY_TABLE);
4051                                    }
4052    
4053                                    query.append(orderByConditionFields[i]);
4054    
4055                                    if ((i + 1) < orderByConditionFields.length) {
4056                                            if (orderByComparator.isAscending() ^ previous) {
4057                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4058                                            }
4059                                            else {
4060                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4061                                            }
4062                                    }
4063                                    else {
4064                                            if (orderByComparator.isAscending() ^ previous) {
4065                                                    query.append(WHERE_GREATER_THAN);
4066                                            }
4067                                            else {
4068                                                    query.append(WHERE_LESSER_THAN);
4069                                            }
4070                                    }
4071                            }
4072    
4073                            query.append(ORDER_BY_CLAUSE);
4074    
4075                            String[] orderByFields = orderByComparator.getOrderByFields();
4076    
4077                            for (int i = 0; i < orderByFields.length; i++) {
4078                                    if (getDB().isSupportsInlineDistinct()) {
4079                                            query.append(_ORDER_BY_ENTITY_ALIAS);
4080                                    }
4081                                    else {
4082                                            query.append(_ORDER_BY_ENTITY_TABLE);
4083                                    }
4084    
4085                                    query.append(orderByFields[i]);
4086    
4087                                    if ((i + 1) < orderByFields.length) {
4088                                            if (orderByComparator.isAscending() ^ previous) {
4089                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4090                                            }
4091                                            else {
4092                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4093                                            }
4094                                    }
4095                                    else {
4096                                            if (orderByComparator.isAscending() ^ previous) {
4097                                                    query.append(ORDER_BY_ASC);
4098                                            }
4099                                            else {
4100                                                    query.append(ORDER_BY_DESC);
4101                                            }
4102                                    }
4103                            }
4104                    }
4105                    else {
4106                            if (getDB().isSupportsInlineDistinct()) {
4107                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
4108                            }
4109                            else {
4110                                    query.append(DLFolderModelImpl.ORDER_BY_SQL);
4111                            }
4112                    }
4113    
4114                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4115                                    DLFolder.class.getName(),
4116                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4117    
4118                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
4119    
4120                    q.setFirstResult(0);
4121                    q.setMaxResults(2);
4122    
4123                    if (getDB().isSupportsInlineDistinct()) {
4124                            q.addEntity(_FILTER_ENTITY_ALIAS, DLFolderImpl.class);
4125                    }
4126                    else {
4127                            q.addEntity(_FILTER_ENTITY_TABLE, DLFolderImpl.class);
4128                    }
4129    
4130                    QueryPos qPos = QueryPos.getInstance(q);
4131    
4132                    qPos.add(groupId);
4133    
4134                    qPos.add(parentFolderId);
4135    
4136                    if (orderByComparator != null) {
4137                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
4138    
4139                            for (Object value : values) {
4140                                    qPos.add(value);
4141                            }
4142                    }
4143    
4144                    List<DLFolder> list = q.list();
4145    
4146                    if (list.size() == 2) {
4147                            return list.get(1);
4148                    }
4149                    else {
4150                            return null;
4151                    }
4152            }
4153    
4154            /**
4155             * Removes all the document library folders where groupId = &#63; and parentFolderId = &#63; from the database.
4156             *
4157             * @param groupId the group ID
4158             * @param parentFolderId the parent folder ID
4159             */
4160            @Override
4161            public void removeByG_P(long groupId, long parentFolderId) {
4162                    for (DLFolder dlFolder : findByG_P(groupId, parentFolderId,
4163                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4164                            remove(dlFolder);
4165                    }
4166            }
4167    
4168            /**
4169             * Returns the number of document library folders where groupId = &#63; and parentFolderId = &#63;.
4170             *
4171             * @param groupId the group ID
4172             * @param parentFolderId the parent folder ID
4173             * @return the number of matching document library folders
4174             */
4175            @Override
4176            public int countByG_P(long groupId, long parentFolderId) {
4177                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_P;
4178    
4179                    Object[] finderArgs = new Object[] { groupId, parentFolderId };
4180    
4181                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
4182    
4183                    if (count == null) {
4184                            StringBundler query = new StringBundler(3);
4185    
4186                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
4187    
4188                            query.append(_FINDER_COLUMN_G_P_GROUPID_2);
4189    
4190                            query.append(_FINDER_COLUMN_G_P_PARENTFOLDERID_2);
4191    
4192                            String sql = query.toString();
4193    
4194                            Session session = null;
4195    
4196                            try {
4197                                    session = openSession();
4198    
4199                                    Query q = session.createQuery(sql);
4200    
4201                                    QueryPos qPos = QueryPos.getInstance(q);
4202    
4203                                    qPos.add(groupId);
4204    
4205                                    qPos.add(parentFolderId);
4206    
4207                                    count = (Long)q.uniqueResult();
4208    
4209                                    finderCache.putResult(finderPath, finderArgs, count);
4210                            }
4211                            catch (Exception e) {
4212                                    finderCache.removeResult(finderPath, finderArgs);
4213    
4214                                    throw processException(e);
4215                            }
4216                            finally {
4217                                    closeSession(session);
4218                            }
4219                    }
4220    
4221                    return count.intValue();
4222            }
4223    
4224            /**
4225             * Returns the number of document library folders that the user has permission to view where groupId = &#63; and parentFolderId = &#63;.
4226             *
4227             * @param groupId the group ID
4228             * @param parentFolderId the parent folder ID
4229             * @return the number of matching document library folders that the user has permission to view
4230             */
4231            @Override
4232            public int filterCountByG_P(long groupId, long parentFolderId) {
4233                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4234                            return countByG_P(groupId, parentFolderId);
4235                    }
4236    
4237                    StringBundler query = new StringBundler(3);
4238    
4239                    query.append(_FILTER_SQL_COUNT_DLFOLDER_WHERE);
4240    
4241                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
4242    
4243                    query.append(_FINDER_COLUMN_G_P_PARENTFOLDERID_2);
4244    
4245                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4246                                    DLFolder.class.getName(),
4247                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4248    
4249                    Session session = null;
4250    
4251                    try {
4252                            session = openSession();
4253    
4254                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
4255    
4256                            q.addScalar(COUNT_COLUMN_NAME,
4257                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
4258    
4259                            QueryPos qPos = QueryPos.getInstance(q);
4260    
4261                            qPos.add(groupId);
4262    
4263                            qPos.add(parentFolderId);
4264    
4265                            Long count = (Long)q.uniqueResult();
4266    
4267                            return count.intValue();
4268                    }
4269                    catch (Exception e) {
4270                            throw processException(e);
4271                    }
4272                    finally {
4273                            closeSession(session);
4274                    }
4275            }
4276    
4277            private static final String _FINDER_COLUMN_G_P_GROUPID_2 = "dlFolder.groupId = ? AND ";
4278            private static final String _FINDER_COLUMN_G_P_PARENTFOLDERID_2 = "dlFolder.parentFolderId = ?";
4279            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_NOTS = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
4280                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
4281                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_NotS",
4282                            new String[] {
4283                                    Long.class.getName(), Integer.class.getName(),
4284                                    
4285                            Integer.class.getName(), Integer.class.getName(),
4286                                    OrderByComparator.class.getName()
4287                            });
4288            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_NOTS = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
4289                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
4290                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByC_NotS",
4291                            new String[] { Long.class.getName(), Integer.class.getName() });
4292    
4293            /**
4294             * Returns all the document library folders where companyId = &#63; and status &ne; &#63;.
4295             *
4296             * @param companyId the company ID
4297             * @param status the status
4298             * @return the matching document library folders
4299             */
4300            @Override
4301            public List<DLFolder> findByC_NotS(long companyId, int status) {
4302                    return findByC_NotS(companyId, status, QueryUtil.ALL_POS,
4303                            QueryUtil.ALL_POS, null);
4304            }
4305    
4306            /**
4307             * Returns a range of all the document library folders where companyId = &#63; and status &ne; &#63;.
4308             *
4309             * <p>
4310             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4311             * </p>
4312             *
4313             * @param companyId the company ID
4314             * @param status the status
4315             * @param start the lower bound of the range of document library folders
4316             * @param end the upper bound of the range of document library folders (not inclusive)
4317             * @return the range of matching document library folders
4318             */
4319            @Override
4320            public List<DLFolder> findByC_NotS(long companyId, int status, int start,
4321                    int end) {
4322                    return findByC_NotS(companyId, status, start, end, null);
4323            }
4324    
4325            /**
4326             * Returns an ordered range of all the document library folders where companyId = &#63; and status &ne; &#63;.
4327             *
4328             * <p>
4329             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4330             * </p>
4331             *
4332             * @param companyId the company ID
4333             * @param status the status
4334             * @param start the lower bound of the range of document library folders
4335             * @param end the upper bound of the range of document library folders (not inclusive)
4336             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4337             * @return the ordered range of matching document library folders
4338             */
4339            @Override
4340            public List<DLFolder> findByC_NotS(long companyId, int status, int start,
4341                    int end, OrderByComparator<DLFolder> orderByComparator) {
4342                    return findByC_NotS(companyId, status, start, end, orderByComparator,
4343                            true);
4344            }
4345    
4346            /**
4347             * Returns an ordered range of all the document library folders where companyId = &#63; and status &ne; &#63;.
4348             *
4349             * <p>
4350             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4351             * </p>
4352             *
4353             * @param companyId the company ID
4354             * @param status the status
4355             * @param start the lower bound of the range of document library folders
4356             * @param end the upper bound of the range of document library folders (not inclusive)
4357             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4358             * @param retrieveFromCache whether to retrieve from the finder cache
4359             * @return the ordered range of matching document library folders
4360             */
4361            @Override
4362            public List<DLFolder> findByC_NotS(long companyId, int status, int start,
4363                    int end, OrderByComparator<DLFolder> orderByComparator,
4364                    boolean retrieveFromCache) {
4365                    boolean pagination = true;
4366                    FinderPath finderPath = null;
4367                    Object[] finderArgs = null;
4368    
4369                    finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_NOTS;
4370                    finderArgs = new Object[] {
4371                                    companyId, status,
4372                                    
4373                                    start, end, orderByComparator
4374                            };
4375    
4376                    List<DLFolder> list = null;
4377    
4378                    if (retrieveFromCache) {
4379                            list = (List<DLFolder>)finderCache.getResult(finderPath,
4380                                            finderArgs, this);
4381    
4382                            if ((list != null) && !list.isEmpty()) {
4383                                    for (DLFolder dlFolder : list) {
4384                                            if ((companyId != dlFolder.getCompanyId()) ||
4385                                                            (status == dlFolder.getStatus())) {
4386                                                    list = null;
4387    
4388                                                    break;
4389                                            }
4390                                    }
4391                            }
4392                    }
4393    
4394                    if (list == null) {
4395                            StringBundler query = null;
4396    
4397                            if (orderByComparator != null) {
4398                                    query = new StringBundler(4 +
4399                                                    (orderByComparator.getOrderByFields().length * 2));
4400                            }
4401                            else {
4402                                    query = new StringBundler(4);
4403                            }
4404    
4405                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
4406    
4407                            query.append(_FINDER_COLUMN_C_NOTS_COMPANYID_2);
4408    
4409                            query.append(_FINDER_COLUMN_C_NOTS_STATUS_2);
4410    
4411                            if (orderByComparator != null) {
4412                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4413                                            orderByComparator);
4414                            }
4415                            else
4416                             if (pagination) {
4417                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
4418                            }
4419    
4420                            String sql = query.toString();
4421    
4422                            Session session = null;
4423    
4424                            try {
4425                                    session = openSession();
4426    
4427                                    Query q = session.createQuery(sql);
4428    
4429                                    QueryPos qPos = QueryPos.getInstance(q);
4430    
4431                                    qPos.add(companyId);
4432    
4433                                    qPos.add(status);
4434    
4435                                    if (!pagination) {
4436                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
4437                                                            start, end, false);
4438    
4439                                            Collections.sort(list);
4440    
4441                                            list = Collections.unmodifiableList(list);
4442                                    }
4443                                    else {
4444                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
4445                                                            start, end);
4446                                    }
4447    
4448                                    cacheResult(list);
4449    
4450                                    finderCache.putResult(finderPath, finderArgs, list);
4451                            }
4452                            catch (Exception e) {
4453                                    finderCache.removeResult(finderPath, finderArgs);
4454    
4455                                    throw processException(e);
4456                            }
4457                            finally {
4458                                    closeSession(session);
4459                            }
4460                    }
4461    
4462                    return list;
4463            }
4464    
4465            /**
4466             * Returns the first document library folder in the ordered set where companyId = &#63; and status &ne; &#63;.
4467             *
4468             * @param companyId the company ID
4469             * @param status the status
4470             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4471             * @return the first matching document library folder
4472             * @throws NoSuchFolderException if a matching document library folder could not be found
4473             */
4474            @Override
4475            public DLFolder findByC_NotS_First(long companyId, int status,
4476                    OrderByComparator<DLFolder> orderByComparator)
4477                    throws NoSuchFolderException {
4478                    DLFolder dlFolder = fetchByC_NotS_First(companyId, status,
4479                                    orderByComparator);
4480    
4481                    if (dlFolder != null) {
4482                            return dlFolder;
4483                    }
4484    
4485                    StringBundler msg = new StringBundler(6);
4486    
4487                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4488    
4489                    msg.append("companyId=");
4490                    msg.append(companyId);
4491    
4492                    msg.append(", status=");
4493                    msg.append(status);
4494    
4495                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4496    
4497                    throw new NoSuchFolderException(msg.toString());
4498            }
4499    
4500            /**
4501             * Returns the first document library folder in the ordered set where companyId = &#63; and status &ne; &#63;.
4502             *
4503             * @param companyId the company ID
4504             * @param status the status
4505             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4506             * @return the first matching document library folder, or <code>null</code> if a matching document library folder could not be found
4507             */
4508            @Override
4509            public DLFolder fetchByC_NotS_First(long companyId, int status,
4510                    OrderByComparator<DLFolder> orderByComparator) {
4511                    List<DLFolder> list = findByC_NotS(companyId, status, 0, 1,
4512                                    orderByComparator);
4513    
4514                    if (!list.isEmpty()) {
4515                            return list.get(0);
4516                    }
4517    
4518                    return null;
4519            }
4520    
4521            /**
4522             * Returns the last document library folder in the ordered set where companyId = &#63; and status &ne; &#63;.
4523             *
4524             * @param companyId the company ID
4525             * @param status the status
4526             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4527             * @return the last matching document library folder
4528             * @throws NoSuchFolderException if a matching document library folder could not be found
4529             */
4530            @Override
4531            public DLFolder findByC_NotS_Last(long companyId, int status,
4532                    OrderByComparator<DLFolder> orderByComparator)
4533                    throws NoSuchFolderException {
4534                    DLFolder dlFolder = fetchByC_NotS_Last(companyId, status,
4535                                    orderByComparator);
4536    
4537                    if (dlFolder != null) {
4538                            return dlFolder;
4539                    }
4540    
4541                    StringBundler msg = new StringBundler(6);
4542    
4543                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4544    
4545                    msg.append("companyId=");
4546                    msg.append(companyId);
4547    
4548                    msg.append(", status=");
4549                    msg.append(status);
4550    
4551                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4552    
4553                    throw new NoSuchFolderException(msg.toString());
4554            }
4555    
4556            /**
4557             * Returns the last document library folder in the ordered set where companyId = &#63; and status &ne; &#63;.
4558             *
4559             * @param companyId the company ID
4560             * @param status the status
4561             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4562             * @return the last matching document library folder, or <code>null</code> if a matching document library folder could not be found
4563             */
4564            @Override
4565            public DLFolder fetchByC_NotS_Last(long companyId, int status,
4566                    OrderByComparator<DLFolder> orderByComparator) {
4567                    int count = countByC_NotS(companyId, status);
4568    
4569                    if (count == 0) {
4570                            return null;
4571                    }
4572    
4573                    List<DLFolder> list = findByC_NotS(companyId, status, count - 1, count,
4574                                    orderByComparator);
4575    
4576                    if (!list.isEmpty()) {
4577                            return list.get(0);
4578                    }
4579    
4580                    return null;
4581            }
4582    
4583            /**
4584             * Returns the document library folders before and after the current document library folder in the ordered set where companyId = &#63; and status &ne; &#63;.
4585             *
4586             * @param folderId the primary key of the current document library folder
4587             * @param companyId the company ID
4588             * @param status the status
4589             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4590             * @return the previous, current, and next document library folder
4591             * @throws NoSuchFolderException if a document library folder with the primary key could not be found
4592             */
4593            @Override
4594            public DLFolder[] findByC_NotS_PrevAndNext(long folderId, long companyId,
4595                    int status, OrderByComparator<DLFolder> orderByComparator)
4596                    throws NoSuchFolderException {
4597                    DLFolder dlFolder = findByPrimaryKey(folderId);
4598    
4599                    Session session = null;
4600    
4601                    try {
4602                            session = openSession();
4603    
4604                            DLFolder[] array = new DLFolderImpl[3];
4605    
4606                            array[0] = getByC_NotS_PrevAndNext(session, dlFolder, companyId,
4607                                            status, orderByComparator, true);
4608    
4609                            array[1] = dlFolder;
4610    
4611                            array[2] = getByC_NotS_PrevAndNext(session, dlFolder, companyId,
4612                                            status, orderByComparator, false);
4613    
4614                            return array;
4615                    }
4616                    catch (Exception e) {
4617                            throw processException(e);
4618                    }
4619                    finally {
4620                            closeSession(session);
4621                    }
4622            }
4623    
4624            protected DLFolder getByC_NotS_PrevAndNext(Session session,
4625                    DLFolder dlFolder, long companyId, int status,
4626                    OrderByComparator<DLFolder> orderByComparator, boolean previous) {
4627                    StringBundler query = null;
4628    
4629                    if (orderByComparator != null) {
4630                            query = new StringBundler(5 +
4631                                            (orderByComparator.getOrderByConditionFields().length * 3) +
4632                                            (orderByComparator.getOrderByFields().length * 3));
4633                    }
4634                    else {
4635                            query = new StringBundler(4);
4636                    }
4637    
4638                    query.append(_SQL_SELECT_DLFOLDER_WHERE);
4639    
4640                    query.append(_FINDER_COLUMN_C_NOTS_COMPANYID_2);
4641    
4642                    query.append(_FINDER_COLUMN_C_NOTS_STATUS_2);
4643    
4644                    if (orderByComparator != null) {
4645                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4646    
4647                            if (orderByConditionFields.length > 0) {
4648                                    query.append(WHERE_AND);
4649                            }
4650    
4651                            for (int i = 0; i < orderByConditionFields.length; i++) {
4652                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4653                                    query.append(orderByConditionFields[i]);
4654    
4655                                    if ((i + 1) < orderByConditionFields.length) {
4656                                            if (orderByComparator.isAscending() ^ previous) {
4657                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4658                                            }
4659                                            else {
4660                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4661                                            }
4662                                    }
4663                                    else {
4664                                            if (orderByComparator.isAscending() ^ previous) {
4665                                                    query.append(WHERE_GREATER_THAN);
4666                                            }
4667                                            else {
4668                                                    query.append(WHERE_LESSER_THAN);
4669                                            }
4670                                    }
4671                            }
4672    
4673                            query.append(ORDER_BY_CLAUSE);
4674    
4675                            String[] orderByFields = orderByComparator.getOrderByFields();
4676    
4677                            for (int i = 0; i < orderByFields.length; i++) {
4678                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4679                                    query.append(orderByFields[i]);
4680    
4681                                    if ((i + 1) < orderByFields.length) {
4682                                            if (orderByComparator.isAscending() ^ previous) {
4683                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4684                                            }
4685                                            else {
4686                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4687                                            }
4688                                    }
4689                                    else {
4690                                            if (orderByComparator.isAscending() ^ previous) {
4691                                                    query.append(ORDER_BY_ASC);
4692                                            }
4693                                            else {
4694                                                    query.append(ORDER_BY_DESC);
4695                                            }
4696                                    }
4697                            }
4698                    }
4699                    else {
4700                            query.append(DLFolderModelImpl.ORDER_BY_JPQL);
4701                    }
4702    
4703                    String sql = query.toString();
4704    
4705                    Query q = session.createQuery(sql);
4706    
4707                    q.setFirstResult(0);
4708                    q.setMaxResults(2);
4709    
4710                    QueryPos qPos = QueryPos.getInstance(q);
4711    
4712                    qPos.add(companyId);
4713    
4714                    qPos.add(status);
4715    
4716                    if (orderByComparator != null) {
4717                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
4718    
4719                            for (Object value : values) {
4720                                    qPos.add(value);
4721                            }
4722                    }
4723    
4724                    List<DLFolder> list = q.list();
4725    
4726                    if (list.size() == 2) {
4727                            return list.get(1);
4728                    }
4729                    else {
4730                            return null;
4731                    }
4732            }
4733    
4734            /**
4735             * Removes all the document library folders where companyId = &#63; and status &ne; &#63; from the database.
4736             *
4737             * @param companyId the company ID
4738             * @param status the status
4739             */
4740            @Override
4741            public void removeByC_NotS(long companyId, int status) {
4742                    for (DLFolder dlFolder : findByC_NotS(companyId, status,
4743                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4744                            remove(dlFolder);
4745                    }
4746            }
4747    
4748            /**
4749             * Returns the number of document library folders where companyId = &#63; and status &ne; &#63;.
4750             *
4751             * @param companyId the company ID
4752             * @param status the status
4753             * @return the number of matching document library folders
4754             */
4755            @Override
4756            public int countByC_NotS(long companyId, int status) {
4757                    FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_NOTS;
4758    
4759                    Object[] finderArgs = new Object[] { companyId, status };
4760    
4761                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
4762    
4763                    if (count == null) {
4764                            StringBundler query = new StringBundler(3);
4765    
4766                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
4767    
4768                            query.append(_FINDER_COLUMN_C_NOTS_COMPANYID_2);
4769    
4770                            query.append(_FINDER_COLUMN_C_NOTS_STATUS_2);
4771    
4772                            String sql = query.toString();
4773    
4774                            Session session = null;
4775    
4776                            try {
4777                                    session = openSession();
4778    
4779                                    Query q = session.createQuery(sql);
4780    
4781                                    QueryPos qPos = QueryPos.getInstance(q);
4782    
4783                                    qPos.add(companyId);
4784    
4785                                    qPos.add(status);
4786    
4787                                    count = (Long)q.uniqueResult();
4788    
4789                                    finderCache.putResult(finderPath, finderArgs, count);
4790                            }
4791                            catch (Exception e) {
4792                                    finderCache.removeResult(finderPath, finderArgs);
4793    
4794                                    throw processException(e);
4795                            }
4796                            finally {
4797                                    closeSession(session);
4798                            }
4799                    }
4800    
4801                    return count.intValue();
4802            }
4803    
4804            private static final String _FINDER_COLUMN_C_NOTS_COMPANYID_2 = "dlFolder.companyId = ? AND ";
4805            private static final String _FINDER_COLUMN_C_NOTS_STATUS_2 = "dlFolder.status != ?";
4806            public static final FinderPath FINDER_PATH_FETCH_BY_R_M = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
4807                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
4808                            FINDER_CLASS_NAME_ENTITY, "fetchByR_M",
4809                            new String[] { Long.class.getName(), Boolean.class.getName() },
4810                            DLFolderModelImpl.REPOSITORYID_COLUMN_BITMASK |
4811                            DLFolderModelImpl.MOUNTPOINT_COLUMN_BITMASK);
4812            public static final FinderPath FINDER_PATH_COUNT_BY_R_M = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
4813                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
4814                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByR_M",
4815                            new String[] { Long.class.getName(), Boolean.class.getName() });
4816    
4817            /**
4818             * Returns the document library folder where repositoryId = &#63; and mountPoint = &#63; or throws a {@link NoSuchFolderException} if it could not be found.
4819             *
4820             * @param repositoryId the repository ID
4821             * @param mountPoint the mount point
4822             * @return the matching document library folder
4823             * @throws NoSuchFolderException if a matching document library folder could not be found
4824             */
4825            @Override
4826            public DLFolder findByR_M(long repositoryId, boolean mountPoint)
4827                    throws NoSuchFolderException {
4828                    DLFolder dlFolder = fetchByR_M(repositoryId, mountPoint);
4829    
4830                    if (dlFolder == null) {
4831                            StringBundler msg = new StringBundler(6);
4832    
4833                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4834    
4835                            msg.append("repositoryId=");
4836                            msg.append(repositoryId);
4837    
4838                            msg.append(", mountPoint=");
4839                            msg.append(mountPoint);
4840    
4841                            msg.append(StringPool.CLOSE_CURLY_BRACE);
4842    
4843                            if (_log.isWarnEnabled()) {
4844                                    _log.warn(msg.toString());
4845                            }
4846    
4847                            throw new NoSuchFolderException(msg.toString());
4848                    }
4849    
4850                    return dlFolder;
4851            }
4852    
4853            /**
4854             * Returns the document library folder where repositoryId = &#63; and mountPoint = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
4855             *
4856             * @param repositoryId the repository ID
4857             * @param mountPoint the mount point
4858             * @return the matching document library folder, or <code>null</code> if a matching document library folder could not be found
4859             */
4860            @Override
4861            public DLFolder fetchByR_M(long repositoryId, boolean mountPoint) {
4862                    return fetchByR_M(repositoryId, mountPoint, true);
4863            }
4864    
4865            /**
4866             * Returns the document library folder where repositoryId = &#63; and mountPoint = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
4867             *
4868             * @param repositoryId the repository ID
4869             * @param mountPoint the mount point
4870             * @param retrieveFromCache whether to retrieve from the finder cache
4871             * @return the matching document library folder, or <code>null</code> if a matching document library folder could not be found
4872             */
4873            @Override
4874            public DLFolder fetchByR_M(long repositoryId, boolean mountPoint,
4875                    boolean retrieveFromCache) {
4876                    Object[] finderArgs = new Object[] { repositoryId, mountPoint };
4877    
4878                    Object result = null;
4879    
4880                    if (retrieveFromCache) {
4881                            result = finderCache.getResult(FINDER_PATH_FETCH_BY_R_M,
4882                                            finderArgs, this);
4883                    }
4884    
4885                    if (result instanceof DLFolder) {
4886                            DLFolder dlFolder = (DLFolder)result;
4887    
4888                            if ((repositoryId != dlFolder.getRepositoryId()) ||
4889                                            (mountPoint != dlFolder.getMountPoint())) {
4890                                    result = null;
4891                            }
4892                    }
4893    
4894                    if (result == null) {
4895                            StringBundler query = new StringBundler(4);
4896    
4897                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
4898    
4899                            query.append(_FINDER_COLUMN_R_M_REPOSITORYID_2);
4900    
4901                            query.append(_FINDER_COLUMN_R_M_MOUNTPOINT_2);
4902    
4903                            String sql = query.toString();
4904    
4905                            Session session = null;
4906    
4907                            try {
4908                                    session = openSession();
4909    
4910                                    Query q = session.createQuery(sql);
4911    
4912                                    QueryPos qPos = QueryPos.getInstance(q);
4913    
4914                                    qPos.add(repositoryId);
4915    
4916                                    qPos.add(mountPoint);
4917    
4918                                    List<DLFolder> list = q.list();
4919    
4920                                    if (list.isEmpty()) {
4921                                            finderCache.putResult(FINDER_PATH_FETCH_BY_R_M, finderArgs,
4922                                                    list);
4923                                    }
4924                                    else {
4925                                            if ((list.size() > 1) && _log.isWarnEnabled()) {
4926                                                    _log.warn(
4927                                                            "DLFolderPersistenceImpl.fetchByR_M(long, boolean, boolean) with parameters (" +
4928                                                            StringUtil.merge(finderArgs) +
4929                                                            ") yields a result set with more than 1 result. This violates the logical unique restriction. There is no order guarantee on which result is returned by this finder.");
4930                                            }
4931    
4932                                            DLFolder dlFolder = list.get(0);
4933    
4934                                            result = dlFolder;
4935    
4936                                            cacheResult(dlFolder);
4937    
4938                                            if ((dlFolder.getRepositoryId() != repositoryId) ||
4939                                                            (dlFolder.getMountPoint() != mountPoint)) {
4940                                                    finderCache.putResult(FINDER_PATH_FETCH_BY_R_M,
4941                                                            finderArgs, dlFolder);
4942                                            }
4943                                    }
4944                            }
4945                            catch (Exception e) {
4946                                    finderCache.removeResult(FINDER_PATH_FETCH_BY_R_M, finderArgs);
4947    
4948                                    throw processException(e);
4949                            }
4950                            finally {
4951                                    closeSession(session);
4952                            }
4953                    }
4954    
4955                    if (result instanceof List<?>) {
4956                            return null;
4957                    }
4958                    else {
4959                            return (DLFolder)result;
4960                    }
4961            }
4962    
4963            /**
4964             * Removes the document library folder where repositoryId = &#63; and mountPoint = &#63; from the database.
4965             *
4966             * @param repositoryId the repository ID
4967             * @param mountPoint the mount point
4968             * @return the document library folder that was removed
4969             */
4970            @Override
4971            public DLFolder removeByR_M(long repositoryId, boolean mountPoint)
4972                    throws NoSuchFolderException {
4973                    DLFolder dlFolder = findByR_M(repositoryId, mountPoint);
4974    
4975                    return remove(dlFolder);
4976            }
4977    
4978            /**
4979             * Returns the number of document library folders where repositoryId = &#63; and mountPoint = &#63;.
4980             *
4981             * @param repositoryId the repository ID
4982             * @param mountPoint the mount point
4983             * @return the number of matching document library folders
4984             */
4985            @Override
4986            public int countByR_M(long repositoryId, boolean mountPoint) {
4987                    FinderPath finderPath = FINDER_PATH_COUNT_BY_R_M;
4988    
4989                    Object[] finderArgs = new Object[] { repositoryId, mountPoint };
4990    
4991                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
4992    
4993                    if (count == null) {
4994                            StringBundler query = new StringBundler(3);
4995    
4996                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
4997    
4998                            query.append(_FINDER_COLUMN_R_M_REPOSITORYID_2);
4999    
5000                            query.append(_FINDER_COLUMN_R_M_MOUNTPOINT_2);
5001    
5002                            String sql = query.toString();
5003    
5004                            Session session = null;
5005    
5006                            try {
5007                                    session = openSession();
5008    
5009                                    Query q = session.createQuery(sql);
5010    
5011                                    QueryPos qPos = QueryPos.getInstance(q);
5012    
5013                                    qPos.add(repositoryId);
5014    
5015                                    qPos.add(mountPoint);
5016    
5017                                    count = (Long)q.uniqueResult();
5018    
5019                                    finderCache.putResult(finderPath, finderArgs, count);
5020                            }
5021                            catch (Exception e) {
5022                                    finderCache.removeResult(finderPath, finderArgs);
5023    
5024                                    throw processException(e);
5025                            }
5026                            finally {
5027                                    closeSession(session);
5028                            }
5029                    }
5030    
5031                    return count.intValue();
5032            }
5033    
5034            private static final String _FINDER_COLUMN_R_M_REPOSITORYID_2 = "dlFolder.repositoryId = ? AND ";
5035            private static final String _FINDER_COLUMN_R_M_MOUNTPOINT_2 = "dlFolder.mountPoint = ?";
5036            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_R_P = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
5037                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
5038                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByR_P",
5039                            new String[] {
5040                                    Long.class.getName(), Long.class.getName(),
5041                                    
5042                            Integer.class.getName(), Integer.class.getName(),
5043                                    OrderByComparator.class.getName()
5044                            });
5045            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_P = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
5046                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
5047                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByR_P",
5048                            new String[] { Long.class.getName(), Long.class.getName() },
5049                            DLFolderModelImpl.REPOSITORYID_COLUMN_BITMASK |
5050                            DLFolderModelImpl.PARENTFOLDERID_COLUMN_BITMASK |
5051                            DLFolderModelImpl.NAME_COLUMN_BITMASK);
5052            public static final FinderPath FINDER_PATH_COUNT_BY_R_P = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
5053                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
5054                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByR_P",
5055                            new String[] { Long.class.getName(), Long.class.getName() });
5056    
5057            /**
5058             * Returns all the document library folders where repositoryId = &#63; and parentFolderId = &#63;.
5059             *
5060             * @param repositoryId the repository ID
5061             * @param parentFolderId the parent folder ID
5062             * @return the matching document library folders
5063             */
5064            @Override
5065            public List<DLFolder> findByR_P(long repositoryId, long parentFolderId) {
5066                    return findByR_P(repositoryId, parentFolderId, QueryUtil.ALL_POS,
5067                            QueryUtil.ALL_POS, null);
5068            }
5069    
5070            /**
5071             * Returns a range of all the document library folders where repositoryId = &#63; and parentFolderId = &#63;.
5072             *
5073             * <p>
5074             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5075             * </p>
5076             *
5077             * @param repositoryId the repository ID
5078             * @param parentFolderId the parent folder ID
5079             * @param start the lower bound of the range of document library folders
5080             * @param end the upper bound of the range of document library folders (not inclusive)
5081             * @return the range of matching document library folders
5082             */
5083            @Override
5084            public List<DLFolder> findByR_P(long repositoryId, long parentFolderId,
5085                    int start, int end) {
5086                    return findByR_P(repositoryId, parentFolderId, start, end, null);
5087            }
5088    
5089            /**
5090             * Returns an ordered range of all the document library folders where repositoryId = &#63; and parentFolderId = &#63;.
5091             *
5092             * <p>
5093             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5094             * </p>
5095             *
5096             * @param repositoryId the repository ID
5097             * @param parentFolderId the parent folder ID
5098             * @param start the lower bound of the range of document library folders
5099             * @param end the upper bound of the range of document library folders (not inclusive)
5100             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5101             * @return the ordered range of matching document library folders
5102             */
5103            @Override
5104            public List<DLFolder> findByR_P(long repositoryId, long parentFolderId,
5105                    int start, int end, OrderByComparator<DLFolder> orderByComparator) {
5106                    return findByR_P(repositoryId, parentFolderId, start, end,
5107                            orderByComparator, true);
5108            }
5109    
5110            /**
5111             * Returns an ordered range of all the document library folders where repositoryId = &#63; and parentFolderId = &#63;.
5112             *
5113             * <p>
5114             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5115             * </p>
5116             *
5117             * @param repositoryId the repository ID
5118             * @param parentFolderId the parent folder ID
5119             * @param start the lower bound of the range of document library folders
5120             * @param end the upper bound of the range of document library folders (not inclusive)
5121             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5122             * @param retrieveFromCache whether to retrieve from the finder cache
5123             * @return the ordered range of matching document library folders
5124             */
5125            @Override
5126            public List<DLFolder> findByR_P(long repositoryId, long parentFolderId,
5127                    int start, int end, OrderByComparator<DLFolder> orderByComparator,
5128                    boolean retrieveFromCache) {
5129                    boolean pagination = true;
5130                    FinderPath finderPath = null;
5131                    Object[] finderArgs = null;
5132    
5133                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5134                                    (orderByComparator == null)) {
5135                            pagination = false;
5136                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_P;
5137                            finderArgs = new Object[] { repositoryId, parentFolderId };
5138                    }
5139                    else {
5140                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_R_P;
5141                            finderArgs = new Object[] {
5142                                            repositoryId, parentFolderId,
5143                                            
5144                                            start, end, orderByComparator
5145                                    };
5146                    }
5147    
5148                    List<DLFolder> list = null;
5149    
5150                    if (retrieveFromCache) {
5151                            list = (List<DLFolder>)finderCache.getResult(finderPath,
5152                                            finderArgs, this);
5153    
5154                            if ((list != null) && !list.isEmpty()) {
5155                                    for (DLFolder dlFolder : list) {
5156                                            if ((repositoryId != dlFolder.getRepositoryId()) ||
5157                                                            (parentFolderId != dlFolder.getParentFolderId())) {
5158                                                    list = null;
5159    
5160                                                    break;
5161                                            }
5162                                    }
5163                            }
5164                    }
5165    
5166                    if (list == null) {
5167                            StringBundler query = null;
5168    
5169                            if (orderByComparator != null) {
5170                                    query = new StringBundler(4 +
5171                                                    (orderByComparator.getOrderByFields().length * 2));
5172                            }
5173                            else {
5174                                    query = new StringBundler(4);
5175                            }
5176    
5177                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
5178    
5179                            query.append(_FINDER_COLUMN_R_P_REPOSITORYID_2);
5180    
5181                            query.append(_FINDER_COLUMN_R_P_PARENTFOLDERID_2);
5182    
5183                            if (orderByComparator != null) {
5184                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5185                                            orderByComparator);
5186                            }
5187                            else
5188                             if (pagination) {
5189                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
5190                            }
5191    
5192                            String sql = query.toString();
5193    
5194                            Session session = null;
5195    
5196                            try {
5197                                    session = openSession();
5198    
5199                                    Query q = session.createQuery(sql);
5200    
5201                                    QueryPos qPos = QueryPos.getInstance(q);
5202    
5203                                    qPos.add(repositoryId);
5204    
5205                                    qPos.add(parentFolderId);
5206    
5207                                    if (!pagination) {
5208                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
5209                                                            start, end, false);
5210    
5211                                            Collections.sort(list);
5212    
5213                                            list = Collections.unmodifiableList(list);
5214                                    }
5215                                    else {
5216                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
5217                                                            start, end);
5218                                    }
5219    
5220                                    cacheResult(list);
5221    
5222                                    finderCache.putResult(finderPath, finderArgs, list);
5223                            }
5224                            catch (Exception e) {
5225                                    finderCache.removeResult(finderPath, finderArgs);
5226    
5227                                    throw processException(e);
5228                            }
5229                            finally {
5230                                    closeSession(session);
5231                            }
5232                    }
5233    
5234                    return list;
5235            }
5236    
5237            /**
5238             * Returns the first document library folder in the ordered set where repositoryId = &#63; and parentFolderId = &#63;.
5239             *
5240             * @param repositoryId the repository ID
5241             * @param parentFolderId the parent folder ID
5242             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5243             * @return the first matching document library folder
5244             * @throws NoSuchFolderException if a matching document library folder could not be found
5245             */
5246            @Override
5247            public DLFolder findByR_P_First(long repositoryId, long parentFolderId,
5248                    OrderByComparator<DLFolder> orderByComparator)
5249                    throws NoSuchFolderException {
5250                    DLFolder dlFolder = fetchByR_P_First(repositoryId, parentFolderId,
5251                                    orderByComparator);
5252    
5253                    if (dlFolder != null) {
5254                            return dlFolder;
5255                    }
5256    
5257                    StringBundler msg = new StringBundler(6);
5258    
5259                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5260    
5261                    msg.append("repositoryId=");
5262                    msg.append(repositoryId);
5263    
5264                    msg.append(", parentFolderId=");
5265                    msg.append(parentFolderId);
5266    
5267                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5268    
5269                    throw new NoSuchFolderException(msg.toString());
5270            }
5271    
5272            /**
5273             * Returns the first document library folder in the ordered set where repositoryId = &#63; and parentFolderId = &#63;.
5274             *
5275             * @param repositoryId the repository ID
5276             * @param parentFolderId the parent folder ID
5277             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5278             * @return the first matching document library folder, or <code>null</code> if a matching document library folder could not be found
5279             */
5280            @Override
5281            public DLFolder fetchByR_P_First(long repositoryId, long parentFolderId,
5282                    OrderByComparator<DLFolder> orderByComparator) {
5283                    List<DLFolder> list = findByR_P(repositoryId, parentFolderId, 0, 1,
5284                                    orderByComparator);
5285    
5286                    if (!list.isEmpty()) {
5287                            return list.get(0);
5288                    }
5289    
5290                    return null;
5291            }
5292    
5293            /**
5294             * Returns the last document library folder in the ordered set where repositoryId = &#63; and parentFolderId = &#63;.
5295             *
5296             * @param repositoryId the repository ID
5297             * @param parentFolderId the parent folder ID
5298             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5299             * @return the last matching document library folder
5300             * @throws NoSuchFolderException if a matching document library folder could not be found
5301             */
5302            @Override
5303            public DLFolder findByR_P_Last(long repositoryId, long parentFolderId,
5304                    OrderByComparator<DLFolder> orderByComparator)
5305                    throws NoSuchFolderException {
5306                    DLFolder dlFolder = fetchByR_P_Last(repositoryId, parentFolderId,
5307                                    orderByComparator);
5308    
5309                    if (dlFolder != null) {
5310                            return dlFolder;
5311                    }
5312    
5313                    StringBundler msg = new StringBundler(6);
5314    
5315                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5316    
5317                    msg.append("repositoryId=");
5318                    msg.append(repositoryId);
5319    
5320                    msg.append(", parentFolderId=");
5321                    msg.append(parentFolderId);
5322    
5323                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5324    
5325                    throw new NoSuchFolderException(msg.toString());
5326            }
5327    
5328            /**
5329             * Returns the last document library folder in the ordered set where repositoryId = &#63; and parentFolderId = &#63;.
5330             *
5331             * @param repositoryId the repository ID
5332             * @param parentFolderId the parent folder ID
5333             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5334             * @return the last matching document library folder, or <code>null</code> if a matching document library folder could not be found
5335             */
5336            @Override
5337            public DLFolder fetchByR_P_Last(long repositoryId, long parentFolderId,
5338                    OrderByComparator<DLFolder> orderByComparator) {
5339                    int count = countByR_P(repositoryId, parentFolderId);
5340    
5341                    if (count == 0) {
5342                            return null;
5343                    }
5344    
5345                    List<DLFolder> list = findByR_P(repositoryId, parentFolderId,
5346                                    count - 1, count, orderByComparator);
5347    
5348                    if (!list.isEmpty()) {
5349                            return list.get(0);
5350                    }
5351    
5352                    return null;
5353            }
5354    
5355            /**
5356             * Returns the document library folders before and after the current document library folder in the ordered set where repositoryId = &#63; and parentFolderId = &#63;.
5357             *
5358             * @param folderId the primary key of the current document library folder
5359             * @param repositoryId the repository ID
5360             * @param parentFolderId the parent folder ID
5361             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5362             * @return the previous, current, and next document library folder
5363             * @throws NoSuchFolderException if a document library folder with the primary key could not be found
5364             */
5365            @Override
5366            public DLFolder[] findByR_P_PrevAndNext(long folderId, long repositoryId,
5367                    long parentFolderId, OrderByComparator<DLFolder> orderByComparator)
5368                    throws NoSuchFolderException {
5369                    DLFolder dlFolder = findByPrimaryKey(folderId);
5370    
5371                    Session session = null;
5372    
5373                    try {
5374                            session = openSession();
5375    
5376                            DLFolder[] array = new DLFolderImpl[3];
5377    
5378                            array[0] = getByR_P_PrevAndNext(session, dlFolder, repositoryId,
5379                                            parentFolderId, orderByComparator, true);
5380    
5381                            array[1] = dlFolder;
5382    
5383                            array[2] = getByR_P_PrevAndNext(session, dlFolder, repositoryId,
5384                                            parentFolderId, orderByComparator, false);
5385    
5386                            return array;
5387                    }
5388                    catch (Exception e) {
5389                            throw processException(e);
5390                    }
5391                    finally {
5392                            closeSession(session);
5393                    }
5394            }
5395    
5396            protected DLFolder getByR_P_PrevAndNext(Session session, DLFolder dlFolder,
5397                    long repositoryId, long parentFolderId,
5398                    OrderByComparator<DLFolder> orderByComparator, boolean previous) {
5399                    StringBundler query = null;
5400    
5401                    if (orderByComparator != null) {
5402                            query = new StringBundler(5 +
5403                                            (orderByComparator.getOrderByConditionFields().length * 3) +
5404                                            (orderByComparator.getOrderByFields().length * 3));
5405                    }
5406                    else {
5407                            query = new StringBundler(4);
5408                    }
5409    
5410                    query.append(_SQL_SELECT_DLFOLDER_WHERE);
5411    
5412                    query.append(_FINDER_COLUMN_R_P_REPOSITORYID_2);
5413    
5414                    query.append(_FINDER_COLUMN_R_P_PARENTFOLDERID_2);
5415    
5416                    if (orderByComparator != null) {
5417                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5418    
5419                            if (orderByConditionFields.length > 0) {
5420                                    query.append(WHERE_AND);
5421                            }
5422    
5423                            for (int i = 0; i < orderByConditionFields.length; i++) {
5424                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5425                                    query.append(orderByConditionFields[i]);
5426    
5427                                    if ((i + 1) < orderByConditionFields.length) {
5428                                            if (orderByComparator.isAscending() ^ previous) {
5429                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5430                                            }
5431                                            else {
5432                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5433                                            }
5434                                    }
5435                                    else {
5436                                            if (orderByComparator.isAscending() ^ previous) {
5437                                                    query.append(WHERE_GREATER_THAN);
5438                                            }
5439                                            else {
5440                                                    query.append(WHERE_LESSER_THAN);
5441                                            }
5442                                    }
5443                            }
5444    
5445                            query.append(ORDER_BY_CLAUSE);
5446    
5447                            String[] orderByFields = orderByComparator.getOrderByFields();
5448    
5449                            for (int i = 0; i < orderByFields.length; i++) {
5450                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5451                                    query.append(orderByFields[i]);
5452    
5453                                    if ((i + 1) < orderByFields.length) {
5454                                            if (orderByComparator.isAscending() ^ previous) {
5455                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5456                                            }
5457                                            else {
5458                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5459                                            }
5460                                    }
5461                                    else {
5462                                            if (orderByComparator.isAscending() ^ previous) {
5463                                                    query.append(ORDER_BY_ASC);
5464                                            }
5465                                            else {
5466                                                    query.append(ORDER_BY_DESC);
5467                                            }
5468                                    }
5469                            }
5470                    }
5471                    else {
5472                            query.append(DLFolderModelImpl.ORDER_BY_JPQL);
5473                    }
5474    
5475                    String sql = query.toString();
5476    
5477                    Query q = session.createQuery(sql);
5478    
5479                    q.setFirstResult(0);
5480                    q.setMaxResults(2);
5481    
5482                    QueryPos qPos = QueryPos.getInstance(q);
5483    
5484                    qPos.add(repositoryId);
5485    
5486                    qPos.add(parentFolderId);
5487    
5488                    if (orderByComparator != null) {
5489                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
5490    
5491                            for (Object value : values) {
5492                                    qPos.add(value);
5493                            }
5494                    }
5495    
5496                    List<DLFolder> list = q.list();
5497    
5498                    if (list.size() == 2) {
5499                            return list.get(1);
5500                    }
5501                    else {
5502                            return null;
5503                    }
5504            }
5505    
5506            /**
5507             * Removes all the document library folders where repositoryId = &#63; and parentFolderId = &#63; from the database.
5508             *
5509             * @param repositoryId the repository ID
5510             * @param parentFolderId the parent folder ID
5511             */
5512            @Override
5513            public void removeByR_P(long repositoryId, long parentFolderId) {
5514                    for (DLFolder dlFolder : findByR_P(repositoryId, parentFolderId,
5515                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
5516                            remove(dlFolder);
5517                    }
5518            }
5519    
5520            /**
5521             * Returns the number of document library folders where repositoryId = &#63; and parentFolderId = &#63;.
5522             *
5523             * @param repositoryId the repository ID
5524             * @param parentFolderId the parent folder ID
5525             * @return the number of matching document library folders
5526             */
5527            @Override
5528            public int countByR_P(long repositoryId, long parentFolderId) {
5529                    FinderPath finderPath = FINDER_PATH_COUNT_BY_R_P;
5530    
5531                    Object[] finderArgs = new Object[] { repositoryId, parentFolderId };
5532    
5533                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
5534    
5535                    if (count == null) {
5536                            StringBundler query = new StringBundler(3);
5537    
5538                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
5539    
5540                            query.append(_FINDER_COLUMN_R_P_REPOSITORYID_2);
5541    
5542                            query.append(_FINDER_COLUMN_R_P_PARENTFOLDERID_2);
5543    
5544                            String sql = query.toString();
5545    
5546                            Session session = null;
5547    
5548                            try {
5549                                    session = openSession();
5550    
5551                                    Query q = session.createQuery(sql);
5552    
5553                                    QueryPos qPos = QueryPos.getInstance(q);
5554    
5555                                    qPos.add(repositoryId);
5556    
5557                                    qPos.add(parentFolderId);
5558    
5559                                    count = (Long)q.uniqueResult();
5560    
5561                                    finderCache.putResult(finderPath, finderArgs, count);
5562                            }
5563                            catch (Exception e) {
5564                                    finderCache.removeResult(finderPath, finderArgs);
5565    
5566                                    throw processException(e);
5567                            }
5568                            finally {
5569                                    closeSession(session);
5570                            }
5571                    }
5572    
5573                    return count.intValue();
5574            }
5575    
5576            private static final String _FINDER_COLUMN_R_P_REPOSITORYID_2 = "dlFolder.repositoryId = ? AND ";
5577            private static final String _FINDER_COLUMN_R_P_PARENTFOLDERID_2 = "dlFolder.parentFolderId = ?";
5578            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_P_N = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
5579                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
5580                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByP_N",
5581                            new String[] {
5582                                    Long.class.getName(), String.class.getName(),
5583                                    
5584                            Integer.class.getName(), Integer.class.getName(),
5585                                    OrderByComparator.class.getName()
5586                            });
5587            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_N = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
5588                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
5589                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByP_N",
5590                            new String[] { Long.class.getName(), String.class.getName() },
5591                            DLFolderModelImpl.PARENTFOLDERID_COLUMN_BITMASK |
5592                            DLFolderModelImpl.NAME_COLUMN_BITMASK);
5593            public static final FinderPath FINDER_PATH_COUNT_BY_P_N = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
5594                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
5595                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByP_N",
5596                            new String[] { Long.class.getName(), String.class.getName() });
5597    
5598            /**
5599             * Returns all the document library folders where parentFolderId = &#63; and name = &#63;.
5600             *
5601             * @param parentFolderId the parent folder ID
5602             * @param name the name
5603             * @return the matching document library folders
5604             */
5605            @Override
5606            public List<DLFolder> findByP_N(long parentFolderId, String name) {
5607                    return findByP_N(parentFolderId, name, QueryUtil.ALL_POS,
5608                            QueryUtil.ALL_POS, null);
5609            }
5610    
5611            /**
5612             * Returns a range of all the document library folders where parentFolderId = &#63; and name = &#63;.
5613             *
5614             * <p>
5615             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5616             * </p>
5617             *
5618             * @param parentFolderId the parent folder ID
5619             * @param name the name
5620             * @param start the lower bound of the range of document library folders
5621             * @param end the upper bound of the range of document library folders (not inclusive)
5622             * @return the range of matching document library folders
5623             */
5624            @Override
5625            public List<DLFolder> findByP_N(long parentFolderId, String name,
5626                    int start, int end) {
5627                    return findByP_N(parentFolderId, name, start, end, null);
5628            }
5629    
5630            /**
5631             * Returns an ordered range of all the document library folders where parentFolderId = &#63; and name = &#63;.
5632             *
5633             * <p>
5634             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5635             * </p>
5636             *
5637             * @param parentFolderId the parent folder ID
5638             * @param name the name
5639             * @param start the lower bound of the range of document library folders
5640             * @param end the upper bound of the range of document library folders (not inclusive)
5641             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5642             * @return the ordered range of matching document library folders
5643             */
5644            @Override
5645            public List<DLFolder> findByP_N(long parentFolderId, String name,
5646                    int start, int end, OrderByComparator<DLFolder> orderByComparator) {
5647                    return findByP_N(parentFolderId, name, start, end, orderByComparator,
5648                            true);
5649            }
5650    
5651            /**
5652             * Returns an ordered range of all the document library folders where parentFolderId = &#63; and name = &#63;.
5653             *
5654             * <p>
5655             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5656             * </p>
5657             *
5658             * @param parentFolderId the parent folder ID
5659             * @param name the name
5660             * @param start the lower bound of the range of document library folders
5661             * @param end the upper bound of the range of document library folders (not inclusive)
5662             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5663             * @param retrieveFromCache whether to retrieve from the finder cache
5664             * @return the ordered range of matching document library folders
5665             */
5666            @Override
5667            public List<DLFolder> findByP_N(long parentFolderId, String name,
5668                    int start, int end, OrderByComparator<DLFolder> orderByComparator,
5669                    boolean retrieveFromCache) {
5670                    boolean pagination = true;
5671                    FinderPath finderPath = null;
5672                    Object[] finderArgs = null;
5673    
5674                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5675                                    (orderByComparator == null)) {
5676                            pagination = false;
5677                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_N;
5678                            finderArgs = new Object[] { parentFolderId, name };
5679                    }
5680                    else {
5681                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_P_N;
5682                            finderArgs = new Object[] {
5683                                            parentFolderId, name,
5684                                            
5685                                            start, end, orderByComparator
5686                                    };
5687                    }
5688    
5689                    List<DLFolder> list = null;
5690    
5691                    if (retrieveFromCache) {
5692                            list = (List<DLFolder>)finderCache.getResult(finderPath,
5693                                            finderArgs, this);
5694    
5695                            if ((list != null) && !list.isEmpty()) {
5696                                    for (DLFolder dlFolder : list) {
5697                                            if ((parentFolderId != dlFolder.getParentFolderId()) ||
5698                                                            !Validator.equals(name, dlFolder.getName())) {
5699                                                    list = null;
5700    
5701                                                    break;
5702                                            }
5703                                    }
5704                            }
5705                    }
5706    
5707                    if (list == null) {
5708                            StringBundler query = null;
5709    
5710                            if (orderByComparator != null) {
5711                                    query = new StringBundler(4 +
5712                                                    (orderByComparator.getOrderByFields().length * 2));
5713                            }
5714                            else {
5715                                    query = new StringBundler(4);
5716                            }
5717    
5718                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
5719    
5720                            query.append(_FINDER_COLUMN_P_N_PARENTFOLDERID_2);
5721    
5722                            boolean bindName = false;
5723    
5724                            if (name == null) {
5725                                    query.append(_FINDER_COLUMN_P_N_NAME_1);
5726                            }
5727                            else if (name.equals(StringPool.BLANK)) {
5728                                    query.append(_FINDER_COLUMN_P_N_NAME_3);
5729                            }
5730                            else {
5731                                    bindName = true;
5732    
5733                                    query.append(_FINDER_COLUMN_P_N_NAME_2);
5734                            }
5735    
5736                            if (orderByComparator != null) {
5737                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5738                                            orderByComparator);
5739                            }
5740                            else
5741                             if (pagination) {
5742                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
5743                            }
5744    
5745                            String sql = query.toString();
5746    
5747                            Session session = null;
5748    
5749                            try {
5750                                    session = openSession();
5751    
5752                                    Query q = session.createQuery(sql);
5753    
5754                                    QueryPos qPos = QueryPos.getInstance(q);
5755    
5756                                    qPos.add(parentFolderId);
5757    
5758                                    if (bindName) {
5759                                            qPos.add(name);
5760                                    }
5761    
5762                                    if (!pagination) {
5763                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
5764                                                            start, end, false);
5765    
5766                                            Collections.sort(list);
5767    
5768                                            list = Collections.unmodifiableList(list);
5769                                    }
5770                                    else {
5771                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
5772                                                            start, end);
5773                                    }
5774    
5775                                    cacheResult(list);
5776    
5777                                    finderCache.putResult(finderPath, finderArgs, list);
5778                            }
5779                            catch (Exception e) {
5780                                    finderCache.removeResult(finderPath, finderArgs);
5781    
5782                                    throw processException(e);
5783                            }
5784                            finally {
5785                                    closeSession(session);
5786                            }
5787                    }
5788    
5789                    return list;
5790            }
5791    
5792            /**
5793             * Returns the first document library folder in the ordered set where parentFolderId = &#63; and name = &#63;.
5794             *
5795             * @param parentFolderId the parent folder ID
5796             * @param name the name
5797             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5798             * @return the first matching document library folder
5799             * @throws NoSuchFolderException if a matching document library folder could not be found
5800             */
5801            @Override
5802            public DLFolder findByP_N_First(long parentFolderId, String name,
5803                    OrderByComparator<DLFolder> orderByComparator)
5804                    throws NoSuchFolderException {
5805                    DLFolder dlFolder = fetchByP_N_First(parentFolderId, name,
5806                                    orderByComparator);
5807    
5808                    if (dlFolder != null) {
5809                            return dlFolder;
5810                    }
5811    
5812                    StringBundler msg = new StringBundler(6);
5813    
5814                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5815    
5816                    msg.append("parentFolderId=");
5817                    msg.append(parentFolderId);
5818    
5819                    msg.append(", name=");
5820                    msg.append(name);
5821    
5822                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5823    
5824                    throw new NoSuchFolderException(msg.toString());
5825            }
5826    
5827            /**
5828             * Returns the first document library folder in the ordered set where parentFolderId = &#63; and name = &#63;.
5829             *
5830             * @param parentFolderId the parent folder ID
5831             * @param name the name
5832             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5833             * @return the first matching document library folder, or <code>null</code> if a matching document library folder could not be found
5834             */
5835            @Override
5836            public DLFolder fetchByP_N_First(long parentFolderId, String name,
5837                    OrderByComparator<DLFolder> orderByComparator) {
5838                    List<DLFolder> list = findByP_N(parentFolderId, name, 0, 1,
5839                                    orderByComparator);
5840    
5841                    if (!list.isEmpty()) {
5842                            return list.get(0);
5843                    }
5844    
5845                    return null;
5846            }
5847    
5848            /**
5849             * Returns the last document library folder in the ordered set where parentFolderId = &#63; and name = &#63;.
5850             *
5851             * @param parentFolderId the parent folder ID
5852             * @param name the name
5853             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5854             * @return the last matching document library folder
5855             * @throws NoSuchFolderException if a matching document library folder could not be found
5856             */
5857            @Override
5858            public DLFolder findByP_N_Last(long parentFolderId, String name,
5859                    OrderByComparator<DLFolder> orderByComparator)
5860                    throws NoSuchFolderException {
5861                    DLFolder dlFolder = fetchByP_N_Last(parentFolderId, name,
5862                                    orderByComparator);
5863    
5864                    if (dlFolder != null) {
5865                            return dlFolder;
5866                    }
5867    
5868                    StringBundler msg = new StringBundler(6);
5869    
5870                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5871    
5872                    msg.append("parentFolderId=");
5873                    msg.append(parentFolderId);
5874    
5875                    msg.append(", name=");
5876                    msg.append(name);
5877    
5878                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5879    
5880                    throw new NoSuchFolderException(msg.toString());
5881            }
5882    
5883            /**
5884             * Returns the last document library folder in the ordered set where parentFolderId = &#63; and name = &#63;.
5885             *
5886             * @param parentFolderId the parent folder ID
5887             * @param name the name
5888             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5889             * @return the last matching document library folder, or <code>null</code> if a matching document library folder could not be found
5890             */
5891            @Override
5892            public DLFolder fetchByP_N_Last(long parentFolderId, String name,
5893                    OrderByComparator<DLFolder> orderByComparator) {
5894                    int count = countByP_N(parentFolderId, name);
5895    
5896                    if (count == 0) {
5897                            return null;
5898                    }
5899    
5900                    List<DLFolder> list = findByP_N(parentFolderId, name, count - 1, count,
5901                                    orderByComparator);
5902    
5903                    if (!list.isEmpty()) {
5904                            return list.get(0);
5905                    }
5906    
5907                    return null;
5908            }
5909    
5910            /**
5911             * Returns the document library folders before and after the current document library folder in the ordered set where parentFolderId = &#63; and name = &#63;.
5912             *
5913             * @param folderId the primary key of the current document library folder
5914             * @param parentFolderId the parent folder ID
5915             * @param name the name
5916             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5917             * @return the previous, current, and next document library folder
5918             * @throws NoSuchFolderException if a document library folder with the primary key could not be found
5919             */
5920            @Override
5921            public DLFolder[] findByP_N_PrevAndNext(long folderId, long parentFolderId,
5922                    String name, OrderByComparator<DLFolder> orderByComparator)
5923                    throws NoSuchFolderException {
5924                    DLFolder dlFolder = findByPrimaryKey(folderId);
5925    
5926                    Session session = null;
5927    
5928                    try {
5929                            session = openSession();
5930    
5931                            DLFolder[] array = new DLFolderImpl[3];
5932    
5933                            array[0] = getByP_N_PrevAndNext(session, dlFolder, parentFolderId,
5934                                            name, orderByComparator, true);
5935    
5936                            array[1] = dlFolder;
5937    
5938                            array[2] = getByP_N_PrevAndNext(session, dlFolder, parentFolderId,
5939                                            name, orderByComparator, false);
5940    
5941                            return array;
5942                    }
5943                    catch (Exception e) {
5944                            throw processException(e);
5945                    }
5946                    finally {
5947                            closeSession(session);
5948                    }
5949            }
5950    
5951            protected DLFolder getByP_N_PrevAndNext(Session session, DLFolder dlFolder,
5952                    long parentFolderId, String name,
5953                    OrderByComparator<DLFolder> orderByComparator, boolean previous) {
5954                    StringBundler query = null;
5955    
5956                    if (orderByComparator != null) {
5957                            query = new StringBundler(5 +
5958                                            (orderByComparator.getOrderByConditionFields().length * 3) +
5959                                            (orderByComparator.getOrderByFields().length * 3));
5960                    }
5961                    else {
5962                            query = new StringBundler(4);
5963                    }
5964    
5965                    query.append(_SQL_SELECT_DLFOLDER_WHERE);
5966    
5967                    query.append(_FINDER_COLUMN_P_N_PARENTFOLDERID_2);
5968    
5969                    boolean bindName = false;
5970    
5971                    if (name == null) {
5972                            query.append(_FINDER_COLUMN_P_N_NAME_1);
5973                    }
5974                    else if (name.equals(StringPool.BLANK)) {
5975                            query.append(_FINDER_COLUMN_P_N_NAME_3);
5976                    }
5977                    else {
5978                            bindName = true;
5979    
5980                            query.append(_FINDER_COLUMN_P_N_NAME_2);
5981                    }
5982    
5983                    if (orderByComparator != null) {
5984                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5985    
5986                            if (orderByConditionFields.length > 0) {
5987                                    query.append(WHERE_AND);
5988                            }
5989    
5990                            for (int i = 0; i < orderByConditionFields.length; i++) {
5991                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5992                                    query.append(orderByConditionFields[i]);
5993    
5994                                    if ((i + 1) < orderByConditionFields.length) {
5995                                            if (orderByComparator.isAscending() ^ previous) {
5996                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5997                                            }
5998                                            else {
5999                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6000                                            }
6001                                    }
6002                                    else {
6003                                            if (orderByComparator.isAscending() ^ previous) {
6004                                                    query.append(WHERE_GREATER_THAN);
6005                                            }
6006                                            else {
6007                                                    query.append(WHERE_LESSER_THAN);
6008                                            }
6009                                    }
6010                            }
6011    
6012                            query.append(ORDER_BY_CLAUSE);
6013    
6014                            String[] orderByFields = orderByComparator.getOrderByFields();
6015    
6016                            for (int i = 0; i < orderByFields.length; i++) {
6017                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6018                                    query.append(orderByFields[i]);
6019    
6020                                    if ((i + 1) < orderByFields.length) {
6021                                            if (orderByComparator.isAscending() ^ previous) {
6022                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6023                                            }
6024                                            else {
6025                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6026                                            }
6027                                    }
6028                                    else {
6029                                            if (orderByComparator.isAscending() ^ previous) {
6030                                                    query.append(ORDER_BY_ASC);
6031                                            }
6032                                            else {
6033                                                    query.append(ORDER_BY_DESC);
6034                                            }
6035                                    }
6036                            }
6037                    }
6038                    else {
6039                            query.append(DLFolderModelImpl.ORDER_BY_JPQL);
6040                    }
6041    
6042                    String sql = query.toString();
6043    
6044                    Query q = session.createQuery(sql);
6045    
6046                    q.setFirstResult(0);
6047                    q.setMaxResults(2);
6048    
6049                    QueryPos qPos = QueryPos.getInstance(q);
6050    
6051                    qPos.add(parentFolderId);
6052    
6053                    if (bindName) {
6054                            qPos.add(name);
6055                    }
6056    
6057                    if (orderByComparator != null) {
6058                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
6059    
6060                            for (Object value : values) {
6061                                    qPos.add(value);
6062                            }
6063                    }
6064    
6065                    List<DLFolder> list = q.list();
6066    
6067                    if (list.size() == 2) {
6068                            return list.get(1);
6069                    }
6070                    else {
6071                            return null;
6072                    }
6073            }
6074    
6075            /**
6076             * Removes all the document library folders where parentFolderId = &#63; and name = &#63; from the database.
6077             *
6078             * @param parentFolderId the parent folder ID
6079             * @param name the name
6080             */
6081            @Override
6082            public void removeByP_N(long parentFolderId, String name) {
6083                    for (DLFolder dlFolder : findByP_N(parentFolderId, name,
6084                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
6085                            remove(dlFolder);
6086                    }
6087            }
6088    
6089            /**
6090             * Returns the number of document library folders where parentFolderId = &#63; and name = &#63;.
6091             *
6092             * @param parentFolderId the parent folder ID
6093             * @param name the name
6094             * @return the number of matching document library folders
6095             */
6096            @Override
6097            public int countByP_N(long parentFolderId, String name) {
6098                    FinderPath finderPath = FINDER_PATH_COUNT_BY_P_N;
6099    
6100                    Object[] finderArgs = new Object[] { parentFolderId, name };
6101    
6102                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
6103    
6104                    if (count == null) {
6105                            StringBundler query = new StringBundler(3);
6106    
6107                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
6108    
6109                            query.append(_FINDER_COLUMN_P_N_PARENTFOLDERID_2);
6110    
6111                            boolean bindName = false;
6112    
6113                            if (name == null) {
6114                                    query.append(_FINDER_COLUMN_P_N_NAME_1);
6115                            }
6116                            else if (name.equals(StringPool.BLANK)) {
6117                                    query.append(_FINDER_COLUMN_P_N_NAME_3);
6118                            }
6119                            else {
6120                                    bindName = true;
6121    
6122                                    query.append(_FINDER_COLUMN_P_N_NAME_2);
6123                            }
6124    
6125                            String sql = query.toString();
6126    
6127                            Session session = null;
6128    
6129                            try {
6130                                    session = openSession();
6131    
6132                                    Query q = session.createQuery(sql);
6133    
6134                                    QueryPos qPos = QueryPos.getInstance(q);
6135    
6136                                    qPos.add(parentFolderId);
6137    
6138                                    if (bindName) {
6139                                            qPos.add(name);
6140                                    }
6141    
6142                                    count = (Long)q.uniqueResult();
6143    
6144                                    finderCache.putResult(finderPath, finderArgs, count);
6145                            }
6146                            catch (Exception e) {
6147                                    finderCache.removeResult(finderPath, finderArgs);
6148    
6149                                    throw processException(e);
6150                            }
6151                            finally {
6152                                    closeSession(session);
6153                            }
6154                    }
6155    
6156                    return count.intValue();
6157            }
6158    
6159            private static final String _FINDER_COLUMN_P_N_PARENTFOLDERID_2 = "dlFolder.parentFolderId = ? AND ";
6160            private static final String _FINDER_COLUMN_P_N_NAME_1 = "dlFolder.name IS NULL";
6161            private static final String _FINDER_COLUMN_P_N_NAME_2 = "dlFolder.name = ?";
6162            private static final String _FINDER_COLUMN_P_N_NAME_3 = "(dlFolder.name IS NULL OR dlFolder.name = '')";
6163            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_M_P = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
6164                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
6165                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_M_P",
6166                            new String[] {
6167                                    Long.class.getName(), Boolean.class.getName(),
6168                                    Long.class.getName(),
6169                                    
6170                            Integer.class.getName(), Integer.class.getName(),
6171                                    OrderByComparator.class.getName()
6172                            });
6173            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
6174                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
6175                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_M_P",
6176                            new String[] {
6177                                    Long.class.getName(), Boolean.class.getName(),
6178                                    Long.class.getName()
6179                            },
6180                            DLFolderModelImpl.GROUPID_COLUMN_BITMASK |
6181                            DLFolderModelImpl.MOUNTPOINT_COLUMN_BITMASK |
6182                            DLFolderModelImpl.PARENTFOLDERID_COLUMN_BITMASK |
6183                            DLFolderModelImpl.NAME_COLUMN_BITMASK);
6184            public static final FinderPath FINDER_PATH_COUNT_BY_G_M_P = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
6185                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
6186                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_M_P",
6187                            new String[] {
6188                                    Long.class.getName(), Boolean.class.getName(),
6189                                    Long.class.getName()
6190                            });
6191    
6192            /**
6193             * Returns all the document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63;.
6194             *
6195             * @param groupId the group ID
6196             * @param mountPoint the mount point
6197             * @param parentFolderId the parent folder ID
6198             * @return the matching document library folders
6199             */
6200            @Override
6201            public List<DLFolder> findByG_M_P(long groupId, boolean mountPoint,
6202                    long parentFolderId) {
6203                    return findByG_M_P(groupId, mountPoint, parentFolderId,
6204                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
6205            }
6206    
6207            /**
6208             * Returns a range of all the document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63;.
6209             *
6210             * <p>
6211             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6212             * </p>
6213             *
6214             * @param groupId the group ID
6215             * @param mountPoint the mount point
6216             * @param parentFolderId the parent folder ID
6217             * @param start the lower bound of the range of document library folders
6218             * @param end the upper bound of the range of document library folders (not inclusive)
6219             * @return the range of matching document library folders
6220             */
6221            @Override
6222            public List<DLFolder> findByG_M_P(long groupId, boolean mountPoint,
6223                    long parentFolderId, int start, int end) {
6224                    return findByG_M_P(groupId, mountPoint, parentFolderId, start, end, null);
6225            }
6226    
6227            /**
6228             * Returns an ordered range of all the document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63;.
6229             *
6230             * <p>
6231             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6232             * </p>
6233             *
6234             * @param groupId the group ID
6235             * @param mountPoint the mount point
6236             * @param parentFolderId the parent folder ID
6237             * @param start the lower bound of the range of document library folders
6238             * @param end the upper bound of the range of document library folders (not inclusive)
6239             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6240             * @return the ordered range of matching document library folders
6241             */
6242            @Override
6243            public List<DLFolder> findByG_M_P(long groupId, boolean mountPoint,
6244                    long parentFolderId, int start, int end,
6245                    OrderByComparator<DLFolder> orderByComparator) {
6246                    return findByG_M_P(groupId, mountPoint, parentFolderId, start, end,
6247                            orderByComparator, true);
6248            }
6249    
6250            /**
6251             * Returns an ordered range of all the document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63;.
6252             *
6253             * <p>
6254             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6255             * </p>
6256             *
6257             * @param groupId the group ID
6258             * @param mountPoint the mount point
6259             * @param parentFolderId the parent folder ID
6260             * @param start the lower bound of the range of document library folders
6261             * @param end the upper bound of the range of document library folders (not inclusive)
6262             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6263             * @param retrieveFromCache whether to retrieve from the finder cache
6264             * @return the ordered range of matching document library folders
6265             */
6266            @Override
6267            public List<DLFolder> findByG_M_P(long groupId, boolean mountPoint,
6268                    long parentFolderId, int start, int end,
6269                    OrderByComparator<DLFolder> orderByComparator, boolean retrieveFromCache) {
6270                    boolean pagination = true;
6271                    FinderPath finderPath = null;
6272                    Object[] finderArgs = null;
6273    
6274                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6275                                    (orderByComparator == null)) {
6276                            pagination = false;
6277                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P;
6278                            finderArgs = new Object[] { groupId, mountPoint, parentFolderId };
6279                    }
6280                    else {
6281                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_M_P;
6282                            finderArgs = new Object[] {
6283                                            groupId, mountPoint, parentFolderId,
6284                                            
6285                                            start, end, orderByComparator
6286                                    };
6287                    }
6288    
6289                    List<DLFolder> list = null;
6290    
6291                    if (retrieveFromCache) {
6292                            list = (List<DLFolder>)finderCache.getResult(finderPath,
6293                                            finderArgs, this);
6294    
6295                            if ((list != null) && !list.isEmpty()) {
6296                                    for (DLFolder dlFolder : list) {
6297                                            if ((groupId != dlFolder.getGroupId()) ||
6298                                                            (mountPoint != dlFolder.getMountPoint()) ||
6299                                                            (parentFolderId != dlFolder.getParentFolderId())) {
6300                                                    list = null;
6301    
6302                                                    break;
6303                                            }
6304                                    }
6305                            }
6306                    }
6307    
6308                    if (list == null) {
6309                            StringBundler query = null;
6310    
6311                            if (orderByComparator != null) {
6312                                    query = new StringBundler(5 +
6313                                                    (orderByComparator.getOrderByFields().length * 2));
6314                            }
6315                            else {
6316                                    query = new StringBundler(5);
6317                            }
6318    
6319                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
6320    
6321                            query.append(_FINDER_COLUMN_G_M_P_GROUPID_2);
6322    
6323                            query.append(_FINDER_COLUMN_G_M_P_MOUNTPOINT_2);
6324    
6325                            query.append(_FINDER_COLUMN_G_M_P_PARENTFOLDERID_2);
6326    
6327                            if (orderByComparator != null) {
6328                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6329                                            orderByComparator);
6330                            }
6331                            else
6332                             if (pagination) {
6333                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
6334                            }
6335    
6336                            String sql = query.toString();
6337    
6338                            Session session = null;
6339    
6340                            try {
6341                                    session = openSession();
6342    
6343                                    Query q = session.createQuery(sql);
6344    
6345                                    QueryPos qPos = QueryPos.getInstance(q);
6346    
6347                                    qPos.add(groupId);
6348    
6349                                    qPos.add(mountPoint);
6350    
6351                                    qPos.add(parentFolderId);
6352    
6353                                    if (!pagination) {
6354                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
6355                                                            start, end, false);
6356    
6357                                            Collections.sort(list);
6358    
6359                                            list = Collections.unmodifiableList(list);
6360                                    }
6361                                    else {
6362                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
6363                                                            start, end);
6364                                    }
6365    
6366                                    cacheResult(list);
6367    
6368                                    finderCache.putResult(finderPath, finderArgs, list);
6369                            }
6370                            catch (Exception e) {
6371                                    finderCache.removeResult(finderPath, finderArgs);
6372    
6373                                    throw processException(e);
6374                            }
6375                            finally {
6376                                    closeSession(session);
6377                            }
6378                    }
6379    
6380                    return list;
6381            }
6382    
6383            /**
6384             * Returns the first document library folder in the ordered set where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63;.
6385             *
6386             * @param groupId the group ID
6387             * @param mountPoint the mount point
6388             * @param parentFolderId the parent folder ID
6389             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6390             * @return the first matching document library folder
6391             * @throws NoSuchFolderException if a matching document library folder could not be found
6392             */
6393            @Override
6394            public DLFolder findByG_M_P_First(long groupId, boolean mountPoint,
6395                    long parentFolderId, OrderByComparator<DLFolder> orderByComparator)
6396                    throws NoSuchFolderException {
6397                    DLFolder dlFolder = fetchByG_M_P_First(groupId, mountPoint,
6398                                    parentFolderId, orderByComparator);
6399    
6400                    if (dlFolder != null) {
6401                            return dlFolder;
6402                    }
6403    
6404                    StringBundler msg = new StringBundler(8);
6405    
6406                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6407    
6408                    msg.append("groupId=");
6409                    msg.append(groupId);
6410    
6411                    msg.append(", mountPoint=");
6412                    msg.append(mountPoint);
6413    
6414                    msg.append(", parentFolderId=");
6415                    msg.append(parentFolderId);
6416    
6417                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6418    
6419                    throw new NoSuchFolderException(msg.toString());
6420            }
6421    
6422            /**
6423             * Returns the first document library folder in the ordered set where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63;.
6424             *
6425             * @param groupId the group ID
6426             * @param mountPoint the mount point
6427             * @param parentFolderId the parent folder ID
6428             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6429             * @return the first matching document library folder, or <code>null</code> if a matching document library folder could not be found
6430             */
6431            @Override
6432            public DLFolder fetchByG_M_P_First(long groupId, boolean mountPoint,
6433                    long parentFolderId, OrderByComparator<DLFolder> orderByComparator) {
6434                    List<DLFolder> list = findByG_M_P(groupId, mountPoint, parentFolderId,
6435                                    0, 1, orderByComparator);
6436    
6437                    if (!list.isEmpty()) {
6438                            return list.get(0);
6439                    }
6440    
6441                    return null;
6442            }
6443    
6444            /**
6445             * Returns the last document library folder in the ordered set where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63;.
6446             *
6447             * @param groupId the group ID
6448             * @param mountPoint the mount point
6449             * @param parentFolderId the parent folder ID
6450             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6451             * @return the last matching document library folder
6452             * @throws NoSuchFolderException if a matching document library folder could not be found
6453             */
6454            @Override
6455            public DLFolder findByG_M_P_Last(long groupId, boolean mountPoint,
6456                    long parentFolderId, OrderByComparator<DLFolder> orderByComparator)
6457                    throws NoSuchFolderException {
6458                    DLFolder dlFolder = fetchByG_M_P_Last(groupId, mountPoint,
6459                                    parentFolderId, orderByComparator);
6460    
6461                    if (dlFolder != null) {
6462                            return dlFolder;
6463                    }
6464    
6465                    StringBundler msg = new StringBundler(8);
6466    
6467                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6468    
6469                    msg.append("groupId=");
6470                    msg.append(groupId);
6471    
6472                    msg.append(", mountPoint=");
6473                    msg.append(mountPoint);
6474    
6475                    msg.append(", parentFolderId=");
6476                    msg.append(parentFolderId);
6477    
6478                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6479    
6480                    throw new NoSuchFolderException(msg.toString());
6481            }
6482    
6483            /**
6484             * Returns the last document library folder in the ordered set where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63;.
6485             *
6486             * @param groupId the group ID
6487             * @param mountPoint the mount point
6488             * @param parentFolderId the parent folder ID
6489             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6490             * @return the last matching document library folder, or <code>null</code> if a matching document library folder could not be found
6491             */
6492            @Override
6493            public DLFolder fetchByG_M_P_Last(long groupId, boolean mountPoint,
6494                    long parentFolderId, OrderByComparator<DLFolder> orderByComparator) {
6495                    int count = countByG_M_P(groupId, mountPoint, parentFolderId);
6496    
6497                    if (count == 0) {
6498                            return null;
6499                    }
6500    
6501                    List<DLFolder> list = findByG_M_P(groupId, mountPoint, parentFolderId,
6502                                    count - 1, count, orderByComparator);
6503    
6504                    if (!list.isEmpty()) {
6505                            return list.get(0);
6506                    }
6507    
6508                    return null;
6509            }
6510    
6511            /**
6512             * Returns the document library folders before and after the current document library folder in the ordered set where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63;.
6513             *
6514             * @param folderId the primary key of the current document library folder
6515             * @param groupId the group ID
6516             * @param mountPoint the mount point
6517             * @param parentFolderId the parent folder ID
6518             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6519             * @return the previous, current, and next document library folder
6520             * @throws NoSuchFolderException if a document library folder with the primary key could not be found
6521             */
6522            @Override
6523            public DLFolder[] findByG_M_P_PrevAndNext(long folderId, long groupId,
6524                    boolean mountPoint, long parentFolderId,
6525                    OrderByComparator<DLFolder> orderByComparator)
6526                    throws NoSuchFolderException {
6527                    DLFolder dlFolder = findByPrimaryKey(folderId);
6528    
6529                    Session session = null;
6530    
6531                    try {
6532                            session = openSession();
6533    
6534                            DLFolder[] array = new DLFolderImpl[3];
6535    
6536                            array[0] = getByG_M_P_PrevAndNext(session, dlFolder, groupId,
6537                                            mountPoint, parentFolderId, orderByComparator, true);
6538    
6539                            array[1] = dlFolder;
6540    
6541                            array[2] = getByG_M_P_PrevAndNext(session, dlFolder, groupId,
6542                                            mountPoint, parentFolderId, orderByComparator, false);
6543    
6544                            return array;
6545                    }
6546                    catch (Exception e) {
6547                            throw processException(e);
6548                    }
6549                    finally {
6550                            closeSession(session);
6551                    }
6552            }
6553    
6554            protected DLFolder getByG_M_P_PrevAndNext(Session session,
6555                    DLFolder dlFolder, long groupId, boolean mountPoint,
6556                    long parentFolderId, OrderByComparator<DLFolder> orderByComparator,
6557                    boolean previous) {
6558                    StringBundler query = null;
6559    
6560                    if (orderByComparator != null) {
6561                            query = new StringBundler(6 +
6562                                            (orderByComparator.getOrderByConditionFields().length * 3) +
6563                                            (orderByComparator.getOrderByFields().length * 3));
6564                    }
6565                    else {
6566                            query = new StringBundler(5);
6567                    }
6568    
6569                    query.append(_SQL_SELECT_DLFOLDER_WHERE);
6570    
6571                    query.append(_FINDER_COLUMN_G_M_P_GROUPID_2);
6572    
6573                    query.append(_FINDER_COLUMN_G_M_P_MOUNTPOINT_2);
6574    
6575                    query.append(_FINDER_COLUMN_G_M_P_PARENTFOLDERID_2);
6576    
6577                    if (orderByComparator != null) {
6578                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6579    
6580                            if (orderByConditionFields.length > 0) {
6581                                    query.append(WHERE_AND);
6582                            }
6583    
6584                            for (int i = 0; i < orderByConditionFields.length; i++) {
6585                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6586                                    query.append(orderByConditionFields[i]);
6587    
6588                                    if ((i + 1) < orderByConditionFields.length) {
6589                                            if (orderByComparator.isAscending() ^ previous) {
6590                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6591                                            }
6592                                            else {
6593                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6594                                            }
6595                                    }
6596                                    else {
6597                                            if (orderByComparator.isAscending() ^ previous) {
6598                                                    query.append(WHERE_GREATER_THAN);
6599                                            }
6600                                            else {
6601                                                    query.append(WHERE_LESSER_THAN);
6602                                            }
6603                                    }
6604                            }
6605    
6606                            query.append(ORDER_BY_CLAUSE);
6607    
6608                            String[] orderByFields = orderByComparator.getOrderByFields();
6609    
6610                            for (int i = 0; i < orderByFields.length; i++) {
6611                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6612                                    query.append(orderByFields[i]);
6613    
6614                                    if ((i + 1) < orderByFields.length) {
6615                                            if (orderByComparator.isAscending() ^ previous) {
6616                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6617                                            }
6618                                            else {
6619                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6620                                            }
6621                                    }
6622                                    else {
6623                                            if (orderByComparator.isAscending() ^ previous) {
6624                                                    query.append(ORDER_BY_ASC);
6625                                            }
6626                                            else {
6627                                                    query.append(ORDER_BY_DESC);
6628                                            }
6629                                    }
6630                            }
6631                    }
6632                    else {
6633                            query.append(DLFolderModelImpl.ORDER_BY_JPQL);
6634                    }
6635    
6636                    String sql = query.toString();
6637    
6638                    Query q = session.createQuery(sql);
6639    
6640                    q.setFirstResult(0);
6641                    q.setMaxResults(2);
6642    
6643                    QueryPos qPos = QueryPos.getInstance(q);
6644    
6645                    qPos.add(groupId);
6646    
6647                    qPos.add(mountPoint);
6648    
6649                    qPos.add(parentFolderId);
6650    
6651                    if (orderByComparator != null) {
6652                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
6653    
6654                            for (Object value : values) {
6655                                    qPos.add(value);
6656                            }
6657                    }
6658    
6659                    List<DLFolder> list = q.list();
6660    
6661                    if (list.size() == 2) {
6662                            return list.get(1);
6663                    }
6664                    else {
6665                            return null;
6666                    }
6667            }
6668    
6669            /**
6670             * Returns all the document library folders that the user has permission to view where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63;.
6671             *
6672             * @param groupId the group ID
6673             * @param mountPoint the mount point
6674             * @param parentFolderId the parent folder ID
6675             * @return the matching document library folders that the user has permission to view
6676             */
6677            @Override
6678            public List<DLFolder> filterFindByG_M_P(long groupId, boolean mountPoint,
6679                    long parentFolderId) {
6680                    return filterFindByG_M_P(groupId, mountPoint, parentFolderId,
6681                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
6682            }
6683    
6684            /**
6685             * Returns a range of all the document library folders that the user has permission to view where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63;.
6686             *
6687             * <p>
6688             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6689             * </p>
6690             *
6691             * @param groupId the group ID
6692             * @param mountPoint the mount point
6693             * @param parentFolderId the parent folder ID
6694             * @param start the lower bound of the range of document library folders
6695             * @param end the upper bound of the range of document library folders (not inclusive)
6696             * @return the range of matching document library folders that the user has permission to view
6697             */
6698            @Override
6699            public List<DLFolder> filterFindByG_M_P(long groupId, boolean mountPoint,
6700                    long parentFolderId, int start, int end) {
6701                    return filterFindByG_M_P(groupId, mountPoint, parentFolderId, start,
6702                            end, null);
6703            }
6704    
6705            /**
6706             * Returns an ordered range of all the document library folders that the user has permissions to view where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63;.
6707             *
6708             * <p>
6709             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6710             * </p>
6711             *
6712             * @param groupId the group ID
6713             * @param mountPoint the mount point
6714             * @param parentFolderId the parent folder ID
6715             * @param start the lower bound of the range of document library folders
6716             * @param end the upper bound of the range of document library folders (not inclusive)
6717             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6718             * @return the ordered range of matching document library folders that the user has permission to view
6719             */
6720            @Override
6721            public List<DLFolder> filterFindByG_M_P(long groupId, boolean mountPoint,
6722                    long parentFolderId, int start, int end,
6723                    OrderByComparator<DLFolder> orderByComparator) {
6724                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6725                            return findByG_M_P(groupId, mountPoint, parentFolderId, start, end,
6726                                    orderByComparator);
6727                    }
6728    
6729                    StringBundler query = null;
6730    
6731                    if (orderByComparator != null) {
6732                            query = new StringBundler(5 +
6733                                            (orderByComparator.getOrderByFields().length * 2));
6734                    }
6735                    else {
6736                            query = new StringBundler(6);
6737                    }
6738    
6739                    if (getDB().isSupportsInlineDistinct()) {
6740                            query.append(_FILTER_SQL_SELECT_DLFOLDER_WHERE);
6741                    }
6742                    else {
6743                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1);
6744                    }
6745    
6746                    query.append(_FINDER_COLUMN_G_M_P_GROUPID_2);
6747    
6748                    query.append(_FINDER_COLUMN_G_M_P_MOUNTPOINT_2);
6749    
6750                    query.append(_FINDER_COLUMN_G_M_P_PARENTFOLDERID_2);
6751    
6752                    if (!getDB().isSupportsInlineDistinct()) {
6753                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2);
6754                    }
6755    
6756                    if (orderByComparator != null) {
6757                            if (getDB().isSupportsInlineDistinct()) {
6758                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6759                                            orderByComparator, true);
6760                            }
6761                            else {
6762                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
6763                                            orderByComparator, true);
6764                            }
6765                    }
6766                    else {
6767                            if (getDB().isSupportsInlineDistinct()) {
6768                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
6769                            }
6770                            else {
6771                                    query.append(DLFolderModelImpl.ORDER_BY_SQL);
6772                            }
6773                    }
6774    
6775                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6776                                    DLFolder.class.getName(),
6777                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6778    
6779                    Session session = null;
6780    
6781                    try {
6782                            session = openSession();
6783    
6784                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
6785    
6786                            if (getDB().isSupportsInlineDistinct()) {
6787                                    q.addEntity(_FILTER_ENTITY_ALIAS, DLFolderImpl.class);
6788                            }
6789                            else {
6790                                    q.addEntity(_FILTER_ENTITY_TABLE, DLFolderImpl.class);
6791                            }
6792    
6793                            QueryPos qPos = QueryPos.getInstance(q);
6794    
6795                            qPos.add(groupId);
6796    
6797                            qPos.add(mountPoint);
6798    
6799                            qPos.add(parentFolderId);
6800    
6801                            return (List<DLFolder>)QueryUtil.list(q, getDialect(), start, end);
6802                    }
6803                    catch (Exception e) {
6804                            throw processException(e);
6805                    }
6806                    finally {
6807                            closeSession(session);
6808                    }
6809            }
6810    
6811            /**
6812             * 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 mountPoint = &#63; and parentFolderId = &#63;.
6813             *
6814             * @param folderId the primary key of the current document library folder
6815             * @param groupId the group ID
6816             * @param mountPoint the mount point
6817             * @param parentFolderId the parent folder ID
6818             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6819             * @return the previous, current, and next document library folder
6820             * @throws NoSuchFolderException if a document library folder with the primary key could not be found
6821             */
6822            @Override
6823            public DLFolder[] filterFindByG_M_P_PrevAndNext(long folderId,
6824                    long groupId, boolean mountPoint, long parentFolderId,
6825                    OrderByComparator<DLFolder> orderByComparator)
6826                    throws NoSuchFolderException {
6827                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6828                            return findByG_M_P_PrevAndNext(folderId, groupId, mountPoint,
6829                                    parentFolderId, orderByComparator);
6830                    }
6831    
6832                    DLFolder dlFolder = findByPrimaryKey(folderId);
6833    
6834                    Session session = null;
6835    
6836                    try {
6837                            session = openSession();
6838    
6839                            DLFolder[] array = new DLFolderImpl[3];
6840    
6841                            array[0] = filterGetByG_M_P_PrevAndNext(session, dlFolder, groupId,
6842                                            mountPoint, parentFolderId, orderByComparator, true);
6843    
6844                            array[1] = dlFolder;
6845    
6846                            array[2] = filterGetByG_M_P_PrevAndNext(session, dlFolder, groupId,
6847                                            mountPoint, parentFolderId, orderByComparator, false);
6848    
6849                            return array;
6850                    }
6851                    catch (Exception e) {
6852                            throw processException(e);
6853                    }
6854                    finally {
6855                            closeSession(session);
6856                    }
6857            }
6858    
6859            protected DLFolder filterGetByG_M_P_PrevAndNext(Session session,
6860                    DLFolder dlFolder, long groupId, boolean mountPoint,
6861                    long parentFolderId, OrderByComparator<DLFolder> orderByComparator,
6862                    boolean previous) {
6863                    StringBundler query = null;
6864    
6865                    if (orderByComparator != null) {
6866                            query = new StringBundler(7 +
6867                                            (orderByComparator.getOrderByConditionFields().length * 3) +
6868                                            (orderByComparator.getOrderByFields().length * 3));
6869                    }
6870                    else {
6871                            query = new StringBundler(6);
6872                    }
6873    
6874                    if (getDB().isSupportsInlineDistinct()) {
6875                            query.append(_FILTER_SQL_SELECT_DLFOLDER_WHERE);
6876                    }
6877                    else {
6878                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1);
6879                    }
6880    
6881                    query.append(_FINDER_COLUMN_G_M_P_GROUPID_2);
6882    
6883                    query.append(_FINDER_COLUMN_G_M_P_MOUNTPOINT_2);
6884    
6885                    query.append(_FINDER_COLUMN_G_M_P_PARENTFOLDERID_2);
6886    
6887                    if (!getDB().isSupportsInlineDistinct()) {
6888                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2);
6889                    }
6890    
6891                    if (orderByComparator != null) {
6892                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6893    
6894                            if (orderByConditionFields.length > 0) {
6895                                    query.append(WHERE_AND);
6896                            }
6897    
6898                            for (int i = 0; i < orderByConditionFields.length; i++) {
6899                                    if (getDB().isSupportsInlineDistinct()) {
6900                                            query.append(_ORDER_BY_ENTITY_ALIAS);
6901                                    }
6902                                    else {
6903                                            query.append(_ORDER_BY_ENTITY_TABLE);
6904                                    }
6905    
6906                                    query.append(orderByConditionFields[i]);
6907    
6908                                    if ((i + 1) < orderByConditionFields.length) {
6909                                            if (orderByComparator.isAscending() ^ previous) {
6910                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6911                                            }
6912                                            else {
6913                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6914                                            }
6915                                    }
6916                                    else {
6917                                            if (orderByComparator.isAscending() ^ previous) {
6918                                                    query.append(WHERE_GREATER_THAN);
6919                                            }
6920                                            else {
6921                                                    query.append(WHERE_LESSER_THAN);
6922                                            }
6923                                    }
6924                            }
6925    
6926                            query.append(ORDER_BY_CLAUSE);
6927    
6928                            String[] orderByFields = orderByComparator.getOrderByFields();
6929    
6930                            for (int i = 0; i < orderByFields.length; i++) {
6931                                    if (getDB().isSupportsInlineDistinct()) {
6932                                            query.append(_ORDER_BY_ENTITY_ALIAS);
6933                                    }
6934                                    else {
6935                                            query.append(_ORDER_BY_ENTITY_TABLE);
6936                                    }
6937    
6938                                    query.append(orderByFields[i]);
6939    
6940                                    if ((i + 1) < orderByFields.length) {
6941                                            if (orderByComparator.isAscending() ^ previous) {
6942                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6943                                            }
6944                                            else {
6945                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6946                                            }
6947                                    }
6948                                    else {
6949                                            if (orderByComparator.isAscending() ^ previous) {
6950                                                    query.append(ORDER_BY_ASC);
6951                                            }
6952                                            else {
6953                                                    query.append(ORDER_BY_DESC);
6954                                            }
6955                                    }
6956                            }
6957                    }
6958                    else {
6959                            if (getDB().isSupportsInlineDistinct()) {
6960                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
6961                            }
6962                            else {
6963                                    query.append(DLFolderModelImpl.ORDER_BY_SQL);
6964                            }
6965                    }
6966    
6967                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6968                                    DLFolder.class.getName(),
6969                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6970    
6971                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
6972    
6973                    q.setFirstResult(0);
6974                    q.setMaxResults(2);
6975    
6976                    if (getDB().isSupportsInlineDistinct()) {
6977                            q.addEntity(_FILTER_ENTITY_ALIAS, DLFolderImpl.class);
6978                    }
6979                    else {
6980                            q.addEntity(_FILTER_ENTITY_TABLE, DLFolderImpl.class);
6981                    }
6982    
6983                    QueryPos qPos = QueryPos.getInstance(q);
6984    
6985                    qPos.add(groupId);
6986    
6987                    qPos.add(mountPoint);
6988    
6989                    qPos.add(parentFolderId);
6990    
6991                    if (orderByComparator != null) {
6992                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
6993    
6994                            for (Object value : values) {
6995                                    qPos.add(value);
6996                            }
6997                    }
6998    
6999                    List<DLFolder> list = q.list();
7000    
7001                    if (list.size() == 2) {
7002                            return list.get(1);
7003                    }
7004                    else {
7005                            return null;
7006                    }
7007            }
7008    
7009            /**
7010             * Removes all the document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; from the database.
7011             *
7012             * @param groupId the group ID
7013             * @param mountPoint the mount point
7014             * @param parentFolderId the parent folder ID
7015             */
7016            @Override
7017            public void removeByG_M_P(long groupId, boolean mountPoint,
7018                    long parentFolderId) {
7019                    for (DLFolder dlFolder : findByG_M_P(groupId, mountPoint,
7020                                    parentFolderId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
7021                            remove(dlFolder);
7022                    }
7023            }
7024    
7025            /**
7026             * Returns the number of document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63;.
7027             *
7028             * @param groupId the group ID
7029             * @param mountPoint the mount point
7030             * @param parentFolderId the parent folder ID
7031             * @return the number of matching document library folders
7032             */
7033            @Override
7034            public int countByG_M_P(long groupId, boolean mountPoint,
7035                    long parentFolderId) {
7036                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_M_P;
7037    
7038                    Object[] finderArgs = new Object[] { groupId, mountPoint, parentFolderId };
7039    
7040                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
7041    
7042                    if (count == null) {
7043                            StringBundler query = new StringBundler(4);
7044    
7045                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
7046    
7047                            query.append(_FINDER_COLUMN_G_M_P_GROUPID_2);
7048    
7049                            query.append(_FINDER_COLUMN_G_M_P_MOUNTPOINT_2);
7050    
7051                            query.append(_FINDER_COLUMN_G_M_P_PARENTFOLDERID_2);
7052    
7053                            String sql = query.toString();
7054    
7055                            Session session = null;
7056    
7057                            try {
7058                                    session = openSession();
7059    
7060                                    Query q = session.createQuery(sql);
7061    
7062                                    QueryPos qPos = QueryPos.getInstance(q);
7063    
7064                                    qPos.add(groupId);
7065    
7066                                    qPos.add(mountPoint);
7067    
7068                                    qPos.add(parentFolderId);
7069    
7070                                    count = (Long)q.uniqueResult();
7071    
7072                                    finderCache.putResult(finderPath, finderArgs, count);
7073                            }
7074                            catch (Exception e) {
7075                                    finderCache.removeResult(finderPath, finderArgs);
7076    
7077                                    throw processException(e);
7078                            }
7079                            finally {
7080                                    closeSession(session);
7081                            }
7082                    }
7083    
7084                    return count.intValue();
7085            }
7086    
7087            /**
7088             * Returns the number of document library folders that the user has permission to view where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63;.
7089             *
7090             * @param groupId the group ID
7091             * @param mountPoint the mount point
7092             * @param parentFolderId the parent folder ID
7093             * @return the number of matching document library folders that the user has permission to view
7094             */
7095            @Override
7096            public int filterCountByG_M_P(long groupId, boolean mountPoint,
7097                    long parentFolderId) {
7098                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7099                            return countByG_M_P(groupId, mountPoint, parentFolderId);
7100                    }
7101    
7102                    StringBundler query = new StringBundler(4);
7103    
7104                    query.append(_FILTER_SQL_COUNT_DLFOLDER_WHERE);
7105    
7106                    query.append(_FINDER_COLUMN_G_M_P_GROUPID_2);
7107    
7108                    query.append(_FINDER_COLUMN_G_M_P_MOUNTPOINT_2);
7109    
7110                    query.append(_FINDER_COLUMN_G_M_P_PARENTFOLDERID_2);
7111    
7112                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7113                                    DLFolder.class.getName(),
7114                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7115    
7116                    Session session = null;
7117    
7118                    try {
7119                            session = openSession();
7120    
7121                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
7122    
7123                            q.addScalar(COUNT_COLUMN_NAME,
7124                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
7125    
7126                            QueryPos qPos = QueryPos.getInstance(q);
7127    
7128                            qPos.add(groupId);
7129    
7130                            qPos.add(mountPoint);
7131    
7132                            qPos.add(parentFolderId);
7133    
7134                            Long count = (Long)q.uniqueResult();
7135    
7136                            return count.intValue();
7137                    }
7138                    catch (Exception e) {
7139                            throw processException(e);
7140                    }
7141                    finally {
7142                            closeSession(session);
7143                    }
7144            }
7145    
7146            private static final String _FINDER_COLUMN_G_M_P_GROUPID_2 = "dlFolder.groupId = ? AND ";
7147            private static final String _FINDER_COLUMN_G_M_P_MOUNTPOINT_2 = "dlFolder.mountPoint = ? AND ";
7148            private static final String _FINDER_COLUMN_G_M_P_PARENTFOLDERID_2 = "dlFolder.parentFolderId = ?";
7149            public static final FinderPath FINDER_PATH_FETCH_BY_G_P_N = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
7150                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
7151                            FINDER_CLASS_NAME_ENTITY, "fetchByG_P_N",
7152                            new String[] {
7153                                    Long.class.getName(), Long.class.getName(),
7154                                    String.class.getName()
7155                            },
7156                            DLFolderModelImpl.GROUPID_COLUMN_BITMASK |
7157                            DLFolderModelImpl.PARENTFOLDERID_COLUMN_BITMASK |
7158                            DLFolderModelImpl.NAME_COLUMN_BITMASK);
7159            public static final FinderPath FINDER_PATH_COUNT_BY_G_P_N = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
7160                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
7161                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P_N",
7162                            new String[] {
7163                                    Long.class.getName(), Long.class.getName(),
7164                                    String.class.getName()
7165                            });
7166    
7167            /**
7168             * Returns the document library folder where groupId = &#63; and parentFolderId = &#63; and name = &#63; or throws a {@link NoSuchFolderException} if it could not be found.
7169             *
7170             * @param groupId the group ID
7171             * @param parentFolderId the parent folder ID
7172             * @param name the name
7173             * @return the matching document library folder
7174             * @throws NoSuchFolderException if a matching document library folder could not be found
7175             */
7176            @Override
7177            public DLFolder findByG_P_N(long groupId, long parentFolderId, String name)
7178                    throws NoSuchFolderException {
7179                    DLFolder dlFolder = fetchByG_P_N(groupId, parentFolderId, name);
7180    
7181                    if (dlFolder == null) {
7182                            StringBundler msg = new StringBundler(8);
7183    
7184                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7185    
7186                            msg.append("groupId=");
7187                            msg.append(groupId);
7188    
7189                            msg.append(", parentFolderId=");
7190                            msg.append(parentFolderId);
7191    
7192                            msg.append(", name=");
7193                            msg.append(name);
7194    
7195                            msg.append(StringPool.CLOSE_CURLY_BRACE);
7196    
7197                            if (_log.isWarnEnabled()) {
7198                                    _log.warn(msg.toString());
7199                            }
7200    
7201                            throw new NoSuchFolderException(msg.toString());
7202                    }
7203    
7204                    return dlFolder;
7205            }
7206    
7207            /**
7208             * 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.
7209             *
7210             * @param groupId the group ID
7211             * @param parentFolderId the parent folder ID
7212             * @param name the name
7213             * @return the matching document library folder, or <code>null</code> if a matching document library folder could not be found
7214             */
7215            @Override
7216            public DLFolder fetchByG_P_N(long groupId, long parentFolderId, String name) {
7217                    return fetchByG_P_N(groupId, parentFolderId, name, true);
7218            }
7219    
7220            /**
7221             * 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.
7222             *
7223             * @param groupId the group ID
7224             * @param parentFolderId the parent folder ID
7225             * @param name the name
7226             * @param retrieveFromCache whether to retrieve from the finder cache
7227             * @return the matching document library folder, or <code>null</code> if a matching document library folder could not be found
7228             */
7229            @Override
7230            public DLFolder fetchByG_P_N(long groupId, long parentFolderId,
7231                    String name, boolean retrieveFromCache) {
7232                    Object[] finderArgs = new Object[] { groupId, parentFolderId, name };
7233    
7234                    Object result = null;
7235    
7236                    if (retrieveFromCache) {
7237                            result = finderCache.getResult(FINDER_PATH_FETCH_BY_G_P_N,
7238                                            finderArgs, this);
7239                    }
7240    
7241                    if (result instanceof DLFolder) {
7242                            DLFolder dlFolder = (DLFolder)result;
7243    
7244                            if ((groupId != dlFolder.getGroupId()) ||
7245                                            (parentFolderId != dlFolder.getParentFolderId()) ||
7246                                            !Validator.equals(name, dlFolder.getName())) {
7247                                    result = null;
7248                            }
7249                    }
7250    
7251                    if (result == null) {
7252                            StringBundler query = new StringBundler(5);
7253    
7254                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
7255    
7256                            query.append(_FINDER_COLUMN_G_P_N_GROUPID_2);
7257    
7258                            query.append(_FINDER_COLUMN_G_P_N_PARENTFOLDERID_2);
7259    
7260                            boolean bindName = false;
7261    
7262                            if (name == null) {
7263                                    query.append(_FINDER_COLUMN_G_P_N_NAME_1);
7264                            }
7265                            else if (name.equals(StringPool.BLANK)) {
7266                                    query.append(_FINDER_COLUMN_G_P_N_NAME_3);
7267                            }
7268                            else {
7269                                    bindName = true;
7270    
7271                                    query.append(_FINDER_COLUMN_G_P_N_NAME_2);
7272                            }
7273    
7274                            String sql = query.toString();
7275    
7276                            Session session = null;
7277    
7278                            try {
7279                                    session = openSession();
7280    
7281                                    Query q = session.createQuery(sql);
7282    
7283                                    QueryPos qPos = QueryPos.getInstance(q);
7284    
7285                                    qPos.add(groupId);
7286    
7287                                    qPos.add(parentFolderId);
7288    
7289                                    if (bindName) {
7290                                            qPos.add(name);
7291                                    }
7292    
7293                                    List<DLFolder> list = q.list();
7294    
7295                                    if (list.isEmpty()) {
7296                                            finderCache.putResult(FINDER_PATH_FETCH_BY_G_P_N,
7297                                                    finderArgs, list);
7298                                    }
7299                                    else {
7300                                            DLFolder dlFolder = list.get(0);
7301    
7302                                            result = dlFolder;
7303    
7304                                            cacheResult(dlFolder);
7305    
7306                                            if ((dlFolder.getGroupId() != groupId) ||
7307                                                            (dlFolder.getParentFolderId() != parentFolderId) ||
7308                                                            (dlFolder.getName() == null) ||
7309                                                            !dlFolder.getName().equals(name)) {
7310                                                    finderCache.putResult(FINDER_PATH_FETCH_BY_G_P_N,
7311                                                            finderArgs, dlFolder);
7312                                            }
7313                                    }
7314                            }
7315                            catch (Exception e) {
7316                                    finderCache.removeResult(FINDER_PATH_FETCH_BY_G_P_N, finderArgs);
7317    
7318                                    throw processException(e);
7319                            }
7320                            finally {
7321                                    closeSession(session);
7322                            }
7323                    }
7324    
7325                    if (result instanceof List<?>) {
7326                            return null;
7327                    }
7328                    else {
7329                            return (DLFolder)result;
7330                    }
7331            }
7332    
7333            /**
7334             * Removes the document library folder where groupId = &#63; and parentFolderId = &#63; and name = &#63; from the database.
7335             *
7336             * @param groupId the group ID
7337             * @param parentFolderId the parent folder ID
7338             * @param name the name
7339             * @return the document library folder that was removed
7340             */
7341            @Override
7342            public DLFolder removeByG_P_N(long groupId, long parentFolderId, String name)
7343                    throws NoSuchFolderException {
7344                    DLFolder dlFolder = findByG_P_N(groupId, parentFolderId, name);
7345    
7346                    return remove(dlFolder);
7347            }
7348    
7349            /**
7350             * Returns the number of document library folders where groupId = &#63; and parentFolderId = &#63; and name = &#63;.
7351             *
7352             * @param groupId the group ID
7353             * @param parentFolderId the parent folder ID
7354             * @param name the name
7355             * @return the number of matching document library folders
7356             */
7357            @Override
7358            public int countByG_P_N(long groupId, long parentFolderId, String name) {
7359                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_P_N;
7360    
7361                    Object[] finderArgs = new Object[] { groupId, parentFolderId, name };
7362    
7363                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
7364    
7365                    if (count == null) {
7366                            StringBundler query = new StringBundler(4);
7367    
7368                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
7369    
7370                            query.append(_FINDER_COLUMN_G_P_N_GROUPID_2);
7371    
7372                            query.append(_FINDER_COLUMN_G_P_N_PARENTFOLDERID_2);
7373    
7374                            boolean bindName = false;
7375    
7376                            if (name == null) {
7377                                    query.append(_FINDER_COLUMN_G_P_N_NAME_1);
7378                            }
7379                            else if (name.equals(StringPool.BLANK)) {
7380                                    query.append(_FINDER_COLUMN_G_P_N_NAME_3);
7381                            }
7382                            else {
7383                                    bindName = true;
7384    
7385                                    query.append(_FINDER_COLUMN_G_P_N_NAME_2);
7386                            }
7387    
7388                            String sql = query.toString();
7389    
7390                            Session session = null;
7391    
7392                            try {
7393                                    session = openSession();
7394    
7395                                    Query q = session.createQuery(sql);
7396    
7397                                    QueryPos qPos = QueryPos.getInstance(q);
7398    
7399                                    qPos.add(groupId);
7400    
7401                                    qPos.add(parentFolderId);
7402    
7403                                    if (bindName) {
7404                                            qPos.add(name);
7405                                    }
7406    
7407                                    count = (Long)q.uniqueResult();
7408    
7409                                    finderCache.putResult(finderPath, finderArgs, count);
7410                            }
7411                            catch (Exception e) {
7412                                    finderCache.removeResult(finderPath, finderArgs);
7413    
7414                                    throw processException(e);
7415                            }
7416                            finally {
7417                                    closeSession(session);
7418                            }
7419                    }
7420    
7421                    return count.intValue();
7422            }
7423    
7424            private static final String _FINDER_COLUMN_G_P_N_GROUPID_2 = "dlFolder.groupId = ? AND ";
7425            private static final String _FINDER_COLUMN_G_P_N_PARENTFOLDERID_2 = "dlFolder.parentFolderId = ? AND ";
7426            private static final String _FINDER_COLUMN_G_P_N_NAME_1 = "dlFolder.name IS NULL";
7427            private static final String _FINDER_COLUMN_G_P_N_NAME_2 = "dlFolder.name = ?";
7428            private static final String _FINDER_COLUMN_G_P_N_NAME_3 = "(dlFolder.name IS NULL OR dlFolder.name = '')";
7429            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_F_C_P_NOTS =
7430                    new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
7431                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
7432                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByF_C_P_NotS",
7433                            new String[] {
7434                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
7435                                    Integer.class.getName(),
7436                                    
7437                            Integer.class.getName(), Integer.class.getName(),
7438                                    OrderByComparator.class.getName()
7439                            });
7440            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_F_C_P_NOTS =
7441                    new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
7442                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
7443                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByF_C_P_NotS",
7444                            new String[] {
7445                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
7446                                    Integer.class.getName()
7447                            });
7448    
7449            /**
7450             * Returns all the document library folders where folderId &gt; &#63; and companyId = &#63; and parentFolderId = &#63; and status &ne; &#63;.
7451             *
7452             * @param folderId the folder ID
7453             * @param companyId the company ID
7454             * @param parentFolderId the parent folder ID
7455             * @param status the status
7456             * @return the matching document library folders
7457             */
7458            @Override
7459            public List<DLFolder> findByF_C_P_NotS(long folderId, long companyId,
7460                    long parentFolderId, int status) {
7461                    return findByF_C_P_NotS(folderId, companyId, parentFolderId, status,
7462                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
7463            }
7464    
7465            /**
7466             * Returns a range of all the document library folders where folderId &gt; &#63; and companyId = &#63; and parentFolderId = &#63; and status &ne; &#63;.
7467             *
7468             * <p>
7469             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7470             * </p>
7471             *
7472             * @param folderId the folder ID
7473             * @param companyId the company ID
7474             * @param parentFolderId the parent folder ID
7475             * @param status the status
7476             * @param start the lower bound of the range of document library folders
7477             * @param end the upper bound of the range of document library folders (not inclusive)
7478             * @return the range of matching document library folders
7479             */
7480            @Override
7481            public List<DLFolder> findByF_C_P_NotS(long folderId, long companyId,
7482                    long parentFolderId, int status, int start, int end) {
7483                    return findByF_C_P_NotS(folderId, companyId, parentFolderId, status,
7484                            start, end, null);
7485            }
7486    
7487            /**
7488             * Returns an ordered range of all the document library folders where folderId &gt; &#63; and companyId = &#63; and parentFolderId = &#63; and status &ne; &#63;.
7489             *
7490             * <p>
7491             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7492             * </p>
7493             *
7494             * @param folderId the folder ID
7495             * @param companyId the company ID
7496             * @param parentFolderId the parent folder ID
7497             * @param status the status
7498             * @param start the lower bound of the range of document library folders
7499             * @param end the upper bound of the range of document library folders (not inclusive)
7500             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7501             * @return the ordered range of matching document library folders
7502             */
7503            @Override
7504            public List<DLFolder> findByF_C_P_NotS(long folderId, long companyId,
7505                    long parentFolderId, int status, int start, int end,
7506                    OrderByComparator<DLFolder> orderByComparator) {
7507                    return findByF_C_P_NotS(folderId, companyId, parentFolderId, status,
7508                            start, end, orderByComparator, true);
7509            }
7510    
7511            /**
7512             * Returns an ordered range of all the document library folders where folderId &gt; &#63; and companyId = &#63; and parentFolderId = &#63; and status &ne; &#63;.
7513             *
7514             * <p>
7515             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7516             * </p>
7517             *
7518             * @param folderId the folder ID
7519             * @param companyId the company ID
7520             * @param parentFolderId the parent folder ID
7521             * @param status the status
7522             * @param start the lower bound of the range of document library folders
7523             * @param end the upper bound of the range of document library folders (not inclusive)
7524             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7525             * @param retrieveFromCache whether to retrieve from the finder cache
7526             * @return the ordered range of matching document library folders
7527             */
7528            @Override
7529            public List<DLFolder> findByF_C_P_NotS(long folderId, long companyId,
7530                    long parentFolderId, int status, int start, int end,
7531                    OrderByComparator<DLFolder> orderByComparator, boolean retrieveFromCache) {
7532                    boolean pagination = true;
7533                    FinderPath finderPath = null;
7534                    Object[] finderArgs = null;
7535    
7536                    finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_F_C_P_NOTS;
7537                    finderArgs = new Object[] {
7538                                    folderId, companyId, parentFolderId, status,
7539                                    
7540                                    start, end, orderByComparator
7541                            };
7542    
7543                    List<DLFolder> list = null;
7544    
7545                    if (retrieveFromCache) {
7546                            list = (List<DLFolder>)finderCache.getResult(finderPath,
7547                                            finderArgs, this);
7548    
7549                            if ((list != null) && !list.isEmpty()) {
7550                                    for (DLFolder dlFolder : list) {
7551                                            if ((folderId >= dlFolder.getFolderId()) ||
7552                                                            (companyId != dlFolder.getCompanyId()) ||
7553                                                            (parentFolderId != dlFolder.getParentFolderId()) ||
7554                                                            (status == dlFolder.getStatus())) {
7555                                                    list = null;
7556    
7557                                                    break;
7558                                            }
7559                                    }
7560                            }
7561                    }
7562    
7563                    if (list == null) {
7564                            StringBundler query = null;
7565    
7566                            if (orderByComparator != null) {
7567                                    query = new StringBundler(6 +
7568                                                    (orderByComparator.getOrderByFields().length * 2));
7569                            }
7570                            else {
7571                                    query = new StringBundler(6);
7572                            }
7573    
7574                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
7575    
7576                            query.append(_FINDER_COLUMN_F_C_P_NOTS_FOLDERID_2);
7577    
7578                            query.append(_FINDER_COLUMN_F_C_P_NOTS_COMPANYID_2);
7579    
7580                            query.append(_FINDER_COLUMN_F_C_P_NOTS_PARENTFOLDERID_2);
7581    
7582                            query.append(_FINDER_COLUMN_F_C_P_NOTS_STATUS_2);
7583    
7584                            if (orderByComparator != null) {
7585                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7586                                            orderByComparator);
7587                            }
7588                            else
7589                             if (pagination) {
7590                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
7591                            }
7592    
7593                            String sql = query.toString();
7594    
7595                            Session session = null;
7596    
7597                            try {
7598                                    session = openSession();
7599    
7600                                    Query q = session.createQuery(sql);
7601    
7602                                    QueryPos qPos = QueryPos.getInstance(q);
7603    
7604                                    qPos.add(folderId);
7605    
7606                                    qPos.add(companyId);
7607    
7608                                    qPos.add(parentFolderId);
7609    
7610                                    qPos.add(status);
7611    
7612                                    if (!pagination) {
7613                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
7614                                                            start, end, false);
7615    
7616                                            Collections.sort(list);
7617    
7618                                            list = Collections.unmodifiableList(list);
7619                                    }
7620                                    else {
7621                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
7622                                                            start, end);
7623                                    }
7624    
7625                                    cacheResult(list);
7626    
7627                                    finderCache.putResult(finderPath, finderArgs, list);
7628                            }
7629                            catch (Exception e) {
7630                                    finderCache.removeResult(finderPath, finderArgs);
7631    
7632                                    throw processException(e);
7633                            }
7634                            finally {
7635                                    closeSession(session);
7636                            }
7637                    }
7638    
7639                    return list;
7640            }
7641    
7642            /**
7643             * Returns the first document library folder in the ordered set where folderId &gt; &#63; and companyId = &#63; and parentFolderId = &#63; and status &ne; &#63;.
7644             *
7645             * @param folderId the folder ID
7646             * @param companyId the company ID
7647             * @param parentFolderId the parent folder ID
7648             * @param status the status
7649             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7650             * @return the first matching document library folder
7651             * @throws NoSuchFolderException if a matching document library folder could not be found
7652             */
7653            @Override
7654            public DLFolder findByF_C_P_NotS_First(long folderId, long companyId,
7655                    long parentFolderId, int status,
7656                    OrderByComparator<DLFolder> orderByComparator)
7657                    throws NoSuchFolderException {
7658                    DLFolder dlFolder = fetchByF_C_P_NotS_First(folderId, companyId,
7659                                    parentFolderId, status, orderByComparator);
7660    
7661                    if (dlFolder != null) {
7662                            return dlFolder;
7663                    }
7664    
7665                    StringBundler msg = new StringBundler(10);
7666    
7667                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7668    
7669                    msg.append("folderId=");
7670                    msg.append(folderId);
7671    
7672                    msg.append(", companyId=");
7673                    msg.append(companyId);
7674    
7675                    msg.append(", parentFolderId=");
7676                    msg.append(parentFolderId);
7677    
7678                    msg.append(", status=");
7679                    msg.append(status);
7680    
7681                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7682    
7683                    throw new NoSuchFolderException(msg.toString());
7684            }
7685    
7686            /**
7687             * Returns the first document library folder in the ordered set where folderId &gt; &#63; and companyId = &#63; and parentFolderId = &#63; and status &ne; &#63;.
7688             *
7689             * @param folderId the folder ID
7690             * @param companyId the company ID
7691             * @param parentFolderId the parent folder ID
7692             * @param status the status
7693             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7694             * @return the first matching document library folder, or <code>null</code> if a matching document library folder could not be found
7695             */
7696            @Override
7697            public DLFolder fetchByF_C_P_NotS_First(long folderId, long companyId,
7698                    long parentFolderId, int status,
7699                    OrderByComparator<DLFolder> orderByComparator) {
7700                    List<DLFolder> list = findByF_C_P_NotS(folderId, companyId,
7701                                    parentFolderId, status, 0, 1, orderByComparator);
7702    
7703                    if (!list.isEmpty()) {
7704                            return list.get(0);
7705                    }
7706    
7707                    return null;
7708            }
7709    
7710            /**
7711             * Returns the last document library folder in the ordered set where folderId &gt; &#63; and companyId = &#63; and parentFolderId = &#63; and status &ne; &#63;.
7712             *
7713             * @param folderId the folder ID
7714             * @param companyId the company ID
7715             * @param parentFolderId the parent folder ID
7716             * @param status the status
7717             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7718             * @return the last matching document library folder
7719             * @throws NoSuchFolderException if a matching document library folder could not be found
7720             */
7721            @Override
7722            public DLFolder findByF_C_P_NotS_Last(long folderId, long companyId,
7723                    long parentFolderId, int status,
7724                    OrderByComparator<DLFolder> orderByComparator)
7725                    throws NoSuchFolderException {
7726                    DLFolder dlFolder = fetchByF_C_P_NotS_Last(folderId, companyId,
7727                                    parentFolderId, status, orderByComparator);
7728    
7729                    if (dlFolder != null) {
7730                            return dlFolder;
7731                    }
7732    
7733                    StringBundler msg = new StringBundler(10);
7734    
7735                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7736    
7737                    msg.append("folderId=");
7738                    msg.append(folderId);
7739    
7740                    msg.append(", companyId=");
7741                    msg.append(companyId);
7742    
7743                    msg.append(", parentFolderId=");
7744                    msg.append(parentFolderId);
7745    
7746                    msg.append(", status=");
7747                    msg.append(status);
7748    
7749                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7750    
7751                    throw new NoSuchFolderException(msg.toString());
7752            }
7753    
7754            /**
7755             * Returns the last document library folder in the ordered set where folderId &gt; &#63; and companyId = &#63; and parentFolderId = &#63; and status &ne; &#63;.
7756             *
7757             * @param folderId the folder ID
7758             * @param companyId the company ID
7759             * @param parentFolderId the parent folder ID
7760             * @param status the status
7761             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7762             * @return the last matching document library folder, or <code>null</code> if a matching document library folder could not be found
7763             */
7764            @Override
7765            public DLFolder fetchByF_C_P_NotS_Last(long folderId, long companyId,
7766                    long parentFolderId, int status,
7767                    OrderByComparator<DLFolder> orderByComparator) {
7768                    int count = countByF_C_P_NotS(folderId, companyId, parentFolderId,
7769                                    status);
7770    
7771                    if (count == 0) {
7772                            return null;
7773                    }
7774    
7775                    List<DLFolder> list = findByF_C_P_NotS(folderId, companyId,
7776                                    parentFolderId, status, count - 1, count, orderByComparator);
7777    
7778                    if (!list.isEmpty()) {
7779                            return list.get(0);
7780                    }
7781    
7782                    return null;
7783            }
7784    
7785            /**
7786             * Removes all the document library folders where folderId &gt; &#63; and companyId = &#63; and parentFolderId = &#63; and status &ne; &#63; from the database.
7787             *
7788             * @param folderId the folder ID
7789             * @param companyId the company ID
7790             * @param parentFolderId the parent folder ID
7791             * @param status the status
7792             */
7793            @Override
7794            public void removeByF_C_P_NotS(long folderId, long companyId,
7795                    long parentFolderId, int status) {
7796                    for (DLFolder dlFolder : findByF_C_P_NotS(folderId, companyId,
7797                                    parentFolderId, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
7798                                    null)) {
7799                            remove(dlFolder);
7800                    }
7801            }
7802    
7803            /**
7804             * Returns the number of document library folders where folderId &gt; &#63; and companyId = &#63; and parentFolderId = &#63; and status &ne; &#63;.
7805             *
7806             * @param folderId the folder ID
7807             * @param companyId the company ID
7808             * @param parentFolderId the parent folder ID
7809             * @param status the status
7810             * @return the number of matching document library folders
7811             */
7812            @Override
7813            public int countByF_C_P_NotS(long folderId, long companyId,
7814                    long parentFolderId, int status) {
7815                    FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_F_C_P_NOTS;
7816    
7817                    Object[] finderArgs = new Object[] {
7818                                    folderId, companyId, parentFolderId, status
7819                            };
7820    
7821                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
7822    
7823                    if (count == null) {
7824                            StringBundler query = new StringBundler(5);
7825    
7826                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
7827    
7828                            query.append(_FINDER_COLUMN_F_C_P_NOTS_FOLDERID_2);
7829    
7830                            query.append(_FINDER_COLUMN_F_C_P_NOTS_COMPANYID_2);
7831    
7832                            query.append(_FINDER_COLUMN_F_C_P_NOTS_PARENTFOLDERID_2);
7833    
7834                            query.append(_FINDER_COLUMN_F_C_P_NOTS_STATUS_2);
7835    
7836                            String sql = query.toString();
7837    
7838                            Session session = null;
7839    
7840                            try {
7841                                    session = openSession();
7842    
7843                                    Query q = session.createQuery(sql);
7844    
7845                                    QueryPos qPos = QueryPos.getInstance(q);
7846    
7847                                    qPos.add(folderId);
7848    
7849                                    qPos.add(companyId);
7850    
7851                                    qPos.add(parentFolderId);
7852    
7853                                    qPos.add(status);
7854    
7855                                    count = (Long)q.uniqueResult();
7856    
7857                                    finderCache.putResult(finderPath, finderArgs, count);
7858                            }
7859                            catch (Exception e) {
7860                                    finderCache.removeResult(finderPath, finderArgs);
7861    
7862                                    throw processException(e);
7863                            }
7864                            finally {
7865                                    closeSession(session);
7866                            }
7867                    }
7868    
7869                    return count.intValue();
7870            }
7871    
7872            private static final String _FINDER_COLUMN_F_C_P_NOTS_FOLDERID_2 = "dlFolder.folderId > ? AND ";
7873            private static final String _FINDER_COLUMN_F_C_P_NOTS_COMPANYID_2 = "dlFolder.companyId = ? AND ";
7874            private static final String _FINDER_COLUMN_F_C_P_NOTS_PARENTFOLDERID_2 = "dlFolder.parentFolderId = ? AND ";
7875            private static final String _FINDER_COLUMN_F_C_P_NOTS_STATUS_2 = "dlFolder.status != ?";
7876            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_M_P_H = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
7877                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
7878                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_M_P_H",
7879                            new String[] {
7880                                    Long.class.getName(), Boolean.class.getName(),
7881                                    Long.class.getName(), Boolean.class.getName(),
7882                                    
7883                            Integer.class.getName(), Integer.class.getName(),
7884                                    OrderByComparator.class.getName()
7885                            });
7886            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P_H =
7887                    new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
7888                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
7889                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_M_P_H",
7890                            new String[] {
7891                                    Long.class.getName(), Boolean.class.getName(),
7892                                    Long.class.getName(), Boolean.class.getName()
7893                            },
7894                            DLFolderModelImpl.GROUPID_COLUMN_BITMASK |
7895                            DLFolderModelImpl.MOUNTPOINT_COLUMN_BITMASK |
7896                            DLFolderModelImpl.PARENTFOLDERID_COLUMN_BITMASK |
7897                            DLFolderModelImpl.HIDDEN_COLUMN_BITMASK |
7898                            DLFolderModelImpl.NAME_COLUMN_BITMASK);
7899            public static final FinderPath FINDER_PATH_COUNT_BY_G_M_P_H = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
7900                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
7901                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_M_P_H",
7902                            new String[] {
7903                                    Long.class.getName(), Boolean.class.getName(),
7904                                    Long.class.getName(), Boolean.class.getName()
7905                            });
7906    
7907            /**
7908             * Returns all the document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63;.
7909             *
7910             * @param groupId the group ID
7911             * @param mountPoint the mount point
7912             * @param parentFolderId the parent folder ID
7913             * @param hidden the hidden
7914             * @return the matching document library folders
7915             */
7916            @Override
7917            public List<DLFolder> findByG_M_P_H(long groupId, boolean mountPoint,
7918                    long parentFolderId, boolean hidden) {
7919                    return findByG_M_P_H(groupId, mountPoint, parentFolderId, hidden,
7920                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
7921            }
7922    
7923            /**
7924             * Returns a range of all the document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63;.
7925             *
7926             * <p>
7927             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7928             * </p>
7929             *
7930             * @param groupId the group ID
7931             * @param mountPoint the mount point
7932             * @param parentFolderId the parent folder ID
7933             * @param hidden the hidden
7934             * @param start the lower bound of the range of document library folders
7935             * @param end the upper bound of the range of document library folders (not inclusive)
7936             * @return the range of matching document library folders
7937             */
7938            @Override
7939            public List<DLFolder> findByG_M_P_H(long groupId, boolean mountPoint,
7940                    long parentFolderId, boolean hidden, int start, int end) {
7941                    return findByG_M_P_H(groupId, mountPoint, parentFolderId, hidden,
7942                            start, end, null);
7943            }
7944    
7945            /**
7946             * Returns an ordered range of all the document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63;.
7947             *
7948             * <p>
7949             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7950             * </p>
7951             *
7952             * @param groupId the group ID
7953             * @param mountPoint the mount point
7954             * @param parentFolderId the parent folder ID
7955             * @param hidden the hidden
7956             * @param start the lower bound of the range of document library folders
7957             * @param end the upper bound of the range of document library folders (not inclusive)
7958             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7959             * @return the ordered range of matching document library folders
7960             */
7961            @Override
7962            public List<DLFolder> findByG_M_P_H(long groupId, boolean mountPoint,
7963                    long parentFolderId, boolean hidden, int start, int end,
7964                    OrderByComparator<DLFolder> orderByComparator) {
7965                    return findByG_M_P_H(groupId, mountPoint, parentFolderId, hidden,
7966                            start, end, orderByComparator, true);
7967            }
7968    
7969            /**
7970             * Returns an ordered range of all the document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63;.
7971             *
7972             * <p>
7973             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7974             * </p>
7975             *
7976             * @param groupId the group ID
7977             * @param mountPoint the mount point
7978             * @param parentFolderId the parent folder ID
7979             * @param hidden the hidden
7980             * @param start the lower bound of the range of document library folders
7981             * @param end the upper bound of the range of document library folders (not inclusive)
7982             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7983             * @param retrieveFromCache whether to retrieve from the finder cache
7984             * @return the ordered range of matching document library folders
7985             */
7986            @Override
7987            public List<DLFolder> findByG_M_P_H(long groupId, boolean mountPoint,
7988                    long parentFolderId, boolean hidden, int start, int end,
7989                    OrderByComparator<DLFolder> orderByComparator, boolean retrieveFromCache) {
7990                    boolean pagination = true;
7991                    FinderPath finderPath = null;
7992                    Object[] finderArgs = null;
7993    
7994                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7995                                    (orderByComparator == null)) {
7996                            pagination = false;
7997                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P_H;
7998                            finderArgs = new Object[] {
7999                                            groupId, mountPoint, parentFolderId, hidden
8000                                    };
8001                    }
8002                    else {
8003                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_M_P_H;
8004                            finderArgs = new Object[] {
8005                                            groupId, mountPoint, parentFolderId, hidden,
8006                                            
8007                                            start, end, orderByComparator
8008                                    };
8009                    }
8010    
8011                    List<DLFolder> list = null;
8012    
8013                    if (retrieveFromCache) {
8014                            list = (List<DLFolder>)finderCache.getResult(finderPath,
8015                                            finderArgs, this);
8016    
8017                            if ((list != null) && !list.isEmpty()) {
8018                                    for (DLFolder dlFolder : list) {
8019                                            if ((groupId != dlFolder.getGroupId()) ||
8020                                                            (mountPoint != dlFolder.getMountPoint()) ||
8021                                                            (parentFolderId != dlFolder.getParentFolderId()) ||
8022                                                            (hidden != dlFolder.getHidden())) {
8023                                                    list = null;
8024    
8025                                                    break;
8026                                            }
8027                                    }
8028                            }
8029                    }
8030    
8031                    if (list == null) {
8032                            StringBundler query = null;
8033    
8034                            if (orderByComparator != null) {
8035                                    query = new StringBundler(6 +
8036                                                    (orderByComparator.getOrderByFields().length * 2));
8037                            }
8038                            else {
8039                                    query = new StringBundler(6);
8040                            }
8041    
8042                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
8043    
8044                            query.append(_FINDER_COLUMN_G_M_P_H_GROUPID_2);
8045    
8046                            query.append(_FINDER_COLUMN_G_M_P_H_MOUNTPOINT_2);
8047    
8048                            query.append(_FINDER_COLUMN_G_M_P_H_PARENTFOLDERID_2);
8049    
8050                            query.append(_FINDER_COLUMN_G_M_P_H_HIDDEN_2);
8051    
8052                            if (orderByComparator != null) {
8053                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8054                                            orderByComparator);
8055                            }
8056                            else
8057                             if (pagination) {
8058                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
8059                            }
8060    
8061                            String sql = query.toString();
8062    
8063                            Session session = null;
8064    
8065                            try {
8066                                    session = openSession();
8067    
8068                                    Query q = session.createQuery(sql);
8069    
8070                                    QueryPos qPos = QueryPos.getInstance(q);
8071    
8072                                    qPos.add(groupId);
8073    
8074                                    qPos.add(mountPoint);
8075    
8076                                    qPos.add(parentFolderId);
8077    
8078                                    qPos.add(hidden);
8079    
8080                                    if (!pagination) {
8081                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
8082                                                            start, end, false);
8083    
8084                                            Collections.sort(list);
8085    
8086                                            list = Collections.unmodifiableList(list);
8087                                    }
8088                                    else {
8089                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
8090                                                            start, end);
8091                                    }
8092    
8093                                    cacheResult(list);
8094    
8095                                    finderCache.putResult(finderPath, finderArgs, list);
8096                            }
8097                            catch (Exception e) {
8098                                    finderCache.removeResult(finderPath, finderArgs);
8099    
8100                                    throw processException(e);
8101                            }
8102                            finally {
8103                                    closeSession(session);
8104                            }
8105                    }
8106    
8107                    return list;
8108            }
8109    
8110            /**
8111             * Returns the first document library folder in the ordered set where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63;.
8112             *
8113             * @param groupId the group ID
8114             * @param mountPoint the mount point
8115             * @param parentFolderId the parent folder ID
8116             * @param hidden the hidden
8117             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8118             * @return the first matching document library folder
8119             * @throws NoSuchFolderException if a matching document library folder could not be found
8120             */
8121            @Override
8122            public DLFolder findByG_M_P_H_First(long groupId, boolean mountPoint,
8123                    long parentFolderId, boolean hidden,
8124                    OrderByComparator<DLFolder> orderByComparator)
8125                    throws NoSuchFolderException {
8126                    DLFolder dlFolder = fetchByG_M_P_H_First(groupId, mountPoint,
8127                                    parentFolderId, hidden, orderByComparator);
8128    
8129                    if (dlFolder != null) {
8130                            return dlFolder;
8131                    }
8132    
8133                    StringBundler msg = new StringBundler(10);
8134    
8135                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8136    
8137                    msg.append("groupId=");
8138                    msg.append(groupId);
8139    
8140                    msg.append(", mountPoint=");
8141                    msg.append(mountPoint);
8142    
8143                    msg.append(", parentFolderId=");
8144                    msg.append(parentFolderId);
8145    
8146                    msg.append(", hidden=");
8147                    msg.append(hidden);
8148    
8149                    msg.append(StringPool.CLOSE_CURLY_BRACE);
8150    
8151                    throw new NoSuchFolderException(msg.toString());
8152            }
8153    
8154            /**
8155             * Returns the first document library folder in the ordered set where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63;.
8156             *
8157             * @param groupId the group ID
8158             * @param mountPoint the mount point
8159             * @param parentFolderId the parent folder ID
8160             * @param hidden the hidden
8161             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8162             * @return the first matching document library folder, or <code>null</code> if a matching document library folder could not be found
8163             */
8164            @Override
8165            public DLFolder fetchByG_M_P_H_First(long groupId, boolean mountPoint,
8166                    long parentFolderId, boolean hidden,
8167                    OrderByComparator<DLFolder> orderByComparator) {
8168                    List<DLFolder> list = findByG_M_P_H(groupId, mountPoint,
8169                                    parentFolderId, hidden, 0, 1, orderByComparator);
8170    
8171                    if (!list.isEmpty()) {
8172                            return list.get(0);
8173                    }
8174    
8175                    return null;
8176            }
8177    
8178            /**
8179             * Returns the last document library folder in the ordered set where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63;.
8180             *
8181             * @param groupId the group ID
8182             * @param mountPoint the mount point
8183             * @param parentFolderId the parent folder ID
8184             * @param hidden the hidden
8185             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8186             * @return the last matching document library folder
8187             * @throws NoSuchFolderException if a matching document library folder could not be found
8188             */
8189            @Override
8190            public DLFolder findByG_M_P_H_Last(long groupId, boolean mountPoint,
8191                    long parentFolderId, boolean hidden,
8192                    OrderByComparator<DLFolder> orderByComparator)
8193                    throws NoSuchFolderException {
8194                    DLFolder dlFolder = fetchByG_M_P_H_Last(groupId, mountPoint,
8195                                    parentFolderId, hidden, orderByComparator);
8196    
8197                    if (dlFolder != null) {
8198                            return dlFolder;
8199                    }
8200    
8201                    StringBundler msg = new StringBundler(10);
8202    
8203                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8204    
8205                    msg.append("groupId=");
8206                    msg.append(groupId);
8207    
8208                    msg.append(", mountPoint=");
8209                    msg.append(mountPoint);
8210    
8211                    msg.append(", parentFolderId=");
8212                    msg.append(parentFolderId);
8213    
8214                    msg.append(", hidden=");
8215                    msg.append(hidden);
8216    
8217                    msg.append(StringPool.CLOSE_CURLY_BRACE);
8218    
8219                    throw new NoSuchFolderException(msg.toString());
8220            }
8221    
8222            /**
8223             * Returns the last document library folder in the ordered set where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63;.
8224             *
8225             * @param groupId the group ID
8226             * @param mountPoint the mount point
8227             * @param parentFolderId the parent folder ID
8228             * @param hidden the hidden
8229             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8230             * @return the last matching document library folder, or <code>null</code> if a matching document library folder could not be found
8231             */
8232            @Override
8233            public DLFolder fetchByG_M_P_H_Last(long groupId, boolean mountPoint,
8234                    long parentFolderId, boolean hidden,
8235                    OrderByComparator<DLFolder> orderByComparator) {
8236                    int count = countByG_M_P_H(groupId, mountPoint, parentFolderId, hidden);
8237    
8238                    if (count == 0) {
8239                            return null;
8240                    }
8241    
8242                    List<DLFolder> list = findByG_M_P_H(groupId, mountPoint,
8243                                    parentFolderId, hidden, count - 1, count, orderByComparator);
8244    
8245                    if (!list.isEmpty()) {
8246                            return list.get(0);
8247                    }
8248    
8249                    return null;
8250            }
8251    
8252            /**
8253             * Returns the document library folders before and after the current document library folder in the ordered set where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63;.
8254             *
8255             * @param folderId the primary key of the current document library folder
8256             * @param groupId the group ID
8257             * @param mountPoint the mount point
8258             * @param parentFolderId the parent folder ID
8259             * @param hidden the hidden
8260             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8261             * @return the previous, current, and next document library folder
8262             * @throws NoSuchFolderException if a document library folder with the primary key could not be found
8263             */
8264            @Override
8265            public DLFolder[] findByG_M_P_H_PrevAndNext(long folderId, long groupId,
8266                    boolean mountPoint, long parentFolderId, boolean hidden,
8267                    OrderByComparator<DLFolder> orderByComparator)
8268                    throws NoSuchFolderException {
8269                    DLFolder dlFolder = findByPrimaryKey(folderId);
8270    
8271                    Session session = null;
8272    
8273                    try {
8274                            session = openSession();
8275    
8276                            DLFolder[] array = new DLFolderImpl[3];
8277    
8278                            array[0] = getByG_M_P_H_PrevAndNext(session, dlFolder, groupId,
8279                                            mountPoint, parentFolderId, hidden, orderByComparator, true);
8280    
8281                            array[1] = dlFolder;
8282    
8283                            array[2] = getByG_M_P_H_PrevAndNext(session, dlFolder, groupId,
8284                                            mountPoint, parentFolderId, hidden, orderByComparator, false);
8285    
8286                            return array;
8287                    }
8288                    catch (Exception e) {
8289                            throw processException(e);
8290                    }
8291                    finally {
8292                            closeSession(session);
8293                    }
8294            }
8295    
8296            protected DLFolder getByG_M_P_H_PrevAndNext(Session session,
8297                    DLFolder dlFolder, long groupId, boolean mountPoint,
8298                    long parentFolderId, boolean hidden,
8299                    OrderByComparator<DLFolder> orderByComparator, boolean previous) {
8300                    StringBundler query = null;
8301    
8302                    if (orderByComparator != null) {
8303                            query = new StringBundler(7 +
8304                                            (orderByComparator.getOrderByConditionFields().length * 3) +
8305                                            (orderByComparator.getOrderByFields().length * 3));
8306                    }
8307                    else {
8308                            query = new StringBundler(6);
8309                    }
8310    
8311                    query.append(_SQL_SELECT_DLFOLDER_WHERE);
8312    
8313                    query.append(_FINDER_COLUMN_G_M_P_H_GROUPID_2);
8314    
8315                    query.append(_FINDER_COLUMN_G_M_P_H_MOUNTPOINT_2);
8316    
8317                    query.append(_FINDER_COLUMN_G_M_P_H_PARENTFOLDERID_2);
8318    
8319                    query.append(_FINDER_COLUMN_G_M_P_H_HIDDEN_2);
8320    
8321                    if (orderByComparator != null) {
8322                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
8323    
8324                            if (orderByConditionFields.length > 0) {
8325                                    query.append(WHERE_AND);
8326                            }
8327    
8328                            for (int i = 0; i < orderByConditionFields.length; i++) {
8329                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8330                                    query.append(orderByConditionFields[i]);
8331    
8332                                    if ((i + 1) < orderByConditionFields.length) {
8333                                            if (orderByComparator.isAscending() ^ previous) {
8334                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
8335                                            }
8336                                            else {
8337                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
8338                                            }
8339                                    }
8340                                    else {
8341                                            if (orderByComparator.isAscending() ^ previous) {
8342                                                    query.append(WHERE_GREATER_THAN);
8343                                            }
8344                                            else {
8345                                                    query.append(WHERE_LESSER_THAN);
8346                                            }
8347                                    }
8348                            }
8349    
8350                            query.append(ORDER_BY_CLAUSE);
8351    
8352                            String[] orderByFields = orderByComparator.getOrderByFields();
8353    
8354                            for (int i = 0; i < orderByFields.length; i++) {
8355                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8356                                    query.append(orderByFields[i]);
8357    
8358                                    if ((i + 1) < orderByFields.length) {
8359                                            if (orderByComparator.isAscending() ^ previous) {
8360                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
8361                                            }
8362                                            else {
8363                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
8364                                            }
8365                                    }
8366                                    else {
8367                                            if (orderByComparator.isAscending() ^ previous) {
8368                                                    query.append(ORDER_BY_ASC);
8369                                            }
8370                                            else {
8371                                                    query.append(ORDER_BY_DESC);
8372                                            }
8373                                    }
8374                            }
8375                    }
8376                    else {
8377                            query.append(DLFolderModelImpl.ORDER_BY_JPQL);
8378                    }
8379    
8380                    String sql = query.toString();
8381    
8382                    Query q = session.createQuery(sql);
8383    
8384                    q.setFirstResult(0);
8385                    q.setMaxResults(2);
8386    
8387                    QueryPos qPos = QueryPos.getInstance(q);
8388    
8389                    qPos.add(groupId);
8390    
8391                    qPos.add(mountPoint);
8392    
8393                    qPos.add(parentFolderId);
8394    
8395                    qPos.add(hidden);
8396    
8397                    if (orderByComparator != null) {
8398                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
8399    
8400                            for (Object value : values) {
8401                                    qPos.add(value);
8402                            }
8403                    }
8404    
8405                    List<DLFolder> list = q.list();
8406    
8407                    if (list.size() == 2) {
8408                            return list.get(1);
8409                    }
8410                    else {
8411                            return null;
8412                    }
8413            }
8414    
8415            /**
8416             * Returns all the document library folders that the user has permission to view where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63;.
8417             *
8418             * @param groupId the group ID
8419             * @param mountPoint the mount point
8420             * @param parentFolderId the parent folder ID
8421             * @param hidden the hidden
8422             * @return the matching document library folders that the user has permission to view
8423             */
8424            @Override
8425            public List<DLFolder> filterFindByG_M_P_H(long groupId, boolean mountPoint,
8426                    long parentFolderId, boolean hidden) {
8427                    return filterFindByG_M_P_H(groupId, mountPoint, parentFolderId, hidden,
8428                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
8429            }
8430    
8431            /**
8432             * Returns a range of all the document library folders that the user has permission to view where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63;.
8433             *
8434             * <p>
8435             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8436             * </p>
8437             *
8438             * @param groupId the group ID
8439             * @param mountPoint the mount point
8440             * @param parentFolderId the parent folder ID
8441             * @param hidden the hidden
8442             * @param start the lower bound of the range of document library folders
8443             * @param end the upper bound of the range of document library folders (not inclusive)
8444             * @return the range of matching document library folders that the user has permission to view
8445             */
8446            @Override
8447            public List<DLFolder> filterFindByG_M_P_H(long groupId, boolean mountPoint,
8448                    long parentFolderId, boolean hidden, int start, int end) {
8449                    return filterFindByG_M_P_H(groupId, mountPoint, parentFolderId, hidden,
8450                            start, end, null);
8451            }
8452    
8453            /**
8454             * Returns an ordered range of all the document library folders that the user has permissions to view where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63;.
8455             *
8456             * <p>
8457             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8458             * </p>
8459             *
8460             * @param groupId the group ID
8461             * @param mountPoint the mount point
8462             * @param parentFolderId the parent folder ID
8463             * @param hidden the hidden
8464             * @param start the lower bound of the range of document library folders
8465             * @param end the upper bound of the range of document library folders (not inclusive)
8466             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8467             * @return the ordered range of matching document library folders that the user has permission to view
8468             */
8469            @Override
8470            public List<DLFolder> filterFindByG_M_P_H(long groupId, boolean mountPoint,
8471                    long parentFolderId, boolean hidden, int start, int end,
8472                    OrderByComparator<DLFolder> orderByComparator) {
8473                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8474                            return findByG_M_P_H(groupId, mountPoint, parentFolderId, hidden,
8475                                    start, end, orderByComparator);
8476                    }
8477    
8478                    StringBundler query = null;
8479    
8480                    if (orderByComparator != null) {
8481                            query = new StringBundler(6 +
8482                                            (orderByComparator.getOrderByFields().length * 2));
8483                    }
8484                    else {
8485                            query = new StringBundler(7);
8486                    }
8487    
8488                    if (getDB().isSupportsInlineDistinct()) {
8489                            query.append(_FILTER_SQL_SELECT_DLFOLDER_WHERE);
8490                    }
8491                    else {
8492                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1);
8493                    }
8494    
8495                    query.append(_FINDER_COLUMN_G_M_P_H_GROUPID_2);
8496    
8497                    query.append(_FINDER_COLUMN_G_M_P_H_MOUNTPOINT_2);
8498    
8499                    query.append(_FINDER_COLUMN_G_M_P_H_PARENTFOLDERID_2);
8500    
8501                    query.append(_FINDER_COLUMN_G_M_P_H_HIDDEN_2_SQL);
8502    
8503                    if (!getDB().isSupportsInlineDistinct()) {
8504                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2);
8505                    }
8506    
8507                    if (orderByComparator != null) {
8508                            if (getDB().isSupportsInlineDistinct()) {
8509                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8510                                            orderByComparator, true);
8511                            }
8512                            else {
8513                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
8514                                            orderByComparator, true);
8515                            }
8516                    }
8517                    else {
8518                            if (getDB().isSupportsInlineDistinct()) {
8519                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
8520                            }
8521                            else {
8522                                    query.append(DLFolderModelImpl.ORDER_BY_SQL);
8523                            }
8524                    }
8525    
8526                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8527                                    DLFolder.class.getName(),
8528                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8529    
8530                    Session session = null;
8531    
8532                    try {
8533                            session = openSession();
8534    
8535                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
8536    
8537                            if (getDB().isSupportsInlineDistinct()) {
8538                                    q.addEntity(_FILTER_ENTITY_ALIAS, DLFolderImpl.class);
8539                            }
8540                            else {
8541                                    q.addEntity(_FILTER_ENTITY_TABLE, DLFolderImpl.class);
8542                            }
8543    
8544                            QueryPos qPos = QueryPos.getInstance(q);
8545    
8546                            qPos.add(groupId);
8547    
8548                            qPos.add(mountPoint);
8549    
8550                            qPos.add(parentFolderId);
8551    
8552                            qPos.add(hidden);
8553    
8554                            return (List<DLFolder>)QueryUtil.list(q, getDialect(), start, end);
8555                    }
8556                    catch (Exception e) {
8557                            throw processException(e);
8558                    }
8559                    finally {
8560                            closeSession(session);
8561                    }
8562            }
8563    
8564            /**
8565             * 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 mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63;.
8566             *
8567             * @param folderId the primary key of the current document library folder
8568             * @param groupId the group ID
8569             * @param mountPoint the mount point
8570             * @param parentFolderId the parent folder ID
8571             * @param hidden the hidden
8572             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8573             * @return the previous, current, and next document library folder
8574             * @throws NoSuchFolderException if a document library folder with the primary key could not be found
8575             */
8576            @Override
8577            public DLFolder[] filterFindByG_M_P_H_PrevAndNext(long folderId,
8578                    long groupId, boolean mountPoint, long parentFolderId, boolean hidden,
8579                    OrderByComparator<DLFolder> orderByComparator)
8580                    throws NoSuchFolderException {
8581                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8582                            return findByG_M_P_H_PrevAndNext(folderId, groupId, mountPoint,
8583                                    parentFolderId, hidden, orderByComparator);
8584                    }
8585    
8586                    DLFolder dlFolder = findByPrimaryKey(folderId);
8587    
8588                    Session session = null;
8589    
8590                    try {
8591                            session = openSession();
8592    
8593                            DLFolder[] array = new DLFolderImpl[3];
8594    
8595                            array[0] = filterGetByG_M_P_H_PrevAndNext(session, dlFolder,
8596                                            groupId, mountPoint, parentFolderId, hidden,
8597                                            orderByComparator, true);
8598    
8599                            array[1] = dlFolder;
8600    
8601                            array[2] = filterGetByG_M_P_H_PrevAndNext(session, dlFolder,
8602                                            groupId, mountPoint, parentFolderId, hidden,
8603                                            orderByComparator, false);
8604    
8605                            return array;
8606                    }
8607                    catch (Exception e) {
8608                            throw processException(e);
8609                    }
8610                    finally {
8611                            closeSession(session);
8612                    }
8613            }
8614    
8615            protected DLFolder filterGetByG_M_P_H_PrevAndNext(Session session,
8616                    DLFolder dlFolder, long groupId, boolean mountPoint,
8617                    long parentFolderId, boolean hidden,
8618                    OrderByComparator<DLFolder> orderByComparator, boolean previous) {
8619                    StringBundler query = null;
8620    
8621                    if (orderByComparator != null) {
8622                            query = new StringBundler(8 +
8623                                            (orderByComparator.getOrderByConditionFields().length * 3) +
8624                                            (orderByComparator.getOrderByFields().length * 3));
8625                    }
8626                    else {
8627                            query = new StringBundler(7);
8628                    }
8629    
8630                    if (getDB().isSupportsInlineDistinct()) {
8631                            query.append(_FILTER_SQL_SELECT_DLFOLDER_WHERE);
8632                    }
8633                    else {
8634                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1);
8635                    }
8636    
8637                    query.append(_FINDER_COLUMN_G_M_P_H_GROUPID_2);
8638    
8639                    query.append(_FINDER_COLUMN_G_M_P_H_MOUNTPOINT_2);
8640    
8641                    query.append(_FINDER_COLUMN_G_M_P_H_PARENTFOLDERID_2);
8642    
8643                    query.append(_FINDER_COLUMN_G_M_P_H_HIDDEN_2_SQL);
8644    
8645                    if (!getDB().isSupportsInlineDistinct()) {
8646                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2);
8647                    }
8648    
8649                    if (orderByComparator != null) {
8650                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
8651    
8652                            if (orderByConditionFields.length > 0) {
8653                                    query.append(WHERE_AND);
8654                            }
8655    
8656                            for (int i = 0; i < orderByConditionFields.length; i++) {
8657                                    if (getDB().isSupportsInlineDistinct()) {
8658                                            query.append(_ORDER_BY_ENTITY_ALIAS);
8659                                    }
8660                                    else {
8661                                            query.append(_ORDER_BY_ENTITY_TABLE);
8662                                    }
8663    
8664                                    query.append(orderByConditionFields[i]);
8665    
8666                                    if ((i + 1) < orderByConditionFields.length) {
8667                                            if (orderByComparator.isAscending() ^ previous) {
8668                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
8669                                            }
8670                                            else {
8671                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
8672                                            }
8673                                    }
8674                                    else {
8675                                            if (orderByComparator.isAscending() ^ previous) {
8676                                                    query.append(WHERE_GREATER_THAN);
8677                                            }
8678                                            else {
8679                                                    query.append(WHERE_LESSER_THAN);
8680                                            }
8681                                    }
8682                            }
8683    
8684                            query.append(ORDER_BY_CLAUSE);
8685    
8686                            String[] orderByFields = orderByComparator.getOrderByFields();
8687    
8688                            for (int i = 0; i < orderByFields.length; i++) {
8689                                    if (getDB().isSupportsInlineDistinct()) {
8690                                            query.append(_ORDER_BY_ENTITY_ALIAS);
8691                                    }
8692                                    else {
8693                                            query.append(_ORDER_BY_ENTITY_TABLE);
8694                                    }
8695    
8696                                    query.append(orderByFields[i]);
8697    
8698                                    if ((i + 1) < orderByFields.length) {
8699                                            if (orderByComparator.isAscending() ^ previous) {
8700                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
8701                                            }
8702                                            else {
8703                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
8704                                            }
8705                                    }
8706                                    else {
8707                                            if (orderByComparator.isAscending() ^ previous) {
8708                                                    query.append(ORDER_BY_ASC);
8709                                            }
8710                                            else {
8711                                                    query.append(ORDER_BY_DESC);
8712                                            }
8713                                    }
8714                            }
8715                    }
8716                    else {
8717                            if (getDB().isSupportsInlineDistinct()) {
8718                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
8719                            }
8720                            else {
8721                                    query.append(DLFolderModelImpl.ORDER_BY_SQL);
8722                            }
8723                    }
8724    
8725                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8726                                    DLFolder.class.getName(),
8727                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8728    
8729                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
8730    
8731                    q.setFirstResult(0);
8732                    q.setMaxResults(2);
8733    
8734                    if (getDB().isSupportsInlineDistinct()) {
8735                            q.addEntity(_FILTER_ENTITY_ALIAS, DLFolderImpl.class);
8736                    }
8737                    else {
8738                            q.addEntity(_FILTER_ENTITY_TABLE, DLFolderImpl.class);
8739                    }
8740    
8741                    QueryPos qPos = QueryPos.getInstance(q);
8742    
8743                    qPos.add(groupId);
8744    
8745                    qPos.add(mountPoint);
8746    
8747                    qPos.add(parentFolderId);
8748    
8749                    qPos.add(hidden);
8750    
8751                    if (orderByComparator != null) {
8752                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
8753    
8754                            for (Object value : values) {
8755                                    qPos.add(value);
8756                            }
8757                    }
8758    
8759                    List<DLFolder> list = q.list();
8760    
8761                    if (list.size() == 2) {
8762                            return list.get(1);
8763                    }
8764                    else {
8765                            return null;
8766                    }
8767            }
8768    
8769            /**
8770             * Removes all the document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63; from the database.
8771             *
8772             * @param groupId the group ID
8773             * @param mountPoint the mount point
8774             * @param parentFolderId the parent folder ID
8775             * @param hidden the hidden
8776             */
8777            @Override
8778            public void removeByG_M_P_H(long groupId, boolean mountPoint,
8779                    long parentFolderId, boolean hidden) {
8780                    for (DLFolder dlFolder : findByG_M_P_H(groupId, mountPoint,
8781                                    parentFolderId, hidden, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
8782                                    null)) {
8783                            remove(dlFolder);
8784                    }
8785            }
8786    
8787            /**
8788             * Returns the number of document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63;.
8789             *
8790             * @param groupId the group ID
8791             * @param mountPoint the mount point
8792             * @param parentFolderId the parent folder ID
8793             * @param hidden the hidden
8794             * @return the number of matching document library folders
8795             */
8796            @Override
8797            public int countByG_M_P_H(long groupId, boolean mountPoint,
8798                    long parentFolderId, boolean hidden) {
8799                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_M_P_H;
8800    
8801                    Object[] finderArgs = new Object[] {
8802                                    groupId, mountPoint, parentFolderId, hidden
8803                            };
8804    
8805                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
8806    
8807                    if (count == null) {
8808                            StringBundler query = new StringBundler(5);
8809    
8810                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
8811    
8812                            query.append(_FINDER_COLUMN_G_M_P_H_GROUPID_2);
8813    
8814                            query.append(_FINDER_COLUMN_G_M_P_H_MOUNTPOINT_2);
8815    
8816                            query.append(_FINDER_COLUMN_G_M_P_H_PARENTFOLDERID_2);
8817    
8818                            query.append(_FINDER_COLUMN_G_M_P_H_HIDDEN_2);
8819    
8820                            String sql = query.toString();
8821    
8822                            Session session = null;
8823    
8824                            try {
8825                                    session = openSession();
8826    
8827                                    Query q = session.createQuery(sql);
8828    
8829                                    QueryPos qPos = QueryPos.getInstance(q);
8830    
8831                                    qPos.add(groupId);
8832    
8833                                    qPos.add(mountPoint);
8834    
8835                                    qPos.add(parentFolderId);
8836    
8837                                    qPos.add(hidden);
8838    
8839                                    count = (Long)q.uniqueResult();
8840    
8841                                    finderCache.putResult(finderPath, finderArgs, count);
8842                            }
8843                            catch (Exception e) {
8844                                    finderCache.removeResult(finderPath, finderArgs);
8845    
8846                                    throw processException(e);
8847                            }
8848                            finally {
8849                                    closeSession(session);
8850                            }
8851                    }
8852    
8853                    return count.intValue();
8854            }
8855    
8856            /**
8857             * Returns the number of document library folders that the user has permission to view where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63;.
8858             *
8859             * @param groupId the group ID
8860             * @param mountPoint the mount point
8861             * @param parentFolderId the parent folder ID
8862             * @param hidden the hidden
8863             * @return the number of matching document library folders that the user has permission to view
8864             */
8865            @Override
8866            public int filterCountByG_M_P_H(long groupId, boolean mountPoint,
8867                    long parentFolderId, boolean hidden) {
8868                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8869                            return countByG_M_P_H(groupId, mountPoint, parentFolderId, hidden);
8870                    }
8871    
8872                    StringBundler query = new StringBundler(5);
8873    
8874                    query.append(_FILTER_SQL_COUNT_DLFOLDER_WHERE);
8875    
8876                    query.append(_FINDER_COLUMN_G_M_P_H_GROUPID_2);
8877    
8878                    query.append(_FINDER_COLUMN_G_M_P_H_MOUNTPOINT_2);
8879    
8880                    query.append(_FINDER_COLUMN_G_M_P_H_PARENTFOLDERID_2);
8881    
8882                    query.append(_FINDER_COLUMN_G_M_P_H_HIDDEN_2_SQL);
8883    
8884                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8885                                    DLFolder.class.getName(),
8886                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8887    
8888                    Session session = null;
8889    
8890                    try {
8891                            session = openSession();
8892    
8893                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
8894    
8895                            q.addScalar(COUNT_COLUMN_NAME,
8896                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
8897    
8898                            QueryPos qPos = QueryPos.getInstance(q);
8899    
8900                            qPos.add(groupId);
8901    
8902                            qPos.add(mountPoint);
8903    
8904                            qPos.add(parentFolderId);
8905    
8906                            qPos.add(hidden);
8907    
8908                            Long count = (Long)q.uniqueResult();
8909    
8910                            return count.intValue();
8911                    }
8912                    catch (Exception e) {
8913                            throw processException(e);
8914                    }
8915                    finally {
8916                            closeSession(session);
8917                    }
8918            }
8919    
8920            private static final String _FINDER_COLUMN_G_M_P_H_GROUPID_2 = "dlFolder.groupId = ? AND ";
8921            private static final String _FINDER_COLUMN_G_M_P_H_MOUNTPOINT_2 = "dlFolder.mountPoint = ? AND ";
8922            private static final String _FINDER_COLUMN_G_M_P_H_PARENTFOLDERID_2 = "dlFolder.parentFolderId = ? AND ";
8923            private static final String _FINDER_COLUMN_G_M_P_H_HIDDEN_2 = "dlFolder.hidden = ?";
8924            private static final String _FINDER_COLUMN_G_M_P_H_HIDDEN_2_SQL = "dlFolder.hidden_ = ?";
8925            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_M_T_H = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
8926                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
8927                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_M_T_H",
8928                            new String[] {
8929                                    Long.class.getName(), Boolean.class.getName(),
8930                                    String.class.getName(), Boolean.class.getName(),
8931                                    
8932                            Integer.class.getName(), Integer.class.getName(),
8933                                    OrderByComparator.class.getName()
8934                            });
8935            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_M_T_H = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
8936                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
8937                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_M_T_H",
8938                            new String[] {
8939                                    Long.class.getName(), Boolean.class.getName(),
8940                                    String.class.getName(), Boolean.class.getName()
8941                            });
8942    
8943            /**
8944             * Returns all the document library folders where groupId = &#63; and mountPoint = &#63; and treePath LIKE &#63; and hidden = &#63;.
8945             *
8946             * @param groupId the group ID
8947             * @param mountPoint the mount point
8948             * @param treePath the tree path
8949             * @param hidden the hidden
8950             * @return the matching document library folders
8951             */
8952            @Override
8953            public List<DLFolder> findByG_M_T_H(long groupId, boolean mountPoint,
8954                    String treePath, boolean hidden) {
8955                    return findByG_M_T_H(groupId, mountPoint, treePath, hidden,
8956                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
8957            }
8958    
8959            /**
8960             * Returns a range of all the document library folders where groupId = &#63; and mountPoint = &#63; and treePath LIKE &#63; and hidden = &#63;.
8961             *
8962             * <p>
8963             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8964             * </p>
8965             *
8966             * @param groupId the group ID
8967             * @param mountPoint the mount point
8968             * @param treePath the tree path
8969             * @param hidden the hidden
8970             * @param start the lower bound of the range of document library folders
8971             * @param end the upper bound of the range of document library folders (not inclusive)
8972             * @return the range of matching document library folders
8973             */
8974            @Override
8975            public List<DLFolder> findByG_M_T_H(long groupId, boolean mountPoint,
8976                    String treePath, boolean hidden, int start, int end) {
8977                    return findByG_M_T_H(groupId, mountPoint, treePath, hidden, start, end,
8978                            null);
8979            }
8980    
8981            /**
8982             * Returns an ordered range of all the document library folders where groupId = &#63; and mountPoint = &#63; and treePath LIKE &#63; and hidden = &#63;.
8983             *
8984             * <p>
8985             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8986             * </p>
8987             *
8988             * @param groupId the group ID
8989             * @param mountPoint the mount point
8990             * @param treePath the tree path
8991             * @param hidden the hidden
8992             * @param start the lower bound of the range of document library folders
8993             * @param end the upper bound of the range of document library folders (not inclusive)
8994             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8995             * @return the ordered range of matching document library folders
8996             */
8997            @Override
8998            public List<DLFolder> findByG_M_T_H(long groupId, boolean mountPoint,
8999                    String treePath, boolean hidden, int start, int end,
9000                    OrderByComparator<DLFolder> orderByComparator) {
9001                    return findByG_M_T_H(groupId, mountPoint, treePath, hidden, start, end,
9002                            orderByComparator, true);
9003            }
9004    
9005            /**
9006             * Returns an ordered range of all the document library folders where groupId = &#63; and mountPoint = &#63; and treePath LIKE &#63; and hidden = &#63;.
9007             *
9008             * <p>
9009             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
9010             * </p>
9011             *
9012             * @param groupId the group ID
9013             * @param mountPoint the mount point
9014             * @param treePath the tree path
9015             * @param hidden the hidden
9016             * @param start the lower bound of the range of document library folders
9017             * @param end the upper bound of the range of document library folders (not inclusive)
9018             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9019             * @param retrieveFromCache whether to retrieve from the finder cache
9020             * @return the ordered range of matching document library folders
9021             */
9022            @Override
9023            public List<DLFolder> findByG_M_T_H(long groupId, boolean mountPoint,
9024                    String treePath, boolean hidden, int start, int end,
9025                    OrderByComparator<DLFolder> orderByComparator, boolean retrieveFromCache) {
9026                    boolean pagination = true;
9027                    FinderPath finderPath = null;
9028                    Object[] finderArgs = null;
9029    
9030                    finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_M_T_H;
9031                    finderArgs = new Object[] {
9032                                    groupId, mountPoint, treePath, hidden,
9033                                    
9034                                    start, end, orderByComparator
9035                            };
9036    
9037                    List<DLFolder> list = null;
9038    
9039                    if (retrieveFromCache) {
9040                            list = (List<DLFolder>)finderCache.getResult(finderPath,
9041                                            finderArgs, this);
9042    
9043                            if ((list != null) && !list.isEmpty()) {
9044                                    for (DLFolder dlFolder : list) {
9045                                            if ((groupId != dlFolder.getGroupId()) ||
9046                                                            (mountPoint != dlFolder.getMountPoint()) ||
9047                                                            !StringUtil.wildcardMatches(
9048                                                                    dlFolder.getTreePath(), treePath,
9049                                                                    CharPool.UNDERLINE, CharPool.PERCENT,
9050                                                                    CharPool.BACK_SLASH, true) ||
9051                                                            (hidden != dlFolder.getHidden())) {
9052                                                    list = null;
9053    
9054                                                    break;
9055                                            }
9056                                    }
9057                            }
9058                    }
9059    
9060                    if (list == null) {
9061                            StringBundler query = null;
9062    
9063                            if (orderByComparator != null) {
9064                                    query = new StringBundler(6 +
9065                                                    (orderByComparator.getOrderByFields().length * 2));
9066                            }
9067                            else {
9068                                    query = new StringBundler(6);
9069                            }
9070    
9071                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
9072    
9073                            query.append(_FINDER_COLUMN_G_M_T_H_GROUPID_2);
9074    
9075                            query.append(_FINDER_COLUMN_G_M_T_H_MOUNTPOINT_2);
9076    
9077                            boolean bindTreePath = false;
9078    
9079                            if (treePath == null) {
9080                                    query.append(_FINDER_COLUMN_G_M_T_H_TREEPATH_1);
9081                            }
9082                            else if (treePath.equals(StringPool.BLANK)) {
9083                                    query.append(_FINDER_COLUMN_G_M_T_H_TREEPATH_3);
9084                            }
9085                            else {
9086                                    bindTreePath = true;
9087    
9088                                    query.append(_FINDER_COLUMN_G_M_T_H_TREEPATH_2);
9089                            }
9090    
9091                            query.append(_FINDER_COLUMN_G_M_T_H_HIDDEN_2);
9092    
9093                            if (orderByComparator != null) {
9094                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9095                                            orderByComparator);
9096                            }
9097                            else
9098                             if (pagination) {
9099                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
9100                            }
9101    
9102                            String sql = query.toString();
9103    
9104                            Session session = null;
9105    
9106                            try {
9107                                    session = openSession();
9108    
9109                                    Query q = session.createQuery(sql);
9110    
9111                                    QueryPos qPos = QueryPos.getInstance(q);
9112    
9113                                    qPos.add(groupId);
9114    
9115                                    qPos.add(mountPoint);
9116    
9117                                    if (bindTreePath) {
9118                                            qPos.add(treePath);
9119                                    }
9120    
9121                                    qPos.add(hidden);
9122    
9123                                    if (!pagination) {
9124                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
9125                                                            start, end, false);
9126    
9127                                            Collections.sort(list);
9128    
9129                                            list = Collections.unmodifiableList(list);
9130                                    }
9131                                    else {
9132                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
9133                                                            start, end);
9134                                    }
9135    
9136                                    cacheResult(list);
9137    
9138                                    finderCache.putResult(finderPath, finderArgs, list);
9139                            }
9140                            catch (Exception e) {
9141                                    finderCache.removeResult(finderPath, finderArgs);
9142    
9143                                    throw processException(e);
9144                            }
9145                            finally {
9146                                    closeSession(session);
9147                            }
9148                    }
9149    
9150                    return list;
9151            }
9152    
9153            /**
9154             * Returns the first document library folder in the ordered set where groupId = &#63; and mountPoint = &#63; and treePath LIKE &#63; and hidden = &#63;.
9155             *
9156             * @param groupId the group ID
9157             * @param mountPoint the mount point
9158             * @param treePath the tree path
9159             * @param hidden the hidden
9160             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9161             * @return the first matching document library folder
9162             * @throws NoSuchFolderException if a matching document library folder could not be found
9163             */
9164            @Override
9165            public DLFolder findByG_M_T_H_First(long groupId, boolean mountPoint,
9166                    String treePath, boolean hidden,
9167                    OrderByComparator<DLFolder> orderByComparator)
9168                    throws NoSuchFolderException {
9169                    DLFolder dlFolder = fetchByG_M_T_H_First(groupId, mountPoint, treePath,
9170                                    hidden, orderByComparator);
9171    
9172                    if (dlFolder != null) {
9173                            return dlFolder;
9174                    }
9175    
9176                    StringBundler msg = new StringBundler(10);
9177    
9178                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9179    
9180                    msg.append("groupId=");
9181                    msg.append(groupId);
9182    
9183                    msg.append(", mountPoint=");
9184                    msg.append(mountPoint);
9185    
9186                    msg.append(", treePath=");
9187                    msg.append(treePath);
9188    
9189                    msg.append(", hidden=");
9190                    msg.append(hidden);
9191    
9192                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9193    
9194                    throw new NoSuchFolderException(msg.toString());
9195            }
9196    
9197            /**
9198             * Returns the first document library folder in the ordered set where groupId = &#63; and mountPoint = &#63; and treePath LIKE &#63; and hidden = &#63;.
9199             *
9200             * @param groupId the group ID
9201             * @param mountPoint the mount point
9202             * @param treePath the tree path
9203             * @param hidden the hidden
9204             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9205             * @return the first matching document library folder, or <code>null</code> if a matching document library folder could not be found
9206             */
9207            @Override
9208            public DLFolder fetchByG_M_T_H_First(long groupId, boolean mountPoint,
9209                    String treePath, boolean hidden,
9210                    OrderByComparator<DLFolder> orderByComparator) {
9211                    List<DLFolder> list = findByG_M_T_H(groupId, mountPoint, treePath,
9212                                    hidden, 0, 1, orderByComparator);
9213    
9214                    if (!list.isEmpty()) {
9215                            return list.get(0);
9216                    }
9217    
9218                    return null;
9219            }
9220    
9221            /**
9222             * Returns the last document library folder in the ordered set where groupId = &#63; and mountPoint = &#63; and treePath LIKE &#63; and hidden = &#63;.
9223             *
9224             * @param groupId the group ID
9225             * @param mountPoint the mount point
9226             * @param treePath the tree path
9227             * @param hidden the hidden
9228             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9229             * @return the last matching document library folder
9230             * @throws NoSuchFolderException if a matching document library folder could not be found
9231             */
9232            @Override
9233            public DLFolder findByG_M_T_H_Last(long groupId, boolean mountPoint,
9234                    String treePath, boolean hidden,
9235                    OrderByComparator<DLFolder> orderByComparator)
9236                    throws NoSuchFolderException {
9237                    DLFolder dlFolder = fetchByG_M_T_H_Last(groupId, mountPoint, treePath,
9238                                    hidden, orderByComparator);
9239    
9240                    if (dlFolder != null) {
9241                            return dlFolder;
9242                    }
9243    
9244                    StringBundler msg = new StringBundler(10);
9245    
9246                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9247    
9248                    msg.append("groupId=");
9249                    msg.append(groupId);
9250    
9251                    msg.append(", mountPoint=");
9252                    msg.append(mountPoint);
9253    
9254                    msg.append(", treePath=");
9255                    msg.append(treePath);
9256    
9257                    msg.append(", hidden=");
9258                    msg.append(hidden);
9259    
9260                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9261    
9262                    throw new NoSuchFolderException(msg.toString());
9263            }
9264    
9265            /**
9266             * Returns the last document library folder in the ordered set where groupId = &#63; and mountPoint = &#63; and treePath LIKE &#63; and hidden = &#63;.
9267             *
9268             * @param groupId the group ID
9269             * @param mountPoint the mount point
9270             * @param treePath the tree path
9271             * @param hidden the hidden
9272             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9273             * @return the last matching document library folder, or <code>null</code> if a matching document library folder could not be found
9274             */
9275            @Override
9276            public DLFolder fetchByG_M_T_H_Last(long groupId, boolean mountPoint,
9277                    String treePath, boolean hidden,
9278                    OrderByComparator<DLFolder> orderByComparator) {
9279                    int count = countByG_M_T_H(groupId, mountPoint, treePath, hidden);
9280    
9281                    if (count == 0) {
9282                            return null;
9283                    }
9284    
9285                    List<DLFolder> list = findByG_M_T_H(groupId, mountPoint, treePath,
9286                                    hidden, count - 1, count, orderByComparator);
9287    
9288                    if (!list.isEmpty()) {
9289                            return list.get(0);
9290                    }
9291    
9292                    return null;
9293            }
9294    
9295            /**
9296             * Returns the document library folders before and after the current document library folder in the ordered set where groupId = &#63; and mountPoint = &#63; and treePath LIKE &#63; and hidden = &#63;.
9297             *
9298             * @param folderId the primary key of the current document library folder
9299             * @param groupId the group ID
9300             * @param mountPoint the mount point
9301             * @param treePath the tree path
9302             * @param hidden the hidden
9303             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9304             * @return the previous, current, and next document library folder
9305             * @throws NoSuchFolderException if a document library folder with the primary key could not be found
9306             */
9307            @Override
9308            public DLFolder[] findByG_M_T_H_PrevAndNext(long folderId, long groupId,
9309                    boolean mountPoint, String treePath, boolean hidden,
9310                    OrderByComparator<DLFolder> orderByComparator)
9311                    throws NoSuchFolderException {
9312                    DLFolder dlFolder = findByPrimaryKey(folderId);
9313    
9314                    Session session = null;
9315    
9316                    try {
9317                            session = openSession();
9318    
9319                            DLFolder[] array = new DLFolderImpl[3];
9320    
9321                            array[0] = getByG_M_T_H_PrevAndNext(session, dlFolder, groupId,
9322                                            mountPoint, treePath, hidden, orderByComparator, true);
9323    
9324                            array[1] = dlFolder;
9325    
9326                            array[2] = getByG_M_T_H_PrevAndNext(session, dlFolder, groupId,
9327                                            mountPoint, treePath, hidden, orderByComparator, false);
9328    
9329                            return array;
9330                    }
9331                    catch (Exception e) {
9332                            throw processException(e);
9333                    }
9334                    finally {
9335                            closeSession(session);
9336                    }
9337            }
9338    
9339            protected DLFolder getByG_M_T_H_PrevAndNext(Session session,
9340                    DLFolder dlFolder, long groupId, boolean mountPoint, String treePath,
9341                    boolean hidden, OrderByComparator<DLFolder> orderByComparator,
9342                    boolean previous) {
9343                    StringBundler query = null;
9344    
9345                    if (orderByComparator != null) {
9346                            query = new StringBundler(7 +
9347                                            (orderByComparator.getOrderByConditionFields().length * 3) +
9348                                            (orderByComparator.getOrderByFields().length * 3));
9349                    }
9350                    else {
9351                            query = new StringBundler(6);
9352                    }
9353    
9354                    query.append(_SQL_SELECT_DLFOLDER_WHERE);
9355    
9356                    query.append(_FINDER_COLUMN_G_M_T_H_GROUPID_2);
9357    
9358                    query.append(_FINDER_COLUMN_G_M_T_H_MOUNTPOINT_2);
9359    
9360                    boolean bindTreePath = false;
9361    
9362                    if (treePath == null) {
9363                            query.append(_FINDER_COLUMN_G_M_T_H_TREEPATH_1);
9364                    }
9365                    else if (treePath.equals(StringPool.BLANK)) {
9366                            query.append(_FINDER_COLUMN_G_M_T_H_TREEPATH_3);
9367                    }
9368                    else {
9369                            bindTreePath = true;
9370    
9371                            query.append(_FINDER_COLUMN_G_M_T_H_TREEPATH_2);
9372                    }
9373    
9374                    query.append(_FINDER_COLUMN_G_M_T_H_HIDDEN_2);
9375    
9376                    if (orderByComparator != null) {
9377                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
9378    
9379                            if (orderByConditionFields.length > 0) {
9380                                    query.append(WHERE_AND);
9381                            }
9382    
9383                            for (int i = 0; i < orderByConditionFields.length; i++) {
9384                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9385                                    query.append(orderByConditionFields[i]);
9386    
9387                                    if ((i + 1) < orderByConditionFields.length) {
9388                                            if (orderByComparator.isAscending() ^ previous) {
9389                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
9390                                            }
9391                                            else {
9392                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
9393                                            }
9394                                    }
9395                                    else {
9396                                            if (orderByComparator.isAscending() ^ previous) {
9397                                                    query.append(WHERE_GREATER_THAN);
9398                                            }
9399                                            else {
9400                                                    query.append(WHERE_LESSER_THAN);
9401                                            }
9402                                    }
9403                            }
9404    
9405                            query.append(ORDER_BY_CLAUSE);
9406    
9407                            String[] orderByFields = orderByComparator.getOrderByFields();
9408    
9409                            for (int i = 0; i < orderByFields.length; i++) {
9410                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9411                                    query.append(orderByFields[i]);
9412    
9413                                    if ((i + 1) < orderByFields.length) {
9414                                            if (orderByComparator.isAscending() ^ previous) {
9415                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
9416                                            }
9417                                            else {
9418                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
9419                                            }
9420                                    }
9421                                    else {
9422                                            if (orderByComparator.isAscending() ^ previous) {
9423                                                    query.append(ORDER_BY_ASC);
9424                                            }
9425                                            else {
9426                                                    query.append(ORDER_BY_DESC);
9427                                            }
9428                                    }
9429                            }
9430                    }
9431                    else {
9432                            query.append(DLFolderModelImpl.ORDER_BY_JPQL);
9433                    }
9434    
9435                    String sql = query.toString();
9436    
9437                    Query q = session.createQuery(sql);
9438    
9439                    q.setFirstResult(0);
9440                    q.setMaxResults(2);
9441    
9442                    QueryPos qPos = QueryPos.getInstance(q);
9443    
9444                    qPos.add(groupId);
9445    
9446                    qPos.add(mountPoint);
9447    
9448                    if (bindTreePath) {
9449                            qPos.add(treePath);
9450                    }
9451    
9452                    qPos.add(hidden);
9453    
9454                    if (orderByComparator != null) {
9455                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
9456    
9457                            for (Object value : values) {
9458                                    qPos.add(value);
9459                            }
9460                    }
9461    
9462                    List<DLFolder> list = q.list();
9463    
9464                    if (list.size() == 2) {
9465                            return list.get(1);
9466                    }
9467                    else {
9468                            return null;
9469                    }
9470            }
9471    
9472            /**
9473             * Returns all the document library folders that the user has permission to view where groupId = &#63; and mountPoint = &#63; and treePath LIKE &#63; and hidden = &#63;.
9474             *
9475             * @param groupId the group ID
9476             * @param mountPoint the mount point
9477             * @param treePath the tree path
9478             * @param hidden the hidden
9479             * @return the matching document library folders that the user has permission to view
9480             */
9481            @Override
9482            public List<DLFolder> filterFindByG_M_T_H(long groupId, boolean mountPoint,
9483                    String treePath, boolean hidden) {
9484                    return filterFindByG_M_T_H(groupId, mountPoint, treePath, hidden,
9485                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
9486            }
9487    
9488            /**
9489             * Returns a range of all the document library folders that the user has permission to view where groupId = &#63; and mountPoint = &#63; and treePath LIKE &#63; and hidden = &#63;.
9490             *
9491             * <p>
9492             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
9493             * </p>
9494             *
9495             * @param groupId the group ID
9496             * @param mountPoint the mount point
9497             * @param treePath the tree path
9498             * @param hidden the hidden
9499             * @param start the lower bound of the range of document library folders
9500             * @param end the upper bound of the range of document library folders (not inclusive)
9501             * @return the range of matching document library folders that the user has permission to view
9502             */
9503            @Override
9504            public List<DLFolder> filterFindByG_M_T_H(long groupId, boolean mountPoint,
9505                    String treePath, boolean hidden, int start, int end) {
9506                    return filterFindByG_M_T_H(groupId, mountPoint, treePath, hidden,
9507                            start, end, null);
9508            }
9509    
9510            /**
9511             * Returns an ordered range of all the document library folders that the user has permissions to view where groupId = &#63; and mountPoint = &#63; and treePath LIKE &#63; and hidden = &#63;.
9512             *
9513             * <p>
9514             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
9515             * </p>
9516             *
9517             * @param groupId the group ID
9518             * @param mountPoint the mount point
9519             * @param treePath the tree path
9520             * @param hidden the hidden
9521             * @param start the lower bound of the range of document library folders
9522             * @param end the upper bound of the range of document library folders (not inclusive)
9523             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9524             * @return the ordered range of matching document library folders that the user has permission to view
9525             */
9526            @Override
9527            public List<DLFolder> filterFindByG_M_T_H(long groupId, boolean mountPoint,
9528                    String treePath, boolean hidden, int start, int end,
9529                    OrderByComparator<DLFolder> orderByComparator) {
9530                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
9531                            return findByG_M_T_H(groupId, mountPoint, treePath, hidden, start,
9532                                    end, orderByComparator);
9533                    }
9534    
9535                    StringBundler query = null;
9536    
9537                    if (orderByComparator != null) {
9538                            query = new StringBundler(6 +
9539                                            (orderByComparator.getOrderByFields().length * 2));
9540                    }
9541                    else {
9542                            query = new StringBundler(7);
9543                    }
9544    
9545                    if (getDB().isSupportsInlineDistinct()) {
9546                            query.append(_FILTER_SQL_SELECT_DLFOLDER_WHERE);
9547                    }
9548                    else {
9549                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1);
9550                    }
9551    
9552                    query.append(_FINDER_COLUMN_G_M_T_H_GROUPID_2);
9553    
9554                    query.append(_FINDER_COLUMN_G_M_T_H_MOUNTPOINT_2);
9555    
9556                    boolean bindTreePath = false;
9557    
9558                    if (treePath == null) {
9559                            query.append(_FINDER_COLUMN_G_M_T_H_TREEPATH_1);
9560                    }
9561                    else if (treePath.equals(StringPool.BLANK)) {
9562                            query.append(_FINDER_COLUMN_G_M_T_H_TREEPATH_3);
9563                    }
9564                    else {
9565                            bindTreePath = true;
9566    
9567                            query.append(_FINDER_COLUMN_G_M_T_H_TREEPATH_2);
9568                    }
9569    
9570                    query.append(_FINDER_COLUMN_G_M_T_H_HIDDEN_2_SQL);
9571    
9572                    if (!getDB().isSupportsInlineDistinct()) {
9573                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2);
9574                    }
9575    
9576                    if (orderByComparator != null) {
9577                            if (getDB().isSupportsInlineDistinct()) {
9578                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9579                                            orderByComparator, true);
9580                            }
9581                            else {
9582                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
9583                                            orderByComparator, true);
9584                            }
9585                    }
9586                    else {
9587                            if (getDB().isSupportsInlineDistinct()) {
9588                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
9589                            }
9590                            else {
9591                                    query.append(DLFolderModelImpl.ORDER_BY_SQL);
9592                            }
9593                    }
9594    
9595                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
9596                                    DLFolder.class.getName(),
9597                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
9598    
9599                    Session session = null;
9600    
9601                    try {
9602                            session = openSession();
9603    
9604                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
9605    
9606                            if (getDB().isSupportsInlineDistinct()) {
9607                                    q.addEntity(_FILTER_ENTITY_ALIAS, DLFolderImpl.class);
9608                            }
9609                            else {
9610                                    q.addEntity(_FILTER_ENTITY_TABLE, DLFolderImpl.class);
9611                            }
9612    
9613                            QueryPos qPos = QueryPos.getInstance(q);
9614    
9615                            qPos.add(groupId);
9616    
9617                            qPos.add(mountPoint);
9618    
9619                            if (bindTreePath) {
9620                                    qPos.add(treePath);
9621                            }
9622    
9623                            qPos.add(hidden);
9624    
9625                            return (List<DLFolder>)QueryUtil.list(q, getDialect(), start, end);
9626                    }
9627                    catch (Exception e) {
9628                            throw processException(e);
9629                    }
9630                    finally {
9631                            closeSession(session);
9632                    }
9633            }
9634    
9635            /**
9636             * 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 mountPoint = &#63; and treePath LIKE &#63; and hidden = &#63;.
9637             *
9638             * @param folderId the primary key of the current document library folder
9639             * @param groupId the group ID
9640             * @param mountPoint the mount point
9641             * @param treePath the tree path
9642             * @param hidden the hidden
9643             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9644             * @return the previous, current, and next document library folder
9645             * @throws NoSuchFolderException if a document library folder with the primary key could not be found
9646             */
9647            @Override
9648            public DLFolder[] filterFindByG_M_T_H_PrevAndNext(long folderId,
9649                    long groupId, boolean mountPoint, String treePath, boolean hidden,
9650                    OrderByComparator<DLFolder> orderByComparator)
9651                    throws NoSuchFolderException {
9652                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
9653                            return findByG_M_T_H_PrevAndNext(folderId, groupId, mountPoint,
9654                                    treePath, hidden, orderByComparator);
9655                    }
9656    
9657                    DLFolder dlFolder = findByPrimaryKey(folderId);
9658    
9659                    Session session = null;
9660    
9661                    try {
9662                            session = openSession();
9663    
9664                            DLFolder[] array = new DLFolderImpl[3];
9665    
9666                            array[0] = filterGetByG_M_T_H_PrevAndNext(session, dlFolder,
9667                                            groupId, mountPoint, treePath, hidden, orderByComparator,
9668                                            true);
9669    
9670                            array[1] = dlFolder;
9671    
9672                            array[2] = filterGetByG_M_T_H_PrevAndNext(session, dlFolder,
9673                                            groupId, mountPoint, treePath, hidden, orderByComparator,
9674                                            false);
9675    
9676                            return array;
9677                    }
9678                    catch (Exception e) {
9679                            throw processException(e);
9680                    }
9681                    finally {
9682                            closeSession(session);
9683                    }
9684            }
9685    
9686            protected DLFolder filterGetByG_M_T_H_PrevAndNext(Session session,
9687                    DLFolder dlFolder, long groupId, boolean mountPoint, String treePath,
9688                    boolean hidden, OrderByComparator<DLFolder> orderByComparator,
9689                    boolean previous) {
9690                    StringBundler query = null;
9691    
9692                    if (orderByComparator != null) {
9693                            query = new StringBundler(8 +
9694                                            (orderByComparator.getOrderByConditionFields().length * 3) +
9695                                            (orderByComparator.getOrderByFields().length * 3));
9696                    }
9697                    else {
9698                            query = new StringBundler(7);
9699                    }
9700    
9701                    if (getDB().isSupportsInlineDistinct()) {
9702                            query.append(_FILTER_SQL_SELECT_DLFOLDER_WHERE);
9703                    }
9704                    else {
9705                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1);
9706                    }
9707    
9708                    query.append(_FINDER_COLUMN_G_M_T_H_GROUPID_2);
9709    
9710                    query.append(_FINDER_COLUMN_G_M_T_H_MOUNTPOINT_2);
9711    
9712                    boolean bindTreePath = false;
9713    
9714                    if (treePath == null) {
9715                            query.append(_FINDER_COLUMN_G_M_T_H_TREEPATH_1);
9716                    }
9717                    else if (treePath.equals(StringPool.BLANK)) {
9718                            query.append(_FINDER_COLUMN_G_M_T_H_TREEPATH_3);
9719                    }
9720                    else {
9721                            bindTreePath = true;
9722    
9723                            query.append(_FINDER_COLUMN_G_M_T_H_TREEPATH_2);
9724                    }
9725    
9726                    query.append(_FINDER_COLUMN_G_M_T_H_HIDDEN_2_SQL);
9727    
9728                    if (!getDB().isSupportsInlineDistinct()) {
9729                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2);
9730                    }
9731    
9732                    if (orderByComparator != null) {
9733                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
9734    
9735                            if (orderByConditionFields.length > 0) {
9736                                    query.append(WHERE_AND);
9737                            }
9738    
9739                            for (int i = 0; i < orderByConditionFields.length; i++) {
9740                                    if (getDB().isSupportsInlineDistinct()) {
9741                                            query.append(_ORDER_BY_ENTITY_ALIAS);
9742                                    }
9743                                    else {
9744                                            query.append(_ORDER_BY_ENTITY_TABLE);
9745                                    }
9746    
9747                                    query.append(orderByConditionFields[i]);
9748    
9749                                    if ((i + 1) < orderByConditionFields.length) {
9750                                            if (orderByComparator.isAscending() ^ previous) {
9751                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
9752                                            }
9753                                            else {
9754                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
9755                                            }
9756                                    }
9757                                    else {
9758                                            if (orderByComparator.isAscending() ^ previous) {
9759                                                    query.append(WHERE_GREATER_THAN);
9760                                            }
9761                                            else {
9762                                                    query.append(WHERE_LESSER_THAN);
9763                                            }
9764                                    }
9765                            }
9766    
9767                            query.append(ORDER_BY_CLAUSE);
9768    
9769                            String[] orderByFields = orderByComparator.getOrderByFields();
9770    
9771                            for (int i = 0; i < orderByFields.length; i++) {
9772                                    if (getDB().isSupportsInlineDistinct()) {
9773                                            query.append(_ORDER_BY_ENTITY_ALIAS);
9774                                    }
9775                                    else {
9776                                            query.append(_ORDER_BY_ENTITY_TABLE);
9777                                    }
9778    
9779                                    query.append(orderByFields[i]);
9780    
9781                                    if ((i + 1) < orderByFields.length) {
9782                                            if (orderByComparator.isAscending() ^ previous) {
9783                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
9784                                            }
9785                                            else {
9786                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
9787                                            }
9788                                    }
9789                                    else {
9790                                            if (orderByComparator.isAscending() ^ previous) {
9791                                                    query.append(ORDER_BY_ASC);
9792                                            }
9793                                            else {
9794                                                    query.append(ORDER_BY_DESC);
9795                                            }
9796                                    }
9797                            }
9798                    }
9799                    else {
9800                            if (getDB().isSupportsInlineDistinct()) {
9801                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
9802                            }
9803                            else {
9804                                    query.append(DLFolderModelImpl.ORDER_BY_SQL);
9805                            }
9806                    }
9807    
9808                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
9809                                    DLFolder.class.getName(),
9810                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
9811    
9812                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
9813    
9814                    q.setFirstResult(0);
9815                    q.setMaxResults(2);
9816    
9817                    if (getDB().isSupportsInlineDistinct()) {
9818                            q.addEntity(_FILTER_ENTITY_ALIAS, DLFolderImpl.class);
9819                    }
9820                    else {
9821                            q.addEntity(_FILTER_ENTITY_TABLE, DLFolderImpl.class);
9822                    }
9823    
9824                    QueryPos qPos = QueryPos.getInstance(q);
9825    
9826                    qPos.add(groupId);
9827    
9828                    qPos.add(mountPoint);
9829    
9830                    if (bindTreePath) {
9831                            qPos.add(treePath);
9832                    }
9833    
9834                    qPos.add(hidden);
9835    
9836                    if (orderByComparator != null) {
9837                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
9838    
9839                            for (Object value : values) {
9840                                    qPos.add(value);
9841                            }
9842                    }
9843    
9844                    List<DLFolder> list = q.list();
9845    
9846                    if (list.size() == 2) {
9847                            return list.get(1);
9848                    }
9849                    else {
9850                            return null;
9851                    }
9852            }
9853    
9854            /**
9855             * Removes all the document library folders where groupId = &#63; and mountPoint = &#63; and treePath LIKE &#63; and hidden = &#63; from the database.
9856             *
9857             * @param groupId the group ID
9858             * @param mountPoint the mount point
9859             * @param treePath the tree path
9860             * @param hidden the hidden
9861             */
9862            @Override
9863            public void removeByG_M_T_H(long groupId, boolean mountPoint,
9864                    String treePath, boolean hidden) {
9865                    for (DLFolder dlFolder : findByG_M_T_H(groupId, mountPoint, treePath,
9866                                    hidden, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
9867                            remove(dlFolder);
9868                    }
9869            }
9870    
9871            /**
9872             * Returns the number of document library folders where groupId = &#63; and mountPoint = &#63; and treePath LIKE &#63; and hidden = &#63;.
9873             *
9874             * @param groupId the group ID
9875             * @param mountPoint the mount point
9876             * @param treePath the tree path
9877             * @param hidden the hidden
9878             * @return the number of matching document library folders
9879             */
9880            @Override
9881            public int countByG_M_T_H(long groupId, boolean mountPoint,
9882                    String treePath, boolean hidden) {
9883                    FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_M_T_H;
9884    
9885                    Object[] finderArgs = new Object[] { groupId, mountPoint, treePath, hidden };
9886    
9887                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
9888    
9889                    if (count == null) {
9890                            StringBundler query = new StringBundler(5);
9891    
9892                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
9893    
9894                            query.append(_FINDER_COLUMN_G_M_T_H_GROUPID_2);
9895    
9896                            query.append(_FINDER_COLUMN_G_M_T_H_MOUNTPOINT_2);
9897    
9898                            boolean bindTreePath = false;
9899    
9900                            if (treePath == null) {
9901                                    query.append(_FINDER_COLUMN_G_M_T_H_TREEPATH_1);
9902                            }
9903                            else if (treePath.equals(StringPool.BLANK)) {
9904                                    query.append(_FINDER_COLUMN_G_M_T_H_TREEPATH_3);
9905                            }
9906                            else {
9907                                    bindTreePath = true;
9908    
9909                                    query.append(_FINDER_COLUMN_G_M_T_H_TREEPATH_2);
9910                            }
9911    
9912                            query.append(_FINDER_COLUMN_G_M_T_H_HIDDEN_2);
9913    
9914                            String sql = query.toString();
9915    
9916                            Session session = null;
9917    
9918                            try {
9919                                    session = openSession();
9920    
9921                                    Query q = session.createQuery(sql);
9922    
9923                                    QueryPos qPos = QueryPos.getInstance(q);
9924    
9925                                    qPos.add(groupId);
9926    
9927                                    qPos.add(mountPoint);
9928    
9929                                    if (bindTreePath) {
9930                                            qPos.add(treePath);
9931                                    }
9932    
9933                                    qPos.add(hidden);
9934    
9935                                    count = (Long)q.uniqueResult();
9936    
9937                                    finderCache.putResult(finderPath, finderArgs, count);
9938                            }
9939                            catch (Exception e) {
9940                                    finderCache.removeResult(finderPath, finderArgs);
9941    
9942                                    throw processException(e);
9943                            }
9944                            finally {
9945                                    closeSession(session);
9946                            }
9947                    }
9948    
9949                    return count.intValue();
9950            }
9951    
9952            /**
9953             * Returns the number of document library folders that the user has permission to view where groupId = &#63; and mountPoint = &#63; and treePath LIKE &#63; and hidden = &#63;.
9954             *
9955             * @param groupId the group ID
9956             * @param mountPoint the mount point
9957             * @param treePath the tree path
9958             * @param hidden the hidden
9959             * @return the number of matching document library folders that the user has permission to view
9960             */
9961            @Override
9962            public int filterCountByG_M_T_H(long groupId, boolean mountPoint,
9963                    String treePath, boolean hidden) {
9964                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
9965                            return countByG_M_T_H(groupId, mountPoint, treePath, hidden);
9966                    }
9967    
9968                    StringBundler query = new StringBundler(5);
9969    
9970                    query.append(_FILTER_SQL_COUNT_DLFOLDER_WHERE);
9971    
9972                    query.append(_FINDER_COLUMN_G_M_T_H_GROUPID_2);
9973    
9974                    query.append(_FINDER_COLUMN_G_M_T_H_MOUNTPOINT_2);
9975    
9976                    boolean bindTreePath = false;
9977    
9978                    if (treePath == null) {
9979                            query.append(_FINDER_COLUMN_G_M_T_H_TREEPATH_1);
9980                    }
9981                    else if (treePath.equals(StringPool.BLANK)) {
9982                            query.append(_FINDER_COLUMN_G_M_T_H_TREEPATH_3);
9983                    }
9984                    else {
9985                            bindTreePath = true;
9986    
9987                            query.append(_FINDER_COLUMN_G_M_T_H_TREEPATH_2);
9988                    }
9989    
9990                    query.append(_FINDER_COLUMN_G_M_T_H_HIDDEN_2_SQL);
9991    
9992                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
9993                                    DLFolder.class.getName(),
9994                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
9995    
9996                    Session session = null;
9997    
9998                    try {
9999                            session = openSession();
10000    
10001                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
10002    
10003                            q.addScalar(COUNT_COLUMN_NAME,
10004                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
10005    
10006                            QueryPos qPos = QueryPos.getInstance(q);
10007    
10008                            qPos.add(groupId);
10009    
10010                            qPos.add(mountPoint);
10011    
10012                            if (bindTreePath) {
10013                                    qPos.add(treePath);
10014                            }
10015    
10016                            qPos.add(hidden);
10017    
10018                            Long count = (Long)q.uniqueResult();
10019    
10020                            return count.intValue();
10021                    }
10022                    catch (Exception e) {
10023                            throw processException(e);
10024                    }
10025                    finally {
10026                            closeSession(session);
10027                    }
10028            }
10029    
10030            private static final String _FINDER_COLUMN_G_M_T_H_GROUPID_2 = "dlFolder.groupId = ? AND ";
10031            private static final String _FINDER_COLUMN_G_M_T_H_MOUNTPOINT_2 = "dlFolder.mountPoint = ? AND ";
10032            private static final String _FINDER_COLUMN_G_M_T_H_TREEPATH_1 = "dlFolder.treePath IS NULL AND ";
10033            private static final String _FINDER_COLUMN_G_M_T_H_TREEPATH_2 = "dlFolder.treePath LIKE ? AND ";
10034            private static final String _FINDER_COLUMN_G_M_T_H_TREEPATH_3 = "(dlFolder.treePath IS NULL OR dlFolder.treePath LIKE '') AND ";
10035            private static final String _FINDER_COLUMN_G_M_T_H_HIDDEN_2 = "dlFolder.hidden = ?";
10036            private static final String _FINDER_COLUMN_G_M_T_H_HIDDEN_2_SQL = "dlFolder.hidden_ = ?";
10037            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_H_S = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
10038                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
10039                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_P_H_S",
10040                            new String[] {
10041                                    Long.class.getName(), Long.class.getName(),
10042                                    Boolean.class.getName(), Integer.class.getName(),
10043                                    
10044                            Integer.class.getName(), Integer.class.getName(),
10045                                    OrderByComparator.class.getName()
10046                            });
10047            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_H_S =
10048                    new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
10049                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
10050                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_P_H_S",
10051                            new String[] {
10052                                    Long.class.getName(), Long.class.getName(),
10053                                    Boolean.class.getName(), Integer.class.getName()
10054                            },
10055                            DLFolderModelImpl.GROUPID_COLUMN_BITMASK |
10056                            DLFolderModelImpl.PARENTFOLDERID_COLUMN_BITMASK |
10057                            DLFolderModelImpl.HIDDEN_COLUMN_BITMASK |
10058                            DLFolderModelImpl.STATUS_COLUMN_BITMASK |
10059                            DLFolderModelImpl.NAME_COLUMN_BITMASK);
10060            public static final FinderPath FINDER_PATH_COUNT_BY_G_P_H_S = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
10061                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
10062                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P_H_S",
10063                            new String[] {
10064                                    Long.class.getName(), Long.class.getName(),
10065                                    Boolean.class.getName(), Integer.class.getName()
10066                            });
10067    
10068            /**
10069             * Returns all the document library folders where groupId = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
10070             *
10071             * @param groupId the group ID
10072             * @param parentFolderId the parent folder ID
10073             * @param hidden the hidden
10074             * @param status the status
10075             * @return the matching document library folders
10076             */
10077            @Override
10078            public List<DLFolder> findByG_P_H_S(long groupId, long parentFolderId,
10079                    boolean hidden, int status) {
10080                    return findByG_P_H_S(groupId, parentFolderId, hidden, status,
10081                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
10082            }
10083    
10084            /**
10085             * Returns a range of all the document library folders where groupId = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
10086             *
10087             * <p>
10088             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
10089             * </p>
10090             *
10091             * @param groupId the group ID
10092             * @param parentFolderId the parent folder ID
10093             * @param hidden the hidden
10094             * @param status the status
10095             * @param start the lower bound of the range of document library folders
10096             * @param end the upper bound of the range of document library folders (not inclusive)
10097             * @return the range of matching document library folders
10098             */
10099            @Override
10100            public List<DLFolder> findByG_P_H_S(long groupId, long parentFolderId,
10101                    boolean hidden, int status, int start, int end) {
10102                    return findByG_P_H_S(groupId, parentFolderId, hidden, status, start,
10103                            end, null);
10104            }
10105    
10106            /**
10107             * Returns an ordered range of all the document library folders where groupId = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
10108             *
10109             * <p>
10110             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
10111             * </p>
10112             *
10113             * @param groupId the group ID
10114             * @param parentFolderId the parent folder ID
10115             * @param hidden the hidden
10116             * @param status the status
10117             * @param start the lower bound of the range of document library folders
10118             * @param end the upper bound of the range of document library folders (not inclusive)
10119             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10120             * @return the ordered range of matching document library folders
10121             */
10122            @Override
10123            public List<DLFolder> findByG_P_H_S(long groupId, long parentFolderId,
10124                    boolean hidden, int status, int start, int end,
10125                    OrderByComparator<DLFolder> orderByComparator) {
10126                    return findByG_P_H_S(groupId, parentFolderId, hidden, status, start,
10127                            end, orderByComparator, true);
10128            }
10129    
10130            /**
10131             * Returns an ordered range of all the document library folders where groupId = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
10132             *
10133             * <p>
10134             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
10135             * </p>
10136             *
10137             * @param groupId the group ID
10138             * @param parentFolderId the parent folder ID
10139             * @param hidden the hidden
10140             * @param status the status
10141             * @param start the lower bound of the range of document library folders
10142             * @param end the upper bound of the range of document library folders (not inclusive)
10143             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10144             * @param retrieveFromCache whether to retrieve from the finder cache
10145             * @return the ordered range of matching document library folders
10146             */
10147            @Override
10148            public List<DLFolder> findByG_P_H_S(long groupId, long parentFolderId,
10149                    boolean hidden, int status, int start, int end,
10150                    OrderByComparator<DLFolder> orderByComparator, boolean retrieveFromCache) {
10151                    boolean pagination = true;
10152                    FinderPath finderPath = null;
10153                    Object[] finderArgs = null;
10154    
10155                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
10156                                    (orderByComparator == null)) {
10157                            pagination = false;
10158                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_H_S;
10159                            finderArgs = new Object[] { groupId, parentFolderId, hidden, status };
10160                    }
10161                    else {
10162                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_H_S;
10163                            finderArgs = new Object[] {
10164                                            groupId, parentFolderId, hidden, status,
10165                                            
10166                                            start, end, orderByComparator
10167                                    };
10168                    }
10169    
10170                    List<DLFolder> list = null;
10171    
10172                    if (retrieveFromCache) {
10173                            list = (List<DLFolder>)finderCache.getResult(finderPath,
10174                                            finderArgs, this);
10175    
10176                            if ((list != null) && !list.isEmpty()) {
10177                                    for (DLFolder dlFolder : list) {
10178                                            if ((groupId != dlFolder.getGroupId()) ||
10179                                                            (parentFolderId != dlFolder.getParentFolderId()) ||
10180                                                            (hidden != dlFolder.getHidden()) ||
10181                                                            (status != dlFolder.getStatus())) {
10182                                                    list = null;
10183    
10184                                                    break;
10185                                            }
10186                                    }
10187                            }
10188                    }
10189    
10190                    if (list == null) {
10191                            StringBundler query = null;
10192    
10193                            if (orderByComparator != null) {
10194                                    query = new StringBundler(6 +
10195                                                    (orderByComparator.getOrderByFields().length * 2));
10196                            }
10197                            else {
10198                                    query = new StringBundler(6);
10199                            }
10200    
10201                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
10202    
10203                            query.append(_FINDER_COLUMN_G_P_H_S_GROUPID_2);
10204    
10205                            query.append(_FINDER_COLUMN_G_P_H_S_PARENTFOLDERID_2);
10206    
10207                            query.append(_FINDER_COLUMN_G_P_H_S_HIDDEN_2);
10208    
10209                            query.append(_FINDER_COLUMN_G_P_H_S_STATUS_2);
10210    
10211                            if (orderByComparator != null) {
10212                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10213                                            orderByComparator);
10214                            }
10215                            else
10216                             if (pagination) {
10217                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
10218                            }
10219    
10220                            String sql = query.toString();
10221    
10222                            Session session = null;
10223    
10224                            try {
10225                                    session = openSession();
10226    
10227                                    Query q = session.createQuery(sql);
10228    
10229                                    QueryPos qPos = QueryPos.getInstance(q);
10230    
10231                                    qPos.add(groupId);
10232    
10233                                    qPos.add(parentFolderId);
10234    
10235                                    qPos.add(hidden);
10236    
10237                                    qPos.add(status);
10238    
10239                                    if (!pagination) {
10240                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
10241                                                            start, end, false);
10242    
10243                                            Collections.sort(list);
10244    
10245                                            list = Collections.unmodifiableList(list);
10246                                    }
10247                                    else {
10248                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
10249                                                            start, end);
10250                                    }
10251    
10252                                    cacheResult(list);
10253    
10254                                    finderCache.putResult(finderPath, finderArgs, list);
10255                            }
10256                            catch (Exception e) {
10257                                    finderCache.removeResult(finderPath, finderArgs);
10258    
10259                                    throw processException(e);
10260                            }
10261                            finally {
10262                                    closeSession(session);
10263                            }
10264                    }
10265    
10266                    return list;
10267            }
10268    
10269            /**
10270             * Returns the first document library folder in the ordered set where groupId = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
10271             *
10272             * @param groupId the group ID
10273             * @param parentFolderId the parent folder ID
10274             * @param hidden the hidden
10275             * @param status the status
10276             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10277             * @return the first matching document library folder
10278             * @throws NoSuchFolderException if a matching document library folder could not be found
10279             */
10280            @Override
10281            public DLFolder findByG_P_H_S_First(long groupId, long parentFolderId,
10282                    boolean hidden, int status,
10283                    OrderByComparator<DLFolder> orderByComparator)
10284                    throws NoSuchFolderException {
10285                    DLFolder dlFolder = fetchByG_P_H_S_First(groupId, parentFolderId,
10286                                    hidden, status, orderByComparator);
10287    
10288                    if (dlFolder != null) {
10289                            return dlFolder;
10290                    }
10291    
10292                    StringBundler msg = new StringBundler(10);
10293    
10294                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10295    
10296                    msg.append("groupId=");
10297                    msg.append(groupId);
10298    
10299                    msg.append(", parentFolderId=");
10300                    msg.append(parentFolderId);
10301    
10302                    msg.append(", hidden=");
10303                    msg.append(hidden);
10304    
10305                    msg.append(", status=");
10306                    msg.append(status);
10307    
10308                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10309    
10310                    throw new NoSuchFolderException(msg.toString());
10311            }
10312    
10313            /**
10314             * Returns the first document library folder in the ordered set where groupId = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
10315             *
10316             * @param groupId the group ID
10317             * @param parentFolderId the parent folder ID
10318             * @param hidden the hidden
10319             * @param status the status
10320             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10321             * @return the first matching document library folder, or <code>null</code> if a matching document library folder could not be found
10322             */
10323            @Override
10324            public DLFolder fetchByG_P_H_S_First(long groupId, long parentFolderId,
10325                    boolean hidden, int status,
10326                    OrderByComparator<DLFolder> orderByComparator) {
10327                    List<DLFolder> list = findByG_P_H_S(groupId, parentFolderId, hidden,
10328                                    status, 0, 1, orderByComparator);
10329    
10330                    if (!list.isEmpty()) {
10331                            return list.get(0);
10332                    }
10333    
10334                    return null;
10335            }
10336    
10337            /**
10338             * Returns the last document library folder in the ordered set where groupId = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
10339             *
10340             * @param groupId the group ID
10341             * @param parentFolderId the parent folder ID
10342             * @param hidden the hidden
10343             * @param status the status
10344             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10345             * @return the last matching document library folder
10346             * @throws NoSuchFolderException if a matching document library folder could not be found
10347             */
10348            @Override
10349            public DLFolder findByG_P_H_S_Last(long groupId, long parentFolderId,
10350                    boolean hidden, int status,
10351                    OrderByComparator<DLFolder> orderByComparator)
10352                    throws NoSuchFolderException {
10353                    DLFolder dlFolder = fetchByG_P_H_S_Last(groupId, parentFolderId,
10354                                    hidden, status, orderByComparator);
10355    
10356                    if (dlFolder != null) {
10357                            return dlFolder;
10358                    }
10359    
10360                    StringBundler msg = new StringBundler(10);
10361    
10362                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10363    
10364                    msg.append("groupId=");
10365                    msg.append(groupId);
10366    
10367                    msg.append(", parentFolderId=");
10368                    msg.append(parentFolderId);
10369    
10370                    msg.append(", hidden=");
10371                    msg.append(hidden);
10372    
10373                    msg.append(", status=");
10374                    msg.append(status);
10375    
10376                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10377    
10378                    throw new NoSuchFolderException(msg.toString());
10379            }
10380    
10381            /**
10382             * Returns the last document library folder in the ordered set where groupId = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
10383             *
10384             * @param groupId the group ID
10385             * @param parentFolderId the parent folder ID
10386             * @param hidden the hidden
10387             * @param status the status
10388             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10389             * @return the last matching document library folder, or <code>null</code> if a matching document library folder could not be found
10390             */
10391            @Override
10392            public DLFolder fetchByG_P_H_S_Last(long groupId, long parentFolderId,
10393                    boolean hidden, int status,
10394                    OrderByComparator<DLFolder> orderByComparator) {
10395                    int count = countByG_P_H_S(groupId, parentFolderId, hidden, status);
10396    
10397                    if (count == 0) {
10398                            return null;
10399                    }
10400    
10401                    List<DLFolder> list = findByG_P_H_S(groupId, parentFolderId, hidden,
10402                                    status, count - 1, count, orderByComparator);
10403    
10404                    if (!list.isEmpty()) {
10405                            return list.get(0);
10406                    }
10407    
10408                    return null;
10409            }
10410    
10411            /**
10412             * Returns the document library folders before and after the current document library folder in the ordered set where groupId = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
10413             *
10414             * @param folderId the primary key of the current document library folder
10415             * @param groupId the group ID
10416             * @param parentFolderId the parent folder ID
10417             * @param hidden the hidden
10418             * @param status the status
10419             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10420             * @return the previous, current, and next document library folder
10421             * @throws NoSuchFolderException if a document library folder with the primary key could not be found
10422             */
10423            @Override
10424            public DLFolder[] findByG_P_H_S_PrevAndNext(long folderId, long groupId,
10425                    long parentFolderId, boolean hidden, int status,
10426                    OrderByComparator<DLFolder> orderByComparator)
10427                    throws NoSuchFolderException {
10428                    DLFolder dlFolder = findByPrimaryKey(folderId);
10429    
10430                    Session session = null;
10431    
10432                    try {
10433                            session = openSession();
10434    
10435                            DLFolder[] array = new DLFolderImpl[3];
10436    
10437                            array[0] = getByG_P_H_S_PrevAndNext(session, dlFolder, groupId,
10438                                            parentFolderId, hidden, status, orderByComparator, true);
10439    
10440                            array[1] = dlFolder;
10441    
10442                            array[2] = getByG_P_H_S_PrevAndNext(session, dlFolder, groupId,
10443                                            parentFolderId, hidden, status, orderByComparator, false);
10444    
10445                            return array;
10446                    }
10447                    catch (Exception e) {
10448                            throw processException(e);
10449                    }
10450                    finally {
10451                            closeSession(session);
10452                    }
10453            }
10454    
10455            protected DLFolder getByG_P_H_S_PrevAndNext(Session session,
10456                    DLFolder dlFolder, long groupId, long parentFolderId, boolean hidden,
10457                    int status, OrderByComparator<DLFolder> orderByComparator,
10458                    boolean previous) {
10459                    StringBundler query = null;
10460    
10461                    if (orderByComparator != null) {
10462                            query = new StringBundler(7 +
10463                                            (orderByComparator.getOrderByConditionFields().length * 3) +
10464                                            (orderByComparator.getOrderByFields().length * 3));
10465                    }
10466                    else {
10467                            query = new StringBundler(6);
10468                    }
10469    
10470                    query.append(_SQL_SELECT_DLFOLDER_WHERE);
10471    
10472                    query.append(_FINDER_COLUMN_G_P_H_S_GROUPID_2);
10473    
10474                    query.append(_FINDER_COLUMN_G_P_H_S_PARENTFOLDERID_2);
10475    
10476                    query.append(_FINDER_COLUMN_G_P_H_S_HIDDEN_2);
10477    
10478                    query.append(_FINDER_COLUMN_G_P_H_S_STATUS_2);
10479    
10480                    if (orderByComparator != null) {
10481                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
10482    
10483                            if (orderByConditionFields.length > 0) {
10484                                    query.append(WHERE_AND);
10485                            }
10486    
10487                            for (int i = 0; i < orderByConditionFields.length; i++) {
10488                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10489                                    query.append(orderByConditionFields[i]);
10490    
10491                                    if ((i + 1) < orderByConditionFields.length) {
10492                                            if (orderByComparator.isAscending() ^ previous) {
10493                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
10494                                            }
10495                                            else {
10496                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
10497                                            }
10498                                    }
10499                                    else {
10500                                            if (orderByComparator.isAscending() ^ previous) {
10501                                                    query.append(WHERE_GREATER_THAN);
10502                                            }
10503                                            else {
10504                                                    query.append(WHERE_LESSER_THAN);
10505                                            }
10506                                    }
10507                            }
10508    
10509                            query.append(ORDER_BY_CLAUSE);
10510    
10511                            String[] orderByFields = orderByComparator.getOrderByFields();
10512    
10513                            for (int i = 0; i < orderByFields.length; i++) {
10514                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10515                                    query.append(orderByFields[i]);
10516    
10517                                    if ((i + 1) < orderByFields.length) {
10518                                            if (orderByComparator.isAscending() ^ previous) {
10519                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
10520                                            }
10521                                            else {
10522                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
10523                                            }
10524                                    }
10525                                    else {
10526                                            if (orderByComparator.isAscending() ^ previous) {
10527                                                    query.append(ORDER_BY_ASC);
10528                                            }
10529                                            else {
10530                                                    query.append(ORDER_BY_DESC);
10531                                            }
10532                                    }
10533                            }
10534                    }
10535                    else {
10536                            query.append(DLFolderModelImpl.ORDER_BY_JPQL);
10537                    }
10538    
10539                    String sql = query.toString();
10540    
10541                    Query q = session.createQuery(sql);
10542    
10543                    q.setFirstResult(0);
10544                    q.setMaxResults(2);
10545    
10546                    QueryPos qPos = QueryPos.getInstance(q);
10547    
10548                    qPos.add(groupId);
10549    
10550                    qPos.add(parentFolderId);
10551    
10552                    qPos.add(hidden);
10553    
10554                    qPos.add(status);
10555    
10556                    if (orderByComparator != null) {
10557                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
10558    
10559                            for (Object value : values) {
10560                                    qPos.add(value);
10561                            }
10562                    }
10563    
10564                    List<DLFolder> list = q.list();
10565    
10566                    if (list.size() == 2) {
10567                            return list.get(1);
10568                    }
10569                    else {
10570                            return null;
10571                    }
10572            }
10573    
10574            /**
10575             * Returns all the document library folders that the user has permission to view where groupId = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
10576             *
10577             * @param groupId the group ID
10578             * @param parentFolderId the parent folder ID
10579             * @param hidden the hidden
10580             * @param status the status
10581             * @return the matching document library folders that the user has permission to view
10582             */
10583            @Override
10584            public List<DLFolder> filterFindByG_P_H_S(long groupId,
10585                    long parentFolderId, boolean hidden, int status) {
10586                    return filterFindByG_P_H_S(groupId, parentFolderId, hidden, status,
10587                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
10588            }
10589    
10590            /**
10591             * Returns a range of all the document library folders that the user has permission to view where groupId = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
10592             *
10593             * <p>
10594             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
10595             * </p>
10596             *
10597             * @param groupId the group ID
10598             * @param parentFolderId the parent folder ID
10599             * @param hidden the hidden
10600             * @param status the status
10601             * @param start the lower bound of the range of document library folders
10602             * @param end the upper bound of the range of document library folders (not inclusive)
10603             * @return the range of matching document library folders that the user has permission to view
10604             */
10605            @Override
10606            public List<DLFolder> filterFindByG_P_H_S(long groupId,
10607                    long parentFolderId, boolean hidden, int status, int start, int end) {
10608                    return filterFindByG_P_H_S(groupId, parentFolderId, hidden, status,
10609                            start, end, null);
10610            }
10611    
10612            /**
10613             * Returns an ordered range of all the document library folders that the user has permissions to view where groupId = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
10614             *
10615             * <p>
10616             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
10617             * </p>
10618             *
10619             * @param groupId the group ID
10620             * @param parentFolderId the parent folder ID
10621             * @param hidden the hidden
10622             * @param status the status
10623             * @param start the lower bound of the range of document library folders
10624             * @param end the upper bound of the range of document library folders (not inclusive)
10625             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10626             * @return the ordered range of matching document library folders that the user has permission to view
10627             */
10628            @Override
10629            public List<DLFolder> filterFindByG_P_H_S(long groupId,
10630                    long parentFolderId, boolean hidden, int status, int start, int end,
10631                    OrderByComparator<DLFolder> orderByComparator) {
10632                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
10633                            return findByG_P_H_S(groupId, parentFolderId, hidden, status,
10634                                    start, end, orderByComparator);
10635                    }
10636    
10637                    StringBundler query = null;
10638    
10639                    if (orderByComparator != null) {
10640                            query = new StringBundler(6 +
10641                                            (orderByComparator.getOrderByFields().length * 2));
10642                    }
10643                    else {
10644                            query = new StringBundler(7);
10645                    }
10646    
10647                    if (getDB().isSupportsInlineDistinct()) {
10648                            query.append(_FILTER_SQL_SELECT_DLFOLDER_WHERE);
10649                    }
10650                    else {
10651                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1);
10652                    }
10653    
10654                    query.append(_FINDER_COLUMN_G_P_H_S_GROUPID_2);
10655    
10656                    query.append(_FINDER_COLUMN_G_P_H_S_PARENTFOLDERID_2);
10657    
10658                    query.append(_FINDER_COLUMN_G_P_H_S_HIDDEN_2_SQL);
10659    
10660                    query.append(_FINDER_COLUMN_G_P_H_S_STATUS_2);
10661    
10662                    if (!getDB().isSupportsInlineDistinct()) {
10663                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2);
10664                    }
10665    
10666                    if (orderByComparator != null) {
10667                            if (getDB().isSupportsInlineDistinct()) {
10668                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10669                                            orderByComparator, true);
10670                            }
10671                            else {
10672                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
10673                                            orderByComparator, true);
10674                            }
10675                    }
10676                    else {
10677                            if (getDB().isSupportsInlineDistinct()) {
10678                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
10679                            }
10680                            else {
10681                                    query.append(DLFolderModelImpl.ORDER_BY_SQL);
10682                            }
10683                    }
10684    
10685                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
10686                                    DLFolder.class.getName(),
10687                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
10688    
10689                    Session session = null;
10690    
10691                    try {
10692                            session = openSession();
10693    
10694                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
10695    
10696                            if (getDB().isSupportsInlineDistinct()) {
10697                                    q.addEntity(_FILTER_ENTITY_ALIAS, DLFolderImpl.class);
10698                            }
10699                            else {
10700                                    q.addEntity(_FILTER_ENTITY_TABLE, DLFolderImpl.class);
10701                            }
10702    
10703                            QueryPos qPos = QueryPos.getInstance(q);
10704    
10705                            qPos.add(groupId);
10706    
10707                            qPos.add(parentFolderId);
10708    
10709                            qPos.add(hidden);
10710    
10711                            qPos.add(status);
10712    
10713                            return (List<DLFolder>)QueryUtil.list(q, getDialect(), start, end);
10714                    }
10715                    catch (Exception e) {
10716                            throw processException(e);
10717                    }
10718                    finally {
10719                            closeSession(session);
10720                    }
10721            }
10722    
10723            /**
10724             * 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 hidden = &#63; and status = &#63;.
10725             *
10726             * @param folderId the primary key of the current document library folder
10727             * @param groupId the group ID
10728             * @param parentFolderId the parent folder ID
10729             * @param hidden the hidden
10730             * @param status the status
10731             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10732             * @return the previous, current, and next document library folder
10733             * @throws NoSuchFolderException if a document library folder with the primary key could not be found
10734             */
10735            @Override
10736            public DLFolder[] filterFindByG_P_H_S_PrevAndNext(long folderId,
10737                    long groupId, long parentFolderId, boolean hidden, int status,
10738                    OrderByComparator<DLFolder> orderByComparator)
10739                    throws NoSuchFolderException {
10740                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
10741                            return findByG_P_H_S_PrevAndNext(folderId, groupId, parentFolderId,
10742                                    hidden, status, orderByComparator);
10743                    }
10744    
10745                    DLFolder dlFolder = findByPrimaryKey(folderId);
10746    
10747                    Session session = null;
10748    
10749                    try {
10750                            session = openSession();
10751    
10752                            DLFolder[] array = new DLFolderImpl[3];
10753    
10754                            array[0] = filterGetByG_P_H_S_PrevAndNext(session, dlFolder,
10755                                            groupId, parentFolderId, hidden, status, orderByComparator,
10756                                            true);
10757    
10758                            array[1] = dlFolder;
10759    
10760                            array[2] = filterGetByG_P_H_S_PrevAndNext(session, dlFolder,
10761                                            groupId, parentFolderId, hidden, status, orderByComparator,
10762                                            false);
10763    
10764                            return array;
10765                    }
10766                    catch (Exception e) {
10767                            throw processException(e);
10768                    }
10769                    finally {
10770                            closeSession(session);
10771                    }
10772            }
10773    
10774            protected DLFolder filterGetByG_P_H_S_PrevAndNext(Session session,
10775                    DLFolder dlFolder, long groupId, long parentFolderId, boolean hidden,
10776                    int status, OrderByComparator<DLFolder> orderByComparator,
10777                    boolean previous) {
10778                    StringBundler query = null;
10779    
10780                    if (orderByComparator != null) {
10781                            query = new StringBundler(8 +
10782                                            (orderByComparator.getOrderByConditionFields().length * 3) +
10783                                            (orderByComparator.getOrderByFields().length * 3));
10784                    }
10785                    else {
10786                            query = new StringBundler(7);
10787                    }
10788    
10789                    if (getDB().isSupportsInlineDistinct()) {
10790                            query.append(_FILTER_SQL_SELECT_DLFOLDER_WHERE);
10791                    }
10792                    else {
10793                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1);
10794                    }
10795    
10796                    query.append(_FINDER_COLUMN_G_P_H_S_GROUPID_2);
10797    
10798                    query.append(_FINDER_COLUMN_G_P_H_S_PARENTFOLDERID_2);
10799    
10800                    query.append(_FINDER_COLUMN_G_P_H_S_HIDDEN_2_SQL);
10801    
10802                    query.append(_FINDER_COLUMN_G_P_H_S_STATUS_2);
10803    
10804                    if (!getDB().isSupportsInlineDistinct()) {
10805                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2);
10806                    }
10807    
10808                    if (orderByComparator != null) {
10809                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
10810    
10811                            if (orderByConditionFields.length > 0) {
10812                                    query.append(WHERE_AND);
10813                            }
10814    
10815                            for (int i = 0; i < orderByConditionFields.length; i++) {
10816                                    if (getDB().isSupportsInlineDistinct()) {
10817                                            query.append(_ORDER_BY_ENTITY_ALIAS);
10818                                    }
10819                                    else {
10820                                            query.append(_ORDER_BY_ENTITY_TABLE);
10821                                    }
10822    
10823                                    query.append(orderByConditionFields[i]);
10824    
10825                                    if ((i + 1) < orderByConditionFields.length) {
10826                                            if (orderByComparator.isAscending() ^ previous) {
10827                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
10828                                            }
10829                                            else {
10830                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
10831                                            }
10832                                    }
10833                                    else {
10834                                            if (orderByComparator.isAscending() ^ previous) {
10835                                                    query.append(WHERE_GREATER_THAN);
10836                                            }
10837                                            else {
10838                                                    query.append(WHERE_LESSER_THAN);
10839                                            }
10840                                    }
10841                            }
10842    
10843                            query.append(ORDER_BY_CLAUSE);
10844    
10845                            String[] orderByFields = orderByComparator.getOrderByFields();
10846    
10847                            for (int i = 0; i < orderByFields.length; i++) {
10848                                    if (getDB().isSupportsInlineDistinct()) {
10849                                            query.append(_ORDER_BY_ENTITY_ALIAS);
10850                                    }
10851                                    else {
10852                                            query.append(_ORDER_BY_ENTITY_TABLE);
10853                                    }
10854    
10855                                    query.append(orderByFields[i]);
10856    
10857                                    if ((i + 1) < orderByFields.length) {
10858                                            if (orderByComparator.isAscending() ^ previous) {
10859                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
10860                                            }
10861                                            else {
10862                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
10863                                            }
10864                                    }
10865                                    else {
10866                                            if (orderByComparator.isAscending() ^ previous) {
10867                                                    query.append(ORDER_BY_ASC);
10868                                            }
10869                                            else {
10870                                                    query.append(ORDER_BY_DESC);
10871                                            }
10872                                    }
10873                            }
10874                    }
10875                    else {
10876                            if (getDB().isSupportsInlineDistinct()) {
10877                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
10878                            }
10879                            else {
10880                                    query.append(DLFolderModelImpl.ORDER_BY_SQL);
10881                            }
10882                    }
10883    
10884                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
10885                                    DLFolder.class.getName(),
10886                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
10887    
10888                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
10889    
10890                    q.setFirstResult(0);
10891                    q.setMaxResults(2);
10892    
10893                    if (getDB().isSupportsInlineDistinct()) {
10894                            q.addEntity(_FILTER_ENTITY_ALIAS, DLFolderImpl.class);
10895                    }
10896                    else {
10897                            q.addEntity(_FILTER_ENTITY_TABLE, DLFolderImpl.class);
10898                    }
10899    
10900                    QueryPos qPos = QueryPos.getInstance(q);
10901    
10902                    qPos.add(groupId);
10903    
10904                    qPos.add(parentFolderId);
10905    
10906                    qPos.add(hidden);
10907    
10908                    qPos.add(status);
10909    
10910                    if (orderByComparator != null) {
10911                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
10912    
10913                            for (Object value : values) {
10914                                    qPos.add(value);
10915                            }
10916                    }
10917    
10918                    List<DLFolder> list = q.list();
10919    
10920                    if (list.size() == 2) {
10921                            return list.get(1);
10922                    }
10923                    else {
10924                            return null;
10925                    }
10926            }
10927    
10928            /**
10929             * Removes all the document library folders where groupId = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63; from the database.
10930             *
10931             * @param groupId the group ID
10932             * @param parentFolderId the parent folder ID
10933             * @param hidden the hidden
10934             * @param status the status
10935             */
10936            @Override
10937            public void removeByG_P_H_S(long groupId, long parentFolderId,
10938                    boolean hidden, int status) {
10939                    for (DLFolder dlFolder : findByG_P_H_S(groupId, parentFolderId, hidden,
10940                                    status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
10941                            remove(dlFolder);
10942                    }
10943            }
10944    
10945            /**
10946             * Returns the number of document library folders where groupId = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
10947             *
10948             * @param groupId the group ID
10949             * @param parentFolderId the parent folder ID
10950             * @param hidden the hidden
10951             * @param status the status
10952             * @return the number of matching document library folders
10953             */
10954            @Override
10955            public int countByG_P_H_S(long groupId, long parentFolderId,
10956                    boolean hidden, int status) {
10957                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_P_H_S;
10958    
10959                    Object[] finderArgs = new Object[] {
10960                                    groupId, parentFolderId, hidden, status
10961                            };
10962    
10963                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
10964    
10965                    if (count == null) {
10966                            StringBundler query = new StringBundler(5);
10967    
10968                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
10969    
10970                            query.append(_FINDER_COLUMN_G_P_H_S_GROUPID_2);
10971    
10972                            query.append(_FINDER_COLUMN_G_P_H_S_PARENTFOLDERID_2);
10973    
10974                            query.append(_FINDER_COLUMN_G_P_H_S_HIDDEN_2);
10975    
10976                            query.append(_FINDER_COLUMN_G_P_H_S_STATUS_2);
10977    
10978                            String sql = query.toString();
10979    
10980                            Session session = null;
10981    
10982                            try {
10983                                    session = openSession();
10984    
10985                                    Query q = session.createQuery(sql);
10986    
10987                                    QueryPos qPos = QueryPos.getInstance(q);
10988    
10989                                    qPos.add(groupId);
10990    
10991                                    qPos.add(parentFolderId);
10992    
10993                                    qPos.add(hidden);
10994    
10995                                    qPos.add(status);
10996    
10997                                    count = (Long)q.uniqueResult();
10998    
10999                                    finderCache.putResult(finderPath, finderArgs, count);
11000                            }
11001                            catch (Exception e) {
11002                                    finderCache.removeResult(finderPath, finderArgs);
11003    
11004                                    throw processException(e);
11005                            }
11006                            finally {
11007                                    closeSession(session);
11008                            }
11009                    }
11010    
11011                    return count.intValue();
11012            }
11013    
11014            /**
11015             * Returns the number of document library folders that the user has permission to view where groupId = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
11016             *
11017             * @param groupId the group ID
11018             * @param parentFolderId the parent folder ID
11019             * @param hidden the hidden
11020             * @param status the status
11021             * @return the number of matching document library folders that the user has permission to view
11022             */
11023            @Override
11024            public int filterCountByG_P_H_S(long groupId, long parentFolderId,
11025                    boolean hidden, int status) {
11026                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
11027                            return countByG_P_H_S(groupId, parentFolderId, hidden, status);
11028                    }
11029    
11030                    StringBundler query = new StringBundler(5);
11031    
11032                    query.append(_FILTER_SQL_COUNT_DLFOLDER_WHERE);
11033    
11034                    query.append(_FINDER_COLUMN_G_P_H_S_GROUPID_2);
11035    
11036                    query.append(_FINDER_COLUMN_G_P_H_S_PARENTFOLDERID_2);
11037    
11038                    query.append(_FINDER_COLUMN_G_P_H_S_HIDDEN_2_SQL);
11039    
11040                    query.append(_FINDER_COLUMN_G_P_H_S_STATUS_2);
11041    
11042                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
11043                                    DLFolder.class.getName(),
11044                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
11045    
11046                    Session session = null;
11047    
11048                    try {
11049                            session = openSession();
11050    
11051                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
11052    
11053                            q.addScalar(COUNT_COLUMN_NAME,
11054                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
11055    
11056                            QueryPos qPos = QueryPos.getInstance(q);
11057    
11058                            qPos.add(groupId);
11059    
11060                            qPos.add(parentFolderId);
11061    
11062                            qPos.add(hidden);
11063    
11064                            qPos.add(status);
11065    
11066                            Long count = (Long)q.uniqueResult();
11067    
11068                            return count.intValue();
11069                    }
11070                    catch (Exception e) {
11071                            throw processException(e);
11072                    }
11073                    finally {
11074                            closeSession(session);
11075                    }
11076            }
11077    
11078            private static final String _FINDER_COLUMN_G_P_H_S_GROUPID_2 = "dlFolder.groupId = ? AND ";
11079            private static final String _FINDER_COLUMN_G_P_H_S_PARENTFOLDERID_2 = "dlFolder.parentFolderId = ? AND ";
11080            private static final String _FINDER_COLUMN_G_P_H_S_HIDDEN_2 = "dlFolder.hidden = ? AND ";
11081            private static final String _FINDER_COLUMN_G_P_H_S_HIDDEN_2_SQL = "dlFolder.hidden_ = ? AND ";
11082            private static final String _FINDER_COLUMN_G_P_H_S_STATUS_2 = "dlFolder.status = ?";
11083            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_M_P_H_S =
11084                    new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
11085                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
11086                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_M_P_H_S",
11087                            new String[] {
11088                                    Long.class.getName(), Boolean.class.getName(),
11089                                    Long.class.getName(), Boolean.class.getName(),
11090                                    Integer.class.getName(),
11091                                    
11092                            Integer.class.getName(), Integer.class.getName(),
11093                                    OrderByComparator.class.getName()
11094                            });
11095            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P_H_S =
11096                    new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
11097                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
11098                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_M_P_H_S",
11099                            new String[] {
11100                                    Long.class.getName(), Boolean.class.getName(),
11101                                    Long.class.getName(), Boolean.class.getName(),
11102                                    Integer.class.getName()
11103                            },
11104                            DLFolderModelImpl.GROUPID_COLUMN_BITMASK |
11105                            DLFolderModelImpl.MOUNTPOINT_COLUMN_BITMASK |
11106                            DLFolderModelImpl.PARENTFOLDERID_COLUMN_BITMASK |
11107                            DLFolderModelImpl.HIDDEN_COLUMN_BITMASK |
11108                            DLFolderModelImpl.STATUS_COLUMN_BITMASK |
11109                            DLFolderModelImpl.NAME_COLUMN_BITMASK);
11110            public static final FinderPath FINDER_PATH_COUNT_BY_G_M_P_H_S = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
11111                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
11112                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_M_P_H_S",
11113                            new String[] {
11114                                    Long.class.getName(), Boolean.class.getName(),
11115                                    Long.class.getName(), Boolean.class.getName(),
11116                                    Integer.class.getName()
11117                            });
11118    
11119            /**
11120             * Returns all the document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
11121             *
11122             * @param groupId the group ID
11123             * @param mountPoint the mount point
11124             * @param parentFolderId the parent folder ID
11125             * @param hidden the hidden
11126             * @param status the status
11127             * @return the matching document library folders
11128             */
11129            @Override
11130            public List<DLFolder> findByG_M_P_H_S(long groupId, boolean mountPoint,
11131                    long parentFolderId, boolean hidden, int status) {
11132                    return findByG_M_P_H_S(groupId, mountPoint, parentFolderId, hidden,
11133                            status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
11134            }
11135    
11136            /**
11137             * Returns a range of all the document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
11138             *
11139             * <p>
11140             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
11141             * </p>
11142             *
11143             * @param groupId the group ID
11144             * @param mountPoint the mount point
11145             * @param parentFolderId the parent folder ID
11146             * @param hidden the hidden
11147             * @param status the status
11148             * @param start the lower bound of the range of document library folders
11149             * @param end the upper bound of the range of document library folders (not inclusive)
11150             * @return the range of matching document library folders
11151             */
11152            @Override
11153            public List<DLFolder> findByG_M_P_H_S(long groupId, boolean mountPoint,
11154                    long parentFolderId, boolean hidden, int status, int start, int end) {
11155                    return findByG_M_P_H_S(groupId, mountPoint, parentFolderId, hidden,
11156                            status, start, end, null);
11157            }
11158    
11159            /**
11160             * Returns an ordered range of all the document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
11161             *
11162             * <p>
11163             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
11164             * </p>
11165             *
11166             * @param groupId the group ID
11167             * @param mountPoint the mount point
11168             * @param parentFolderId the parent folder ID
11169             * @param hidden the hidden
11170             * @param status the status
11171             * @param start the lower bound of the range of document library folders
11172             * @param end the upper bound of the range of document library folders (not inclusive)
11173             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
11174             * @return the ordered range of matching document library folders
11175             */
11176            @Override
11177            public List<DLFolder> findByG_M_P_H_S(long groupId, boolean mountPoint,
11178                    long parentFolderId, boolean hidden, int status, int start, int end,
11179                    OrderByComparator<DLFolder> orderByComparator) {
11180                    return findByG_M_P_H_S(groupId, mountPoint, parentFolderId, hidden,
11181                            status, start, end, orderByComparator, true);
11182            }
11183    
11184            /**
11185             * Returns an ordered range of all the document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
11186             *
11187             * <p>
11188             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
11189             * </p>
11190             *
11191             * @param groupId the group ID
11192             * @param mountPoint the mount point
11193             * @param parentFolderId the parent folder ID
11194             * @param hidden the hidden
11195             * @param status the status
11196             * @param start the lower bound of the range of document library folders
11197             * @param end the upper bound of the range of document library folders (not inclusive)
11198             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
11199             * @param retrieveFromCache whether to retrieve from the finder cache
11200             * @return the ordered range of matching document library folders
11201             */
11202            @Override
11203            public List<DLFolder> findByG_M_P_H_S(long groupId, boolean mountPoint,
11204                    long parentFolderId, boolean hidden, int status, int start, int end,
11205                    OrderByComparator<DLFolder> orderByComparator, boolean retrieveFromCache) {
11206                    boolean pagination = true;
11207                    FinderPath finderPath = null;
11208                    Object[] finderArgs = null;
11209    
11210                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
11211                                    (orderByComparator == null)) {
11212                            pagination = false;
11213                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P_H_S;
11214                            finderArgs = new Object[] {
11215                                            groupId, mountPoint, parentFolderId, hidden, status
11216                                    };
11217                    }
11218                    else {
11219                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_M_P_H_S;
11220                            finderArgs = new Object[] {
11221                                            groupId, mountPoint, parentFolderId, hidden, status,
11222                                            
11223                                            start, end, orderByComparator
11224                                    };
11225                    }
11226    
11227                    List<DLFolder> list = null;
11228    
11229                    if (retrieveFromCache) {
11230                            list = (List<DLFolder>)finderCache.getResult(finderPath,
11231                                            finderArgs, this);
11232    
11233                            if ((list != null) && !list.isEmpty()) {
11234                                    for (DLFolder dlFolder : list) {
11235                                            if ((groupId != dlFolder.getGroupId()) ||
11236                                                            (mountPoint != dlFolder.getMountPoint()) ||
11237                                                            (parentFolderId != dlFolder.getParentFolderId()) ||
11238                                                            (hidden != dlFolder.getHidden()) ||
11239                                                            (status != dlFolder.getStatus())) {
11240                                                    list = null;
11241    
11242                                                    break;
11243                                            }
11244                                    }
11245                            }
11246                    }
11247    
11248                    if (list == null) {
11249                            StringBundler query = null;
11250    
11251                            if (orderByComparator != null) {
11252                                    query = new StringBundler(7 +
11253                                                    (orderByComparator.getOrderByFields().length * 2));
11254                            }
11255                            else {
11256                                    query = new StringBundler(7);
11257                            }
11258    
11259                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
11260    
11261                            query.append(_FINDER_COLUMN_G_M_P_H_S_GROUPID_2);
11262    
11263                            query.append(_FINDER_COLUMN_G_M_P_H_S_MOUNTPOINT_2);
11264    
11265                            query.append(_FINDER_COLUMN_G_M_P_H_S_PARENTFOLDERID_2);
11266    
11267                            query.append(_FINDER_COLUMN_G_M_P_H_S_HIDDEN_2);
11268    
11269                            query.append(_FINDER_COLUMN_G_M_P_H_S_STATUS_2);
11270    
11271                            if (orderByComparator != null) {
11272                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
11273                                            orderByComparator);
11274                            }
11275                            else
11276                             if (pagination) {
11277                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
11278                            }
11279    
11280                            String sql = query.toString();
11281    
11282                            Session session = null;
11283    
11284                            try {
11285                                    session = openSession();
11286    
11287                                    Query q = session.createQuery(sql);
11288    
11289                                    QueryPos qPos = QueryPos.getInstance(q);
11290    
11291                                    qPos.add(groupId);
11292    
11293                                    qPos.add(mountPoint);
11294    
11295                                    qPos.add(parentFolderId);
11296    
11297                                    qPos.add(hidden);
11298    
11299                                    qPos.add(status);
11300    
11301                                    if (!pagination) {
11302                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
11303                                                            start, end, false);
11304    
11305                                            Collections.sort(list);
11306    
11307                                            list = Collections.unmodifiableList(list);
11308                                    }
11309                                    else {
11310                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
11311                                                            start, end);
11312                                    }
11313    
11314                                    cacheResult(list);
11315    
11316                                    finderCache.putResult(finderPath, finderArgs, list);
11317                            }
11318                            catch (Exception e) {
11319                                    finderCache.removeResult(finderPath, finderArgs);
11320    
11321                                    throw processException(e);
11322                            }
11323                            finally {
11324                                    closeSession(session);
11325                            }
11326                    }
11327    
11328                    return list;
11329            }
11330    
11331            /**
11332             * Returns the first document library folder in the ordered set where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
11333             *
11334             * @param groupId the group ID
11335             * @param mountPoint the mount point
11336             * @param parentFolderId the parent folder ID
11337             * @param hidden the hidden
11338             * @param status the status
11339             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11340             * @return the first matching document library folder
11341             * @throws NoSuchFolderException if a matching document library folder could not be found
11342             */
11343            @Override
11344            public DLFolder findByG_M_P_H_S_First(long groupId, boolean mountPoint,
11345                    long parentFolderId, boolean hidden, int status,
11346                    OrderByComparator<DLFolder> orderByComparator)
11347                    throws NoSuchFolderException {
11348                    DLFolder dlFolder = fetchByG_M_P_H_S_First(groupId, mountPoint,
11349                                    parentFolderId, hidden, status, orderByComparator);
11350    
11351                    if (dlFolder != null) {
11352                            return dlFolder;
11353                    }
11354    
11355                    StringBundler msg = new StringBundler(12);
11356    
11357                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
11358    
11359                    msg.append("groupId=");
11360                    msg.append(groupId);
11361    
11362                    msg.append(", mountPoint=");
11363                    msg.append(mountPoint);
11364    
11365                    msg.append(", parentFolderId=");
11366                    msg.append(parentFolderId);
11367    
11368                    msg.append(", hidden=");
11369                    msg.append(hidden);
11370    
11371                    msg.append(", status=");
11372                    msg.append(status);
11373    
11374                    msg.append(StringPool.CLOSE_CURLY_BRACE);
11375    
11376                    throw new NoSuchFolderException(msg.toString());
11377            }
11378    
11379            /**
11380             * Returns the first document library folder in the ordered set where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
11381             *
11382             * @param groupId the group ID
11383             * @param mountPoint the mount point
11384             * @param parentFolderId the parent folder ID
11385             * @param hidden the hidden
11386             * @param status the status
11387             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11388             * @return the first matching document library folder, or <code>null</code> if a matching document library folder could not be found
11389             */
11390            @Override
11391            public DLFolder fetchByG_M_P_H_S_First(long groupId, boolean mountPoint,
11392                    long parentFolderId, boolean hidden, int status,
11393                    OrderByComparator<DLFolder> orderByComparator) {
11394                    List<DLFolder> list = findByG_M_P_H_S(groupId, mountPoint,
11395                                    parentFolderId, hidden, status, 0, 1, orderByComparator);
11396    
11397                    if (!list.isEmpty()) {
11398                            return list.get(0);
11399                    }
11400    
11401                    return null;
11402            }
11403    
11404            /**
11405             * Returns the last document library folder in the ordered set where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
11406             *
11407             * @param groupId the group ID
11408             * @param mountPoint the mount point
11409             * @param parentFolderId the parent folder ID
11410             * @param hidden the hidden
11411             * @param status the status
11412             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11413             * @return the last matching document library folder
11414             * @throws NoSuchFolderException if a matching document library folder could not be found
11415             */
11416            @Override
11417            public DLFolder findByG_M_P_H_S_Last(long groupId, boolean mountPoint,
11418                    long parentFolderId, boolean hidden, int status,
11419                    OrderByComparator<DLFolder> orderByComparator)
11420                    throws NoSuchFolderException {
11421                    DLFolder dlFolder = fetchByG_M_P_H_S_Last(groupId, mountPoint,
11422                                    parentFolderId, hidden, status, orderByComparator);
11423    
11424                    if (dlFolder != null) {
11425                            return dlFolder;
11426                    }
11427    
11428                    StringBundler msg = new StringBundler(12);
11429    
11430                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
11431    
11432                    msg.append("groupId=");
11433                    msg.append(groupId);
11434    
11435                    msg.append(", mountPoint=");
11436                    msg.append(mountPoint);
11437    
11438                    msg.append(", parentFolderId=");
11439                    msg.append(parentFolderId);
11440    
11441                    msg.append(", hidden=");
11442                    msg.append(hidden);
11443    
11444                    msg.append(", status=");
11445                    msg.append(status);
11446    
11447                    msg.append(StringPool.CLOSE_CURLY_BRACE);
11448    
11449                    throw new NoSuchFolderException(msg.toString());
11450            }
11451    
11452            /**
11453             * Returns the last document library folder in the ordered set where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
11454             *
11455             * @param groupId the group ID
11456             * @param mountPoint the mount point
11457             * @param parentFolderId the parent folder ID
11458             * @param hidden the hidden
11459             * @param status the status
11460             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11461             * @return the last matching document library folder, or <code>null</code> if a matching document library folder could not be found
11462             */
11463            @Override
11464            public DLFolder fetchByG_M_P_H_S_Last(long groupId, boolean mountPoint,
11465                    long parentFolderId, boolean hidden, int status,
11466                    OrderByComparator<DLFolder> orderByComparator) {
11467                    int count = countByG_M_P_H_S(groupId, mountPoint, parentFolderId,
11468                                    hidden, status);
11469    
11470                    if (count == 0) {
11471                            return null;
11472                    }
11473    
11474                    List<DLFolder> list = findByG_M_P_H_S(groupId, mountPoint,
11475                                    parentFolderId, hidden, status, count - 1, count,
11476                                    orderByComparator);
11477    
11478                    if (!list.isEmpty()) {
11479                            return list.get(0);
11480                    }
11481    
11482                    return null;
11483            }
11484    
11485            /**
11486             * Returns the document library folders before and after the current document library folder in the ordered set where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
11487             *
11488             * @param folderId the primary key of the current document library folder
11489             * @param groupId the group ID
11490             * @param mountPoint the mount point
11491             * @param parentFolderId the parent folder ID
11492             * @param hidden the hidden
11493             * @param status the status
11494             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11495             * @return the previous, current, and next document library folder
11496             * @throws NoSuchFolderException if a document library folder with the primary key could not be found
11497             */
11498            @Override
11499            public DLFolder[] findByG_M_P_H_S_PrevAndNext(long folderId, long groupId,
11500                    boolean mountPoint, long parentFolderId, boolean hidden, int status,
11501                    OrderByComparator<DLFolder> orderByComparator)
11502                    throws NoSuchFolderException {
11503                    DLFolder dlFolder = findByPrimaryKey(folderId);
11504    
11505                    Session session = null;
11506    
11507                    try {
11508                            session = openSession();
11509    
11510                            DLFolder[] array = new DLFolderImpl[3];
11511    
11512                            array[0] = getByG_M_P_H_S_PrevAndNext(session, dlFolder, groupId,
11513                                            mountPoint, parentFolderId, hidden, status,
11514                                            orderByComparator, true);
11515    
11516                            array[1] = dlFolder;
11517    
11518                            array[2] = getByG_M_P_H_S_PrevAndNext(session, dlFolder, groupId,
11519                                            mountPoint, parentFolderId, hidden, status,
11520                                            orderByComparator, false);
11521    
11522                            return array;
11523                    }
11524                    catch (Exception e) {
11525                            throw processException(e);
11526                    }
11527                    finally {
11528                            closeSession(session);
11529                    }
11530            }
11531    
11532            protected DLFolder getByG_M_P_H_S_PrevAndNext(Session session,
11533                    DLFolder dlFolder, long groupId, boolean mountPoint,
11534                    long parentFolderId, boolean hidden, int status,
11535                    OrderByComparator<DLFolder> orderByComparator, boolean previous) {
11536                    StringBundler query = null;
11537    
11538                    if (orderByComparator != null) {
11539                            query = new StringBundler(8 +
11540                                            (orderByComparator.getOrderByConditionFields().length * 3) +
11541                                            (orderByComparator.getOrderByFields().length * 3));
11542                    }
11543                    else {
11544                            query = new StringBundler(7);
11545                    }
11546    
11547                    query.append(_SQL_SELECT_DLFOLDER_WHERE);
11548    
11549                    query.append(_FINDER_COLUMN_G_M_P_H_S_GROUPID_2);
11550    
11551                    query.append(_FINDER_COLUMN_G_M_P_H_S_MOUNTPOINT_2);
11552    
11553                    query.append(_FINDER_COLUMN_G_M_P_H_S_PARENTFOLDERID_2);
11554    
11555                    query.append(_FINDER_COLUMN_G_M_P_H_S_HIDDEN_2);
11556    
11557                    query.append(_FINDER_COLUMN_G_M_P_H_S_STATUS_2);
11558    
11559                    if (orderByComparator != null) {
11560                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
11561    
11562                            if (orderByConditionFields.length > 0) {
11563                                    query.append(WHERE_AND);
11564                            }
11565    
11566                            for (int i = 0; i < orderByConditionFields.length; i++) {
11567                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11568                                    query.append(orderByConditionFields[i]);
11569    
11570                                    if ((i + 1) < orderByConditionFields.length) {
11571                                            if (orderByComparator.isAscending() ^ previous) {
11572                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
11573                                            }
11574                                            else {
11575                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
11576                                            }
11577                                    }
11578                                    else {
11579                                            if (orderByComparator.isAscending() ^ previous) {
11580                                                    query.append(WHERE_GREATER_THAN);
11581                                            }
11582                                            else {
11583                                                    query.append(WHERE_LESSER_THAN);
11584                                            }
11585                                    }
11586                            }
11587    
11588                            query.append(ORDER_BY_CLAUSE);
11589    
11590                            String[] orderByFields = orderByComparator.getOrderByFields();
11591    
11592                            for (int i = 0; i < orderByFields.length; i++) {
11593                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11594                                    query.append(orderByFields[i]);
11595    
11596                                    if ((i + 1) < orderByFields.length) {
11597                                            if (orderByComparator.isAscending() ^ previous) {
11598                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
11599                                            }
11600                                            else {
11601                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
11602                                            }
11603                                    }
11604                                    else {
11605                                            if (orderByComparator.isAscending() ^ previous) {
11606                                                    query.append(ORDER_BY_ASC);
11607                                            }
11608                                            else {
11609                                                    query.append(ORDER_BY_DESC);
11610                                            }
11611                                    }
11612                            }
11613                    }
11614                    else {
11615                            query.append(DLFolderModelImpl.ORDER_BY_JPQL);
11616                    }
11617    
11618                    String sql = query.toString();
11619    
11620                    Query q = session.createQuery(sql);
11621    
11622                    q.setFirstResult(0);
11623                    q.setMaxResults(2);
11624    
11625                    QueryPos qPos = QueryPos.getInstance(q);
11626    
11627                    qPos.add(groupId);
11628    
11629                    qPos.add(mountPoint);
11630    
11631                    qPos.add(parentFolderId);
11632    
11633                    qPos.add(hidden);
11634    
11635                    qPos.add(status);
11636    
11637                    if (orderByComparator != null) {
11638                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
11639    
11640                            for (Object value : values) {
11641                                    qPos.add(value);
11642                            }
11643                    }
11644    
11645                    List<DLFolder> list = q.list();
11646    
11647                    if (list.size() == 2) {
11648                            return list.get(1);
11649                    }
11650                    else {
11651                            return null;
11652                    }
11653            }
11654    
11655            /**
11656             * Returns all the document library folders that the user has permission to view where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
11657             *
11658             * @param groupId the group ID
11659             * @param mountPoint the mount point
11660             * @param parentFolderId the parent folder ID
11661             * @param hidden the hidden
11662             * @param status the status
11663             * @return the matching document library folders that the user has permission to view
11664             */
11665            @Override
11666            public List<DLFolder> filterFindByG_M_P_H_S(long groupId,
11667                    boolean mountPoint, long parentFolderId, boolean hidden, int status) {
11668                    return filterFindByG_M_P_H_S(groupId, mountPoint, parentFolderId,
11669                            hidden, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
11670            }
11671    
11672            /**
11673             * Returns a range of all the document library folders that the user has permission to view where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
11674             *
11675             * <p>
11676             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
11677             * </p>
11678             *
11679             * @param groupId the group ID
11680             * @param mountPoint the mount point
11681             * @param parentFolderId the parent folder ID
11682             * @param hidden the hidden
11683             * @param status the status
11684             * @param start the lower bound of the range of document library folders
11685             * @param end the upper bound of the range of document library folders (not inclusive)
11686             * @return the range of matching document library folders that the user has permission to view
11687             */
11688            @Override
11689            public List<DLFolder> filterFindByG_M_P_H_S(long groupId,
11690                    boolean mountPoint, long parentFolderId, boolean hidden, int status,
11691                    int start, int end) {
11692                    return filterFindByG_M_P_H_S(groupId, mountPoint, parentFolderId,
11693                            hidden, status, start, end, null);
11694            }
11695    
11696            /**
11697             * Returns an ordered range of all the document library folders that the user has permissions to view where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
11698             *
11699             * <p>
11700             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
11701             * </p>
11702             *
11703             * @param groupId the group ID
11704             * @param mountPoint the mount point
11705             * @param parentFolderId the parent folder ID
11706             * @param hidden the hidden
11707             * @param status the status
11708             * @param start the lower bound of the range of document library folders
11709             * @param end the upper bound of the range of document library folders (not inclusive)
11710             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
11711             * @return the ordered range of matching document library folders that the user has permission to view
11712             */
11713            @Override
11714            public List<DLFolder> filterFindByG_M_P_H_S(long groupId,
11715                    boolean mountPoint, long parentFolderId, boolean hidden, int status,
11716                    int start, int end, OrderByComparator<DLFolder> orderByComparator) {
11717                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
11718                            return findByG_M_P_H_S(groupId, mountPoint, parentFolderId, hidden,
11719                                    status, start, end, orderByComparator);
11720                    }
11721    
11722                    StringBundler query = null;
11723    
11724                    if (orderByComparator != null) {
11725                            query = new StringBundler(7 +
11726                                            (orderByComparator.getOrderByFields().length * 2));
11727                    }
11728                    else {
11729                            query = new StringBundler(8);
11730                    }
11731    
11732                    if (getDB().isSupportsInlineDistinct()) {
11733                            query.append(_FILTER_SQL_SELECT_DLFOLDER_WHERE);
11734                    }
11735                    else {
11736                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1);
11737                    }
11738    
11739                    query.append(_FINDER_COLUMN_G_M_P_H_S_GROUPID_2);
11740    
11741                    query.append(_FINDER_COLUMN_G_M_P_H_S_MOUNTPOINT_2);
11742    
11743                    query.append(_FINDER_COLUMN_G_M_P_H_S_PARENTFOLDERID_2);
11744    
11745                    query.append(_FINDER_COLUMN_G_M_P_H_S_HIDDEN_2_SQL);
11746    
11747                    query.append(_FINDER_COLUMN_G_M_P_H_S_STATUS_2);
11748    
11749                    if (!getDB().isSupportsInlineDistinct()) {
11750                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2);
11751                    }
11752    
11753                    if (orderByComparator != null) {
11754                            if (getDB().isSupportsInlineDistinct()) {
11755                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
11756                                            orderByComparator, true);
11757                            }
11758                            else {
11759                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
11760                                            orderByComparator, true);
11761                            }
11762                    }
11763                    else {
11764                            if (getDB().isSupportsInlineDistinct()) {
11765                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
11766                            }
11767                            else {
11768                                    query.append(DLFolderModelImpl.ORDER_BY_SQL);
11769                            }
11770                    }
11771    
11772                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
11773                                    DLFolder.class.getName(),
11774                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
11775    
11776                    Session session = null;
11777    
11778                    try {
11779                            session = openSession();
11780    
11781                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
11782    
11783                            if (getDB().isSupportsInlineDistinct()) {
11784                                    q.addEntity(_FILTER_ENTITY_ALIAS, DLFolderImpl.class);
11785                            }
11786                            else {
11787                                    q.addEntity(_FILTER_ENTITY_TABLE, DLFolderImpl.class);
11788                            }
11789    
11790                            QueryPos qPos = QueryPos.getInstance(q);
11791    
11792                            qPos.add(groupId);
11793    
11794                            qPos.add(mountPoint);
11795    
11796                            qPos.add(parentFolderId);
11797    
11798                            qPos.add(hidden);
11799    
11800                            qPos.add(status);
11801    
11802                            return (List<DLFolder>)QueryUtil.list(q, getDialect(), start, end);
11803                    }
11804                    catch (Exception e) {
11805                            throw processException(e);
11806                    }
11807                    finally {
11808                            closeSession(session);
11809                    }
11810            }
11811    
11812            /**
11813             * 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 mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
11814             *
11815             * @param folderId the primary key of the current document library folder
11816             * @param groupId the group ID
11817             * @param mountPoint the mount point
11818             * @param parentFolderId the parent folder ID
11819             * @param hidden the hidden
11820             * @param status the status
11821             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11822             * @return the previous, current, and next document library folder
11823             * @throws NoSuchFolderException if a document library folder with the primary key could not be found
11824             */
11825            @Override
11826            public DLFolder[] filterFindByG_M_P_H_S_PrevAndNext(long folderId,
11827                    long groupId, boolean mountPoint, long parentFolderId, boolean hidden,
11828                    int status, OrderByComparator<DLFolder> orderByComparator)
11829                    throws NoSuchFolderException {
11830                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
11831                            return findByG_M_P_H_S_PrevAndNext(folderId, groupId, mountPoint,
11832                                    parentFolderId, hidden, status, orderByComparator);
11833                    }
11834    
11835                    DLFolder dlFolder = findByPrimaryKey(folderId);
11836    
11837                    Session session = null;
11838    
11839                    try {
11840                            session = openSession();
11841    
11842                            DLFolder[] array = new DLFolderImpl[3];
11843    
11844                            array[0] = filterGetByG_M_P_H_S_PrevAndNext(session, dlFolder,
11845                                            groupId, mountPoint, parentFolderId, hidden, status,
11846                                            orderByComparator, true);
11847    
11848                            array[1] = dlFolder;
11849    
11850                            array[2] = filterGetByG_M_P_H_S_PrevAndNext(session, dlFolder,
11851                                            groupId, mountPoint, parentFolderId, hidden, status,
11852                                            orderByComparator, false);
11853    
11854                            return array;
11855                    }
11856                    catch (Exception e) {
11857                            throw processException(e);
11858                    }
11859                    finally {
11860                            closeSession(session);
11861                    }
11862            }
11863    
11864            protected DLFolder filterGetByG_M_P_H_S_PrevAndNext(Session session,
11865                    DLFolder dlFolder, long groupId, boolean mountPoint,
11866                    long parentFolderId, boolean hidden, int status,
11867                    OrderByComparator<DLFolder> orderByComparator, boolean previous) {
11868                    StringBundler query = null;
11869    
11870                    if (orderByComparator != null) {
11871                            query = new StringBundler(9 +
11872                                            (orderByComparator.getOrderByConditionFields().length * 3) +
11873                                            (orderByComparator.getOrderByFields().length * 3));
11874                    }
11875                    else {
11876                            query = new StringBundler(8);
11877                    }
11878    
11879                    if (getDB().isSupportsInlineDistinct()) {
11880                            query.append(_FILTER_SQL_SELECT_DLFOLDER_WHERE);
11881                    }
11882                    else {
11883                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1);
11884                    }
11885    
11886                    query.append(_FINDER_COLUMN_G_M_P_H_S_GROUPID_2);
11887    
11888                    query.append(_FINDER_COLUMN_G_M_P_H_S_MOUNTPOINT_2);
11889    
11890                    query.append(_FINDER_COLUMN_G_M_P_H_S_PARENTFOLDERID_2);
11891    
11892                    query.append(_FINDER_COLUMN_G_M_P_H_S_HIDDEN_2_SQL);
11893    
11894                    query.append(_FINDER_COLUMN_G_M_P_H_S_STATUS_2);
11895    
11896                    if (!getDB().isSupportsInlineDistinct()) {
11897                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2);
11898                    }
11899    
11900                    if (orderByComparator != null) {
11901                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
11902    
11903                            if (orderByConditionFields.length > 0) {
11904                                    query.append(WHERE_AND);
11905                            }
11906    
11907                            for (int i = 0; i < orderByConditionFields.length; i++) {
11908                                    if (getDB().isSupportsInlineDistinct()) {
11909                                            query.append(_ORDER_BY_ENTITY_ALIAS);
11910                                    }
11911                                    else {
11912                                            query.append(_ORDER_BY_ENTITY_TABLE);
11913                                    }
11914    
11915                                    query.append(orderByConditionFields[i]);
11916    
11917                                    if ((i + 1) < orderByConditionFields.length) {
11918                                            if (orderByComparator.isAscending() ^ previous) {
11919                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
11920                                            }
11921                                            else {
11922                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
11923                                            }
11924                                    }
11925                                    else {
11926                                            if (orderByComparator.isAscending() ^ previous) {
11927                                                    query.append(WHERE_GREATER_THAN);
11928                                            }
11929                                            else {
11930                                                    query.append(WHERE_LESSER_THAN);
11931                                            }
11932                                    }
11933                            }
11934    
11935                            query.append(ORDER_BY_CLAUSE);
11936    
11937                            String[] orderByFields = orderByComparator.getOrderByFields();
11938    
11939                            for (int i = 0; i < orderByFields.length; i++) {
11940                                    if (getDB().isSupportsInlineDistinct()) {
11941                                            query.append(_ORDER_BY_ENTITY_ALIAS);
11942                                    }
11943                                    else {
11944                                            query.append(_ORDER_BY_ENTITY_TABLE);
11945                                    }
11946    
11947                                    query.append(orderByFields[i]);
11948    
11949                                    if ((i + 1) < orderByFields.length) {
11950                                            if (orderByComparator.isAscending() ^ previous) {
11951                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
11952                                            }
11953                                            else {
11954                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
11955                                            }
11956                                    }
11957                                    else {
11958                                            if (orderByComparator.isAscending() ^ previous) {
11959                                                    query.append(ORDER_BY_ASC);
11960                                            }
11961                                            else {
11962                                                    query.append(ORDER_BY_DESC);
11963                                            }
11964                                    }
11965                            }
11966                    }
11967                    else {
11968                            if (getDB().isSupportsInlineDistinct()) {
11969                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
11970                            }
11971                            else {
11972                                    query.append(DLFolderModelImpl.ORDER_BY_SQL);
11973                            }
11974                    }
11975    
11976                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
11977                                    DLFolder.class.getName(),
11978                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
11979    
11980                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
11981    
11982                    q.setFirstResult(0);
11983                    q.setMaxResults(2);
11984    
11985                    if (getDB().isSupportsInlineDistinct()) {
11986                            q.addEntity(_FILTER_ENTITY_ALIAS, DLFolderImpl.class);
11987                    }
11988                    else {
11989                            q.addEntity(_FILTER_ENTITY_TABLE, DLFolderImpl.class);
11990                    }
11991    
11992                    QueryPos qPos = QueryPos.getInstance(q);
11993    
11994                    qPos.add(groupId);
11995    
11996                    qPos.add(mountPoint);
11997    
11998                    qPos.add(parentFolderId);
11999    
12000                    qPos.add(hidden);
12001    
12002                    qPos.add(status);
12003    
12004                    if (orderByComparator != null) {
12005                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
12006    
12007                            for (Object value : values) {
12008                                    qPos.add(value);
12009                            }
12010                    }
12011    
12012                    List<DLFolder> list = q.list();
12013    
12014                    if (list.size() == 2) {
12015                            return list.get(1);
12016                    }
12017                    else {
12018                            return null;
12019                    }
12020            }
12021    
12022            /**
12023             * Removes all the document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63; from the database.
12024             *
12025             * @param groupId the group ID
12026             * @param mountPoint the mount point
12027             * @param parentFolderId the parent folder ID
12028             * @param hidden the hidden
12029             * @param status the status
12030             */
12031            @Override
12032            public void removeByG_M_P_H_S(long groupId, boolean mountPoint,
12033                    long parentFolderId, boolean hidden, int status) {
12034                    for (DLFolder dlFolder : findByG_M_P_H_S(groupId, mountPoint,
12035                                    parentFolderId, hidden, status, QueryUtil.ALL_POS,
12036                                    QueryUtil.ALL_POS, null)) {
12037                            remove(dlFolder);
12038                    }
12039            }
12040    
12041            /**
12042             * Returns the number of document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
12043             *
12044             * @param groupId the group ID
12045             * @param mountPoint the mount point
12046             * @param parentFolderId the parent folder ID
12047             * @param hidden the hidden
12048             * @param status the status
12049             * @return the number of matching document library folders
12050             */
12051            @Override
12052            public int countByG_M_P_H_S(long groupId, boolean mountPoint,
12053                    long parentFolderId, boolean hidden, int status) {
12054                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_M_P_H_S;
12055    
12056                    Object[] finderArgs = new Object[] {
12057                                    groupId, mountPoint, parentFolderId, hidden, status
12058                            };
12059    
12060                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
12061    
12062                    if (count == null) {
12063                            StringBundler query = new StringBundler(6);
12064    
12065                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
12066    
12067                            query.append(_FINDER_COLUMN_G_M_P_H_S_GROUPID_2);
12068    
12069                            query.append(_FINDER_COLUMN_G_M_P_H_S_MOUNTPOINT_2);
12070    
12071                            query.append(_FINDER_COLUMN_G_M_P_H_S_PARENTFOLDERID_2);
12072    
12073                            query.append(_FINDER_COLUMN_G_M_P_H_S_HIDDEN_2);
12074    
12075                            query.append(_FINDER_COLUMN_G_M_P_H_S_STATUS_2);
12076    
12077                            String sql = query.toString();
12078    
12079                            Session session = null;
12080    
12081                            try {
12082                                    session = openSession();
12083    
12084                                    Query q = session.createQuery(sql);
12085    
12086                                    QueryPos qPos = QueryPos.getInstance(q);
12087    
12088                                    qPos.add(groupId);
12089    
12090                                    qPos.add(mountPoint);
12091    
12092                                    qPos.add(parentFolderId);
12093    
12094                                    qPos.add(hidden);
12095    
12096                                    qPos.add(status);
12097    
12098                                    count = (Long)q.uniqueResult();
12099    
12100                                    finderCache.putResult(finderPath, finderArgs, count);
12101                            }
12102                            catch (Exception e) {
12103                                    finderCache.removeResult(finderPath, finderArgs);
12104    
12105                                    throw processException(e);
12106                            }
12107                            finally {
12108                                    closeSession(session);
12109                            }
12110                    }
12111    
12112                    return count.intValue();
12113            }
12114    
12115            /**
12116             * Returns the number of document library folders that the user has permission to view where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
12117             *
12118             * @param groupId the group ID
12119             * @param mountPoint the mount point
12120             * @param parentFolderId the parent folder ID
12121             * @param hidden the hidden
12122             * @param status the status
12123             * @return the number of matching document library folders that the user has permission to view
12124             */
12125            @Override
12126            public int filterCountByG_M_P_H_S(long groupId, boolean mountPoint,
12127                    long parentFolderId, boolean hidden, int status) {
12128                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
12129                            return countByG_M_P_H_S(groupId, mountPoint, parentFolderId,
12130                                    hidden, status);
12131                    }
12132    
12133                    StringBundler query = new StringBundler(6);
12134    
12135                    query.append(_FILTER_SQL_COUNT_DLFOLDER_WHERE);
12136    
12137                    query.append(_FINDER_COLUMN_G_M_P_H_S_GROUPID_2);
12138    
12139                    query.append(_FINDER_COLUMN_G_M_P_H_S_MOUNTPOINT_2);
12140    
12141                    query.append(_FINDER_COLUMN_G_M_P_H_S_PARENTFOLDERID_2);
12142    
12143                    query.append(_FINDER_COLUMN_G_M_P_H_S_HIDDEN_2_SQL);
12144    
12145                    query.append(_FINDER_COLUMN_G_M_P_H_S_STATUS_2);
12146    
12147                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
12148                                    DLFolder.class.getName(),
12149                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
12150    
12151                    Session session = null;
12152    
12153                    try {
12154                            session = openSession();
12155    
12156                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
12157    
12158                            q.addScalar(COUNT_COLUMN_NAME,
12159                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
12160    
12161                            QueryPos qPos = QueryPos.getInstance(q);
12162    
12163                            qPos.add(groupId);
12164    
12165                            qPos.add(mountPoint);
12166    
12167                            qPos.add(parentFolderId);
12168    
12169                            qPos.add(hidden);
12170    
12171                            qPos.add(status);
12172    
12173                            Long count = (Long)q.uniqueResult();
12174    
12175                            return count.intValue();
12176                    }
12177                    catch (Exception e) {
12178                            throw processException(e);
12179                    }
12180                    finally {
12181                            closeSession(session);
12182                    }
12183            }
12184    
12185            private static final String _FINDER_COLUMN_G_M_P_H_S_GROUPID_2 = "dlFolder.groupId = ? AND ";
12186            private static final String _FINDER_COLUMN_G_M_P_H_S_MOUNTPOINT_2 = "dlFolder.mountPoint = ? AND ";
12187            private static final String _FINDER_COLUMN_G_M_P_H_S_PARENTFOLDERID_2 = "dlFolder.parentFolderId = ? AND ";
12188            private static final String _FINDER_COLUMN_G_M_P_H_S_HIDDEN_2 = "dlFolder.hidden = ? AND ";
12189            private static final String _FINDER_COLUMN_G_M_P_H_S_HIDDEN_2_SQL = "dlFolder.hidden_ = ? AND ";
12190            private static final String _FINDER_COLUMN_G_M_P_H_S_STATUS_2 = "dlFolder.status = ?";
12191    
12192            public DLFolderPersistenceImpl() {
12193                    setModelClass(DLFolder.class);
12194            }
12195    
12196            /**
12197             * Caches the document library folder in the entity cache if it is enabled.
12198             *
12199             * @param dlFolder the document library folder
12200             */
12201            @Override
12202            public void cacheResult(DLFolder dlFolder) {
12203                    entityCache.putResult(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
12204                            DLFolderImpl.class, dlFolder.getPrimaryKey(), dlFolder);
12205    
12206                    finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G,
12207                            new Object[] { dlFolder.getUuid(), dlFolder.getGroupId() }, dlFolder);
12208    
12209                    finderCache.putResult(FINDER_PATH_FETCH_BY_R_M,
12210                            new Object[] { dlFolder.getRepositoryId(), dlFolder.getMountPoint() },
12211                            dlFolder);
12212    
12213                    finderCache.putResult(FINDER_PATH_FETCH_BY_G_P_N,
12214                            new Object[] {
12215                                    dlFolder.getGroupId(), dlFolder.getParentFolderId(),
12216                                    dlFolder.getName()
12217                            }, dlFolder);
12218    
12219                    dlFolder.resetOriginalValues();
12220            }
12221    
12222            /**
12223             * Caches the document library folders in the entity cache if it is enabled.
12224             *
12225             * @param dlFolders the document library folders
12226             */
12227            @Override
12228            public void cacheResult(List<DLFolder> dlFolders) {
12229                    for (DLFolder dlFolder : dlFolders) {
12230                            if (entityCache.getResult(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
12231                                                    DLFolderImpl.class, dlFolder.getPrimaryKey()) == null) {
12232                                    cacheResult(dlFolder);
12233                            }
12234                            else {
12235                                    dlFolder.resetOriginalValues();
12236                            }
12237                    }
12238            }
12239    
12240            /**
12241             * Clears the cache for all document library folders.
12242             *
12243             * <p>
12244             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
12245             * </p>
12246             */
12247            @Override
12248            public void clearCache() {
12249                    entityCache.clearCache(DLFolderImpl.class);
12250    
12251                    finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
12252                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
12253                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
12254            }
12255    
12256            /**
12257             * Clears the cache for the document library folder.
12258             *
12259             * <p>
12260             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
12261             * </p>
12262             */
12263            @Override
12264            public void clearCache(DLFolder dlFolder) {
12265                    entityCache.removeResult(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
12266                            DLFolderImpl.class, dlFolder.getPrimaryKey());
12267    
12268                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
12269                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
12270    
12271                    clearUniqueFindersCache((DLFolderModelImpl)dlFolder);
12272            }
12273    
12274            @Override
12275            public void clearCache(List<DLFolder> dlFolders) {
12276                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
12277                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
12278    
12279                    for (DLFolder dlFolder : dlFolders) {
12280                            entityCache.removeResult(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
12281                                    DLFolderImpl.class, dlFolder.getPrimaryKey());
12282    
12283                            clearUniqueFindersCache((DLFolderModelImpl)dlFolder);
12284                    }
12285            }
12286    
12287            protected void cacheUniqueFindersCache(
12288                    DLFolderModelImpl dlFolderModelImpl, boolean isNew) {
12289                    if (isNew) {
12290                            Object[] args = new Object[] {
12291                                            dlFolderModelImpl.getUuid(), dlFolderModelImpl.getGroupId()
12292                                    };
12293    
12294                            finderCache.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
12295                                    Long.valueOf(1));
12296                            finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
12297                                    dlFolderModelImpl);
12298    
12299                            args = new Object[] {
12300                                            dlFolderModelImpl.getRepositoryId(),
12301                                            dlFolderModelImpl.getMountPoint()
12302                                    };
12303    
12304                            finderCache.putResult(FINDER_PATH_COUNT_BY_R_M, args,
12305                                    Long.valueOf(1));
12306                            finderCache.putResult(FINDER_PATH_FETCH_BY_R_M, args,
12307                                    dlFolderModelImpl);
12308    
12309                            args = new Object[] {
12310                                            dlFolderModelImpl.getGroupId(),
12311                                            dlFolderModelImpl.getParentFolderId(),
12312                                            dlFolderModelImpl.getName()
12313                                    };
12314    
12315                            finderCache.putResult(FINDER_PATH_COUNT_BY_G_P_N, args,
12316                                    Long.valueOf(1));
12317                            finderCache.putResult(FINDER_PATH_FETCH_BY_G_P_N, args,
12318                                    dlFolderModelImpl);
12319                    }
12320                    else {
12321                            if ((dlFolderModelImpl.getColumnBitmask() &
12322                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
12323                                    Object[] args = new Object[] {
12324                                                    dlFolderModelImpl.getUuid(),
12325                                                    dlFolderModelImpl.getGroupId()
12326                                            };
12327    
12328                                    finderCache.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
12329                                            Long.valueOf(1));
12330                                    finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
12331                                            dlFolderModelImpl);
12332                            }
12333    
12334                            if ((dlFolderModelImpl.getColumnBitmask() &
12335                                            FINDER_PATH_FETCH_BY_R_M.getColumnBitmask()) != 0) {
12336                                    Object[] args = new Object[] {
12337                                                    dlFolderModelImpl.getRepositoryId(),
12338                                                    dlFolderModelImpl.getMountPoint()
12339                                            };
12340    
12341                                    finderCache.putResult(FINDER_PATH_COUNT_BY_R_M, args,
12342                                            Long.valueOf(1));
12343                                    finderCache.putResult(FINDER_PATH_FETCH_BY_R_M, args,
12344                                            dlFolderModelImpl);
12345                            }
12346    
12347                            if ((dlFolderModelImpl.getColumnBitmask() &
12348                                            FINDER_PATH_FETCH_BY_G_P_N.getColumnBitmask()) != 0) {
12349                                    Object[] args = new Object[] {
12350                                                    dlFolderModelImpl.getGroupId(),
12351                                                    dlFolderModelImpl.getParentFolderId(),
12352                                                    dlFolderModelImpl.getName()
12353                                            };
12354    
12355                                    finderCache.putResult(FINDER_PATH_COUNT_BY_G_P_N, args,
12356                                            Long.valueOf(1));
12357                                    finderCache.putResult(FINDER_PATH_FETCH_BY_G_P_N, args,
12358                                            dlFolderModelImpl);
12359                            }
12360                    }
12361            }
12362    
12363            protected void clearUniqueFindersCache(DLFolderModelImpl dlFolderModelImpl) {
12364                    Object[] args = new Object[] {
12365                                    dlFolderModelImpl.getUuid(), dlFolderModelImpl.getGroupId()
12366                            };
12367    
12368                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
12369                    finderCache.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
12370    
12371                    if ((dlFolderModelImpl.getColumnBitmask() &
12372                                    FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
12373                            args = new Object[] {
12374                                            dlFolderModelImpl.getOriginalUuid(),
12375                                            dlFolderModelImpl.getOriginalGroupId()
12376                                    };
12377    
12378                            finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
12379                            finderCache.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
12380                    }
12381    
12382                    args = new Object[] {
12383                                    dlFolderModelImpl.getRepositoryId(),
12384                                    dlFolderModelImpl.getMountPoint()
12385                            };
12386    
12387                    finderCache.removeResult(FINDER_PATH_COUNT_BY_R_M, args);
12388                    finderCache.removeResult(FINDER_PATH_FETCH_BY_R_M, args);
12389    
12390                    if ((dlFolderModelImpl.getColumnBitmask() &
12391                                    FINDER_PATH_FETCH_BY_R_M.getColumnBitmask()) != 0) {
12392                            args = new Object[] {
12393                                            dlFolderModelImpl.getOriginalRepositoryId(),
12394                                            dlFolderModelImpl.getOriginalMountPoint()
12395                                    };
12396    
12397                            finderCache.removeResult(FINDER_PATH_COUNT_BY_R_M, args);
12398                            finderCache.removeResult(FINDER_PATH_FETCH_BY_R_M, args);
12399                    }
12400    
12401                    args = new Object[] {
12402                                    dlFolderModelImpl.getGroupId(),
12403                                    dlFolderModelImpl.getParentFolderId(),
12404                                    dlFolderModelImpl.getName()
12405                            };
12406    
12407                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_P_N, args);
12408                    finderCache.removeResult(FINDER_PATH_FETCH_BY_G_P_N, args);
12409    
12410                    if ((dlFolderModelImpl.getColumnBitmask() &
12411                                    FINDER_PATH_FETCH_BY_G_P_N.getColumnBitmask()) != 0) {
12412                            args = new Object[] {
12413                                            dlFolderModelImpl.getOriginalGroupId(),
12414                                            dlFolderModelImpl.getOriginalParentFolderId(),
12415                                            dlFolderModelImpl.getOriginalName()
12416                                    };
12417    
12418                            finderCache.removeResult(FINDER_PATH_COUNT_BY_G_P_N, args);
12419                            finderCache.removeResult(FINDER_PATH_FETCH_BY_G_P_N, args);
12420                    }
12421            }
12422    
12423            /**
12424             * Creates a new document library folder with the primary key. Does not add the document library folder to the database.
12425             *
12426             * @param folderId the primary key for the new document library folder
12427             * @return the new document library folder
12428             */
12429            @Override
12430            public DLFolder create(long folderId) {
12431                    DLFolder dlFolder = new DLFolderImpl();
12432    
12433                    dlFolder.setNew(true);
12434                    dlFolder.setPrimaryKey(folderId);
12435    
12436                    String uuid = PortalUUIDUtil.generate();
12437    
12438                    dlFolder.setUuid(uuid);
12439    
12440                    dlFolder.setCompanyId(companyProvider.getCompanyId());
12441    
12442                    return dlFolder;
12443            }
12444    
12445            /**
12446             * Removes the document library folder with the primary key from the database. Also notifies the appropriate model listeners.
12447             *
12448             * @param folderId the primary key of the document library folder
12449             * @return the document library folder that was removed
12450             * @throws NoSuchFolderException if a document library folder with the primary key could not be found
12451             */
12452            @Override
12453            public DLFolder remove(long folderId) throws NoSuchFolderException {
12454                    return remove((Serializable)folderId);
12455            }
12456    
12457            /**
12458             * Removes the document library folder with the primary key from the database. Also notifies the appropriate model listeners.
12459             *
12460             * @param primaryKey the primary key of the document library folder
12461             * @return the document library folder that was removed
12462             * @throws NoSuchFolderException if a document library folder with the primary key could not be found
12463             */
12464            @Override
12465            public DLFolder remove(Serializable primaryKey)
12466                    throws NoSuchFolderException {
12467                    Session session = null;
12468    
12469                    try {
12470                            session = openSession();
12471    
12472                            DLFolder dlFolder = (DLFolder)session.get(DLFolderImpl.class,
12473                                            primaryKey);
12474    
12475                            if (dlFolder == null) {
12476                                    if (_log.isWarnEnabled()) {
12477                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
12478                                    }
12479    
12480                                    throw new NoSuchFolderException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
12481                                            primaryKey);
12482                            }
12483    
12484                            return remove(dlFolder);
12485                    }
12486                    catch (NoSuchFolderException nsee) {
12487                            throw nsee;
12488                    }
12489                    catch (Exception e) {
12490                            throw processException(e);
12491                    }
12492                    finally {
12493                            closeSession(session);
12494                    }
12495            }
12496    
12497            @Override
12498            protected DLFolder removeImpl(DLFolder dlFolder) {
12499                    dlFolder = toUnwrappedModel(dlFolder);
12500    
12501                    dlFolderToDLFileEntryTypeTableMapper.deleteLeftPrimaryKeyTableMappings(dlFolder.getPrimaryKey());
12502    
12503                    Session session = null;
12504    
12505                    try {
12506                            session = openSession();
12507    
12508                            if (!session.contains(dlFolder)) {
12509                                    dlFolder = (DLFolder)session.get(DLFolderImpl.class,
12510                                                    dlFolder.getPrimaryKeyObj());
12511                            }
12512    
12513                            if (dlFolder != null) {
12514                                    session.delete(dlFolder);
12515                            }
12516                    }
12517                    catch (Exception e) {
12518                            throw processException(e);
12519                    }
12520                    finally {
12521                            closeSession(session);
12522                    }
12523    
12524                    if (dlFolder != null) {
12525                            clearCache(dlFolder);
12526                    }
12527    
12528                    return dlFolder;
12529            }
12530    
12531            @Override
12532            public DLFolder updateImpl(DLFolder dlFolder) {
12533                    dlFolder = toUnwrappedModel(dlFolder);
12534    
12535                    boolean isNew = dlFolder.isNew();
12536    
12537                    DLFolderModelImpl dlFolderModelImpl = (DLFolderModelImpl)dlFolder;
12538    
12539                    if (Validator.isNull(dlFolder.getUuid())) {
12540                            String uuid = PortalUUIDUtil.generate();
12541    
12542                            dlFolder.setUuid(uuid);
12543                    }
12544    
12545                    ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();
12546    
12547                    Date now = new Date();
12548    
12549                    if (isNew && (dlFolder.getCreateDate() == null)) {
12550                            if (serviceContext == null) {
12551                                    dlFolder.setCreateDate(now);
12552                            }
12553                            else {
12554                                    dlFolder.setCreateDate(serviceContext.getCreateDate(now));
12555                            }
12556                    }
12557    
12558                    if (!dlFolderModelImpl.hasSetModifiedDate()) {
12559                            if (serviceContext == null) {
12560                                    dlFolder.setModifiedDate(now);
12561                            }
12562                            else {
12563                                    dlFolder.setModifiedDate(serviceContext.getModifiedDate(now));
12564                            }
12565                    }
12566    
12567                    Session session = null;
12568    
12569                    try {
12570                            session = openSession();
12571    
12572                            if (dlFolder.isNew()) {
12573                                    session.save(dlFolder);
12574    
12575                                    dlFolder.setNew(false);
12576                            }
12577                            else {
12578                                    dlFolder = (DLFolder)session.merge(dlFolder);
12579                            }
12580                    }
12581                    catch (Exception e) {
12582                            throw processException(e);
12583                    }
12584                    finally {
12585                            closeSession(session);
12586                    }
12587    
12588                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
12589    
12590                    if (isNew || !DLFolderModelImpl.COLUMN_BITMASK_ENABLED) {
12591                            finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
12592                    }
12593    
12594                    else {
12595                            if ((dlFolderModelImpl.getColumnBitmask() &
12596                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
12597                                    Object[] args = new Object[] { dlFolderModelImpl.getOriginalUuid() };
12598    
12599                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
12600                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
12601                                            args);
12602    
12603                                    args = new Object[] { dlFolderModelImpl.getUuid() };
12604    
12605                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
12606                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
12607                                            args);
12608                            }
12609    
12610                            if ((dlFolderModelImpl.getColumnBitmask() &
12611                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
12612                                    Object[] args = new Object[] {
12613                                                    dlFolderModelImpl.getOriginalUuid(),
12614                                                    dlFolderModelImpl.getOriginalCompanyId()
12615                                            };
12616    
12617                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
12618                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
12619                                            args);
12620    
12621                                    args = new Object[] {
12622                                                    dlFolderModelImpl.getUuid(),
12623                                                    dlFolderModelImpl.getCompanyId()
12624                                            };
12625    
12626                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
12627                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
12628                                            args);
12629                            }
12630    
12631                            if ((dlFolderModelImpl.getColumnBitmask() &
12632                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
12633                                    Object[] args = new Object[] {
12634                                                    dlFolderModelImpl.getOriginalGroupId()
12635                                            };
12636    
12637                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
12638                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
12639                                            args);
12640    
12641                                    args = new Object[] { dlFolderModelImpl.getGroupId() };
12642    
12643                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
12644                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
12645                                            args);
12646                            }
12647    
12648                            if ((dlFolderModelImpl.getColumnBitmask() &
12649                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
12650                                    Object[] args = new Object[] {
12651                                                    dlFolderModelImpl.getOriginalCompanyId()
12652                                            };
12653    
12654                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_COMPANYID, args);
12655                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
12656                                            args);
12657    
12658                                    args = new Object[] { dlFolderModelImpl.getCompanyId() };
12659    
12660                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_COMPANYID, args);
12661                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
12662                                            args);
12663                            }
12664    
12665                            if ((dlFolderModelImpl.getColumnBitmask() &
12666                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_REPOSITORYID.getColumnBitmask()) != 0) {
12667                                    Object[] args = new Object[] {
12668                                                    dlFolderModelImpl.getOriginalRepositoryId()
12669                                            };
12670    
12671                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_REPOSITORYID, args);
12672                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_REPOSITORYID,
12673                                            args);
12674    
12675                                    args = new Object[] { dlFolderModelImpl.getRepositoryId() };
12676    
12677                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_REPOSITORYID, args);
12678                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_REPOSITORYID,
12679                                            args);
12680                            }
12681    
12682                            if ((dlFolderModelImpl.getColumnBitmask() &
12683                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P.getColumnBitmask()) != 0) {
12684                                    Object[] args = new Object[] {
12685                                                    dlFolderModelImpl.getOriginalGroupId(),
12686                                                    dlFolderModelImpl.getOriginalParentFolderId()
12687                                            };
12688    
12689                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_P, args);
12690                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P,
12691                                            args);
12692    
12693                                    args = new Object[] {
12694                                                    dlFolderModelImpl.getGroupId(),
12695                                                    dlFolderModelImpl.getParentFolderId()
12696                                            };
12697    
12698                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_P, args);
12699                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P,
12700                                            args);
12701                            }
12702    
12703                            if ((dlFolderModelImpl.getColumnBitmask() &
12704                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_P.getColumnBitmask()) != 0) {
12705                                    Object[] args = new Object[] {
12706                                                    dlFolderModelImpl.getOriginalRepositoryId(),
12707                                                    dlFolderModelImpl.getOriginalParentFolderId()
12708                                            };
12709    
12710                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_R_P, args);
12711                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_P,
12712                                            args);
12713    
12714                                    args = new Object[] {
12715                                                    dlFolderModelImpl.getRepositoryId(),
12716                                                    dlFolderModelImpl.getParentFolderId()
12717                                            };
12718    
12719                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_R_P, args);
12720                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_P,
12721                                            args);
12722                            }
12723    
12724                            if ((dlFolderModelImpl.getColumnBitmask() &
12725                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_N.getColumnBitmask()) != 0) {
12726                                    Object[] args = new Object[] {
12727                                                    dlFolderModelImpl.getOriginalParentFolderId(),
12728                                                    dlFolderModelImpl.getOriginalName()
12729                                            };
12730    
12731                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_P_N, args);
12732                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_N,
12733                                            args);
12734    
12735                                    args = new Object[] {
12736                                                    dlFolderModelImpl.getParentFolderId(),
12737                                                    dlFolderModelImpl.getName()
12738                                            };
12739    
12740                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_P_N, args);
12741                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_N,
12742                                            args);
12743                            }
12744    
12745                            if ((dlFolderModelImpl.getColumnBitmask() &
12746                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P.getColumnBitmask()) != 0) {
12747                                    Object[] args = new Object[] {
12748                                                    dlFolderModelImpl.getOriginalGroupId(),
12749                                                    dlFolderModelImpl.getOriginalMountPoint(),
12750                                                    dlFolderModelImpl.getOriginalParentFolderId()
12751                                            };
12752    
12753                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_M_P, args);
12754                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P,
12755                                            args);
12756    
12757                                    args = new Object[] {
12758                                                    dlFolderModelImpl.getGroupId(),
12759                                                    dlFolderModelImpl.getMountPoint(),
12760                                                    dlFolderModelImpl.getParentFolderId()
12761                                            };
12762    
12763                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_M_P, args);
12764                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P,
12765                                            args);
12766                            }
12767    
12768                            if ((dlFolderModelImpl.getColumnBitmask() &
12769                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P_H.getColumnBitmask()) != 0) {
12770                                    Object[] args = new Object[] {
12771                                                    dlFolderModelImpl.getOriginalGroupId(),
12772                                                    dlFolderModelImpl.getOriginalMountPoint(),
12773                                                    dlFolderModelImpl.getOriginalParentFolderId(),
12774                                                    dlFolderModelImpl.getOriginalHidden()
12775                                            };
12776    
12777                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_M_P_H, args);
12778                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P_H,
12779                                            args);
12780    
12781                                    args = new Object[] {
12782                                                    dlFolderModelImpl.getGroupId(),
12783                                                    dlFolderModelImpl.getMountPoint(),
12784                                                    dlFolderModelImpl.getParentFolderId(),
12785                                                    dlFolderModelImpl.getHidden()
12786                                            };
12787    
12788                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_M_P_H, args);
12789                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P_H,
12790                                            args);
12791                            }
12792    
12793                            if ((dlFolderModelImpl.getColumnBitmask() &
12794                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_H_S.getColumnBitmask()) != 0) {
12795                                    Object[] args = new Object[] {
12796                                                    dlFolderModelImpl.getOriginalGroupId(),
12797                                                    dlFolderModelImpl.getOriginalParentFolderId(),
12798                                                    dlFolderModelImpl.getOriginalHidden(),
12799                                                    dlFolderModelImpl.getOriginalStatus()
12800                                            };
12801    
12802                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_P_H_S, args);
12803                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_H_S,
12804                                            args);
12805    
12806                                    args = new Object[] {
12807                                                    dlFolderModelImpl.getGroupId(),
12808                                                    dlFolderModelImpl.getParentFolderId(),
12809                                                    dlFolderModelImpl.getHidden(),
12810                                                    dlFolderModelImpl.getStatus()
12811                                            };
12812    
12813                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_P_H_S, args);
12814                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_H_S,
12815                                            args);
12816                            }
12817    
12818                            if ((dlFolderModelImpl.getColumnBitmask() &
12819                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P_H_S.getColumnBitmask()) != 0) {
12820                                    Object[] args = new Object[] {
12821                                                    dlFolderModelImpl.getOriginalGroupId(),
12822                                                    dlFolderModelImpl.getOriginalMountPoint(),
12823                                                    dlFolderModelImpl.getOriginalParentFolderId(),
12824                                                    dlFolderModelImpl.getOriginalHidden(),
12825                                                    dlFolderModelImpl.getOriginalStatus()
12826                                            };
12827    
12828                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_M_P_H_S, args);
12829                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P_H_S,
12830                                            args);
12831    
12832                                    args = new Object[] {
12833                                                    dlFolderModelImpl.getGroupId(),
12834                                                    dlFolderModelImpl.getMountPoint(),
12835                                                    dlFolderModelImpl.getParentFolderId(),
12836                                                    dlFolderModelImpl.getHidden(),
12837                                                    dlFolderModelImpl.getStatus()
12838                                            };
12839    
12840                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_M_P_H_S, args);
12841                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P_H_S,
12842                                            args);
12843                            }
12844                    }
12845    
12846                    entityCache.putResult(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
12847                            DLFolderImpl.class, dlFolder.getPrimaryKey(), dlFolder, false);
12848    
12849                    clearUniqueFindersCache(dlFolderModelImpl);
12850                    cacheUniqueFindersCache(dlFolderModelImpl, isNew);
12851    
12852                    dlFolder.resetOriginalValues();
12853    
12854                    return dlFolder;
12855            }
12856    
12857            protected DLFolder toUnwrappedModel(DLFolder dlFolder) {
12858                    if (dlFolder instanceof DLFolderImpl) {
12859                            return dlFolder;
12860                    }
12861    
12862                    DLFolderImpl dlFolderImpl = new DLFolderImpl();
12863    
12864                    dlFolderImpl.setNew(dlFolder.isNew());
12865                    dlFolderImpl.setPrimaryKey(dlFolder.getPrimaryKey());
12866    
12867                    dlFolderImpl.setUuid(dlFolder.getUuid());
12868                    dlFolderImpl.setFolderId(dlFolder.getFolderId());
12869                    dlFolderImpl.setGroupId(dlFolder.getGroupId());
12870                    dlFolderImpl.setCompanyId(dlFolder.getCompanyId());
12871                    dlFolderImpl.setUserId(dlFolder.getUserId());
12872                    dlFolderImpl.setUserName(dlFolder.getUserName());
12873                    dlFolderImpl.setCreateDate(dlFolder.getCreateDate());
12874                    dlFolderImpl.setModifiedDate(dlFolder.getModifiedDate());
12875                    dlFolderImpl.setRepositoryId(dlFolder.getRepositoryId());
12876                    dlFolderImpl.setMountPoint(dlFolder.isMountPoint());
12877                    dlFolderImpl.setParentFolderId(dlFolder.getParentFolderId());
12878                    dlFolderImpl.setTreePath(dlFolder.getTreePath());
12879                    dlFolderImpl.setName(dlFolder.getName());
12880                    dlFolderImpl.setDescription(dlFolder.getDescription());
12881                    dlFolderImpl.setLastPostDate(dlFolder.getLastPostDate());
12882                    dlFolderImpl.setDefaultFileEntryTypeId(dlFolder.getDefaultFileEntryTypeId());
12883                    dlFolderImpl.setHidden(dlFolder.isHidden());
12884                    dlFolderImpl.setRestrictionType(dlFolder.getRestrictionType());
12885                    dlFolderImpl.setLastPublishDate(dlFolder.getLastPublishDate());
12886                    dlFolderImpl.setStatus(dlFolder.getStatus());
12887                    dlFolderImpl.setStatusByUserId(dlFolder.getStatusByUserId());
12888                    dlFolderImpl.setStatusByUserName(dlFolder.getStatusByUserName());
12889                    dlFolderImpl.setStatusDate(dlFolder.getStatusDate());
12890    
12891                    return dlFolderImpl;
12892            }
12893    
12894            /**
12895             * Returns the document library folder with the primary key or throws a {@link com.liferay.portal.exception.NoSuchModelException} if it could not be found.
12896             *
12897             * @param primaryKey the primary key of the document library folder
12898             * @return the document library folder
12899             * @throws NoSuchFolderException if a document library folder with the primary key could not be found
12900             */
12901            @Override
12902            public DLFolder findByPrimaryKey(Serializable primaryKey)
12903                    throws NoSuchFolderException {
12904                    DLFolder dlFolder = fetchByPrimaryKey(primaryKey);
12905    
12906                    if (dlFolder == null) {
12907                            if (_log.isWarnEnabled()) {
12908                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
12909                            }
12910    
12911                            throw new NoSuchFolderException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
12912                                    primaryKey);
12913                    }
12914    
12915                    return dlFolder;
12916            }
12917    
12918            /**
12919             * Returns the document library folder with the primary key or throws a {@link NoSuchFolderException} if it could not be found.
12920             *
12921             * @param folderId the primary key of the document library folder
12922             * @return the document library folder
12923             * @throws NoSuchFolderException if a document library folder with the primary key could not be found
12924             */
12925            @Override
12926            public DLFolder findByPrimaryKey(long folderId)
12927                    throws NoSuchFolderException {
12928                    return findByPrimaryKey((Serializable)folderId);
12929            }
12930    
12931            /**
12932             * Returns the document library folder with the primary key or returns <code>null</code> if it could not be found.
12933             *
12934             * @param primaryKey the primary key of the document library folder
12935             * @return the document library folder, or <code>null</code> if a document library folder with the primary key could not be found
12936             */
12937            @Override
12938            public DLFolder fetchByPrimaryKey(Serializable primaryKey) {
12939                    DLFolder dlFolder = (DLFolder)entityCache.getResult(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
12940                                    DLFolderImpl.class, primaryKey);
12941    
12942                    if (dlFolder == _nullDLFolder) {
12943                            return null;
12944                    }
12945    
12946                    if (dlFolder == null) {
12947                            Session session = null;
12948    
12949                            try {
12950                                    session = openSession();
12951    
12952                                    dlFolder = (DLFolder)session.get(DLFolderImpl.class, primaryKey);
12953    
12954                                    if (dlFolder != null) {
12955                                            cacheResult(dlFolder);
12956                                    }
12957                                    else {
12958                                            entityCache.putResult(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
12959                                                    DLFolderImpl.class, primaryKey, _nullDLFolder);
12960                                    }
12961                            }
12962                            catch (Exception e) {
12963                                    entityCache.removeResult(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
12964                                            DLFolderImpl.class, primaryKey);
12965    
12966                                    throw processException(e);
12967                            }
12968                            finally {
12969                                    closeSession(session);
12970                            }
12971                    }
12972    
12973                    return dlFolder;
12974            }
12975    
12976            /**
12977             * Returns the document library folder with the primary key or returns <code>null</code> if it could not be found.
12978             *
12979             * @param folderId the primary key of the document library folder
12980             * @return the document library folder, or <code>null</code> if a document library folder with the primary key could not be found
12981             */
12982            @Override
12983            public DLFolder fetchByPrimaryKey(long folderId) {
12984                    return fetchByPrimaryKey((Serializable)folderId);
12985            }
12986    
12987            @Override
12988            public Map<Serializable, DLFolder> fetchByPrimaryKeys(
12989                    Set<Serializable> primaryKeys) {
12990                    if (primaryKeys.isEmpty()) {
12991                            return Collections.emptyMap();
12992                    }
12993    
12994                    Map<Serializable, DLFolder> map = new HashMap<Serializable, DLFolder>();
12995    
12996                    if (primaryKeys.size() == 1) {
12997                            Iterator<Serializable> iterator = primaryKeys.iterator();
12998    
12999                            Serializable primaryKey = iterator.next();
13000    
13001                            DLFolder dlFolder = fetchByPrimaryKey(primaryKey);
13002    
13003                            if (dlFolder != null) {
13004                                    map.put(primaryKey, dlFolder);
13005                            }
13006    
13007                            return map;
13008                    }
13009    
13010                    Set<Serializable> uncachedPrimaryKeys = null;
13011    
13012                    for (Serializable primaryKey : primaryKeys) {
13013                            DLFolder dlFolder = (DLFolder)entityCache.getResult(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
13014                                            DLFolderImpl.class, primaryKey);
13015    
13016                            if (dlFolder == null) {
13017                                    if (uncachedPrimaryKeys == null) {
13018                                            uncachedPrimaryKeys = new HashSet<Serializable>();
13019                                    }
13020    
13021                                    uncachedPrimaryKeys.add(primaryKey);
13022                            }
13023                            else {
13024                                    map.put(primaryKey, dlFolder);
13025                            }
13026                    }
13027    
13028                    if (uncachedPrimaryKeys == null) {
13029                            return map;
13030                    }
13031    
13032                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
13033                                    1);
13034    
13035                    query.append(_SQL_SELECT_DLFOLDER_WHERE_PKS_IN);
13036    
13037                    for (Serializable primaryKey : uncachedPrimaryKeys) {
13038                            query.append(String.valueOf(primaryKey));
13039    
13040                            query.append(StringPool.COMMA);
13041                    }
13042    
13043                    query.setIndex(query.index() - 1);
13044    
13045                    query.append(StringPool.CLOSE_PARENTHESIS);
13046    
13047                    String sql = query.toString();
13048    
13049                    Session session = null;
13050    
13051                    try {
13052                            session = openSession();
13053    
13054                            Query q = session.createQuery(sql);
13055    
13056                            for (DLFolder dlFolder : (List<DLFolder>)q.list()) {
13057                                    map.put(dlFolder.getPrimaryKeyObj(), dlFolder);
13058    
13059                                    cacheResult(dlFolder);
13060    
13061                                    uncachedPrimaryKeys.remove(dlFolder.getPrimaryKeyObj());
13062                            }
13063    
13064                            for (Serializable primaryKey : uncachedPrimaryKeys) {
13065                                    entityCache.putResult(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
13066                                            DLFolderImpl.class, primaryKey, _nullDLFolder);
13067                            }
13068                    }
13069                    catch (Exception e) {
13070                            throw processException(e);
13071                    }
13072                    finally {
13073                            closeSession(session);
13074                    }
13075    
13076                    return map;
13077            }
13078    
13079            /**
13080             * Returns all the document library folders.
13081             *
13082             * @return the document library folders
13083             */
13084            @Override
13085            public List<DLFolder> findAll() {
13086                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
13087            }
13088    
13089            /**
13090             * Returns a range of all the document library folders.
13091             *
13092             * <p>
13093             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
13094             * </p>
13095             *
13096             * @param start the lower bound of the range of document library folders
13097             * @param end the upper bound of the range of document library folders (not inclusive)
13098             * @return the range of document library folders
13099             */
13100            @Override
13101            public List<DLFolder> findAll(int start, int end) {
13102                    return findAll(start, end, null);
13103            }
13104    
13105            /**
13106             * Returns an ordered range of all the document library folders.
13107             *
13108             * <p>
13109             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
13110             * </p>
13111             *
13112             * @param start the lower bound of the range of document library folders
13113             * @param end the upper bound of the range of document library folders (not inclusive)
13114             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
13115             * @return the ordered range of document library folders
13116             */
13117            @Override
13118            public List<DLFolder> findAll(int start, int end,
13119                    OrderByComparator<DLFolder> orderByComparator) {
13120                    return findAll(start, end, orderByComparator, true);
13121            }
13122    
13123            /**
13124             * Returns an ordered range of all the document library folders.
13125             *
13126             * <p>
13127             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
13128             * </p>
13129             *
13130             * @param start the lower bound of the range of document library folders
13131             * @param end the upper bound of the range of document library folders (not inclusive)
13132             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
13133             * @param retrieveFromCache whether to retrieve from the finder cache
13134             * @return the ordered range of document library folders
13135             */
13136            @Override
13137            public List<DLFolder> findAll(int start, int end,
13138                    OrderByComparator<DLFolder> orderByComparator, boolean retrieveFromCache) {
13139                    boolean pagination = true;
13140                    FinderPath finderPath = null;
13141                    Object[] finderArgs = null;
13142    
13143                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
13144                                    (orderByComparator == null)) {
13145                            pagination = false;
13146                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
13147                            finderArgs = FINDER_ARGS_EMPTY;
13148                    }
13149                    else {
13150                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
13151                            finderArgs = new Object[] { start, end, orderByComparator };
13152                    }
13153    
13154                    List<DLFolder> list = null;
13155    
13156                    if (retrieveFromCache) {
13157                            list = (List<DLFolder>)finderCache.getResult(finderPath,
13158                                            finderArgs, this);
13159                    }
13160    
13161                    if (list == null) {
13162                            StringBundler query = null;
13163                            String sql = null;
13164    
13165                            if (orderByComparator != null) {
13166                                    query = new StringBundler(2 +
13167                                                    (orderByComparator.getOrderByFields().length * 2));
13168    
13169                                    query.append(_SQL_SELECT_DLFOLDER);
13170    
13171                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
13172                                            orderByComparator);
13173    
13174                                    sql = query.toString();
13175                            }
13176                            else {
13177                                    sql = _SQL_SELECT_DLFOLDER;
13178    
13179                                    if (pagination) {
13180                                            sql = sql.concat(DLFolderModelImpl.ORDER_BY_JPQL);
13181                                    }
13182                            }
13183    
13184                            Session session = null;
13185    
13186                            try {
13187                                    session = openSession();
13188    
13189                                    Query q = session.createQuery(sql);
13190    
13191                                    if (!pagination) {
13192                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
13193                                                            start, end, false);
13194    
13195                                            Collections.sort(list);
13196    
13197                                            list = Collections.unmodifiableList(list);
13198                                    }
13199                                    else {
13200                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
13201                                                            start, end);
13202                                    }
13203    
13204                                    cacheResult(list);
13205    
13206                                    finderCache.putResult(finderPath, finderArgs, list);
13207                            }
13208                            catch (Exception e) {
13209                                    finderCache.removeResult(finderPath, finderArgs);
13210    
13211                                    throw processException(e);
13212                            }
13213                            finally {
13214                                    closeSession(session);
13215                            }
13216                    }
13217    
13218                    return list;
13219            }
13220    
13221            /**
13222             * Removes all the document library folders from the database.
13223             *
13224             */
13225            @Override
13226            public void removeAll() {
13227                    for (DLFolder dlFolder : findAll()) {
13228                            remove(dlFolder);
13229                    }
13230            }
13231    
13232            /**
13233             * Returns the number of document library folders.
13234             *
13235             * @return the number of document library folders
13236             */
13237            @Override
13238            public int countAll() {
13239                    Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
13240                                    FINDER_ARGS_EMPTY, this);
13241    
13242                    if (count == null) {
13243                            Session session = null;
13244    
13245                            try {
13246                                    session = openSession();
13247    
13248                                    Query q = session.createQuery(_SQL_COUNT_DLFOLDER);
13249    
13250                                    count = (Long)q.uniqueResult();
13251    
13252                                    finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
13253                                            count);
13254                            }
13255                            catch (Exception e) {
13256                                    finderCache.removeResult(FINDER_PATH_COUNT_ALL,
13257                                            FINDER_ARGS_EMPTY);
13258    
13259                                    throw processException(e);
13260                            }
13261                            finally {
13262                                    closeSession(session);
13263                            }
13264                    }
13265    
13266                    return count.intValue();
13267            }
13268    
13269            /**
13270             * Returns the primaryKeys of document library file entry types associated with the document library folder.
13271             *
13272             * @param pk the primary key of the document library folder
13273             * @return long[] of the primaryKeys of document library file entry types associated with the document library folder
13274             */
13275            @Override
13276            public long[] getDLFileEntryTypePrimaryKeys(long pk) {
13277                    long[] pks = dlFolderToDLFileEntryTypeTableMapper.getRightPrimaryKeys(pk);
13278    
13279                    return pks.clone();
13280            }
13281    
13282            /**
13283             * Returns all the document library file entry types associated with the document library folder.
13284             *
13285             * @param pk the primary key of the document library folder
13286             * @return the document library file entry types associated with the document library folder
13287             */
13288            @Override
13289            public List<com.liferay.portlet.documentlibrary.model.DLFileEntryType> getDLFileEntryTypes(
13290                    long pk) {
13291                    return getDLFileEntryTypes(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
13292            }
13293    
13294            /**
13295             * Returns a range of all the document library file entry types associated with the document library folder.
13296             *
13297             * <p>
13298             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
13299             * </p>
13300             *
13301             * @param pk the primary key of the document library folder
13302             * @param start the lower bound of the range of document library folders
13303             * @param end the upper bound of the range of document library folders (not inclusive)
13304             * @return the range of document library file entry types associated with the document library folder
13305             */
13306            @Override
13307            public List<com.liferay.portlet.documentlibrary.model.DLFileEntryType> getDLFileEntryTypes(
13308                    long pk, int start, int end) {
13309                    return getDLFileEntryTypes(pk, start, end, null);
13310            }
13311    
13312            /**
13313             * Returns an ordered range of all the document library file entry types associated with the document library folder.
13314             *
13315             * <p>
13316             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
13317             * </p>
13318             *
13319             * @param pk the primary key of the document library folder
13320             * @param start the lower bound of the range of document library folders
13321             * @param end the upper bound of the range of document library folders (not inclusive)
13322             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
13323             * @return the ordered range of document library file entry types associated with the document library folder
13324             */
13325            @Override
13326            public List<com.liferay.portlet.documentlibrary.model.DLFileEntryType> getDLFileEntryTypes(
13327                    long pk, int start, int end,
13328                    OrderByComparator<com.liferay.portlet.documentlibrary.model.DLFileEntryType> orderByComparator) {
13329                    return dlFolderToDLFileEntryTypeTableMapper.getRightBaseModels(pk,
13330                            start, end, orderByComparator);
13331            }
13332    
13333            /**
13334             * Returns the number of document library file entry types associated with the document library folder.
13335             *
13336             * @param pk the primary key of the document library folder
13337             * @return the number of document library file entry types associated with the document library folder
13338             */
13339            @Override
13340            public int getDLFileEntryTypesSize(long pk) {
13341                    long[] pks = dlFolderToDLFileEntryTypeTableMapper.getRightPrimaryKeys(pk);
13342    
13343                    return pks.length;
13344            }
13345    
13346            /**
13347             * Returns <code>true</code> if the document library file entry type is associated with the document library folder.
13348             *
13349             * @param pk the primary key of the document library folder
13350             * @param dlFileEntryTypePK the primary key of the document library file entry type
13351             * @return <code>true</code> if the document library file entry type is associated with the document library folder; <code>false</code> otherwise
13352             */
13353            @Override
13354            public boolean containsDLFileEntryType(long pk, long dlFileEntryTypePK) {
13355                    return dlFolderToDLFileEntryTypeTableMapper.containsTableMapping(pk,
13356                            dlFileEntryTypePK);
13357            }
13358    
13359            /**
13360             * Returns <code>true</code> if the document library folder has any document library file entry types associated with it.
13361             *
13362             * @param pk the primary key of the document library folder to check for associations with document library file entry types
13363             * @return <code>true</code> if the document library folder has any document library file entry types associated with it; <code>false</code> otherwise
13364             */
13365            @Override
13366            public boolean containsDLFileEntryTypes(long pk) {
13367                    if (getDLFileEntryTypesSize(pk) > 0) {
13368                            return true;
13369                    }
13370                    else {
13371                            return false;
13372                    }
13373            }
13374    
13375            /**
13376             * 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.
13377             *
13378             * @param pk the primary key of the document library folder
13379             * @param dlFileEntryTypePK the primary key of the document library file entry type
13380             */
13381            @Override
13382            public void addDLFileEntryType(long pk, long dlFileEntryTypePK) {
13383                    DLFolder dlFolder = fetchByPrimaryKey(pk);
13384    
13385                    if (dlFolder == null) {
13386                            dlFolderToDLFileEntryTypeTableMapper.addTableMapping(companyProvider.getCompanyId(),
13387                                    pk, dlFileEntryTypePK);
13388                    }
13389                    else {
13390                            dlFolderToDLFileEntryTypeTableMapper.addTableMapping(dlFolder.getCompanyId(),
13391                                    pk, dlFileEntryTypePK);
13392                    }
13393            }
13394    
13395            /**
13396             * 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.
13397             *
13398             * @param pk the primary key of the document library folder
13399             * @param dlFileEntryType the document library file entry type
13400             */
13401            @Override
13402            public void addDLFileEntryType(long pk,
13403                    com.liferay.portlet.documentlibrary.model.DLFileEntryType dlFileEntryType) {
13404                    DLFolder dlFolder = fetchByPrimaryKey(pk);
13405    
13406                    if (dlFolder == null) {
13407                            dlFolderToDLFileEntryTypeTableMapper.addTableMapping(companyProvider.getCompanyId(),
13408                                    pk, dlFileEntryType.getPrimaryKey());
13409                    }
13410                    else {
13411                            dlFolderToDLFileEntryTypeTableMapper.addTableMapping(dlFolder.getCompanyId(),
13412                                    pk, dlFileEntryType.getPrimaryKey());
13413                    }
13414            }
13415    
13416            /**
13417             * 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.
13418             *
13419             * @param pk the primary key of the document library folder
13420             * @param dlFileEntryTypePKs the primary keys of the document library file entry types
13421             */
13422            @Override
13423            public void addDLFileEntryTypes(long pk, long[] dlFileEntryTypePKs) {
13424                    long companyId = 0;
13425    
13426                    DLFolder dlFolder = fetchByPrimaryKey(pk);
13427    
13428                    if (dlFolder == null) {
13429                            companyId = companyProvider.getCompanyId();
13430                    }
13431                    else {
13432                            companyId = dlFolder.getCompanyId();
13433                    }
13434    
13435                    for (long dlFileEntryTypePK : dlFileEntryTypePKs) {
13436                            dlFolderToDLFileEntryTypeTableMapper.addTableMapping(companyId, pk,
13437                                    dlFileEntryTypePK);
13438                    }
13439            }
13440    
13441            /**
13442             * 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.
13443             *
13444             * @param pk the primary key of the document library folder
13445             * @param dlFileEntryTypes the document library file entry types
13446             */
13447            @Override
13448            public void addDLFileEntryTypes(long pk,
13449                    List<com.liferay.portlet.documentlibrary.model.DLFileEntryType> dlFileEntryTypes) {
13450                    long companyId = 0;
13451    
13452                    DLFolder dlFolder = fetchByPrimaryKey(pk);
13453    
13454                    if (dlFolder == null) {
13455                            companyId = companyProvider.getCompanyId();
13456                    }
13457                    else {
13458                            companyId = dlFolder.getCompanyId();
13459                    }
13460    
13461                    for (com.liferay.portlet.documentlibrary.model.DLFileEntryType dlFileEntryType : dlFileEntryTypes) {
13462                            dlFolderToDLFileEntryTypeTableMapper.addTableMapping(companyId, pk,
13463                                    dlFileEntryType.getPrimaryKey());
13464                    }
13465            }
13466    
13467            /**
13468             * 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.
13469             *
13470             * @param pk the primary key of the document library folder to clear the associated document library file entry types from
13471             */
13472            @Override
13473            public void clearDLFileEntryTypes(long pk) {
13474                    dlFolderToDLFileEntryTypeTableMapper.deleteLeftPrimaryKeyTableMappings(pk);
13475            }
13476    
13477            /**
13478             * 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.
13479             *
13480             * @param pk the primary key of the document library folder
13481             * @param dlFileEntryTypePK the primary key of the document library file entry type
13482             */
13483            @Override
13484            public void removeDLFileEntryType(long pk, long dlFileEntryTypePK) {
13485                    dlFolderToDLFileEntryTypeTableMapper.deleteTableMapping(pk,
13486                            dlFileEntryTypePK);
13487            }
13488    
13489            /**
13490             * 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.
13491             *
13492             * @param pk the primary key of the document library folder
13493             * @param dlFileEntryType the document library file entry type
13494             */
13495            @Override
13496            public void removeDLFileEntryType(long pk,
13497                    com.liferay.portlet.documentlibrary.model.DLFileEntryType dlFileEntryType) {
13498                    dlFolderToDLFileEntryTypeTableMapper.deleteTableMapping(pk,
13499                            dlFileEntryType.getPrimaryKey());
13500            }
13501    
13502            /**
13503             * 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.
13504             *
13505             * @param pk the primary key of the document library folder
13506             * @param dlFileEntryTypePKs the primary keys of the document library file entry types
13507             */
13508            @Override
13509            public void removeDLFileEntryTypes(long pk, long[] dlFileEntryTypePKs) {
13510                    for (long dlFileEntryTypePK : dlFileEntryTypePKs) {
13511                            dlFolderToDLFileEntryTypeTableMapper.deleteTableMapping(pk,
13512                                    dlFileEntryTypePK);
13513                    }
13514            }
13515    
13516            /**
13517             * 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.
13518             *
13519             * @param pk the primary key of the document library folder
13520             * @param dlFileEntryTypes the document library file entry types
13521             */
13522            @Override
13523            public void removeDLFileEntryTypes(long pk,
13524                    List<com.liferay.portlet.documentlibrary.model.DLFileEntryType> dlFileEntryTypes) {
13525                    for (com.liferay.portlet.documentlibrary.model.DLFileEntryType dlFileEntryType : dlFileEntryTypes) {
13526                            dlFolderToDLFileEntryTypeTableMapper.deleteTableMapping(pk,
13527                                    dlFileEntryType.getPrimaryKey());
13528                    }
13529            }
13530    
13531            /**
13532             * 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.
13533             *
13534             * @param pk the primary key of the document library folder
13535             * @param dlFileEntryTypePKs the primary keys of the document library file entry types to be associated with the document library folder
13536             */
13537            @Override
13538            public void setDLFileEntryTypes(long pk, long[] dlFileEntryTypePKs) {
13539                    Set<Long> newDLFileEntryTypePKsSet = SetUtil.fromArray(dlFileEntryTypePKs);
13540                    Set<Long> oldDLFileEntryTypePKsSet = SetUtil.fromArray(dlFolderToDLFileEntryTypeTableMapper.getRightPrimaryKeys(
13541                                            pk));
13542    
13543                    Set<Long> removeDLFileEntryTypePKsSet = new HashSet<Long>(oldDLFileEntryTypePKsSet);
13544    
13545                    removeDLFileEntryTypePKsSet.removeAll(newDLFileEntryTypePKsSet);
13546    
13547                    for (long removeDLFileEntryTypePK : removeDLFileEntryTypePKsSet) {
13548                            dlFolderToDLFileEntryTypeTableMapper.deleteTableMapping(pk,
13549                                    removeDLFileEntryTypePK);
13550                    }
13551    
13552                    newDLFileEntryTypePKsSet.removeAll(oldDLFileEntryTypePKsSet);
13553    
13554                    long companyId = 0;
13555    
13556                    DLFolder dlFolder = fetchByPrimaryKey(pk);
13557    
13558                    if (dlFolder == null) {
13559                            companyId = companyProvider.getCompanyId();
13560                    }
13561                    else {
13562                            companyId = dlFolder.getCompanyId();
13563                    }
13564    
13565                    for (long newDLFileEntryTypePK : newDLFileEntryTypePKsSet) {
13566                            dlFolderToDLFileEntryTypeTableMapper.addTableMapping(companyId, pk,
13567                                    newDLFileEntryTypePK);
13568                    }
13569            }
13570    
13571            /**
13572             * 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.
13573             *
13574             * @param pk the primary key of the document library folder
13575             * @param dlFileEntryTypes the document library file entry types to be associated with the document library folder
13576             */
13577            @Override
13578            public void setDLFileEntryTypes(long pk,
13579                    List<com.liferay.portlet.documentlibrary.model.DLFileEntryType> dlFileEntryTypes) {
13580                    try {
13581                            long[] dlFileEntryTypePKs = new long[dlFileEntryTypes.size()];
13582    
13583                            for (int i = 0; i < dlFileEntryTypes.size(); i++) {
13584                                    com.liferay.portlet.documentlibrary.model.DLFileEntryType dlFileEntryType =
13585                                            dlFileEntryTypes.get(i);
13586    
13587                                    dlFileEntryTypePKs[i] = dlFileEntryType.getPrimaryKey();
13588                            }
13589    
13590                            setDLFileEntryTypes(pk, dlFileEntryTypePKs);
13591                    }
13592                    catch (Exception e) {
13593                            throw processException(e);
13594                    }
13595            }
13596    
13597            @Override
13598            public Set<String> getBadColumnNames() {
13599                    return _badColumnNames;
13600            }
13601    
13602            @Override
13603            protected Map<String, Integer> getTableColumnsMap() {
13604                    return DLFolderModelImpl.TABLE_COLUMNS_MAP;
13605            }
13606    
13607            /**
13608             * Initializes the document library folder persistence.
13609             */
13610            public void afterPropertiesSet() {
13611                    dlFolderToDLFileEntryTypeTableMapper = TableMapperFactory.getTableMapper("DLFileEntryTypes_DLFolders",
13612                                    "companyId", "folderId", "fileEntryTypeId", this,
13613                                    dlFileEntryTypePersistence);
13614            }
13615    
13616            public void destroy() {
13617                    entityCache.removeCache(DLFolderImpl.class.getName());
13618                    finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
13619                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
13620                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
13621    
13622                    TableMapperFactory.removeTableMapper("DLFileEntryTypes_DLFolders");
13623            }
13624    
13625            @BeanReference(type = CompanyProviderWrapper.class)
13626            protected CompanyProvider companyProvider;
13627            protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
13628            protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
13629            @BeanReference(type = DLFileEntryTypePersistence.class)
13630            protected DLFileEntryTypePersistence dlFileEntryTypePersistence;
13631            protected TableMapper<DLFolder, com.liferay.portlet.documentlibrary.model.DLFileEntryType> dlFolderToDLFileEntryTypeTableMapper;
13632            private static final String _SQL_SELECT_DLFOLDER = "SELECT dlFolder FROM DLFolder dlFolder";
13633            private static final String _SQL_SELECT_DLFOLDER_WHERE_PKS_IN = "SELECT dlFolder FROM DLFolder dlFolder WHERE folderId IN (";
13634            private static final String _SQL_SELECT_DLFOLDER_WHERE = "SELECT dlFolder FROM DLFolder dlFolder WHERE ";
13635            private static final String _SQL_COUNT_DLFOLDER = "SELECT COUNT(dlFolder) FROM DLFolder dlFolder";
13636            private static final String _SQL_COUNT_DLFOLDER_WHERE = "SELECT COUNT(dlFolder) FROM DLFolder dlFolder WHERE ";
13637            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "dlFolder.folderId";
13638            private static final String _FILTER_SQL_SELECT_DLFOLDER_WHERE = "SELECT DISTINCT {dlFolder.*} FROM DLFolder dlFolder WHERE ";
13639            private static final String _FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1 =
13640                    "SELECT {DLFolder.*} FROM (SELECT DISTINCT dlFolder.folderId FROM DLFolder dlFolder WHERE ";
13641            private static final String _FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2 =
13642                    ") TEMP_TABLE INNER JOIN DLFolder ON TEMP_TABLE.folderId = DLFolder.folderId";
13643            private static final String _FILTER_SQL_COUNT_DLFOLDER_WHERE = "SELECT COUNT(DISTINCT dlFolder.folderId) AS COUNT_VALUE FROM DLFolder dlFolder WHERE ";
13644            private static final String _FILTER_ENTITY_ALIAS = "dlFolder";
13645            private static final String _FILTER_ENTITY_TABLE = "DLFolder";
13646            private static final String _ORDER_BY_ENTITY_ALIAS = "dlFolder.";
13647            private static final String _ORDER_BY_ENTITY_TABLE = "DLFolder.";
13648            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No DLFolder exists with the primary key ";
13649            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No DLFolder exists with the key {";
13650            private static final Log _log = LogFactoryUtil.getLog(DLFolderPersistenceImpl.class);
13651            private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
13652                                    "uuid", "hidden"
13653                            });
13654            private static final DLFolder _nullDLFolder = new DLFolderImpl() {
13655                            @Override
13656                            public Object clone() {
13657                                    return this;
13658                            }
13659    
13660                            @Override
13661                            public CacheModel<DLFolder> toCacheModel() {
13662                                    return _nullDLFolderCacheModel;
13663                            }
13664                    };
13665    
13666            private static final CacheModel<DLFolder> _nullDLFolderCacheModel = new CacheModel<DLFolder>() {
13667                            @Override
13668                            public DLFolder toEntityModel() {
13669                                    return _nullDLFolder;
13670                            }
13671                    };
13672    }