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.document.library.kernel.exception.NoSuchFolderException;
020    import com.liferay.document.library.kernel.model.DLFolder;
021    import com.liferay.document.library.kernel.service.persistence.DLFileEntryTypePersistence;
022    import com.liferay.document.library.kernel.service.persistence.DLFolderPersistence;
023    
024    import com.liferay.portal.kernel.bean.BeanReference;
025    import com.liferay.portal.kernel.dao.orm.EntityCache;
026    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
027    import com.liferay.portal.kernel.dao.orm.FinderCache;
028    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
029    import com.liferay.portal.kernel.dao.orm.FinderPath;
030    import com.liferay.portal.kernel.dao.orm.Query;
031    import com.liferay.portal.kernel.dao.orm.QueryPos;
032    import com.liferay.portal.kernel.dao.orm.QueryUtil;
033    import com.liferay.portal.kernel.dao.orm.SQLQuery;
034    import com.liferay.portal.kernel.dao.orm.Session;
035    import com.liferay.portal.kernel.log.Log;
036    import com.liferay.portal.kernel.log.LogFactoryUtil;
037    import com.liferay.portal.kernel.model.CacheModel;
038    import com.liferay.portal.kernel.security.permission.InlineSQLHelperUtil;
039    import com.liferay.portal.kernel.service.ServiceContext;
040    import com.liferay.portal.kernel.service.ServiceContextThreadLocal;
041    import com.liferay.portal.kernel.service.persistence.CompanyProvider;
042    import com.liferay.portal.kernel.service.persistence.CompanyProviderWrapper;
043    import com.liferay.portal.kernel.service.persistence.impl.BasePersistenceImpl;
044    import com.liferay.portal.kernel.service.persistence.impl.TableMapper;
045    import com.liferay.portal.kernel.service.persistence.impl.TableMapperFactory;
046    import com.liferay.portal.kernel.util.CharPool;
047    import com.liferay.portal.kernel.util.OrderByComparator;
048    import com.liferay.portal.kernel.util.SetUtil;
049    import com.liferay.portal.kernel.util.StringBundler;
050    import com.liferay.portal.kernel.util.StringPool;
051    import com.liferay.portal.kernel.util.StringUtil;
052    import com.liferay.portal.kernel.util.Validator;
053    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
054    
055    import com.liferay.portlet.documentlibrary.model.impl.DLFolderImpl;
056    import com.liferay.portlet.documentlibrary.model.impl.DLFolderModelImpl;
057    
058    import java.io.Serializable;
059    
060    import java.util.Collections;
061    import java.util.Date;
062    import java.util.HashMap;
063    import java.util.HashSet;
064    import java.util.Iterator;
065    import java.util.List;
066    import java.util.Map;
067    import java.util.Set;
068    
069    /**
070     * The persistence implementation for the document library folder service.
071     *
072     * <p>
073     * Caching information and settings can be found in <code>portal.properties</code>
074     * </p>
075     *
076     * @author Brian Wing Shun Chan
077     * @see DLFolderPersistence
078     * @see com.liferay.document.library.kernel.service.persistence.DLFolderUtil
079     * @generated
080     */
081    @ProviderType
082    public class DLFolderPersistenceImpl extends BasePersistenceImpl<DLFolder>
083            implements DLFolderPersistence {
084            /*
085             * NOTE FOR DEVELOPERS:
086             *
087             * 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.
088             */
089            public static final String FINDER_CLASS_NAME_ENTITY = DLFolderImpl.class.getName();
090            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
091                    ".List1";
092            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
093                    ".List2";
094            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
095                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
096                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
097            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
098                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
099                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
100            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
101                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
102                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
103            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
104                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
105                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
106                            new String[] {
107                                    String.class.getName(),
108                                    
109                            Integer.class.getName(), Integer.class.getName(),
110                                    OrderByComparator.class.getName()
111                            });
112            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
113                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
114                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
115                            new String[] { String.class.getName() },
116                            DLFolderModelImpl.UUID_COLUMN_BITMASK |
117                            DLFolderModelImpl.PARENTFOLDERID_COLUMN_BITMASK |
118                            DLFolderModelImpl.NAME_COLUMN_BITMASK);
119            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
120                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
121                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
122                            new String[] { String.class.getName() });
123    
124            /**
125             * Returns all the document library folders where uuid = &#63;.
126             *
127             * @param uuid the uuid
128             * @return the matching document library folders
129             */
130            @Override
131            public List<DLFolder> findByUuid(String uuid) {
132                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
133            }
134    
135            /**
136             * Returns a range of all the document library folders where uuid = &#63;.
137             *
138             * <p>
139             * 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.
140             * </p>
141             *
142             * @param uuid the uuid
143             * @param start the lower bound of the range of document library folders
144             * @param end the upper bound of the range of document library folders (not inclusive)
145             * @return the range of matching document library folders
146             */
147            @Override
148            public List<DLFolder> findByUuid(String uuid, int start, int end) {
149                    return findByUuid(uuid, start, end, null);
150            }
151    
152            /**
153             * Returns an ordered range of all the document library folders where uuid = &#63;.
154             *
155             * <p>
156             * 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.
157             * </p>
158             *
159             * @param uuid the uuid
160             * @param start the lower bound of the range of document library folders
161             * @param end the upper bound of the range of document library folders (not inclusive)
162             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
163             * @return the ordered range of matching document library folders
164             */
165            @Override
166            public List<DLFolder> findByUuid(String uuid, int start, int end,
167                    OrderByComparator<DLFolder> orderByComparator) {
168                    return findByUuid(uuid, start, end, orderByComparator, true);
169            }
170    
171            /**
172             * Returns an ordered range of all the document library folders where uuid = &#63;.
173             *
174             * <p>
175             * 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.
176             * </p>
177             *
178             * @param uuid the uuid
179             * @param start the lower bound of the range of document library folders
180             * @param end the upper bound of the range of document library folders (not inclusive)
181             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
182             * @param retrieveFromCache whether to retrieve from the finder cache
183             * @return the ordered range of matching document library folders
184             */
185            @Override
186            public List<DLFolder> findByUuid(String uuid, int start, int end,
187                    OrderByComparator<DLFolder> orderByComparator, boolean retrieveFromCache) {
188                    boolean pagination = true;
189                    FinderPath finderPath = null;
190                    Object[] finderArgs = null;
191    
192                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
193                                    (orderByComparator == null)) {
194                            pagination = false;
195                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
196                            finderArgs = new Object[] { uuid };
197                    }
198                    else {
199                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
200                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
201                    }
202    
203                    List<DLFolder> list = null;
204    
205                    if (retrieveFromCache) {
206                            list = (List<DLFolder>)finderCache.getResult(finderPath,
207                                            finderArgs, this);
208    
209                            if ((list != null) && !list.isEmpty()) {
210                                    for (DLFolder dlFolder : list) {
211                                            if (!Validator.equals(uuid, dlFolder.getUuid())) {
212                                                    list = null;
213    
214                                                    break;
215                                            }
216                                    }
217                            }
218                    }
219    
220                    if (list == null) {
221                            StringBundler query = null;
222    
223                            if (orderByComparator != null) {
224                                    query = new StringBundler(3 +
225                                                    (orderByComparator.getOrderByFields().length * 2));
226                            }
227                            else {
228                                    query = new StringBundler(3);
229                            }
230    
231                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
232    
233                            boolean bindUuid = false;
234    
235                            if (uuid == null) {
236                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
237                            }
238                            else if (uuid.equals(StringPool.BLANK)) {
239                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
240                            }
241                            else {
242                                    bindUuid = true;
243    
244                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
245                            }
246    
247                            if (orderByComparator != null) {
248                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
249                                            orderByComparator);
250                            }
251                            else
252                             if (pagination) {
253                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
254                            }
255    
256                            String sql = query.toString();
257    
258                            Session session = null;
259    
260                            try {
261                                    session = openSession();
262    
263                                    Query q = session.createQuery(sql);
264    
265                                    QueryPos qPos = QueryPos.getInstance(q);
266    
267                                    if (bindUuid) {
268                                            qPos.add(uuid);
269                                    }
270    
271                                    if (!pagination) {
272                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
273                                                            start, end, false);
274    
275                                            Collections.sort(list);
276    
277                                            list = Collections.unmodifiableList(list);
278                                    }
279                                    else {
280                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
281                                                            start, end);
282                                    }
283    
284                                    cacheResult(list);
285    
286                                    finderCache.putResult(finderPath, finderArgs, list);
287                            }
288                            catch (Exception e) {
289                                    finderCache.removeResult(finderPath, finderArgs);
290    
291                                    throw processException(e);
292                            }
293                            finally {
294                                    closeSession(session);
295                            }
296                    }
297    
298                    return list;
299            }
300    
301            /**
302             * Returns the first document library folder in the ordered set where uuid = &#63;.
303             *
304             * @param uuid the uuid
305             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
306             * @return the first matching document library folder
307             * @throws NoSuchFolderException if a matching document library folder could not be found
308             */
309            @Override
310            public DLFolder findByUuid_First(String uuid,
311                    OrderByComparator<DLFolder> orderByComparator)
312                    throws NoSuchFolderException {
313                    DLFolder dlFolder = fetchByUuid_First(uuid, orderByComparator);
314    
315                    if (dlFolder != null) {
316                            return dlFolder;
317                    }
318    
319                    StringBundler msg = new StringBundler(4);
320    
321                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
322    
323                    msg.append("uuid=");
324                    msg.append(uuid);
325    
326                    msg.append(StringPool.CLOSE_CURLY_BRACE);
327    
328                    throw new NoSuchFolderException(msg.toString());
329            }
330    
331            /**
332             * Returns the first document library folder in the ordered set where uuid = &#63;.
333             *
334             * @param uuid the uuid
335             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
336             * @return the first matching document library folder, or <code>null</code> if a matching document library folder could not be found
337             */
338            @Override
339            public DLFolder fetchByUuid_First(String uuid,
340                    OrderByComparator<DLFolder> orderByComparator) {
341                    List<DLFolder> list = findByUuid(uuid, 0, 1, orderByComparator);
342    
343                    if (!list.isEmpty()) {
344                            return list.get(0);
345                    }
346    
347                    return null;
348            }
349    
350            /**
351             * Returns the last document library folder in the ordered set where uuid = &#63;.
352             *
353             * @param uuid the uuid
354             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
355             * @return the last matching document library folder
356             * @throws NoSuchFolderException if a matching document library folder could not be found
357             */
358            @Override
359            public DLFolder findByUuid_Last(String uuid,
360                    OrderByComparator<DLFolder> orderByComparator)
361                    throws NoSuchFolderException {
362                    DLFolder dlFolder = fetchByUuid_Last(uuid, orderByComparator);
363    
364                    if (dlFolder != null) {
365                            return dlFolder;
366                    }
367    
368                    StringBundler msg = new StringBundler(4);
369    
370                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
371    
372                    msg.append("uuid=");
373                    msg.append(uuid);
374    
375                    msg.append(StringPool.CLOSE_CURLY_BRACE);
376    
377                    throw new NoSuchFolderException(msg.toString());
378            }
379    
380            /**
381             * Returns the last document library folder in the ordered set where uuid = &#63;.
382             *
383             * @param uuid the uuid
384             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
385             * @return the last matching document library folder, or <code>null</code> if a matching document library folder could not be found
386             */
387            @Override
388            public DLFolder fetchByUuid_Last(String uuid,
389                    OrderByComparator<DLFolder> orderByComparator) {
390                    int count = countByUuid(uuid);
391    
392                    if (count == 0) {
393                            return null;
394                    }
395    
396                    List<DLFolder> list = findByUuid(uuid, count - 1, count,
397                                    orderByComparator);
398    
399                    if (!list.isEmpty()) {
400                            return list.get(0);
401                    }
402    
403                    return null;
404            }
405    
406            /**
407             * Returns the document library folders before and after the current document library folder in the ordered set where uuid = &#63;.
408             *
409             * @param folderId the primary key of the current document library folder
410             * @param uuid the uuid
411             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
412             * @return the previous, current, and next document library folder
413             * @throws NoSuchFolderException if a document library folder with the primary key could not be found
414             */
415            @Override
416            public DLFolder[] findByUuid_PrevAndNext(long folderId, String uuid,
417                    OrderByComparator<DLFolder> orderByComparator)
418                    throws NoSuchFolderException {
419                    DLFolder dlFolder = findByPrimaryKey(folderId);
420    
421                    Session session = null;
422    
423                    try {
424                            session = openSession();
425    
426                            DLFolder[] array = new DLFolderImpl[3];
427    
428                            array[0] = getByUuid_PrevAndNext(session, dlFolder, uuid,
429                                            orderByComparator, true);
430    
431                            array[1] = dlFolder;
432    
433                            array[2] = getByUuid_PrevAndNext(session, dlFolder, uuid,
434                                            orderByComparator, false);
435    
436                            return array;
437                    }
438                    catch (Exception e) {
439                            throw processException(e);
440                    }
441                    finally {
442                            closeSession(session);
443                    }
444            }
445    
446            protected DLFolder getByUuid_PrevAndNext(Session session,
447                    DLFolder dlFolder, String uuid,
448                    OrderByComparator<DLFolder> orderByComparator, boolean previous) {
449                    StringBundler query = null;
450    
451                    if (orderByComparator != null) {
452                            query = new StringBundler(4 +
453                                            (orderByComparator.getOrderByConditionFields().length * 3) +
454                                            (orderByComparator.getOrderByFields().length * 3));
455                    }
456                    else {
457                            query = new StringBundler(3);
458                    }
459    
460                    query.append(_SQL_SELECT_DLFOLDER_WHERE);
461    
462                    boolean bindUuid = false;
463    
464                    if (uuid == null) {
465                            query.append(_FINDER_COLUMN_UUID_UUID_1);
466                    }
467                    else if (uuid.equals(StringPool.BLANK)) {
468                            query.append(_FINDER_COLUMN_UUID_UUID_3);
469                    }
470                    else {
471                            bindUuid = true;
472    
473                            query.append(_FINDER_COLUMN_UUID_UUID_2);
474                    }
475    
476                    if (orderByComparator != null) {
477                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
478    
479                            if (orderByConditionFields.length > 0) {
480                                    query.append(WHERE_AND);
481                            }
482    
483                            for (int i = 0; i < orderByConditionFields.length; i++) {
484                                    query.append(_ORDER_BY_ENTITY_ALIAS);
485                                    query.append(orderByConditionFields[i]);
486    
487                                    if ((i + 1) < orderByConditionFields.length) {
488                                            if (orderByComparator.isAscending() ^ previous) {
489                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
490                                            }
491                                            else {
492                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
493                                            }
494                                    }
495                                    else {
496                                            if (orderByComparator.isAscending() ^ previous) {
497                                                    query.append(WHERE_GREATER_THAN);
498                                            }
499                                            else {
500                                                    query.append(WHERE_LESSER_THAN);
501                                            }
502                                    }
503                            }
504    
505                            query.append(ORDER_BY_CLAUSE);
506    
507                            String[] orderByFields = orderByComparator.getOrderByFields();
508    
509                            for (int i = 0; i < orderByFields.length; i++) {
510                                    query.append(_ORDER_BY_ENTITY_ALIAS);
511                                    query.append(orderByFields[i]);
512    
513                                    if ((i + 1) < orderByFields.length) {
514                                            if (orderByComparator.isAscending() ^ previous) {
515                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
516                                            }
517                                            else {
518                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
519                                            }
520                                    }
521                                    else {
522                                            if (orderByComparator.isAscending() ^ previous) {
523                                                    query.append(ORDER_BY_ASC);
524                                            }
525                                            else {
526                                                    query.append(ORDER_BY_DESC);
527                                            }
528                                    }
529                            }
530                    }
531                    else {
532                            query.append(DLFolderModelImpl.ORDER_BY_JPQL);
533                    }
534    
535                    String sql = query.toString();
536    
537                    Query q = session.createQuery(sql);
538    
539                    q.setFirstResult(0);
540                    q.setMaxResults(2);
541    
542                    QueryPos qPos = QueryPos.getInstance(q);
543    
544                    if (bindUuid) {
545                            qPos.add(uuid);
546                    }
547    
548                    if (orderByComparator != null) {
549                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
550    
551                            for (Object value : values) {
552                                    qPos.add(value);
553                            }
554                    }
555    
556                    List<DLFolder> list = q.list();
557    
558                    if (list.size() == 2) {
559                            return list.get(1);
560                    }
561                    else {
562                            return null;
563                    }
564            }
565    
566            /**
567             * Removes all the document library folders where uuid = &#63; from the database.
568             *
569             * @param uuid the uuid
570             */
571            @Override
572            public void removeByUuid(String uuid) {
573                    for (DLFolder dlFolder : findByUuid(uuid, QueryUtil.ALL_POS,
574                                    QueryUtil.ALL_POS, null)) {
575                            remove(dlFolder);
576                    }
577            }
578    
579            /**
580             * Returns the number of document library folders where uuid = &#63;.
581             *
582             * @param uuid the uuid
583             * @return the number of matching document library folders
584             */
585            @Override
586            public int countByUuid(String uuid) {
587                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
588    
589                    Object[] finderArgs = new Object[] { uuid };
590    
591                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
592    
593                    if (count == null) {
594                            StringBundler query = new StringBundler(2);
595    
596                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
597    
598                            boolean bindUuid = false;
599    
600                            if (uuid == null) {
601                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
602                            }
603                            else if (uuid.equals(StringPool.BLANK)) {
604                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
605                            }
606                            else {
607                                    bindUuid = true;
608    
609                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
610                            }
611    
612                            String sql = query.toString();
613    
614                            Session session = null;
615    
616                            try {
617                                    session = openSession();
618    
619                                    Query q = session.createQuery(sql);
620    
621                                    QueryPos qPos = QueryPos.getInstance(q);
622    
623                                    if (bindUuid) {
624                                            qPos.add(uuid);
625                                    }
626    
627                                    count = (Long)q.uniqueResult();
628    
629                                    finderCache.putResult(finderPath, finderArgs, count);
630                            }
631                            catch (Exception e) {
632                                    finderCache.removeResult(finderPath, finderArgs);
633    
634                                    throw processException(e);
635                            }
636                            finally {
637                                    closeSession(session);
638                            }
639                    }
640    
641                    return count.intValue();
642            }
643    
644            private static final String _FINDER_COLUMN_UUID_UUID_1 = "dlFolder.uuid IS NULL";
645            private static final String _FINDER_COLUMN_UUID_UUID_2 = "dlFolder.uuid = ?";
646            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(dlFolder.uuid IS NULL OR dlFolder.uuid = '')";
647            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
648                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
649                            FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
650                            new String[] { String.class.getName(), Long.class.getName() },
651                            DLFolderModelImpl.UUID_COLUMN_BITMASK |
652                            DLFolderModelImpl.GROUPID_COLUMN_BITMASK);
653            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
654                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
655                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
656                            new String[] { String.class.getName(), Long.class.getName() });
657    
658            /**
659             * Returns the document library folder where uuid = &#63; and groupId = &#63; or throws a {@link NoSuchFolderException} if it could not be found.
660             *
661             * @param uuid the uuid
662             * @param groupId the group ID
663             * @return the matching document library folder
664             * @throws NoSuchFolderException if a matching document library folder could not be found
665             */
666            @Override
667            public DLFolder findByUUID_G(String uuid, long groupId)
668                    throws NoSuchFolderException {
669                    DLFolder dlFolder = fetchByUUID_G(uuid, groupId);
670    
671                    if (dlFolder == null) {
672                            StringBundler msg = new StringBundler(6);
673    
674                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
675    
676                            msg.append("uuid=");
677                            msg.append(uuid);
678    
679                            msg.append(", groupId=");
680                            msg.append(groupId);
681    
682                            msg.append(StringPool.CLOSE_CURLY_BRACE);
683    
684                            if (_log.isWarnEnabled()) {
685                                    _log.warn(msg.toString());
686                            }
687    
688                            throw new NoSuchFolderException(msg.toString());
689                    }
690    
691                    return dlFolder;
692            }
693    
694            /**
695             * 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.
696             *
697             * @param uuid the uuid
698             * @param groupId the group ID
699             * @return the matching document library folder, or <code>null</code> if a matching document library folder could not be found
700             */
701            @Override
702            public DLFolder fetchByUUID_G(String uuid, long groupId) {
703                    return fetchByUUID_G(uuid, groupId, true);
704            }
705    
706            /**
707             * 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.
708             *
709             * @param uuid the uuid
710             * @param groupId the group ID
711             * @param retrieveFromCache whether to retrieve from the finder cache
712             * @return the matching document library folder, or <code>null</code> if a matching document library folder could not be found
713             */
714            @Override
715            public DLFolder fetchByUUID_G(String uuid, long groupId,
716                    boolean retrieveFromCache) {
717                    Object[] finderArgs = new Object[] { uuid, groupId };
718    
719                    Object result = null;
720    
721                    if (retrieveFromCache) {
722                            result = finderCache.getResult(FINDER_PATH_FETCH_BY_UUID_G,
723                                            finderArgs, this);
724                    }
725    
726                    if (result instanceof DLFolder) {
727                            DLFolder dlFolder = (DLFolder)result;
728    
729                            if (!Validator.equals(uuid, dlFolder.getUuid()) ||
730                                            (groupId != dlFolder.getGroupId())) {
731                                    result = null;
732                            }
733                    }
734    
735                    if (result == null) {
736                            StringBundler query = new StringBundler(4);
737    
738                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
739    
740                            boolean bindUuid = false;
741    
742                            if (uuid == null) {
743                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
744                            }
745                            else if (uuid.equals(StringPool.BLANK)) {
746                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
747                            }
748                            else {
749                                    bindUuid = true;
750    
751                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
752                            }
753    
754                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
755    
756                            String sql = query.toString();
757    
758                            Session session = null;
759    
760                            try {
761                                    session = openSession();
762    
763                                    Query q = session.createQuery(sql);
764    
765                                    QueryPos qPos = QueryPos.getInstance(q);
766    
767                                    if (bindUuid) {
768                                            qPos.add(uuid);
769                                    }
770    
771                                    qPos.add(groupId);
772    
773                                    List<DLFolder> list = q.list();
774    
775                                    if (list.isEmpty()) {
776                                            finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G,
777                                                    finderArgs, list);
778                                    }
779                                    else {
780                                            DLFolder dlFolder = list.get(0);
781    
782                                            result = dlFolder;
783    
784                                            cacheResult(dlFolder);
785    
786                                            if ((dlFolder.getUuid() == null) ||
787                                                            !dlFolder.getUuid().equals(uuid) ||
788                                                            (dlFolder.getGroupId() != groupId)) {
789                                                    finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G,
790                                                            finderArgs, dlFolder);
791                                            }
792                                    }
793                            }
794                            catch (Exception e) {
795                                    finderCache.removeResult(FINDER_PATH_FETCH_BY_UUID_G, finderArgs);
796    
797                                    throw processException(e);
798                            }
799                            finally {
800                                    closeSession(session);
801                            }
802                    }
803    
804                    if (result instanceof List<?>) {
805                            return null;
806                    }
807                    else {
808                            return (DLFolder)result;
809                    }
810            }
811    
812            /**
813             * Removes the document library folder where uuid = &#63; and groupId = &#63; from the database.
814             *
815             * @param uuid the uuid
816             * @param groupId the group ID
817             * @return the document library folder that was removed
818             */
819            @Override
820            public DLFolder removeByUUID_G(String uuid, long groupId)
821                    throws NoSuchFolderException {
822                    DLFolder dlFolder = findByUUID_G(uuid, groupId);
823    
824                    return remove(dlFolder);
825            }
826    
827            /**
828             * Returns the number of document library folders where uuid = &#63; and groupId = &#63;.
829             *
830             * @param uuid the uuid
831             * @param groupId the group ID
832             * @return the number of matching document library folders
833             */
834            @Override
835            public int countByUUID_G(String uuid, long groupId) {
836                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G;
837    
838                    Object[] finderArgs = new Object[] { uuid, groupId };
839    
840                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
841    
842                    if (count == null) {
843                            StringBundler query = new StringBundler(3);
844    
845                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
846    
847                            boolean bindUuid = false;
848    
849                            if (uuid == null) {
850                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
851                            }
852                            else if (uuid.equals(StringPool.BLANK)) {
853                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
854                            }
855                            else {
856                                    bindUuid = true;
857    
858                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
859                            }
860    
861                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
862    
863                            String sql = query.toString();
864    
865                            Session session = null;
866    
867                            try {
868                                    session = openSession();
869    
870                                    Query q = session.createQuery(sql);
871    
872                                    QueryPos qPos = QueryPos.getInstance(q);
873    
874                                    if (bindUuid) {
875                                            qPos.add(uuid);
876                                    }
877    
878                                    qPos.add(groupId);
879    
880                                    count = (Long)q.uniqueResult();
881    
882                                    finderCache.putResult(finderPath, finderArgs, count);
883                            }
884                            catch (Exception e) {
885                                    finderCache.removeResult(finderPath, finderArgs);
886    
887                                    throw processException(e);
888                            }
889                            finally {
890                                    closeSession(session);
891                            }
892                    }
893    
894                    return count.intValue();
895            }
896    
897            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "dlFolder.uuid IS NULL AND ";
898            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "dlFolder.uuid = ? AND ";
899            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(dlFolder.uuid IS NULL OR dlFolder.uuid = '') AND ";
900            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "dlFolder.groupId = ?";
901            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
902                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
903                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
904                            new String[] {
905                                    String.class.getName(), Long.class.getName(),
906                                    
907                            Integer.class.getName(), Integer.class.getName(),
908                                    OrderByComparator.class.getName()
909                            });
910            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
911                    new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
912                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
913                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
914                            new String[] { String.class.getName(), Long.class.getName() },
915                            DLFolderModelImpl.UUID_COLUMN_BITMASK |
916                            DLFolderModelImpl.COMPANYID_COLUMN_BITMASK |
917                            DLFolderModelImpl.PARENTFOLDERID_COLUMN_BITMASK |
918                            DLFolderModelImpl.NAME_COLUMN_BITMASK);
919            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
920                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
921                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
922                            new String[] { String.class.getName(), Long.class.getName() });
923    
924            /**
925             * Returns all the document library folders where uuid = &#63; and companyId = &#63;.
926             *
927             * @param uuid the uuid
928             * @param companyId the company ID
929             * @return the matching document library folders
930             */
931            @Override
932            public List<DLFolder> findByUuid_C(String uuid, long companyId) {
933                    return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
934                            QueryUtil.ALL_POS, null);
935            }
936    
937            /**
938             * Returns a range of all the document library folders where uuid = &#63; and companyId = &#63;.
939             *
940             * <p>
941             * 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.
942             * </p>
943             *
944             * @param uuid the uuid
945             * @param companyId the company ID
946             * @param start the lower bound of the range of document library folders
947             * @param end the upper bound of the range of document library folders (not inclusive)
948             * @return the range of matching document library folders
949             */
950            @Override
951            public List<DLFolder> findByUuid_C(String uuid, long companyId, int start,
952                    int end) {
953                    return findByUuid_C(uuid, companyId, start, end, null);
954            }
955    
956            /**
957             * Returns an ordered range of all the document library folders where uuid = &#63; and companyId = &#63;.
958             *
959             * <p>
960             * 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.
961             * </p>
962             *
963             * @param uuid the uuid
964             * @param companyId the company ID
965             * @param start the lower bound of the range of document library folders
966             * @param end the upper bound of the range of document library folders (not inclusive)
967             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
968             * @return the ordered range of matching document library folders
969             */
970            @Override
971            public List<DLFolder> findByUuid_C(String uuid, long companyId, int start,
972                    int end, OrderByComparator<DLFolder> orderByComparator) {
973                    return findByUuid_C(uuid, companyId, start, end, orderByComparator, true);
974            }
975    
976            /**
977             * Returns an ordered range of all the document library folders where uuid = &#63; and companyId = &#63;.
978             *
979             * <p>
980             * 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.
981             * </p>
982             *
983             * @param uuid the uuid
984             * @param companyId the company ID
985             * @param start the lower bound of the range of document library folders
986             * @param end the upper bound of the range of document library folders (not inclusive)
987             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
988             * @param retrieveFromCache whether to retrieve from the finder cache
989             * @return the ordered range of matching document library folders
990             */
991            @Override
992            public List<DLFolder> findByUuid_C(String uuid, long companyId, int start,
993                    int end, OrderByComparator<DLFolder> orderByComparator,
994                    boolean retrieveFromCache) {
995                    boolean pagination = true;
996                    FinderPath finderPath = null;
997                    Object[] finderArgs = null;
998    
999                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1000                                    (orderByComparator == null)) {
1001                            pagination = false;
1002                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
1003                            finderArgs = new Object[] { uuid, companyId };
1004                    }
1005                    else {
1006                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
1007                            finderArgs = new Object[] {
1008                                            uuid, companyId,
1009                                            
1010                                            start, end, orderByComparator
1011                                    };
1012                    }
1013    
1014                    List<DLFolder> list = null;
1015    
1016                    if (retrieveFromCache) {
1017                            list = (List<DLFolder>)finderCache.getResult(finderPath,
1018                                            finderArgs, this);
1019    
1020                            if ((list != null) && !list.isEmpty()) {
1021                                    for (DLFolder dlFolder : list) {
1022                                            if (!Validator.equals(uuid, dlFolder.getUuid()) ||
1023                                                            (companyId != dlFolder.getCompanyId())) {
1024                                                    list = null;
1025    
1026                                                    break;
1027                                            }
1028                                    }
1029                            }
1030                    }
1031    
1032                    if (list == null) {
1033                            StringBundler query = null;
1034    
1035                            if (orderByComparator != null) {
1036                                    query = new StringBundler(4 +
1037                                                    (orderByComparator.getOrderByFields().length * 2));
1038                            }
1039                            else {
1040                                    query = new StringBundler(4);
1041                            }
1042    
1043                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
1044    
1045                            boolean bindUuid = false;
1046    
1047                            if (uuid == null) {
1048                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1049                            }
1050                            else if (uuid.equals(StringPool.BLANK)) {
1051                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1052                            }
1053                            else {
1054                                    bindUuid = true;
1055    
1056                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1057                            }
1058    
1059                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1060    
1061                            if (orderByComparator != null) {
1062                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1063                                            orderByComparator);
1064                            }
1065                            else
1066                             if (pagination) {
1067                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
1068                            }
1069    
1070                            String sql = query.toString();
1071    
1072                            Session session = null;
1073    
1074                            try {
1075                                    session = openSession();
1076    
1077                                    Query q = session.createQuery(sql);
1078    
1079                                    QueryPos qPos = QueryPos.getInstance(q);
1080    
1081                                    if (bindUuid) {
1082                                            qPos.add(uuid);
1083                                    }
1084    
1085                                    qPos.add(companyId);
1086    
1087                                    if (!pagination) {
1088                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
1089                                                            start, end, false);
1090    
1091                                            Collections.sort(list);
1092    
1093                                            list = Collections.unmodifiableList(list);
1094                                    }
1095                                    else {
1096                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
1097                                                            start, end);
1098                                    }
1099    
1100                                    cacheResult(list);
1101    
1102                                    finderCache.putResult(finderPath, finderArgs, list);
1103                            }
1104                            catch (Exception e) {
1105                                    finderCache.removeResult(finderPath, finderArgs);
1106    
1107                                    throw processException(e);
1108                            }
1109                            finally {
1110                                    closeSession(session);
1111                            }
1112                    }
1113    
1114                    return list;
1115            }
1116    
1117            /**
1118             * Returns the first document library folder in the ordered set where uuid = &#63; and companyId = &#63;.
1119             *
1120             * @param uuid the uuid
1121             * @param companyId the company ID
1122             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1123             * @return the first matching document library folder
1124             * @throws NoSuchFolderException if a matching document library folder could not be found
1125             */
1126            @Override
1127            public DLFolder findByUuid_C_First(String uuid, long companyId,
1128                    OrderByComparator<DLFolder> orderByComparator)
1129                    throws NoSuchFolderException {
1130                    DLFolder dlFolder = fetchByUuid_C_First(uuid, companyId,
1131                                    orderByComparator);
1132    
1133                    if (dlFolder != null) {
1134                            return dlFolder;
1135                    }
1136    
1137                    StringBundler msg = new StringBundler(6);
1138    
1139                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1140    
1141                    msg.append("uuid=");
1142                    msg.append(uuid);
1143    
1144                    msg.append(", companyId=");
1145                    msg.append(companyId);
1146    
1147                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1148    
1149                    throw new NoSuchFolderException(msg.toString());
1150            }
1151    
1152            /**
1153             * Returns the first document library folder in the ordered set where uuid = &#63; and companyId = &#63;.
1154             *
1155             * @param uuid the uuid
1156             * @param companyId the company ID
1157             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1158             * @return the first matching document library folder, or <code>null</code> if a matching document library folder could not be found
1159             */
1160            @Override
1161            public DLFolder fetchByUuid_C_First(String uuid, long companyId,
1162                    OrderByComparator<DLFolder> orderByComparator) {
1163                    List<DLFolder> list = findByUuid_C(uuid, companyId, 0, 1,
1164                                    orderByComparator);
1165    
1166                    if (!list.isEmpty()) {
1167                            return list.get(0);
1168                    }
1169    
1170                    return null;
1171            }
1172    
1173            /**
1174             * Returns the last document library folder in the ordered set where uuid = &#63; and companyId = &#63;.
1175             *
1176             * @param uuid the uuid
1177             * @param companyId the company ID
1178             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1179             * @return the last matching document library folder
1180             * @throws NoSuchFolderException if a matching document library folder could not be found
1181             */
1182            @Override
1183            public DLFolder findByUuid_C_Last(String uuid, long companyId,
1184                    OrderByComparator<DLFolder> orderByComparator)
1185                    throws NoSuchFolderException {
1186                    DLFolder dlFolder = fetchByUuid_C_Last(uuid, companyId,
1187                                    orderByComparator);
1188    
1189                    if (dlFolder != null) {
1190                            return dlFolder;
1191                    }
1192    
1193                    StringBundler msg = new StringBundler(6);
1194    
1195                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1196    
1197                    msg.append("uuid=");
1198                    msg.append(uuid);
1199    
1200                    msg.append(", companyId=");
1201                    msg.append(companyId);
1202    
1203                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1204    
1205                    throw new NoSuchFolderException(msg.toString());
1206            }
1207    
1208            /**
1209             * Returns the last document library folder in the ordered set where uuid = &#63; and companyId = &#63;.
1210             *
1211             * @param uuid the uuid
1212             * @param companyId the company ID
1213             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1214             * @return the last matching document library folder, or <code>null</code> if a matching document library folder could not be found
1215             */
1216            @Override
1217            public DLFolder fetchByUuid_C_Last(String uuid, long companyId,
1218                    OrderByComparator<DLFolder> orderByComparator) {
1219                    int count = countByUuid_C(uuid, companyId);
1220    
1221                    if (count == 0) {
1222                            return null;
1223                    }
1224    
1225                    List<DLFolder> list = findByUuid_C(uuid, companyId, count - 1, count,
1226                                    orderByComparator);
1227    
1228                    if (!list.isEmpty()) {
1229                            return list.get(0);
1230                    }
1231    
1232                    return null;
1233            }
1234    
1235            /**
1236             * Returns the document library folders before and after the current document library folder in the ordered set where uuid = &#63; and companyId = &#63;.
1237             *
1238             * @param folderId the primary key of the current document library folder
1239             * @param uuid the uuid
1240             * @param companyId the company ID
1241             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1242             * @return the previous, current, and next document library folder
1243             * @throws NoSuchFolderException if a document library folder with the primary key could not be found
1244             */
1245            @Override
1246            public DLFolder[] findByUuid_C_PrevAndNext(long folderId, String uuid,
1247                    long companyId, OrderByComparator<DLFolder> orderByComparator)
1248                    throws NoSuchFolderException {
1249                    DLFolder dlFolder = findByPrimaryKey(folderId);
1250    
1251                    Session session = null;
1252    
1253                    try {
1254                            session = openSession();
1255    
1256                            DLFolder[] array = new DLFolderImpl[3];
1257    
1258                            array[0] = getByUuid_C_PrevAndNext(session, dlFolder, uuid,
1259                                            companyId, orderByComparator, true);
1260    
1261                            array[1] = dlFolder;
1262    
1263                            array[2] = getByUuid_C_PrevAndNext(session, dlFolder, uuid,
1264                                            companyId, orderByComparator, false);
1265    
1266                            return array;
1267                    }
1268                    catch (Exception e) {
1269                            throw processException(e);
1270                    }
1271                    finally {
1272                            closeSession(session);
1273                    }
1274            }
1275    
1276            protected DLFolder getByUuid_C_PrevAndNext(Session session,
1277                    DLFolder dlFolder, String uuid, long companyId,
1278                    OrderByComparator<DLFolder> orderByComparator, boolean previous) {
1279                    StringBundler query = null;
1280    
1281                    if (orderByComparator != null) {
1282                            query = new StringBundler(5 +
1283                                            (orderByComparator.getOrderByConditionFields().length * 3) +
1284                                            (orderByComparator.getOrderByFields().length * 3));
1285                    }
1286                    else {
1287                            query = new StringBundler(4);
1288                    }
1289    
1290                    query.append(_SQL_SELECT_DLFOLDER_WHERE);
1291    
1292                    boolean bindUuid = false;
1293    
1294                    if (uuid == null) {
1295                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1296                    }
1297                    else if (uuid.equals(StringPool.BLANK)) {
1298                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1299                    }
1300                    else {
1301                            bindUuid = true;
1302    
1303                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1304                    }
1305    
1306                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1307    
1308                    if (orderByComparator != null) {
1309                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1310    
1311                            if (orderByConditionFields.length > 0) {
1312                                    query.append(WHERE_AND);
1313                            }
1314    
1315                            for (int i = 0; i < orderByConditionFields.length; i++) {
1316                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1317                                    query.append(orderByConditionFields[i]);
1318    
1319                                    if ((i + 1) < orderByConditionFields.length) {
1320                                            if (orderByComparator.isAscending() ^ previous) {
1321                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1322                                            }
1323                                            else {
1324                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1325                                            }
1326                                    }
1327                                    else {
1328                                            if (orderByComparator.isAscending() ^ previous) {
1329                                                    query.append(WHERE_GREATER_THAN);
1330                                            }
1331                                            else {
1332                                                    query.append(WHERE_LESSER_THAN);
1333                                            }
1334                                    }
1335                            }
1336    
1337                            query.append(ORDER_BY_CLAUSE);
1338    
1339                            String[] orderByFields = orderByComparator.getOrderByFields();
1340    
1341                            for (int i = 0; i < orderByFields.length; i++) {
1342                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1343                                    query.append(orderByFields[i]);
1344    
1345                                    if ((i + 1) < orderByFields.length) {
1346                                            if (orderByComparator.isAscending() ^ previous) {
1347                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1348                                            }
1349                                            else {
1350                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1351                                            }
1352                                    }
1353                                    else {
1354                                            if (orderByComparator.isAscending() ^ previous) {
1355                                                    query.append(ORDER_BY_ASC);
1356                                            }
1357                                            else {
1358                                                    query.append(ORDER_BY_DESC);
1359                                            }
1360                                    }
1361                            }
1362                    }
1363                    else {
1364                            query.append(DLFolderModelImpl.ORDER_BY_JPQL);
1365                    }
1366    
1367                    String sql = query.toString();
1368    
1369                    Query q = session.createQuery(sql);
1370    
1371                    q.setFirstResult(0);
1372                    q.setMaxResults(2);
1373    
1374                    QueryPos qPos = QueryPos.getInstance(q);
1375    
1376                    if (bindUuid) {
1377                            qPos.add(uuid);
1378                    }
1379    
1380                    qPos.add(companyId);
1381    
1382                    if (orderByComparator != null) {
1383                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
1384    
1385                            for (Object value : values) {
1386                                    qPos.add(value);
1387                            }
1388                    }
1389    
1390                    List<DLFolder> list = q.list();
1391    
1392                    if (list.size() == 2) {
1393                            return list.get(1);
1394                    }
1395                    else {
1396                            return null;
1397                    }
1398            }
1399    
1400            /**
1401             * Removes all the document library folders where uuid = &#63; and companyId = &#63; from the database.
1402             *
1403             * @param uuid the uuid
1404             * @param companyId the company ID
1405             */
1406            @Override
1407            public void removeByUuid_C(String uuid, long companyId) {
1408                    for (DLFolder dlFolder : findByUuid_C(uuid, companyId,
1409                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1410                            remove(dlFolder);
1411                    }
1412            }
1413    
1414            /**
1415             * Returns the number of document library folders where uuid = &#63; and companyId = &#63;.
1416             *
1417             * @param uuid the uuid
1418             * @param companyId the company ID
1419             * @return the number of matching document library folders
1420             */
1421            @Override
1422            public int countByUuid_C(String uuid, long companyId) {
1423                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1424    
1425                    Object[] finderArgs = new Object[] { uuid, companyId };
1426    
1427                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1428    
1429                    if (count == null) {
1430                            StringBundler query = new StringBundler(3);
1431    
1432                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
1433    
1434                            boolean bindUuid = false;
1435    
1436                            if (uuid == null) {
1437                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1438                            }
1439                            else if (uuid.equals(StringPool.BLANK)) {
1440                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1441                            }
1442                            else {
1443                                    bindUuid = true;
1444    
1445                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1446                            }
1447    
1448                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1449    
1450                            String sql = query.toString();
1451    
1452                            Session session = null;
1453    
1454                            try {
1455                                    session = openSession();
1456    
1457                                    Query q = session.createQuery(sql);
1458    
1459                                    QueryPos qPos = QueryPos.getInstance(q);
1460    
1461                                    if (bindUuid) {
1462                                            qPos.add(uuid);
1463                                    }
1464    
1465                                    qPos.add(companyId);
1466    
1467                                    count = (Long)q.uniqueResult();
1468    
1469                                    finderCache.putResult(finderPath, finderArgs, count);
1470                            }
1471                            catch (Exception e) {
1472                                    finderCache.removeResult(finderPath, finderArgs);
1473    
1474                                    throw processException(e);
1475                            }
1476                            finally {
1477                                    closeSession(session);
1478                            }
1479                    }
1480    
1481                    return count.intValue();
1482            }
1483    
1484            private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "dlFolder.uuid IS NULL AND ";
1485            private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "dlFolder.uuid = ? AND ";
1486            private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(dlFolder.uuid IS NULL OR dlFolder.uuid = '') AND ";
1487            private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "dlFolder.companyId = ?";
1488            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
1489                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
1490                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
1491                            new String[] {
1492                                    Long.class.getName(),
1493                                    
1494                            Integer.class.getName(), Integer.class.getName(),
1495                                    OrderByComparator.class.getName()
1496                            });
1497            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
1498                    new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
1499                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
1500                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
1501                            new String[] { Long.class.getName() },
1502                            DLFolderModelImpl.GROUPID_COLUMN_BITMASK |
1503                            DLFolderModelImpl.PARENTFOLDERID_COLUMN_BITMASK |
1504                            DLFolderModelImpl.NAME_COLUMN_BITMASK);
1505            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
1506                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
1507                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
1508                            new String[] { Long.class.getName() });
1509    
1510            /**
1511             * Returns all the document library folders where groupId = &#63;.
1512             *
1513             * @param groupId the group ID
1514             * @return the matching document library folders
1515             */
1516            @Override
1517            public List<DLFolder> findByGroupId(long groupId) {
1518                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1519            }
1520    
1521            /**
1522             * Returns a range of all the document library folders where groupId = &#63;.
1523             *
1524             * <p>
1525             * 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.
1526             * </p>
1527             *
1528             * @param groupId the group ID
1529             * @param start the lower bound of the range of document library folders
1530             * @param end the upper bound of the range of document library folders (not inclusive)
1531             * @return the range of matching document library folders
1532             */
1533            @Override
1534            public List<DLFolder> findByGroupId(long groupId, int start, int end) {
1535                    return findByGroupId(groupId, start, end, null);
1536            }
1537    
1538            /**
1539             * Returns an ordered range of all the document library folders where groupId = &#63;.
1540             *
1541             * <p>
1542             * 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.
1543             * </p>
1544             *
1545             * @param groupId the group ID
1546             * @param start the lower bound of the range of document library folders
1547             * @param end the upper bound of the range of document library folders (not inclusive)
1548             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1549             * @return the ordered range of matching document library folders
1550             */
1551            @Override
1552            public List<DLFolder> findByGroupId(long groupId, int start, int end,
1553                    OrderByComparator<DLFolder> orderByComparator) {
1554                    return findByGroupId(groupId, start, end, orderByComparator, true);
1555            }
1556    
1557            /**
1558             * Returns an ordered range of all the document library folders where groupId = &#63;.
1559             *
1560             * <p>
1561             * 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.
1562             * </p>
1563             *
1564             * @param groupId the group ID
1565             * @param start the lower bound of the range of document library folders
1566             * @param end the upper bound of the range of document library folders (not inclusive)
1567             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1568             * @param retrieveFromCache whether to retrieve from the finder cache
1569             * @return the ordered range of matching document library folders
1570             */
1571            @Override
1572            public List<DLFolder> findByGroupId(long groupId, int start, int end,
1573                    OrderByComparator<DLFolder> orderByComparator, boolean retrieveFromCache) {
1574                    boolean pagination = true;
1575                    FinderPath finderPath = null;
1576                    Object[] finderArgs = null;
1577    
1578                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1579                                    (orderByComparator == null)) {
1580                            pagination = false;
1581                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1582                            finderArgs = new Object[] { groupId };
1583                    }
1584                    else {
1585                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1586                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
1587                    }
1588    
1589                    List<DLFolder> list = null;
1590    
1591                    if (retrieveFromCache) {
1592                            list = (List<DLFolder>)finderCache.getResult(finderPath,
1593                                            finderArgs, this);
1594    
1595                            if ((list != null) && !list.isEmpty()) {
1596                                    for (DLFolder dlFolder : list) {
1597                                            if ((groupId != dlFolder.getGroupId())) {
1598                                                    list = null;
1599    
1600                                                    break;
1601                                            }
1602                                    }
1603                            }
1604                    }
1605    
1606                    if (list == null) {
1607                            StringBundler query = null;
1608    
1609                            if (orderByComparator != null) {
1610                                    query = new StringBundler(3 +
1611                                                    (orderByComparator.getOrderByFields().length * 2));
1612                            }
1613                            else {
1614                                    query = new StringBundler(3);
1615                            }
1616    
1617                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
1618    
1619                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1620    
1621                            if (orderByComparator != null) {
1622                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1623                                            orderByComparator);
1624                            }
1625                            else
1626                             if (pagination) {
1627                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
1628                            }
1629    
1630                            String sql = query.toString();
1631    
1632                            Session session = null;
1633    
1634                            try {
1635                                    session = openSession();
1636    
1637                                    Query q = session.createQuery(sql);
1638    
1639                                    QueryPos qPos = QueryPos.getInstance(q);
1640    
1641                                    qPos.add(groupId);
1642    
1643                                    if (!pagination) {
1644                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
1645                                                            start, end, false);
1646    
1647                                            Collections.sort(list);
1648    
1649                                            list = Collections.unmodifiableList(list);
1650                                    }
1651                                    else {
1652                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
1653                                                            start, end);
1654                                    }
1655    
1656                                    cacheResult(list);
1657    
1658                                    finderCache.putResult(finderPath, finderArgs, list);
1659                            }
1660                            catch (Exception e) {
1661                                    finderCache.removeResult(finderPath, finderArgs);
1662    
1663                                    throw processException(e);
1664                            }
1665                            finally {
1666                                    closeSession(session);
1667                            }
1668                    }
1669    
1670                    return list;
1671            }
1672    
1673            /**
1674             * Returns the first document library folder in the ordered set where groupId = &#63;.
1675             *
1676             * @param groupId the group ID
1677             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1678             * @return the first matching document library folder
1679             * @throws NoSuchFolderException if a matching document library folder could not be found
1680             */
1681            @Override
1682            public DLFolder findByGroupId_First(long groupId,
1683                    OrderByComparator<DLFolder> orderByComparator)
1684                    throws NoSuchFolderException {
1685                    DLFolder dlFolder = fetchByGroupId_First(groupId, orderByComparator);
1686    
1687                    if (dlFolder != null) {
1688                            return dlFolder;
1689                    }
1690    
1691                    StringBundler msg = new StringBundler(4);
1692    
1693                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1694    
1695                    msg.append("groupId=");
1696                    msg.append(groupId);
1697    
1698                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1699    
1700                    throw new NoSuchFolderException(msg.toString());
1701            }
1702    
1703            /**
1704             * Returns the first document library folder in the ordered set where groupId = &#63;.
1705             *
1706             * @param groupId the group ID
1707             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1708             * @return the first matching document library folder, or <code>null</code> if a matching document library folder could not be found
1709             */
1710            @Override
1711            public DLFolder fetchByGroupId_First(long groupId,
1712                    OrderByComparator<DLFolder> orderByComparator) {
1713                    List<DLFolder> list = findByGroupId(groupId, 0, 1, orderByComparator);
1714    
1715                    if (!list.isEmpty()) {
1716                            return list.get(0);
1717                    }
1718    
1719                    return null;
1720            }
1721    
1722            /**
1723             * Returns the last document library folder in the ordered set where groupId = &#63;.
1724             *
1725             * @param groupId the group ID
1726             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1727             * @return the last matching document library folder
1728             * @throws NoSuchFolderException if a matching document library folder could not be found
1729             */
1730            @Override
1731            public DLFolder findByGroupId_Last(long groupId,
1732                    OrderByComparator<DLFolder> orderByComparator)
1733                    throws NoSuchFolderException {
1734                    DLFolder dlFolder = fetchByGroupId_Last(groupId, orderByComparator);
1735    
1736                    if (dlFolder != null) {
1737                            return dlFolder;
1738                    }
1739    
1740                    StringBundler msg = new StringBundler(4);
1741    
1742                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1743    
1744                    msg.append("groupId=");
1745                    msg.append(groupId);
1746    
1747                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1748    
1749                    throw new NoSuchFolderException(msg.toString());
1750            }
1751    
1752            /**
1753             * Returns the last document library folder in the ordered set where groupId = &#63;.
1754             *
1755             * @param groupId the group ID
1756             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1757             * @return the last matching document library folder, or <code>null</code> if a matching document library folder could not be found
1758             */
1759            @Override
1760            public DLFolder fetchByGroupId_Last(long groupId,
1761                    OrderByComparator<DLFolder> orderByComparator) {
1762                    int count = countByGroupId(groupId);
1763    
1764                    if (count == 0) {
1765                            return null;
1766                    }
1767    
1768                    List<DLFolder> list = findByGroupId(groupId, count - 1, count,
1769                                    orderByComparator);
1770    
1771                    if (!list.isEmpty()) {
1772                            return list.get(0);
1773                    }
1774    
1775                    return null;
1776            }
1777    
1778            /**
1779             * Returns the document library folders before and after the current document library folder in the ordered set where groupId = &#63;.
1780             *
1781             * @param folderId the primary key of the current document library folder
1782             * @param groupId the group ID
1783             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1784             * @return the previous, current, and next document library folder
1785             * @throws NoSuchFolderException if a document library folder with the primary key could not be found
1786             */
1787            @Override
1788            public DLFolder[] findByGroupId_PrevAndNext(long folderId, long groupId,
1789                    OrderByComparator<DLFolder> orderByComparator)
1790                    throws NoSuchFolderException {
1791                    DLFolder dlFolder = findByPrimaryKey(folderId);
1792    
1793                    Session session = null;
1794    
1795                    try {
1796                            session = openSession();
1797    
1798                            DLFolder[] array = new DLFolderImpl[3];
1799    
1800                            array[0] = getByGroupId_PrevAndNext(session, dlFolder, groupId,
1801                                            orderByComparator, true);
1802    
1803                            array[1] = dlFolder;
1804    
1805                            array[2] = getByGroupId_PrevAndNext(session, dlFolder, groupId,
1806                                            orderByComparator, false);
1807    
1808                            return array;
1809                    }
1810                    catch (Exception e) {
1811                            throw processException(e);
1812                    }
1813                    finally {
1814                            closeSession(session);
1815                    }
1816            }
1817    
1818            protected DLFolder getByGroupId_PrevAndNext(Session session,
1819                    DLFolder dlFolder, long groupId,
1820                    OrderByComparator<DLFolder> orderByComparator, boolean previous) {
1821                    StringBundler query = null;
1822    
1823                    if (orderByComparator != null) {
1824                            query = new StringBundler(4 +
1825                                            (orderByComparator.getOrderByConditionFields().length * 3) +
1826                                            (orderByComparator.getOrderByFields().length * 3));
1827                    }
1828                    else {
1829                            query = new StringBundler(3);
1830                    }
1831    
1832                    query.append(_SQL_SELECT_DLFOLDER_WHERE);
1833    
1834                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1835    
1836                    if (orderByComparator != null) {
1837                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1838    
1839                            if (orderByConditionFields.length > 0) {
1840                                    query.append(WHERE_AND);
1841                            }
1842    
1843                            for (int i = 0; i < orderByConditionFields.length; i++) {
1844                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1845                                    query.append(orderByConditionFields[i]);
1846    
1847                                    if ((i + 1) < orderByConditionFields.length) {
1848                                            if (orderByComparator.isAscending() ^ previous) {
1849                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1850                                            }
1851                                            else {
1852                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1853                                            }
1854                                    }
1855                                    else {
1856                                            if (orderByComparator.isAscending() ^ previous) {
1857                                                    query.append(WHERE_GREATER_THAN);
1858                                            }
1859                                            else {
1860                                                    query.append(WHERE_LESSER_THAN);
1861                                            }
1862                                    }
1863                            }
1864    
1865                            query.append(ORDER_BY_CLAUSE);
1866    
1867                            String[] orderByFields = orderByComparator.getOrderByFields();
1868    
1869                            for (int i = 0; i < orderByFields.length; i++) {
1870                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1871                                    query.append(orderByFields[i]);
1872    
1873                                    if ((i + 1) < orderByFields.length) {
1874                                            if (orderByComparator.isAscending() ^ previous) {
1875                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1876                                            }
1877                                            else {
1878                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1879                                            }
1880                                    }
1881                                    else {
1882                                            if (orderByComparator.isAscending() ^ previous) {
1883                                                    query.append(ORDER_BY_ASC);
1884                                            }
1885                                            else {
1886                                                    query.append(ORDER_BY_DESC);
1887                                            }
1888                                    }
1889                            }
1890                    }
1891                    else {
1892                            query.append(DLFolderModelImpl.ORDER_BY_JPQL);
1893                    }
1894    
1895                    String sql = query.toString();
1896    
1897                    Query q = session.createQuery(sql);
1898    
1899                    q.setFirstResult(0);
1900                    q.setMaxResults(2);
1901    
1902                    QueryPos qPos = QueryPos.getInstance(q);
1903    
1904                    qPos.add(groupId);
1905    
1906                    if (orderByComparator != null) {
1907                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
1908    
1909                            for (Object value : values) {
1910                                    qPos.add(value);
1911                            }
1912                    }
1913    
1914                    List<DLFolder> list = q.list();
1915    
1916                    if (list.size() == 2) {
1917                            return list.get(1);
1918                    }
1919                    else {
1920                            return null;
1921                    }
1922            }
1923    
1924            /**
1925             * Returns all the document library folders that the user has permission to view where groupId = &#63;.
1926             *
1927             * @param groupId the group ID
1928             * @return the matching document library folders that the user has permission to view
1929             */
1930            @Override
1931            public List<DLFolder> filterFindByGroupId(long groupId) {
1932                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1933                            QueryUtil.ALL_POS, null);
1934            }
1935    
1936            /**
1937             * Returns a range of all the document library folders that the user has permission to view where groupId = &#63;.
1938             *
1939             * <p>
1940             * 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.
1941             * </p>
1942             *
1943             * @param groupId the group ID
1944             * @param start the lower bound of the range of document library folders
1945             * @param end the upper bound of the range of document library folders (not inclusive)
1946             * @return the range of matching document library folders that the user has permission to view
1947             */
1948            @Override
1949            public List<DLFolder> filterFindByGroupId(long groupId, int start, int end) {
1950                    return filterFindByGroupId(groupId, start, end, null);
1951            }
1952    
1953            /**
1954             * Returns an ordered range of all the document library folders that the user has permissions to view where groupId = &#63;.
1955             *
1956             * <p>
1957             * 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.
1958             * </p>
1959             *
1960             * @param groupId the group ID
1961             * @param start the lower bound of the range of document library folders
1962             * @param end the upper bound of the range of document library folders (not inclusive)
1963             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1964             * @return the ordered range of matching document library folders that the user has permission to view
1965             */
1966            @Override
1967            public List<DLFolder> filterFindByGroupId(long groupId, int start, int end,
1968                    OrderByComparator<DLFolder> orderByComparator) {
1969                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1970                            return findByGroupId(groupId, start, end, orderByComparator);
1971                    }
1972    
1973                    StringBundler query = null;
1974    
1975                    if (orderByComparator != null) {
1976                            query = new StringBundler(3 +
1977                                            (orderByComparator.getOrderByFields().length * 2));
1978                    }
1979                    else {
1980                            query = new StringBundler(4);
1981                    }
1982    
1983                    if (getDB().isSupportsInlineDistinct()) {
1984                            query.append(_FILTER_SQL_SELECT_DLFOLDER_WHERE);
1985                    }
1986                    else {
1987                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1);
1988                    }
1989    
1990                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1991    
1992                    if (!getDB().isSupportsInlineDistinct()) {
1993                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2);
1994                    }
1995    
1996                    if (orderByComparator != null) {
1997                            if (getDB().isSupportsInlineDistinct()) {
1998                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1999                                            orderByComparator, true);
2000                            }
2001                            else {
2002                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2003                                            orderByComparator, true);
2004                            }
2005                    }
2006                    else {
2007                            if (getDB().isSupportsInlineDistinct()) {
2008                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
2009                            }
2010                            else {
2011                                    query.append(DLFolderModelImpl.ORDER_BY_SQL);
2012                            }
2013                    }
2014    
2015                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2016                                    DLFolder.class.getName(),
2017                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2018    
2019                    Session session = null;
2020    
2021                    try {
2022                            session = openSession();
2023    
2024                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
2025    
2026                            if (getDB().isSupportsInlineDistinct()) {
2027                                    q.addEntity(_FILTER_ENTITY_ALIAS, DLFolderImpl.class);
2028                            }
2029                            else {
2030                                    q.addEntity(_FILTER_ENTITY_TABLE, DLFolderImpl.class);
2031                            }
2032    
2033                            QueryPos qPos = QueryPos.getInstance(q);
2034    
2035                            qPos.add(groupId);
2036    
2037                            return (List<DLFolder>)QueryUtil.list(q, getDialect(), start, end);
2038                    }
2039                    catch (Exception e) {
2040                            throw processException(e);
2041                    }
2042                    finally {
2043                            closeSession(session);
2044                    }
2045            }
2046    
2047            /**
2048             * 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;.
2049             *
2050             * @param folderId the primary key of the current document library folder
2051             * @param groupId the group ID
2052             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2053             * @return the previous, current, and next document library folder
2054             * @throws NoSuchFolderException if a document library folder with the primary key could not be found
2055             */
2056            @Override
2057            public DLFolder[] filterFindByGroupId_PrevAndNext(long folderId,
2058                    long groupId, OrderByComparator<DLFolder> orderByComparator)
2059                    throws NoSuchFolderException {
2060                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2061                            return findByGroupId_PrevAndNext(folderId, groupId,
2062                                    orderByComparator);
2063                    }
2064    
2065                    DLFolder dlFolder = findByPrimaryKey(folderId);
2066    
2067                    Session session = null;
2068    
2069                    try {
2070                            session = openSession();
2071    
2072                            DLFolder[] array = new DLFolderImpl[3];
2073    
2074                            array[0] = filterGetByGroupId_PrevAndNext(session, dlFolder,
2075                                            groupId, orderByComparator, true);
2076    
2077                            array[1] = dlFolder;
2078    
2079                            array[2] = filterGetByGroupId_PrevAndNext(session, dlFolder,
2080                                            groupId, orderByComparator, false);
2081    
2082                            return array;
2083                    }
2084                    catch (Exception e) {
2085                            throw processException(e);
2086                    }
2087                    finally {
2088                            closeSession(session);
2089                    }
2090            }
2091    
2092            protected DLFolder filterGetByGroupId_PrevAndNext(Session session,
2093                    DLFolder dlFolder, long groupId,
2094                    OrderByComparator<DLFolder> orderByComparator, boolean previous) {
2095                    StringBundler query = null;
2096    
2097                    if (orderByComparator != null) {
2098                            query = new StringBundler(5 +
2099                                            (orderByComparator.getOrderByConditionFields().length * 3) +
2100                                            (orderByComparator.getOrderByFields().length * 3));
2101                    }
2102                    else {
2103                            query = new StringBundler(4);
2104                    }
2105    
2106                    if (getDB().isSupportsInlineDistinct()) {
2107                            query.append(_FILTER_SQL_SELECT_DLFOLDER_WHERE);
2108                    }
2109                    else {
2110                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1);
2111                    }
2112    
2113                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2114    
2115                    if (!getDB().isSupportsInlineDistinct()) {
2116                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2);
2117                    }
2118    
2119                    if (orderByComparator != null) {
2120                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2121    
2122                            if (orderByConditionFields.length > 0) {
2123                                    query.append(WHERE_AND);
2124                            }
2125    
2126                            for (int i = 0; i < orderByConditionFields.length; i++) {
2127                                    if (getDB().isSupportsInlineDistinct()) {
2128                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2129                                    }
2130                                    else {
2131                                            query.append(_ORDER_BY_ENTITY_TABLE);
2132                                    }
2133    
2134                                    query.append(orderByConditionFields[i]);
2135    
2136                                    if ((i + 1) < orderByConditionFields.length) {
2137                                            if (orderByComparator.isAscending() ^ previous) {
2138                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2139                                            }
2140                                            else {
2141                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2142                                            }
2143                                    }
2144                                    else {
2145                                            if (orderByComparator.isAscending() ^ previous) {
2146                                                    query.append(WHERE_GREATER_THAN);
2147                                            }
2148                                            else {
2149                                                    query.append(WHERE_LESSER_THAN);
2150                                            }
2151                                    }
2152                            }
2153    
2154                            query.append(ORDER_BY_CLAUSE);
2155    
2156                            String[] orderByFields = orderByComparator.getOrderByFields();
2157    
2158                            for (int i = 0; i < orderByFields.length; i++) {
2159                                    if (getDB().isSupportsInlineDistinct()) {
2160                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2161                                    }
2162                                    else {
2163                                            query.append(_ORDER_BY_ENTITY_TABLE);
2164                                    }
2165    
2166                                    query.append(orderByFields[i]);
2167    
2168                                    if ((i + 1) < orderByFields.length) {
2169                                            if (orderByComparator.isAscending() ^ previous) {
2170                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2171                                            }
2172                                            else {
2173                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2174                                            }
2175                                    }
2176                                    else {
2177                                            if (orderByComparator.isAscending() ^ previous) {
2178                                                    query.append(ORDER_BY_ASC);
2179                                            }
2180                                            else {
2181                                                    query.append(ORDER_BY_DESC);
2182                                            }
2183                                    }
2184                            }
2185                    }
2186                    else {
2187                            if (getDB().isSupportsInlineDistinct()) {
2188                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
2189                            }
2190                            else {
2191                                    query.append(DLFolderModelImpl.ORDER_BY_SQL);
2192                            }
2193                    }
2194    
2195                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2196                                    DLFolder.class.getName(),
2197                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2198    
2199                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
2200    
2201                    q.setFirstResult(0);
2202                    q.setMaxResults(2);
2203    
2204                    if (getDB().isSupportsInlineDistinct()) {
2205                            q.addEntity(_FILTER_ENTITY_ALIAS, DLFolderImpl.class);
2206                    }
2207                    else {
2208                            q.addEntity(_FILTER_ENTITY_TABLE, DLFolderImpl.class);
2209                    }
2210    
2211                    QueryPos qPos = QueryPos.getInstance(q);
2212    
2213                    qPos.add(groupId);
2214    
2215                    if (orderByComparator != null) {
2216                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
2217    
2218                            for (Object value : values) {
2219                                    qPos.add(value);
2220                            }
2221                    }
2222    
2223                    List<DLFolder> list = q.list();
2224    
2225                    if (list.size() == 2) {
2226                            return list.get(1);
2227                    }
2228                    else {
2229                            return null;
2230                    }
2231            }
2232    
2233            /**
2234             * Removes all the document library folders where groupId = &#63; from the database.
2235             *
2236             * @param groupId the group ID
2237             */
2238            @Override
2239            public void removeByGroupId(long groupId) {
2240                    for (DLFolder dlFolder : findByGroupId(groupId, QueryUtil.ALL_POS,
2241                                    QueryUtil.ALL_POS, null)) {
2242                            remove(dlFolder);
2243                    }
2244            }
2245    
2246            /**
2247             * Returns the number of document library folders where groupId = &#63;.
2248             *
2249             * @param groupId the group ID
2250             * @return the number of matching document library folders
2251             */
2252            @Override
2253            public int countByGroupId(long groupId) {
2254                    FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
2255    
2256                    Object[] finderArgs = new Object[] { groupId };
2257    
2258                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
2259    
2260                    if (count == null) {
2261                            StringBundler query = new StringBundler(2);
2262    
2263                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
2264    
2265                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2266    
2267                            String sql = query.toString();
2268    
2269                            Session session = null;
2270    
2271                            try {
2272                                    session = openSession();
2273    
2274                                    Query q = session.createQuery(sql);
2275    
2276                                    QueryPos qPos = QueryPos.getInstance(q);
2277    
2278                                    qPos.add(groupId);
2279    
2280                                    count = (Long)q.uniqueResult();
2281    
2282                                    finderCache.putResult(finderPath, finderArgs, count);
2283                            }
2284                            catch (Exception e) {
2285                                    finderCache.removeResult(finderPath, finderArgs);
2286    
2287                                    throw processException(e);
2288                            }
2289                            finally {
2290                                    closeSession(session);
2291                            }
2292                    }
2293    
2294                    return count.intValue();
2295            }
2296    
2297            /**
2298             * Returns the number of document library folders that the user has permission to view where groupId = &#63;.
2299             *
2300             * @param groupId the group ID
2301             * @return the number of matching document library folders that the user has permission to view
2302             */
2303            @Override
2304            public int filterCountByGroupId(long groupId) {
2305                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2306                            return countByGroupId(groupId);
2307                    }
2308    
2309                    StringBundler query = new StringBundler(2);
2310    
2311                    query.append(_FILTER_SQL_COUNT_DLFOLDER_WHERE);
2312    
2313                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2314    
2315                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2316                                    DLFolder.class.getName(),
2317                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2318    
2319                    Session session = null;
2320    
2321                    try {
2322                            session = openSession();
2323    
2324                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
2325    
2326                            q.addScalar(COUNT_COLUMN_NAME,
2327                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
2328    
2329                            QueryPos qPos = QueryPos.getInstance(q);
2330    
2331                            qPos.add(groupId);
2332    
2333                            Long count = (Long)q.uniqueResult();
2334    
2335                            return count.intValue();
2336                    }
2337                    catch (Exception e) {
2338                            throw processException(e);
2339                    }
2340                    finally {
2341                            closeSession(session);
2342                    }
2343            }
2344    
2345            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "dlFolder.groupId = ?";
2346            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
2347                    new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
2348                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
2349                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
2350                            new String[] {
2351                                    Long.class.getName(),
2352                                    
2353                            Integer.class.getName(), Integer.class.getName(),
2354                                    OrderByComparator.class.getName()
2355                            });
2356            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
2357                    new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
2358                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
2359                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
2360                            new String[] { Long.class.getName() },
2361                            DLFolderModelImpl.COMPANYID_COLUMN_BITMASK |
2362                            DLFolderModelImpl.PARENTFOLDERID_COLUMN_BITMASK |
2363                            DLFolderModelImpl.NAME_COLUMN_BITMASK);
2364            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
2365                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
2366                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
2367                            new String[] { Long.class.getName() });
2368    
2369            /**
2370             * Returns all the document library folders where companyId = &#63;.
2371             *
2372             * @param companyId the company ID
2373             * @return the matching document library folders
2374             */
2375            @Override
2376            public List<DLFolder> findByCompanyId(long companyId) {
2377                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2378                            null);
2379            }
2380    
2381            /**
2382             * Returns a range of all the document library folders where companyId = &#63;.
2383             *
2384             * <p>
2385             * 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.
2386             * </p>
2387             *
2388             * @param companyId the company ID
2389             * @param start the lower bound of the range of document library folders
2390             * @param end the upper bound of the range of document library folders (not inclusive)
2391             * @return the range of matching document library folders
2392             */
2393            @Override
2394            public List<DLFolder> findByCompanyId(long companyId, int start, int end) {
2395                    return findByCompanyId(companyId, start, end, null);
2396            }
2397    
2398            /**
2399             * Returns an ordered range of all the document library folders where companyId = &#63;.
2400             *
2401             * <p>
2402             * 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.
2403             * </p>
2404             *
2405             * @param companyId the company ID
2406             * @param start the lower bound of the range of document library folders
2407             * @param end the upper bound of the range of document library folders (not inclusive)
2408             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2409             * @return the ordered range of matching document library folders
2410             */
2411            @Override
2412            public List<DLFolder> findByCompanyId(long companyId, int start, int end,
2413                    OrderByComparator<DLFolder> orderByComparator) {
2414                    return findByCompanyId(companyId, start, end, orderByComparator, true);
2415            }
2416    
2417            /**
2418             * Returns an ordered range of all the document library folders where companyId = &#63;.
2419             *
2420             * <p>
2421             * 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.
2422             * </p>
2423             *
2424             * @param companyId the company ID
2425             * @param start the lower bound of the range of document library folders
2426             * @param end the upper bound of the range of document library folders (not inclusive)
2427             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2428             * @param retrieveFromCache whether to retrieve from the finder cache
2429             * @return the ordered range of matching document library folders
2430             */
2431            @Override
2432            public List<DLFolder> findByCompanyId(long companyId, int start, int end,
2433                    OrderByComparator<DLFolder> orderByComparator, boolean retrieveFromCache) {
2434                    boolean pagination = true;
2435                    FinderPath finderPath = null;
2436                    Object[] finderArgs = null;
2437    
2438                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2439                                    (orderByComparator == null)) {
2440                            pagination = false;
2441                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
2442                            finderArgs = new Object[] { companyId };
2443                    }
2444                    else {
2445                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
2446                            finderArgs = new Object[] { companyId, start, end, orderByComparator };
2447                    }
2448    
2449                    List<DLFolder> list = null;
2450    
2451                    if (retrieveFromCache) {
2452                            list = (List<DLFolder>)finderCache.getResult(finderPath,
2453                                            finderArgs, this);
2454    
2455                            if ((list != null) && !list.isEmpty()) {
2456                                    for (DLFolder dlFolder : list) {
2457                                            if ((companyId != dlFolder.getCompanyId())) {
2458                                                    list = null;
2459    
2460                                                    break;
2461                                            }
2462                                    }
2463                            }
2464                    }
2465    
2466                    if (list == null) {
2467                            StringBundler query = null;
2468    
2469                            if (orderByComparator != null) {
2470                                    query = new StringBundler(3 +
2471                                                    (orderByComparator.getOrderByFields().length * 2));
2472                            }
2473                            else {
2474                                    query = new StringBundler(3);
2475                            }
2476    
2477                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
2478    
2479                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2480    
2481                            if (orderByComparator != null) {
2482                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2483                                            orderByComparator);
2484                            }
2485                            else
2486                             if (pagination) {
2487                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
2488                            }
2489    
2490                            String sql = query.toString();
2491    
2492                            Session session = null;
2493    
2494                            try {
2495                                    session = openSession();
2496    
2497                                    Query q = session.createQuery(sql);
2498    
2499                                    QueryPos qPos = QueryPos.getInstance(q);
2500    
2501                                    qPos.add(companyId);
2502    
2503                                    if (!pagination) {
2504                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
2505                                                            start, end, false);
2506    
2507                                            Collections.sort(list);
2508    
2509                                            list = Collections.unmodifiableList(list);
2510                                    }
2511                                    else {
2512                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
2513                                                            start, end);
2514                                    }
2515    
2516                                    cacheResult(list);
2517    
2518                                    finderCache.putResult(finderPath, finderArgs, list);
2519                            }
2520                            catch (Exception e) {
2521                                    finderCache.removeResult(finderPath, finderArgs);
2522    
2523                                    throw processException(e);
2524                            }
2525                            finally {
2526                                    closeSession(session);
2527                            }
2528                    }
2529    
2530                    return list;
2531            }
2532    
2533            /**
2534             * Returns the first document library folder in the ordered set where companyId = &#63;.
2535             *
2536             * @param companyId the company ID
2537             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2538             * @return the first matching document library folder
2539             * @throws NoSuchFolderException if a matching document library folder could not be found
2540             */
2541            @Override
2542            public DLFolder findByCompanyId_First(long companyId,
2543                    OrderByComparator<DLFolder> orderByComparator)
2544                    throws NoSuchFolderException {
2545                    DLFolder dlFolder = fetchByCompanyId_First(companyId, orderByComparator);
2546    
2547                    if (dlFolder != null) {
2548                            return dlFolder;
2549                    }
2550    
2551                    StringBundler msg = new StringBundler(4);
2552    
2553                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2554    
2555                    msg.append("companyId=");
2556                    msg.append(companyId);
2557    
2558                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2559    
2560                    throw new NoSuchFolderException(msg.toString());
2561            }
2562    
2563            /**
2564             * Returns the first document library folder in the ordered set where companyId = &#63;.
2565             *
2566             * @param companyId the company ID
2567             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2568             * @return the first matching document library folder, or <code>null</code> if a matching document library folder could not be found
2569             */
2570            @Override
2571            public DLFolder fetchByCompanyId_First(long companyId,
2572                    OrderByComparator<DLFolder> orderByComparator) {
2573                    List<DLFolder> list = findByCompanyId(companyId, 0, 1, orderByComparator);
2574    
2575                    if (!list.isEmpty()) {
2576                            return list.get(0);
2577                    }
2578    
2579                    return null;
2580            }
2581    
2582            /**
2583             * Returns the last document library folder in the ordered set where companyId = &#63;.
2584             *
2585             * @param companyId the company ID
2586             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2587             * @return the last matching document library folder
2588             * @throws NoSuchFolderException if a matching document library folder could not be found
2589             */
2590            @Override
2591            public DLFolder findByCompanyId_Last(long companyId,
2592                    OrderByComparator<DLFolder> orderByComparator)
2593                    throws NoSuchFolderException {
2594                    DLFolder dlFolder = fetchByCompanyId_Last(companyId, orderByComparator);
2595    
2596                    if (dlFolder != null) {
2597                            return dlFolder;
2598                    }
2599    
2600                    StringBundler msg = new StringBundler(4);
2601    
2602                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2603    
2604                    msg.append("companyId=");
2605                    msg.append(companyId);
2606    
2607                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2608    
2609                    throw new NoSuchFolderException(msg.toString());
2610            }
2611    
2612            /**
2613             * Returns the last document library folder in the ordered set where companyId = &#63;.
2614             *
2615             * @param companyId the company ID
2616             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2617             * @return the last matching document library folder, or <code>null</code> if a matching document library folder could not be found
2618             */
2619            @Override
2620            public DLFolder fetchByCompanyId_Last(long companyId,
2621                    OrderByComparator<DLFolder> orderByComparator) {
2622                    int count = countByCompanyId(companyId);
2623    
2624                    if (count == 0) {
2625                            return null;
2626                    }
2627    
2628                    List<DLFolder> list = findByCompanyId(companyId, count - 1, count,
2629                                    orderByComparator);
2630    
2631                    if (!list.isEmpty()) {
2632                            return list.get(0);
2633                    }
2634    
2635                    return null;
2636            }
2637    
2638            /**
2639             * Returns the document library folders before and after the current document library folder in the ordered set where companyId = &#63;.
2640             *
2641             * @param folderId the primary key of the current document library folder
2642             * @param companyId the company ID
2643             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2644             * @return the previous, current, and next document library folder
2645             * @throws NoSuchFolderException if a document library folder with the primary key could not be found
2646             */
2647            @Override
2648            public DLFolder[] findByCompanyId_PrevAndNext(long folderId,
2649                    long companyId, OrderByComparator<DLFolder> orderByComparator)
2650                    throws NoSuchFolderException {
2651                    DLFolder dlFolder = findByPrimaryKey(folderId);
2652    
2653                    Session session = null;
2654    
2655                    try {
2656                            session = openSession();
2657    
2658                            DLFolder[] array = new DLFolderImpl[3];
2659    
2660                            array[0] = getByCompanyId_PrevAndNext(session, dlFolder, companyId,
2661                                            orderByComparator, true);
2662    
2663                            array[1] = dlFolder;
2664    
2665                            array[2] = getByCompanyId_PrevAndNext(session, dlFolder, companyId,
2666                                            orderByComparator, false);
2667    
2668                            return array;
2669                    }
2670                    catch (Exception e) {
2671                            throw processException(e);
2672                    }
2673                    finally {
2674                            closeSession(session);
2675                    }
2676            }
2677    
2678            protected DLFolder getByCompanyId_PrevAndNext(Session session,
2679                    DLFolder dlFolder, long companyId,
2680                    OrderByComparator<DLFolder> orderByComparator, boolean previous) {
2681                    StringBundler query = null;
2682    
2683                    if (orderByComparator != null) {
2684                            query = new StringBundler(4 +
2685                                            (orderByComparator.getOrderByConditionFields().length * 3) +
2686                                            (orderByComparator.getOrderByFields().length * 3));
2687                    }
2688                    else {
2689                            query = new StringBundler(3);
2690                    }
2691    
2692                    query.append(_SQL_SELECT_DLFOLDER_WHERE);
2693    
2694                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2695    
2696                    if (orderByComparator != null) {
2697                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2698    
2699                            if (orderByConditionFields.length > 0) {
2700                                    query.append(WHERE_AND);
2701                            }
2702    
2703                            for (int i = 0; i < orderByConditionFields.length; i++) {
2704                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2705                                    query.append(orderByConditionFields[i]);
2706    
2707                                    if ((i + 1) < orderByConditionFields.length) {
2708                                            if (orderByComparator.isAscending() ^ previous) {
2709                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2710                                            }
2711                                            else {
2712                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2713                                            }
2714                                    }
2715                                    else {
2716                                            if (orderByComparator.isAscending() ^ previous) {
2717                                                    query.append(WHERE_GREATER_THAN);
2718                                            }
2719                                            else {
2720                                                    query.append(WHERE_LESSER_THAN);
2721                                            }
2722                                    }
2723                            }
2724    
2725                            query.append(ORDER_BY_CLAUSE);
2726    
2727                            String[] orderByFields = orderByComparator.getOrderByFields();
2728    
2729                            for (int i = 0; i < orderByFields.length; i++) {
2730                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2731                                    query.append(orderByFields[i]);
2732    
2733                                    if ((i + 1) < orderByFields.length) {
2734                                            if (orderByComparator.isAscending() ^ previous) {
2735                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2736                                            }
2737                                            else {
2738                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2739                                            }
2740                                    }
2741                                    else {
2742                                            if (orderByComparator.isAscending() ^ previous) {
2743                                                    query.append(ORDER_BY_ASC);
2744                                            }
2745                                            else {
2746                                                    query.append(ORDER_BY_DESC);
2747                                            }
2748                                    }
2749                            }
2750                    }
2751                    else {
2752                            query.append(DLFolderModelImpl.ORDER_BY_JPQL);
2753                    }
2754    
2755                    String sql = query.toString();
2756    
2757                    Query q = session.createQuery(sql);
2758    
2759                    q.setFirstResult(0);
2760                    q.setMaxResults(2);
2761    
2762                    QueryPos qPos = QueryPos.getInstance(q);
2763    
2764                    qPos.add(companyId);
2765    
2766                    if (orderByComparator != null) {
2767                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
2768    
2769                            for (Object value : values) {
2770                                    qPos.add(value);
2771                            }
2772                    }
2773    
2774                    List<DLFolder> list = q.list();
2775    
2776                    if (list.size() == 2) {
2777                            return list.get(1);
2778                    }
2779                    else {
2780                            return null;
2781                    }
2782            }
2783    
2784            /**
2785             * Removes all the document library folders where companyId = &#63; from the database.
2786             *
2787             * @param companyId the company ID
2788             */
2789            @Override
2790            public void removeByCompanyId(long companyId) {
2791                    for (DLFolder dlFolder : findByCompanyId(companyId, QueryUtil.ALL_POS,
2792                                    QueryUtil.ALL_POS, null)) {
2793                            remove(dlFolder);
2794                    }
2795            }
2796    
2797            /**
2798             * Returns the number of document library folders where companyId = &#63;.
2799             *
2800             * @param companyId the company ID
2801             * @return the number of matching document library folders
2802             */
2803            @Override
2804            public int countByCompanyId(long companyId) {
2805                    FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
2806    
2807                    Object[] finderArgs = new Object[] { companyId };
2808    
2809                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
2810    
2811                    if (count == null) {
2812                            StringBundler query = new StringBundler(2);
2813    
2814                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
2815    
2816                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2817    
2818                            String sql = query.toString();
2819    
2820                            Session session = null;
2821    
2822                            try {
2823                                    session = openSession();
2824    
2825                                    Query q = session.createQuery(sql);
2826    
2827                                    QueryPos qPos = QueryPos.getInstance(q);
2828    
2829                                    qPos.add(companyId);
2830    
2831                                    count = (Long)q.uniqueResult();
2832    
2833                                    finderCache.putResult(finderPath, finderArgs, count);
2834                            }
2835                            catch (Exception e) {
2836                                    finderCache.removeResult(finderPath, finderArgs);
2837    
2838                                    throw processException(e);
2839                            }
2840                            finally {
2841                                    closeSession(session);
2842                            }
2843                    }
2844    
2845                    return count.intValue();
2846            }
2847    
2848            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "dlFolder.companyId = ?";
2849            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_REPOSITORYID =
2850                    new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
2851                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
2852                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByRepositoryId",
2853                            new String[] {
2854                                    Long.class.getName(),
2855                                    
2856                            Integer.class.getName(), Integer.class.getName(),
2857                                    OrderByComparator.class.getName()
2858                            });
2859            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_REPOSITORYID =
2860                    new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
2861                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
2862                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByRepositoryId",
2863                            new String[] { Long.class.getName() },
2864                            DLFolderModelImpl.REPOSITORYID_COLUMN_BITMASK |
2865                            DLFolderModelImpl.PARENTFOLDERID_COLUMN_BITMASK |
2866                            DLFolderModelImpl.NAME_COLUMN_BITMASK);
2867            public static final FinderPath FINDER_PATH_COUNT_BY_REPOSITORYID = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
2868                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
2869                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByRepositoryId",
2870                            new String[] { Long.class.getName() });
2871    
2872            /**
2873             * Returns all the document library folders where repositoryId = &#63;.
2874             *
2875             * @param repositoryId the repository ID
2876             * @return the matching document library folders
2877             */
2878            @Override
2879            public List<DLFolder> findByRepositoryId(long repositoryId) {
2880                    return findByRepositoryId(repositoryId, QueryUtil.ALL_POS,
2881                            QueryUtil.ALL_POS, null);
2882            }
2883    
2884            /**
2885             * Returns a range of all the document library folders where repositoryId = &#63;.
2886             *
2887             * <p>
2888             * 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.
2889             * </p>
2890             *
2891             * @param repositoryId the repository ID
2892             * @param start the lower bound of the range of document library folders
2893             * @param end the upper bound of the range of document library folders (not inclusive)
2894             * @return the range of matching document library folders
2895             */
2896            @Override
2897            public List<DLFolder> findByRepositoryId(long repositoryId, int start,
2898                    int end) {
2899                    return findByRepositoryId(repositoryId, start, end, null);
2900            }
2901    
2902            /**
2903             * Returns an ordered range of all the document library folders where repositoryId = &#63;.
2904             *
2905             * <p>
2906             * 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.
2907             * </p>
2908             *
2909             * @param repositoryId the repository ID
2910             * @param start the lower bound of the range of document library folders
2911             * @param end the upper bound of the range of document library folders (not inclusive)
2912             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2913             * @return the ordered range of matching document library folders
2914             */
2915            @Override
2916            public List<DLFolder> findByRepositoryId(long repositoryId, int start,
2917                    int end, OrderByComparator<DLFolder> orderByComparator) {
2918                    return findByRepositoryId(repositoryId, start, end, orderByComparator,
2919                            true);
2920            }
2921    
2922            /**
2923             * Returns an ordered range of all the document library folders where repositoryId = &#63;.
2924             *
2925             * <p>
2926             * 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.
2927             * </p>
2928             *
2929             * @param repositoryId the repository ID
2930             * @param start the lower bound of the range of document library folders
2931             * @param end the upper bound of the range of document library folders (not inclusive)
2932             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2933             * @param retrieveFromCache whether to retrieve from the finder cache
2934             * @return the ordered range of matching document library folders
2935             */
2936            @Override
2937            public List<DLFolder> findByRepositoryId(long repositoryId, int start,
2938                    int end, OrderByComparator<DLFolder> orderByComparator,
2939                    boolean retrieveFromCache) {
2940                    boolean pagination = true;
2941                    FinderPath finderPath = null;
2942                    Object[] finderArgs = null;
2943    
2944                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2945                                    (orderByComparator == null)) {
2946                            pagination = false;
2947                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_REPOSITORYID;
2948                            finderArgs = new Object[] { repositoryId };
2949                    }
2950                    else {
2951                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_REPOSITORYID;
2952                            finderArgs = new Object[] {
2953                                            repositoryId,
2954                                            
2955                                            start, end, orderByComparator
2956                                    };
2957                    }
2958    
2959                    List<DLFolder> list = null;
2960    
2961                    if (retrieveFromCache) {
2962                            list = (List<DLFolder>)finderCache.getResult(finderPath,
2963                                            finderArgs, this);
2964    
2965                            if ((list != null) && !list.isEmpty()) {
2966                                    for (DLFolder dlFolder : list) {
2967                                            if ((repositoryId != dlFolder.getRepositoryId())) {
2968                                                    list = null;
2969    
2970                                                    break;
2971                                            }
2972                                    }
2973                            }
2974                    }
2975    
2976                    if (list == null) {
2977                            StringBundler query = null;
2978    
2979                            if (orderByComparator != null) {
2980                                    query = new StringBundler(3 +
2981                                                    (orderByComparator.getOrderByFields().length * 2));
2982                            }
2983                            else {
2984                                    query = new StringBundler(3);
2985                            }
2986    
2987                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
2988    
2989                            query.append(_FINDER_COLUMN_REPOSITORYID_REPOSITORYID_2);
2990    
2991                            if (orderByComparator != null) {
2992                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2993                                            orderByComparator);
2994                            }
2995                            else
2996                             if (pagination) {
2997                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
2998                            }
2999    
3000                            String sql = query.toString();
3001    
3002                            Session session = null;
3003    
3004                            try {
3005                                    session = openSession();
3006    
3007                                    Query q = session.createQuery(sql);
3008    
3009                                    QueryPos qPos = QueryPos.getInstance(q);
3010    
3011                                    qPos.add(repositoryId);
3012    
3013                                    if (!pagination) {
3014                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
3015                                                            start, end, false);
3016    
3017                                            Collections.sort(list);
3018    
3019                                            list = Collections.unmodifiableList(list);
3020                                    }
3021                                    else {
3022                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
3023                                                            start, end);
3024                                    }
3025    
3026                                    cacheResult(list);
3027    
3028                                    finderCache.putResult(finderPath, finderArgs, list);
3029                            }
3030                            catch (Exception e) {
3031                                    finderCache.removeResult(finderPath, finderArgs);
3032    
3033                                    throw processException(e);
3034                            }
3035                            finally {
3036                                    closeSession(session);
3037                            }
3038                    }
3039    
3040                    return list;
3041            }
3042    
3043            /**
3044             * Returns the first document library folder in the ordered set where repositoryId = &#63;.
3045             *
3046             * @param repositoryId the repository ID
3047             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3048             * @return the first matching document library folder
3049             * @throws NoSuchFolderException if a matching document library folder could not be found
3050             */
3051            @Override
3052            public DLFolder findByRepositoryId_First(long repositoryId,
3053                    OrderByComparator<DLFolder> orderByComparator)
3054                    throws NoSuchFolderException {
3055                    DLFolder dlFolder = fetchByRepositoryId_First(repositoryId,
3056                                    orderByComparator);
3057    
3058                    if (dlFolder != null) {
3059                            return dlFolder;
3060                    }
3061    
3062                    StringBundler msg = new StringBundler(4);
3063    
3064                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3065    
3066                    msg.append("repositoryId=");
3067                    msg.append(repositoryId);
3068    
3069                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3070    
3071                    throw new NoSuchFolderException(msg.toString());
3072            }
3073    
3074            /**
3075             * Returns the first document library folder in the ordered set where repositoryId = &#63;.
3076             *
3077             * @param repositoryId the repository ID
3078             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3079             * @return the first matching document library folder, or <code>null</code> if a matching document library folder could not be found
3080             */
3081            @Override
3082            public DLFolder fetchByRepositoryId_First(long repositoryId,
3083                    OrderByComparator<DLFolder> orderByComparator) {
3084                    List<DLFolder> list = findByRepositoryId(repositoryId, 0, 1,
3085                                    orderByComparator);
3086    
3087                    if (!list.isEmpty()) {
3088                            return list.get(0);
3089                    }
3090    
3091                    return null;
3092            }
3093    
3094            /**
3095             * Returns the last document library folder in the ordered set where repositoryId = &#63;.
3096             *
3097             * @param repositoryId the repository ID
3098             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3099             * @return the last matching document library folder
3100             * @throws NoSuchFolderException if a matching document library folder could not be found
3101             */
3102            @Override
3103            public DLFolder findByRepositoryId_Last(long repositoryId,
3104                    OrderByComparator<DLFolder> orderByComparator)
3105                    throws NoSuchFolderException {
3106                    DLFolder dlFolder = fetchByRepositoryId_Last(repositoryId,
3107                                    orderByComparator);
3108    
3109                    if (dlFolder != null) {
3110                            return dlFolder;
3111                    }
3112    
3113                    StringBundler msg = new StringBundler(4);
3114    
3115                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3116    
3117                    msg.append("repositoryId=");
3118                    msg.append(repositoryId);
3119    
3120                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3121    
3122                    throw new NoSuchFolderException(msg.toString());
3123            }
3124    
3125            /**
3126             * Returns the last document library folder in the ordered set where repositoryId = &#63;.
3127             *
3128             * @param repositoryId the repository ID
3129             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3130             * @return the last matching document library folder, or <code>null</code> if a matching document library folder could not be found
3131             */
3132            @Override
3133            public DLFolder fetchByRepositoryId_Last(long repositoryId,
3134                    OrderByComparator<DLFolder> orderByComparator) {
3135                    int count = countByRepositoryId(repositoryId);
3136    
3137                    if (count == 0) {
3138                            return null;
3139                    }
3140    
3141                    List<DLFolder> list = findByRepositoryId(repositoryId, count - 1,
3142                                    count, orderByComparator);
3143    
3144                    if (!list.isEmpty()) {
3145                            return list.get(0);
3146                    }
3147    
3148                    return null;
3149            }
3150    
3151            /**
3152             * Returns the document library folders before and after the current document library folder in the ordered set where repositoryId = &#63;.
3153             *
3154             * @param folderId the primary key of the current document library folder
3155             * @param repositoryId the repository ID
3156             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3157             * @return the previous, current, and next document library folder
3158             * @throws NoSuchFolderException if a document library folder with the primary key could not be found
3159             */
3160            @Override
3161            public DLFolder[] findByRepositoryId_PrevAndNext(long folderId,
3162                    long repositoryId, OrderByComparator<DLFolder> orderByComparator)
3163                    throws NoSuchFolderException {
3164                    DLFolder dlFolder = findByPrimaryKey(folderId);
3165    
3166                    Session session = null;
3167    
3168                    try {
3169                            session = openSession();
3170    
3171                            DLFolder[] array = new DLFolderImpl[3];
3172    
3173                            array[0] = getByRepositoryId_PrevAndNext(session, dlFolder,
3174                                            repositoryId, orderByComparator, true);
3175    
3176                            array[1] = dlFolder;
3177    
3178                            array[2] = getByRepositoryId_PrevAndNext(session, dlFolder,
3179                                            repositoryId, orderByComparator, false);
3180    
3181                            return array;
3182                    }
3183                    catch (Exception e) {
3184                            throw processException(e);
3185                    }
3186                    finally {
3187                            closeSession(session);
3188                    }
3189            }
3190    
3191            protected DLFolder getByRepositoryId_PrevAndNext(Session session,
3192                    DLFolder dlFolder, long repositoryId,
3193                    OrderByComparator<DLFolder> orderByComparator, boolean previous) {
3194                    StringBundler query = null;
3195    
3196                    if (orderByComparator != null) {
3197                            query = new StringBundler(4 +
3198                                            (orderByComparator.getOrderByConditionFields().length * 3) +
3199                                            (orderByComparator.getOrderByFields().length * 3));
3200                    }
3201                    else {
3202                            query = new StringBundler(3);
3203                    }
3204    
3205                    query.append(_SQL_SELECT_DLFOLDER_WHERE);
3206    
3207                    query.append(_FINDER_COLUMN_REPOSITORYID_REPOSITORYID_2);
3208    
3209                    if (orderByComparator != null) {
3210                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3211    
3212                            if (orderByConditionFields.length > 0) {
3213                                    query.append(WHERE_AND);
3214                            }
3215    
3216                            for (int i = 0; i < orderByConditionFields.length; i++) {
3217                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3218                                    query.append(orderByConditionFields[i]);
3219    
3220                                    if ((i + 1) < orderByConditionFields.length) {
3221                                            if (orderByComparator.isAscending() ^ previous) {
3222                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3223                                            }
3224                                            else {
3225                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3226                                            }
3227                                    }
3228                                    else {
3229                                            if (orderByComparator.isAscending() ^ previous) {
3230                                                    query.append(WHERE_GREATER_THAN);
3231                                            }
3232                                            else {
3233                                                    query.append(WHERE_LESSER_THAN);
3234                                            }
3235                                    }
3236                            }
3237    
3238                            query.append(ORDER_BY_CLAUSE);
3239    
3240                            String[] orderByFields = orderByComparator.getOrderByFields();
3241    
3242                            for (int i = 0; i < orderByFields.length; i++) {
3243                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3244                                    query.append(orderByFields[i]);
3245    
3246                                    if ((i + 1) < orderByFields.length) {
3247                                            if (orderByComparator.isAscending() ^ previous) {
3248                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3249                                            }
3250                                            else {
3251                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3252                                            }
3253                                    }
3254                                    else {
3255                                            if (orderByComparator.isAscending() ^ previous) {
3256                                                    query.append(ORDER_BY_ASC);
3257                                            }
3258                                            else {
3259                                                    query.append(ORDER_BY_DESC);
3260                                            }
3261                                    }
3262                            }
3263                    }
3264                    else {
3265                            query.append(DLFolderModelImpl.ORDER_BY_JPQL);
3266                    }
3267    
3268                    String sql = query.toString();
3269    
3270                    Query q = session.createQuery(sql);
3271    
3272                    q.setFirstResult(0);
3273                    q.setMaxResults(2);
3274    
3275                    QueryPos qPos = QueryPos.getInstance(q);
3276    
3277                    qPos.add(repositoryId);
3278    
3279                    if (orderByComparator != null) {
3280                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
3281    
3282                            for (Object value : values) {
3283                                    qPos.add(value);
3284                            }
3285                    }
3286    
3287                    List<DLFolder> list = q.list();
3288    
3289                    if (list.size() == 2) {
3290                            return list.get(1);
3291                    }
3292                    else {
3293                            return null;
3294                    }
3295            }
3296    
3297            /**
3298             * Removes all the document library folders where repositoryId = &#63; from the database.
3299             *
3300             * @param repositoryId the repository ID
3301             */
3302            @Override
3303            public void removeByRepositoryId(long repositoryId) {
3304                    for (DLFolder dlFolder : findByRepositoryId(repositoryId,
3305                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3306                            remove(dlFolder);
3307                    }
3308            }
3309    
3310            /**
3311             * Returns the number of document library folders where repositoryId = &#63;.
3312             *
3313             * @param repositoryId the repository ID
3314             * @return the number of matching document library folders
3315             */
3316            @Override
3317            public int countByRepositoryId(long repositoryId) {
3318                    FinderPath finderPath = FINDER_PATH_COUNT_BY_REPOSITORYID;
3319    
3320                    Object[] finderArgs = new Object[] { repositoryId };
3321    
3322                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
3323    
3324                    if (count == null) {
3325                            StringBundler query = new StringBundler(2);
3326    
3327                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
3328    
3329                            query.append(_FINDER_COLUMN_REPOSITORYID_REPOSITORYID_2);
3330    
3331                            String sql = query.toString();
3332    
3333                            Session session = null;
3334    
3335                            try {
3336                                    session = openSession();
3337    
3338                                    Query q = session.createQuery(sql);
3339    
3340                                    QueryPos qPos = QueryPos.getInstance(q);
3341    
3342                                    qPos.add(repositoryId);
3343    
3344                                    count = (Long)q.uniqueResult();
3345    
3346                                    finderCache.putResult(finderPath, finderArgs, count);
3347                            }
3348                            catch (Exception e) {
3349                                    finderCache.removeResult(finderPath, finderArgs);
3350    
3351                                    throw processException(e);
3352                            }
3353                            finally {
3354                                    closeSession(session);
3355                            }
3356                    }
3357    
3358                    return count.intValue();
3359            }
3360    
3361            private static final String _FINDER_COLUMN_REPOSITORYID_REPOSITORYID_2 = "dlFolder.repositoryId = ?";
3362            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
3363                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
3364                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_P",
3365                            new String[] {
3366                                    Long.class.getName(), Long.class.getName(),
3367                                    
3368                            Integer.class.getName(), Integer.class.getName(),
3369                                    OrderByComparator.class.getName()
3370                            });
3371            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
3372                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
3373                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_P",
3374                            new String[] { Long.class.getName(), Long.class.getName() },
3375                            DLFolderModelImpl.GROUPID_COLUMN_BITMASK |
3376                            DLFolderModelImpl.PARENTFOLDERID_COLUMN_BITMASK |
3377                            DLFolderModelImpl.NAME_COLUMN_BITMASK);
3378            public static final FinderPath FINDER_PATH_COUNT_BY_G_P = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
3379                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
3380                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P",
3381                            new String[] { Long.class.getName(), Long.class.getName() });
3382    
3383            /**
3384             * Returns all the document library folders where groupId = &#63; and parentFolderId = &#63;.
3385             *
3386             * @param groupId the group ID
3387             * @param parentFolderId the parent folder ID
3388             * @return the matching document library folders
3389             */
3390            @Override
3391            public List<DLFolder> findByG_P(long groupId, long parentFolderId) {
3392                    return findByG_P(groupId, parentFolderId, QueryUtil.ALL_POS,
3393                            QueryUtil.ALL_POS, null);
3394            }
3395    
3396            /**
3397             * Returns a range of all the document library folders where groupId = &#63; and parentFolderId = &#63;.
3398             *
3399             * <p>
3400             * 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.
3401             * </p>
3402             *
3403             * @param groupId the group ID
3404             * @param parentFolderId the parent folder ID
3405             * @param start the lower bound of the range of document library folders
3406             * @param end the upper bound of the range of document library folders (not inclusive)
3407             * @return the range of matching document library folders
3408             */
3409            @Override
3410            public List<DLFolder> findByG_P(long groupId, long parentFolderId,
3411                    int start, int end) {
3412                    return findByG_P(groupId, parentFolderId, start, end, null);
3413            }
3414    
3415            /**
3416             * Returns an ordered range of all the document library folders where groupId = &#63; and parentFolderId = &#63;.
3417             *
3418             * <p>
3419             * 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.
3420             * </p>
3421             *
3422             * @param groupId the group ID
3423             * @param parentFolderId the parent folder ID
3424             * @param start the lower bound of the range of document library folders
3425             * @param end the upper bound of the range of document library folders (not inclusive)
3426             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3427             * @return the ordered range of matching document library folders
3428             */
3429            @Override
3430            public List<DLFolder> findByG_P(long groupId, long parentFolderId,
3431                    int start, int end, OrderByComparator<DLFolder> orderByComparator) {
3432                    return findByG_P(groupId, parentFolderId, start, end,
3433                            orderByComparator, true);
3434            }
3435    
3436            /**
3437             * Returns an ordered range of all the document library folders where groupId = &#63; and parentFolderId = &#63;.
3438             *
3439             * <p>
3440             * 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.
3441             * </p>
3442             *
3443             * @param groupId the group ID
3444             * @param parentFolderId the parent folder ID
3445             * @param start the lower bound of the range of document library folders
3446             * @param end the upper bound of the range of document library folders (not inclusive)
3447             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3448             * @param retrieveFromCache whether to retrieve from the finder cache
3449             * @return the ordered range of matching document library folders
3450             */
3451            @Override
3452            public List<DLFolder> findByG_P(long groupId, long parentFolderId,
3453                    int start, int end, OrderByComparator<DLFolder> orderByComparator,
3454                    boolean retrieveFromCache) {
3455                    boolean pagination = true;
3456                    FinderPath finderPath = null;
3457                    Object[] finderArgs = null;
3458    
3459                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3460                                    (orderByComparator == null)) {
3461                            pagination = false;
3462                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P;
3463                            finderArgs = new Object[] { groupId, parentFolderId };
3464                    }
3465                    else {
3466                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P;
3467                            finderArgs = new Object[] {
3468                                            groupId, parentFolderId,
3469                                            
3470                                            start, end, orderByComparator
3471                                    };
3472                    }
3473    
3474                    List<DLFolder> list = null;
3475    
3476                    if (retrieveFromCache) {
3477                            list = (List<DLFolder>)finderCache.getResult(finderPath,
3478                                            finderArgs, this);
3479    
3480                            if ((list != null) && !list.isEmpty()) {
3481                                    for (DLFolder dlFolder : list) {
3482                                            if ((groupId != dlFolder.getGroupId()) ||
3483                                                            (parentFolderId != dlFolder.getParentFolderId())) {
3484                                                    list = null;
3485    
3486                                                    break;
3487                                            }
3488                                    }
3489                            }
3490                    }
3491    
3492                    if (list == null) {
3493                            StringBundler query = null;
3494    
3495                            if (orderByComparator != null) {
3496                                    query = new StringBundler(4 +
3497                                                    (orderByComparator.getOrderByFields().length * 2));
3498                            }
3499                            else {
3500                                    query = new StringBundler(4);
3501                            }
3502    
3503                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
3504    
3505                            query.append(_FINDER_COLUMN_G_P_GROUPID_2);
3506    
3507                            query.append(_FINDER_COLUMN_G_P_PARENTFOLDERID_2);
3508    
3509                            if (orderByComparator != null) {
3510                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3511                                            orderByComparator);
3512                            }
3513                            else
3514                             if (pagination) {
3515                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
3516                            }
3517    
3518                            String sql = query.toString();
3519    
3520                            Session session = null;
3521    
3522                            try {
3523                                    session = openSession();
3524    
3525                                    Query q = session.createQuery(sql);
3526    
3527                                    QueryPos qPos = QueryPos.getInstance(q);
3528    
3529                                    qPos.add(groupId);
3530    
3531                                    qPos.add(parentFolderId);
3532    
3533                                    if (!pagination) {
3534                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
3535                                                            start, end, false);
3536    
3537                                            Collections.sort(list);
3538    
3539                                            list = Collections.unmodifiableList(list);
3540                                    }
3541                                    else {
3542                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
3543                                                            start, end);
3544                                    }
3545    
3546                                    cacheResult(list);
3547    
3548                                    finderCache.putResult(finderPath, finderArgs, list);
3549                            }
3550                            catch (Exception e) {
3551                                    finderCache.removeResult(finderPath, finderArgs);
3552    
3553                                    throw processException(e);
3554                            }
3555                            finally {
3556                                    closeSession(session);
3557                            }
3558                    }
3559    
3560                    return list;
3561            }
3562    
3563            /**
3564             * Returns the first document library folder in the ordered set where groupId = &#63; and parentFolderId = &#63;.
3565             *
3566             * @param groupId the group ID
3567             * @param parentFolderId the parent folder ID
3568             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3569             * @return the first matching document library folder
3570             * @throws NoSuchFolderException if a matching document library folder could not be found
3571             */
3572            @Override
3573            public DLFolder findByG_P_First(long groupId, long parentFolderId,
3574                    OrderByComparator<DLFolder> orderByComparator)
3575                    throws NoSuchFolderException {
3576                    DLFolder dlFolder = fetchByG_P_First(groupId, parentFolderId,
3577                                    orderByComparator);
3578    
3579                    if (dlFolder != null) {
3580                            return dlFolder;
3581                    }
3582    
3583                    StringBundler msg = new StringBundler(6);
3584    
3585                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3586    
3587                    msg.append("groupId=");
3588                    msg.append(groupId);
3589    
3590                    msg.append(", parentFolderId=");
3591                    msg.append(parentFolderId);
3592    
3593                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3594    
3595                    throw new NoSuchFolderException(msg.toString());
3596            }
3597    
3598            /**
3599             * Returns the first document library folder in the ordered set where groupId = &#63; and parentFolderId = &#63;.
3600             *
3601             * @param groupId the group ID
3602             * @param parentFolderId the parent folder ID
3603             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3604             * @return the first matching document library folder, or <code>null</code> if a matching document library folder could not be found
3605             */
3606            @Override
3607            public DLFolder fetchByG_P_First(long groupId, long parentFolderId,
3608                    OrderByComparator<DLFolder> orderByComparator) {
3609                    List<DLFolder> list = findByG_P(groupId, parentFolderId, 0, 1,
3610                                    orderByComparator);
3611    
3612                    if (!list.isEmpty()) {
3613                            return list.get(0);
3614                    }
3615    
3616                    return null;
3617            }
3618    
3619            /**
3620             * Returns the last document library folder in the ordered set where groupId = &#63; and parentFolderId = &#63;.
3621             *
3622             * @param groupId the group ID
3623             * @param parentFolderId the parent folder ID
3624             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3625             * @return the last matching document library folder
3626             * @throws NoSuchFolderException if a matching document library folder could not be found
3627             */
3628            @Override
3629            public DLFolder findByG_P_Last(long groupId, long parentFolderId,
3630                    OrderByComparator<DLFolder> orderByComparator)
3631                    throws NoSuchFolderException {
3632                    DLFolder dlFolder = fetchByG_P_Last(groupId, parentFolderId,
3633                                    orderByComparator);
3634    
3635                    if (dlFolder != null) {
3636                            return dlFolder;
3637                    }
3638    
3639                    StringBundler msg = new StringBundler(6);
3640    
3641                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3642    
3643                    msg.append("groupId=");
3644                    msg.append(groupId);
3645    
3646                    msg.append(", parentFolderId=");
3647                    msg.append(parentFolderId);
3648    
3649                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3650    
3651                    throw new NoSuchFolderException(msg.toString());
3652            }
3653    
3654            /**
3655             * Returns the last document library folder in the ordered set where groupId = &#63; and parentFolderId = &#63;.
3656             *
3657             * @param groupId the group ID
3658             * @param parentFolderId the parent folder ID
3659             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3660             * @return the last matching document library folder, or <code>null</code> if a matching document library folder could not be found
3661             */
3662            @Override
3663            public DLFolder fetchByG_P_Last(long groupId, long parentFolderId,
3664                    OrderByComparator<DLFolder> orderByComparator) {
3665                    int count = countByG_P(groupId, parentFolderId);
3666    
3667                    if (count == 0) {
3668                            return null;
3669                    }
3670    
3671                    List<DLFolder> list = findByG_P(groupId, parentFolderId, count - 1,
3672                                    count, orderByComparator);
3673    
3674                    if (!list.isEmpty()) {
3675                            return list.get(0);
3676                    }
3677    
3678                    return null;
3679            }
3680    
3681            /**
3682             * Returns the document library folders before and after the current document library folder in the ordered set where groupId = &#63; and parentFolderId = &#63;.
3683             *
3684             * @param folderId the primary key of the current document library folder
3685             * @param groupId the group ID
3686             * @param parentFolderId the parent folder ID
3687             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3688             * @return the previous, current, and next document library folder
3689             * @throws NoSuchFolderException if a document library folder with the primary key could not be found
3690             */
3691            @Override
3692            public DLFolder[] findByG_P_PrevAndNext(long folderId, long groupId,
3693                    long parentFolderId, OrderByComparator<DLFolder> orderByComparator)
3694                    throws NoSuchFolderException {
3695                    DLFolder dlFolder = findByPrimaryKey(folderId);
3696    
3697                    Session session = null;
3698    
3699                    try {
3700                            session = openSession();
3701    
3702                            DLFolder[] array = new DLFolderImpl[3];
3703    
3704                            array[0] = getByG_P_PrevAndNext(session, dlFolder, groupId,
3705                                            parentFolderId, orderByComparator, true);
3706    
3707                            array[1] = dlFolder;
3708    
3709                            array[2] = getByG_P_PrevAndNext(session, dlFolder, groupId,
3710                                            parentFolderId, orderByComparator, false);
3711    
3712                            return array;
3713                    }
3714                    catch (Exception e) {
3715                            throw processException(e);
3716                    }
3717                    finally {
3718                            closeSession(session);
3719                    }
3720            }
3721    
3722            protected DLFolder getByG_P_PrevAndNext(Session session, DLFolder dlFolder,
3723                    long groupId, long parentFolderId,
3724                    OrderByComparator<DLFolder> orderByComparator, boolean previous) {
3725                    StringBundler query = null;
3726    
3727                    if (orderByComparator != null) {
3728                            query = new StringBundler(5 +
3729                                            (orderByComparator.getOrderByConditionFields().length * 3) +
3730                                            (orderByComparator.getOrderByFields().length * 3));
3731                    }
3732                    else {
3733                            query = new StringBundler(4);
3734                    }
3735    
3736                    query.append(_SQL_SELECT_DLFOLDER_WHERE);
3737    
3738                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
3739    
3740                    query.append(_FINDER_COLUMN_G_P_PARENTFOLDERID_2);
3741    
3742                    if (orderByComparator != null) {
3743                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3744    
3745                            if (orderByConditionFields.length > 0) {
3746                                    query.append(WHERE_AND);
3747                            }
3748    
3749                            for (int i = 0; i < orderByConditionFields.length; i++) {
3750                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3751                                    query.append(orderByConditionFields[i]);
3752    
3753                                    if ((i + 1) < orderByConditionFields.length) {
3754                                            if (orderByComparator.isAscending() ^ previous) {
3755                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3756                                            }
3757                                            else {
3758                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3759                                            }
3760                                    }
3761                                    else {
3762                                            if (orderByComparator.isAscending() ^ previous) {
3763                                                    query.append(WHERE_GREATER_THAN);
3764                                            }
3765                                            else {
3766                                                    query.append(WHERE_LESSER_THAN);
3767                                            }
3768                                    }
3769                            }
3770    
3771                            query.append(ORDER_BY_CLAUSE);
3772    
3773                            String[] orderByFields = orderByComparator.getOrderByFields();
3774    
3775                            for (int i = 0; i < orderByFields.length; i++) {
3776                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3777                                    query.append(orderByFields[i]);
3778    
3779                                    if ((i + 1) < orderByFields.length) {
3780                                            if (orderByComparator.isAscending() ^ previous) {
3781                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3782                                            }
3783                                            else {
3784                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3785                                            }
3786                                    }
3787                                    else {
3788                                            if (orderByComparator.isAscending() ^ previous) {
3789                                                    query.append(ORDER_BY_ASC);
3790                                            }
3791                                            else {
3792                                                    query.append(ORDER_BY_DESC);
3793                                            }
3794                                    }
3795                            }
3796                    }
3797                    else {
3798                            query.append(DLFolderModelImpl.ORDER_BY_JPQL);
3799                    }
3800    
3801                    String sql = query.toString();
3802    
3803                    Query q = session.createQuery(sql);
3804    
3805                    q.setFirstResult(0);
3806                    q.setMaxResults(2);
3807    
3808                    QueryPos qPos = QueryPos.getInstance(q);
3809    
3810                    qPos.add(groupId);
3811    
3812                    qPos.add(parentFolderId);
3813    
3814                    if (orderByComparator != null) {
3815                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
3816    
3817                            for (Object value : values) {
3818                                    qPos.add(value);
3819                            }
3820                    }
3821    
3822                    List<DLFolder> list = q.list();
3823    
3824                    if (list.size() == 2) {
3825                            return list.get(1);
3826                    }
3827                    else {
3828                            return null;
3829                    }
3830            }
3831    
3832            /**
3833             * Returns all the document library folders that the user has permission to view where groupId = &#63; and parentFolderId = &#63;.
3834             *
3835             * @param groupId the group ID
3836             * @param parentFolderId the parent folder ID
3837             * @return the matching document library folders that the user has permission to view
3838             */
3839            @Override
3840            public List<DLFolder> filterFindByG_P(long groupId, long parentFolderId) {
3841                    return filterFindByG_P(groupId, parentFolderId, QueryUtil.ALL_POS,
3842                            QueryUtil.ALL_POS, null);
3843            }
3844    
3845            /**
3846             * Returns a range of all the document library folders that the user has permission to view where groupId = &#63; and parentFolderId = &#63;.
3847             *
3848             * <p>
3849             * 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.
3850             * </p>
3851             *
3852             * @param groupId the group ID
3853             * @param parentFolderId the parent folder ID
3854             * @param start the lower bound of the range of document library folders
3855             * @param end the upper bound of the range of document library folders (not inclusive)
3856             * @return the range of matching document library folders that the user has permission to view
3857             */
3858            @Override
3859            public List<DLFolder> filterFindByG_P(long groupId, long parentFolderId,
3860                    int start, int end) {
3861                    return filterFindByG_P(groupId, parentFolderId, start, end, null);
3862            }
3863    
3864            /**
3865             * Returns an ordered range of all the document library folders that the user has permissions to view where groupId = &#63; and parentFolderId = &#63;.
3866             *
3867             * <p>
3868             * 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.
3869             * </p>
3870             *
3871             * @param groupId the group ID
3872             * @param parentFolderId the parent folder ID
3873             * @param start the lower bound of the range of document library folders
3874             * @param end the upper bound of the range of document library folders (not inclusive)
3875             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3876             * @return the ordered range of matching document library folders that the user has permission to view
3877             */
3878            @Override
3879            public List<DLFolder> filterFindByG_P(long groupId, long parentFolderId,
3880                    int start, int end, OrderByComparator<DLFolder> orderByComparator) {
3881                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3882                            return findByG_P(groupId, parentFolderId, start, end,
3883                                    orderByComparator);
3884                    }
3885    
3886                    StringBundler query = null;
3887    
3888                    if (orderByComparator != null) {
3889                            query = new StringBundler(4 +
3890                                            (orderByComparator.getOrderByFields().length * 2));
3891                    }
3892                    else {
3893                            query = new StringBundler(5);
3894                    }
3895    
3896                    if (getDB().isSupportsInlineDistinct()) {
3897                            query.append(_FILTER_SQL_SELECT_DLFOLDER_WHERE);
3898                    }
3899                    else {
3900                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1);
3901                    }
3902    
3903                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
3904    
3905                    query.append(_FINDER_COLUMN_G_P_PARENTFOLDERID_2);
3906    
3907                    if (!getDB().isSupportsInlineDistinct()) {
3908                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2);
3909                    }
3910    
3911                    if (orderByComparator != null) {
3912                            if (getDB().isSupportsInlineDistinct()) {
3913                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3914                                            orderByComparator, true);
3915                            }
3916                            else {
3917                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3918                                            orderByComparator, true);
3919                            }
3920                    }
3921                    else {
3922                            if (getDB().isSupportsInlineDistinct()) {
3923                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
3924                            }
3925                            else {
3926                                    query.append(DLFolderModelImpl.ORDER_BY_SQL);
3927                            }
3928                    }
3929    
3930                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3931                                    DLFolder.class.getName(),
3932                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3933    
3934                    Session session = null;
3935    
3936                    try {
3937                            session = openSession();
3938    
3939                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
3940    
3941                            if (getDB().isSupportsInlineDistinct()) {
3942                                    q.addEntity(_FILTER_ENTITY_ALIAS, DLFolderImpl.class);
3943                            }
3944                            else {
3945                                    q.addEntity(_FILTER_ENTITY_TABLE, DLFolderImpl.class);
3946                            }
3947    
3948                            QueryPos qPos = QueryPos.getInstance(q);
3949    
3950                            qPos.add(groupId);
3951    
3952                            qPos.add(parentFolderId);
3953    
3954                            return (List<DLFolder>)QueryUtil.list(q, getDialect(), start, end);
3955                    }
3956                    catch (Exception e) {
3957                            throw processException(e);
3958                    }
3959                    finally {
3960                            closeSession(session);
3961                    }
3962            }
3963    
3964            /**
3965             * 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;.
3966             *
3967             * @param folderId the primary key of the current document library folder
3968             * @param groupId the group ID
3969             * @param parentFolderId the parent folder ID
3970             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3971             * @return the previous, current, and next document library folder
3972             * @throws NoSuchFolderException if a document library folder with the primary key could not be found
3973             */
3974            @Override
3975            public DLFolder[] filterFindByG_P_PrevAndNext(long folderId, long groupId,
3976                    long parentFolderId, OrderByComparator<DLFolder> orderByComparator)
3977                    throws NoSuchFolderException {
3978                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3979                            return findByG_P_PrevAndNext(folderId, groupId, parentFolderId,
3980                                    orderByComparator);
3981                    }
3982    
3983                    DLFolder dlFolder = findByPrimaryKey(folderId);
3984    
3985                    Session session = null;
3986    
3987                    try {
3988                            session = openSession();
3989    
3990                            DLFolder[] array = new DLFolderImpl[3];
3991    
3992                            array[0] = filterGetByG_P_PrevAndNext(session, dlFolder, groupId,
3993                                            parentFolderId, orderByComparator, true);
3994    
3995                            array[1] = dlFolder;
3996    
3997                            array[2] = filterGetByG_P_PrevAndNext(session, dlFolder, groupId,
3998                                            parentFolderId, orderByComparator, false);
3999    
4000                            return array;
4001                    }
4002                    catch (Exception e) {
4003                            throw processException(e);
4004                    }
4005                    finally {
4006                            closeSession(session);
4007                    }
4008            }
4009    
4010            protected DLFolder filterGetByG_P_PrevAndNext(Session session,
4011                    DLFolder dlFolder, long groupId, long parentFolderId,
4012                    OrderByComparator<DLFolder> orderByComparator, boolean previous) {
4013                    StringBundler query = null;
4014    
4015                    if (orderByComparator != null) {
4016                            query = new StringBundler(6 +
4017                                            (orderByComparator.getOrderByConditionFields().length * 3) +
4018                                            (orderByComparator.getOrderByFields().length * 3));
4019                    }
4020                    else {
4021                            query = new StringBundler(5);
4022                    }
4023    
4024                    if (getDB().isSupportsInlineDistinct()) {
4025                            query.append(_FILTER_SQL_SELECT_DLFOLDER_WHERE);
4026                    }
4027                    else {
4028                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1);
4029                    }
4030    
4031                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
4032    
4033                    query.append(_FINDER_COLUMN_G_P_PARENTFOLDERID_2);
4034    
4035                    if (!getDB().isSupportsInlineDistinct()) {
4036                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2);
4037                    }
4038    
4039                    if (orderByComparator != null) {
4040                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4041    
4042                            if (orderByConditionFields.length > 0) {
4043                                    query.append(WHERE_AND);
4044                            }
4045    
4046                            for (int i = 0; i < orderByConditionFields.length; i++) {
4047                                    if (getDB().isSupportsInlineDistinct()) {
4048                                            query.append(_ORDER_BY_ENTITY_ALIAS);
4049                                    }
4050                                    else {
4051                                            query.append(_ORDER_BY_ENTITY_TABLE);
4052                                    }
4053    
4054                                    query.append(orderByConditionFields[i]);
4055    
4056                                    if ((i + 1) < orderByConditionFields.length) {
4057                                            if (orderByComparator.isAscending() ^ previous) {
4058                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4059                                            }
4060                                            else {
4061                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4062                                            }
4063                                    }
4064                                    else {
4065                                            if (orderByComparator.isAscending() ^ previous) {
4066                                                    query.append(WHERE_GREATER_THAN);
4067                                            }
4068                                            else {
4069                                                    query.append(WHERE_LESSER_THAN);
4070                                            }
4071                                    }
4072                            }
4073    
4074                            query.append(ORDER_BY_CLAUSE);
4075    
4076                            String[] orderByFields = orderByComparator.getOrderByFields();
4077    
4078                            for (int i = 0; i < orderByFields.length; i++) {
4079                                    if (getDB().isSupportsInlineDistinct()) {
4080                                            query.append(_ORDER_BY_ENTITY_ALIAS);
4081                                    }
4082                                    else {
4083                                            query.append(_ORDER_BY_ENTITY_TABLE);
4084                                    }
4085    
4086                                    query.append(orderByFields[i]);
4087    
4088                                    if ((i + 1) < orderByFields.length) {
4089                                            if (orderByComparator.isAscending() ^ previous) {
4090                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4091                                            }
4092                                            else {
4093                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4094                                            }
4095                                    }
4096                                    else {
4097                                            if (orderByComparator.isAscending() ^ previous) {
4098                                                    query.append(ORDER_BY_ASC);
4099                                            }
4100                                            else {
4101                                                    query.append(ORDER_BY_DESC);
4102                                            }
4103                                    }
4104                            }
4105                    }
4106                    else {
4107                            if (getDB().isSupportsInlineDistinct()) {
4108                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
4109                            }
4110                            else {
4111                                    query.append(DLFolderModelImpl.ORDER_BY_SQL);
4112                            }
4113                    }
4114    
4115                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4116                                    DLFolder.class.getName(),
4117                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4118    
4119                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
4120    
4121                    q.setFirstResult(0);
4122                    q.setMaxResults(2);
4123    
4124                    if (getDB().isSupportsInlineDistinct()) {
4125                            q.addEntity(_FILTER_ENTITY_ALIAS, DLFolderImpl.class);
4126                    }
4127                    else {
4128                            q.addEntity(_FILTER_ENTITY_TABLE, DLFolderImpl.class);
4129                    }
4130    
4131                    QueryPos qPos = QueryPos.getInstance(q);
4132    
4133                    qPos.add(groupId);
4134    
4135                    qPos.add(parentFolderId);
4136    
4137                    if (orderByComparator != null) {
4138                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
4139    
4140                            for (Object value : values) {
4141                                    qPos.add(value);
4142                            }
4143                    }
4144    
4145                    List<DLFolder> list = q.list();
4146    
4147                    if (list.size() == 2) {
4148                            return list.get(1);
4149                    }
4150                    else {
4151                            return null;
4152                    }
4153            }
4154    
4155            /**
4156             * Removes all the document library folders where groupId = &#63; and parentFolderId = &#63; from the database.
4157             *
4158             * @param groupId the group ID
4159             * @param parentFolderId the parent folder ID
4160             */
4161            @Override
4162            public void removeByG_P(long groupId, long parentFolderId) {
4163                    for (DLFolder dlFolder : findByG_P(groupId, parentFolderId,
4164                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4165                            remove(dlFolder);
4166                    }
4167            }
4168    
4169            /**
4170             * Returns the number of document library folders where groupId = &#63; and parentFolderId = &#63;.
4171             *
4172             * @param groupId the group ID
4173             * @param parentFolderId the parent folder ID
4174             * @return the number of matching document library folders
4175             */
4176            @Override
4177            public int countByG_P(long groupId, long parentFolderId) {
4178                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_P;
4179    
4180                    Object[] finderArgs = new Object[] { groupId, parentFolderId };
4181    
4182                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
4183    
4184                    if (count == null) {
4185                            StringBundler query = new StringBundler(3);
4186    
4187                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
4188    
4189                            query.append(_FINDER_COLUMN_G_P_GROUPID_2);
4190    
4191                            query.append(_FINDER_COLUMN_G_P_PARENTFOLDERID_2);
4192    
4193                            String sql = query.toString();
4194    
4195                            Session session = null;
4196    
4197                            try {
4198                                    session = openSession();
4199    
4200                                    Query q = session.createQuery(sql);
4201    
4202                                    QueryPos qPos = QueryPos.getInstance(q);
4203    
4204                                    qPos.add(groupId);
4205    
4206                                    qPos.add(parentFolderId);
4207    
4208                                    count = (Long)q.uniqueResult();
4209    
4210                                    finderCache.putResult(finderPath, finderArgs, count);
4211                            }
4212                            catch (Exception e) {
4213                                    finderCache.removeResult(finderPath, finderArgs);
4214    
4215                                    throw processException(e);
4216                            }
4217                            finally {
4218                                    closeSession(session);
4219                            }
4220                    }
4221    
4222                    return count.intValue();
4223            }
4224    
4225            /**
4226             * Returns the number of document library folders that the user has permission to view where groupId = &#63; and parentFolderId = &#63;.
4227             *
4228             * @param groupId the group ID
4229             * @param parentFolderId the parent folder ID
4230             * @return the number of matching document library folders that the user has permission to view
4231             */
4232            @Override
4233            public int filterCountByG_P(long groupId, long parentFolderId) {
4234                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4235                            return countByG_P(groupId, parentFolderId);
4236                    }
4237    
4238                    StringBundler query = new StringBundler(3);
4239    
4240                    query.append(_FILTER_SQL_COUNT_DLFOLDER_WHERE);
4241    
4242                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
4243    
4244                    query.append(_FINDER_COLUMN_G_P_PARENTFOLDERID_2);
4245    
4246                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4247                                    DLFolder.class.getName(),
4248                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4249    
4250                    Session session = null;
4251    
4252                    try {
4253                            session = openSession();
4254    
4255                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
4256    
4257                            q.addScalar(COUNT_COLUMN_NAME,
4258                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
4259    
4260                            QueryPos qPos = QueryPos.getInstance(q);
4261    
4262                            qPos.add(groupId);
4263    
4264                            qPos.add(parentFolderId);
4265    
4266                            Long count = (Long)q.uniqueResult();
4267    
4268                            return count.intValue();
4269                    }
4270                    catch (Exception e) {
4271                            throw processException(e);
4272                    }
4273                    finally {
4274                            closeSession(session);
4275                    }
4276            }
4277    
4278            private static final String _FINDER_COLUMN_G_P_GROUPID_2 = "dlFolder.groupId = ? AND ";
4279            private static final String _FINDER_COLUMN_G_P_PARENTFOLDERID_2 = "dlFolder.parentFolderId = ?";
4280            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_NOTS = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
4281                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
4282                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_NotS",
4283                            new String[] {
4284                                    Long.class.getName(), Integer.class.getName(),
4285                                    
4286                            Integer.class.getName(), Integer.class.getName(),
4287                                    OrderByComparator.class.getName()
4288                            });
4289            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_NOTS = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
4290                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
4291                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByC_NotS",
4292                            new String[] { Long.class.getName(), Integer.class.getName() });
4293    
4294            /**
4295             * Returns all the document library folders where companyId = &#63; and status &ne; &#63;.
4296             *
4297             * @param companyId the company ID
4298             * @param status the status
4299             * @return the matching document library folders
4300             */
4301            @Override
4302            public List<DLFolder> findByC_NotS(long companyId, int status) {
4303                    return findByC_NotS(companyId, status, QueryUtil.ALL_POS,
4304                            QueryUtil.ALL_POS, null);
4305            }
4306    
4307            /**
4308             * Returns a range of all the document library folders where companyId = &#63; and status &ne; &#63;.
4309             *
4310             * <p>
4311             * 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.
4312             * </p>
4313             *
4314             * @param companyId the company ID
4315             * @param status the status
4316             * @param start the lower bound of the range of document library folders
4317             * @param end the upper bound of the range of document library folders (not inclusive)
4318             * @return the range of matching document library folders
4319             */
4320            @Override
4321            public List<DLFolder> findByC_NotS(long companyId, int status, int start,
4322                    int end) {
4323                    return findByC_NotS(companyId, status, start, end, null);
4324            }
4325    
4326            /**
4327             * Returns an ordered range of all the document library folders where companyId = &#63; and status &ne; &#63;.
4328             *
4329             * <p>
4330             * 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.
4331             * </p>
4332             *
4333             * @param companyId the company ID
4334             * @param status the status
4335             * @param start the lower bound of the range of document library folders
4336             * @param end the upper bound of the range of document library folders (not inclusive)
4337             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4338             * @return the ordered range of matching document library folders
4339             */
4340            @Override
4341            public List<DLFolder> findByC_NotS(long companyId, int status, int start,
4342                    int end, OrderByComparator<DLFolder> orderByComparator) {
4343                    return findByC_NotS(companyId, status, start, end, orderByComparator,
4344                            true);
4345            }
4346    
4347            /**
4348             * Returns an ordered range of all the document library folders where companyId = &#63; and status &ne; &#63;.
4349             *
4350             * <p>
4351             * 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.
4352             * </p>
4353             *
4354             * @param companyId the company ID
4355             * @param status the status
4356             * @param start the lower bound of the range of document library folders
4357             * @param end the upper bound of the range of document library folders (not inclusive)
4358             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4359             * @param retrieveFromCache whether to retrieve from the finder cache
4360             * @return the ordered range of matching document library folders
4361             */
4362            @Override
4363            public List<DLFolder> findByC_NotS(long companyId, int status, int start,
4364                    int end, OrderByComparator<DLFolder> orderByComparator,
4365                    boolean retrieveFromCache) {
4366                    boolean pagination = true;
4367                    FinderPath finderPath = null;
4368                    Object[] finderArgs = null;
4369    
4370                    finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_NOTS;
4371                    finderArgs = new Object[] {
4372                                    companyId, status,
4373                                    
4374                                    start, end, orderByComparator
4375                            };
4376    
4377                    List<DLFolder> list = null;
4378    
4379                    if (retrieveFromCache) {
4380                            list = (List<DLFolder>)finderCache.getResult(finderPath,
4381                                            finderArgs, this);
4382    
4383                            if ((list != null) && !list.isEmpty()) {
4384                                    for (DLFolder dlFolder : list) {
4385                                            if ((companyId != dlFolder.getCompanyId()) ||
4386                                                            (status == dlFolder.getStatus())) {
4387                                                    list = null;
4388    
4389                                                    break;
4390                                            }
4391                                    }
4392                            }
4393                    }
4394    
4395                    if (list == null) {
4396                            StringBundler query = null;
4397    
4398                            if (orderByComparator != null) {
4399                                    query = new StringBundler(4 +
4400                                                    (orderByComparator.getOrderByFields().length * 2));
4401                            }
4402                            else {
4403                                    query = new StringBundler(4);
4404                            }
4405    
4406                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
4407    
4408                            query.append(_FINDER_COLUMN_C_NOTS_COMPANYID_2);
4409    
4410                            query.append(_FINDER_COLUMN_C_NOTS_STATUS_2);
4411    
4412                            if (orderByComparator != null) {
4413                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4414                                            orderByComparator);
4415                            }
4416                            else
4417                             if (pagination) {
4418                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
4419                            }
4420    
4421                            String sql = query.toString();
4422    
4423                            Session session = null;
4424    
4425                            try {
4426                                    session = openSession();
4427    
4428                                    Query q = session.createQuery(sql);
4429    
4430                                    QueryPos qPos = QueryPos.getInstance(q);
4431    
4432                                    qPos.add(companyId);
4433    
4434                                    qPos.add(status);
4435    
4436                                    if (!pagination) {
4437                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
4438                                                            start, end, false);
4439    
4440                                            Collections.sort(list);
4441    
4442                                            list = Collections.unmodifiableList(list);
4443                                    }
4444                                    else {
4445                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
4446                                                            start, end);
4447                                    }
4448    
4449                                    cacheResult(list);
4450    
4451                                    finderCache.putResult(finderPath, finderArgs, list);
4452                            }
4453                            catch (Exception e) {
4454                                    finderCache.removeResult(finderPath, finderArgs);
4455    
4456                                    throw processException(e);
4457                            }
4458                            finally {
4459                                    closeSession(session);
4460                            }
4461                    }
4462    
4463                    return list;
4464            }
4465    
4466            /**
4467             * Returns the first document library folder in the ordered set where companyId = &#63; and status &ne; &#63;.
4468             *
4469             * @param companyId the company ID
4470             * @param status the status
4471             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4472             * @return the first matching document library folder
4473             * @throws NoSuchFolderException if a matching document library folder could not be found
4474             */
4475            @Override
4476            public DLFolder findByC_NotS_First(long companyId, int status,
4477                    OrderByComparator<DLFolder> orderByComparator)
4478                    throws NoSuchFolderException {
4479                    DLFolder dlFolder = fetchByC_NotS_First(companyId, status,
4480                                    orderByComparator);
4481    
4482                    if (dlFolder != null) {
4483                            return dlFolder;
4484                    }
4485    
4486                    StringBundler msg = new StringBundler(6);
4487    
4488                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4489    
4490                    msg.append("companyId=");
4491                    msg.append(companyId);
4492    
4493                    msg.append(", status=");
4494                    msg.append(status);
4495    
4496                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4497    
4498                    throw new NoSuchFolderException(msg.toString());
4499            }
4500    
4501            /**
4502             * Returns the first document library folder in the ordered set where companyId = &#63; and status &ne; &#63;.
4503             *
4504             * @param companyId the company ID
4505             * @param status the status
4506             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4507             * @return the first matching document library folder, or <code>null</code> if a matching document library folder could not be found
4508             */
4509            @Override
4510            public DLFolder fetchByC_NotS_First(long companyId, int status,
4511                    OrderByComparator<DLFolder> orderByComparator) {
4512                    List<DLFolder> list = findByC_NotS(companyId, status, 0, 1,
4513                                    orderByComparator);
4514    
4515                    if (!list.isEmpty()) {
4516                            return list.get(0);
4517                    }
4518    
4519                    return null;
4520            }
4521    
4522            /**
4523             * Returns the last document library folder in the ordered set where companyId = &#63; and status &ne; &#63;.
4524             *
4525             * @param companyId the company ID
4526             * @param status the status
4527             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4528             * @return the last matching document library folder
4529             * @throws NoSuchFolderException if a matching document library folder could not be found
4530             */
4531            @Override
4532            public DLFolder findByC_NotS_Last(long companyId, int status,
4533                    OrderByComparator<DLFolder> orderByComparator)
4534                    throws NoSuchFolderException {
4535                    DLFolder dlFolder = fetchByC_NotS_Last(companyId, status,
4536                                    orderByComparator);
4537    
4538                    if (dlFolder != null) {
4539                            return dlFolder;
4540                    }
4541    
4542                    StringBundler msg = new StringBundler(6);
4543    
4544                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4545    
4546                    msg.append("companyId=");
4547                    msg.append(companyId);
4548    
4549                    msg.append(", status=");
4550                    msg.append(status);
4551    
4552                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4553    
4554                    throw new NoSuchFolderException(msg.toString());
4555            }
4556    
4557            /**
4558             * Returns the last document library folder in the ordered set where companyId = &#63; and status &ne; &#63;.
4559             *
4560             * @param companyId the company ID
4561             * @param status the status
4562             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4563             * @return the last matching document library folder, or <code>null</code> if a matching document library folder could not be found
4564             */
4565            @Override
4566            public DLFolder fetchByC_NotS_Last(long companyId, int status,
4567                    OrderByComparator<DLFolder> orderByComparator) {
4568                    int count = countByC_NotS(companyId, status);
4569    
4570                    if (count == 0) {
4571                            return null;
4572                    }
4573    
4574                    List<DLFolder> list = findByC_NotS(companyId, status, count - 1, count,
4575                                    orderByComparator);
4576    
4577                    if (!list.isEmpty()) {
4578                            return list.get(0);
4579                    }
4580    
4581                    return null;
4582            }
4583    
4584            /**
4585             * Returns the document library folders before and after the current document library folder in the ordered set where companyId = &#63; and status &ne; &#63;.
4586             *
4587             * @param folderId the primary key of the current document library folder
4588             * @param companyId the company ID
4589             * @param status the status
4590             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4591             * @return the previous, current, and next document library folder
4592             * @throws NoSuchFolderException if a document library folder with the primary key could not be found
4593             */
4594            @Override
4595            public DLFolder[] findByC_NotS_PrevAndNext(long folderId, long companyId,
4596                    int status, OrderByComparator<DLFolder> orderByComparator)
4597                    throws NoSuchFolderException {
4598                    DLFolder dlFolder = findByPrimaryKey(folderId);
4599    
4600                    Session session = null;
4601    
4602                    try {
4603                            session = openSession();
4604    
4605                            DLFolder[] array = new DLFolderImpl[3];
4606    
4607                            array[0] = getByC_NotS_PrevAndNext(session, dlFolder, companyId,
4608                                            status, orderByComparator, true);
4609    
4610                            array[1] = dlFolder;
4611    
4612                            array[2] = getByC_NotS_PrevAndNext(session, dlFolder, companyId,
4613                                            status, orderByComparator, false);
4614    
4615                            return array;
4616                    }
4617                    catch (Exception e) {
4618                            throw processException(e);
4619                    }
4620                    finally {
4621                            closeSession(session);
4622                    }
4623            }
4624    
4625            protected DLFolder getByC_NotS_PrevAndNext(Session session,
4626                    DLFolder dlFolder, long companyId, int status,
4627                    OrderByComparator<DLFolder> orderByComparator, boolean previous) {
4628                    StringBundler query = null;
4629    
4630                    if (orderByComparator != null) {
4631                            query = new StringBundler(5 +
4632                                            (orderByComparator.getOrderByConditionFields().length * 3) +
4633                                            (orderByComparator.getOrderByFields().length * 3));
4634                    }
4635                    else {
4636                            query = new StringBundler(4);
4637                    }
4638    
4639                    query.append(_SQL_SELECT_DLFOLDER_WHERE);
4640    
4641                    query.append(_FINDER_COLUMN_C_NOTS_COMPANYID_2);
4642    
4643                    query.append(_FINDER_COLUMN_C_NOTS_STATUS_2);
4644    
4645                    if (orderByComparator != null) {
4646                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4647    
4648                            if (orderByConditionFields.length > 0) {
4649                                    query.append(WHERE_AND);
4650                            }
4651    
4652                            for (int i = 0; i < orderByConditionFields.length; i++) {
4653                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4654                                    query.append(orderByConditionFields[i]);
4655    
4656                                    if ((i + 1) < orderByConditionFields.length) {
4657                                            if (orderByComparator.isAscending() ^ previous) {
4658                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4659                                            }
4660                                            else {
4661                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4662                                            }
4663                                    }
4664                                    else {
4665                                            if (orderByComparator.isAscending() ^ previous) {
4666                                                    query.append(WHERE_GREATER_THAN);
4667                                            }
4668                                            else {
4669                                                    query.append(WHERE_LESSER_THAN);
4670                                            }
4671                                    }
4672                            }
4673    
4674                            query.append(ORDER_BY_CLAUSE);
4675    
4676                            String[] orderByFields = orderByComparator.getOrderByFields();
4677    
4678                            for (int i = 0; i < orderByFields.length; i++) {
4679                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4680                                    query.append(orderByFields[i]);
4681    
4682                                    if ((i + 1) < orderByFields.length) {
4683                                            if (orderByComparator.isAscending() ^ previous) {
4684                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4685                                            }
4686                                            else {
4687                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4688                                            }
4689                                    }
4690                                    else {
4691                                            if (orderByComparator.isAscending() ^ previous) {
4692                                                    query.append(ORDER_BY_ASC);
4693                                            }
4694                                            else {
4695                                                    query.append(ORDER_BY_DESC);
4696                                            }
4697                                    }
4698                            }
4699                    }
4700                    else {
4701                            query.append(DLFolderModelImpl.ORDER_BY_JPQL);
4702                    }
4703    
4704                    String sql = query.toString();
4705    
4706                    Query q = session.createQuery(sql);
4707    
4708                    q.setFirstResult(0);
4709                    q.setMaxResults(2);
4710    
4711                    QueryPos qPos = QueryPos.getInstance(q);
4712    
4713                    qPos.add(companyId);
4714    
4715                    qPos.add(status);
4716    
4717                    if (orderByComparator != null) {
4718                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
4719    
4720                            for (Object value : values) {
4721                                    qPos.add(value);
4722                            }
4723                    }
4724    
4725                    List<DLFolder> list = q.list();
4726    
4727                    if (list.size() == 2) {
4728                            return list.get(1);
4729                    }
4730                    else {
4731                            return null;
4732                    }
4733            }
4734    
4735            /**
4736             * Removes all the document library folders where companyId = &#63; and status &ne; &#63; from the database.
4737             *
4738             * @param companyId the company ID
4739             * @param status the status
4740             */
4741            @Override
4742            public void removeByC_NotS(long companyId, int status) {
4743                    for (DLFolder dlFolder : findByC_NotS(companyId, status,
4744                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4745                            remove(dlFolder);
4746                    }
4747            }
4748    
4749            /**
4750             * Returns the number of document library folders where companyId = &#63; and status &ne; &#63;.
4751             *
4752             * @param companyId the company ID
4753             * @param status the status
4754             * @return the number of matching document library folders
4755             */
4756            @Override
4757            public int countByC_NotS(long companyId, int status) {
4758                    FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_NOTS;
4759    
4760                    Object[] finderArgs = new Object[] { companyId, status };
4761    
4762                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
4763    
4764                    if (count == null) {
4765                            StringBundler query = new StringBundler(3);
4766    
4767                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
4768    
4769                            query.append(_FINDER_COLUMN_C_NOTS_COMPANYID_2);
4770    
4771                            query.append(_FINDER_COLUMN_C_NOTS_STATUS_2);
4772    
4773                            String sql = query.toString();
4774    
4775                            Session session = null;
4776    
4777                            try {
4778                                    session = openSession();
4779    
4780                                    Query q = session.createQuery(sql);
4781    
4782                                    QueryPos qPos = QueryPos.getInstance(q);
4783    
4784                                    qPos.add(companyId);
4785    
4786                                    qPos.add(status);
4787    
4788                                    count = (Long)q.uniqueResult();
4789    
4790                                    finderCache.putResult(finderPath, finderArgs, count);
4791                            }
4792                            catch (Exception e) {
4793                                    finderCache.removeResult(finderPath, finderArgs);
4794    
4795                                    throw processException(e);
4796                            }
4797                            finally {
4798                                    closeSession(session);
4799                            }
4800                    }
4801    
4802                    return count.intValue();
4803            }
4804    
4805            private static final String _FINDER_COLUMN_C_NOTS_COMPANYID_2 = "dlFolder.companyId = ? AND ";
4806            private static final String _FINDER_COLUMN_C_NOTS_STATUS_2 = "dlFolder.status != ?";
4807            public static final FinderPath FINDER_PATH_FETCH_BY_R_M = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
4808                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
4809                            FINDER_CLASS_NAME_ENTITY, "fetchByR_M",
4810                            new String[] { Long.class.getName(), Boolean.class.getName() },
4811                            DLFolderModelImpl.REPOSITORYID_COLUMN_BITMASK |
4812                            DLFolderModelImpl.MOUNTPOINT_COLUMN_BITMASK);
4813            public static final FinderPath FINDER_PATH_COUNT_BY_R_M = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
4814                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
4815                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByR_M",
4816                            new String[] { Long.class.getName(), Boolean.class.getName() });
4817    
4818            /**
4819             * Returns the document library folder where repositoryId = &#63; and mountPoint = &#63; or throws a {@link NoSuchFolderException} if it could not be found.
4820             *
4821             * @param repositoryId the repository ID
4822             * @param mountPoint the mount point
4823             * @return the matching document library folder
4824             * @throws NoSuchFolderException if a matching document library folder could not be found
4825             */
4826            @Override
4827            public DLFolder findByR_M(long repositoryId, boolean mountPoint)
4828                    throws NoSuchFolderException {
4829                    DLFolder dlFolder = fetchByR_M(repositoryId, mountPoint);
4830    
4831                    if (dlFolder == null) {
4832                            StringBundler msg = new StringBundler(6);
4833    
4834                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4835    
4836                            msg.append("repositoryId=");
4837                            msg.append(repositoryId);
4838    
4839                            msg.append(", mountPoint=");
4840                            msg.append(mountPoint);
4841    
4842                            msg.append(StringPool.CLOSE_CURLY_BRACE);
4843    
4844                            if (_log.isWarnEnabled()) {
4845                                    _log.warn(msg.toString());
4846                            }
4847    
4848                            throw new NoSuchFolderException(msg.toString());
4849                    }
4850    
4851                    return dlFolder;
4852            }
4853    
4854            /**
4855             * 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.
4856             *
4857             * @param repositoryId the repository ID
4858             * @param mountPoint the mount point
4859             * @return the matching document library folder, or <code>null</code> if a matching document library folder could not be found
4860             */
4861            @Override
4862            public DLFolder fetchByR_M(long repositoryId, boolean mountPoint) {
4863                    return fetchByR_M(repositoryId, mountPoint, true);
4864            }
4865    
4866            /**
4867             * 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.
4868             *
4869             * @param repositoryId the repository ID
4870             * @param mountPoint the mount point
4871             * @param retrieveFromCache whether to retrieve from the finder cache
4872             * @return the matching document library folder, or <code>null</code> if a matching document library folder could not be found
4873             */
4874            @Override
4875            public DLFolder fetchByR_M(long repositoryId, boolean mountPoint,
4876                    boolean retrieveFromCache) {
4877                    Object[] finderArgs = new Object[] { repositoryId, mountPoint };
4878    
4879                    Object result = null;
4880    
4881                    if (retrieveFromCache) {
4882                            result = finderCache.getResult(FINDER_PATH_FETCH_BY_R_M,
4883                                            finderArgs, this);
4884                    }
4885    
4886                    if (result instanceof DLFolder) {
4887                            DLFolder dlFolder = (DLFolder)result;
4888    
4889                            if ((repositoryId != dlFolder.getRepositoryId()) ||
4890                                            (mountPoint != dlFolder.getMountPoint())) {
4891                                    result = null;
4892                            }
4893                    }
4894    
4895                    if (result == null) {
4896                            StringBundler query = new StringBundler(4);
4897    
4898                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
4899    
4900                            query.append(_FINDER_COLUMN_R_M_REPOSITORYID_2);
4901    
4902                            query.append(_FINDER_COLUMN_R_M_MOUNTPOINT_2);
4903    
4904                            String sql = query.toString();
4905    
4906                            Session session = null;
4907    
4908                            try {
4909                                    session = openSession();
4910    
4911                                    Query q = session.createQuery(sql);
4912    
4913                                    QueryPos qPos = QueryPos.getInstance(q);
4914    
4915                                    qPos.add(repositoryId);
4916    
4917                                    qPos.add(mountPoint);
4918    
4919                                    List<DLFolder> list = q.list();
4920    
4921                                    if (list.isEmpty()) {
4922                                            finderCache.putResult(FINDER_PATH_FETCH_BY_R_M, finderArgs,
4923                                                    list);
4924                                    }
4925                                    else {
4926                                            if ((list.size() > 1) && _log.isWarnEnabled()) {
4927                                                    _log.warn(
4928                                                            "DLFolderPersistenceImpl.fetchByR_M(long, boolean, boolean) with parameters (" +
4929                                                            StringUtil.merge(finderArgs) +
4930                                                            ") 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.");
4931                                            }
4932    
4933                                            DLFolder dlFolder = list.get(0);
4934    
4935                                            result = dlFolder;
4936    
4937                                            cacheResult(dlFolder);
4938    
4939                                            if ((dlFolder.getRepositoryId() != repositoryId) ||
4940                                                            (dlFolder.getMountPoint() != mountPoint)) {
4941                                                    finderCache.putResult(FINDER_PATH_FETCH_BY_R_M,
4942                                                            finderArgs, dlFolder);
4943                                            }
4944                                    }
4945                            }
4946                            catch (Exception e) {
4947                                    finderCache.removeResult(FINDER_PATH_FETCH_BY_R_M, finderArgs);
4948    
4949                                    throw processException(e);
4950                            }
4951                            finally {
4952                                    closeSession(session);
4953                            }
4954                    }
4955    
4956                    if (result instanceof List<?>) {
4957                            return null;
4958                    }
4959                    else {
4960                            return (DLFolder)result;
4961                    }
4962            }
4963    
4964            /**
4965             * Removes the document library folder where repositoryId = &#63; and mountPoint = &#63; from the database.
4966             *
4967             * @param repositoryId the repository ID
4968             * @param mountPoint the mount point
4969             * @return the document library folder that was removed
4970             */
4971            @Override
4972            public DLFolder removeByR_M(long repositoryId, boolean mountPoint)
4973                    throws NoSuchFolderException {
4974                    DLFolder dlFolder = findByR_M(repositoryId, mountPoint);
4975    
4976                    return remove(dlFolder);
4977            }
4978    
4979            /**
4980             * Returns the number of document library folders where repositoryId = &#63; and mountPoint = &#63;.
4981             *
4982             * @param repositoryId the repository ID
4983             * @param mountPoint the mount point
4984             * @return the number of matching document library folders
4985             */
4986            @Override
4987            public int countByR_M(long repositoryId, boolean mountPoint) {
4988                    FinderPath finderPath = FINDER_PATH_COUNT_BY_R_M;
4989    
4990                    Object[] finderArgs = new Object[] { repositoryId, mountPoint };
4991    
4992                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
4993    
4994                    if (count == null) {
4995                            StringBundler query = new StringBundler(3);
4996    
4997                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
4998    
4999                            query.append(_FINDER_COLUMN_R_M_REPOSITORYID_2);
5000    
5001                            query.append(_FINDER_COLUMN_R_M_MOUNTPOINT_2);
5002    
5003                            String sql = query.toString();
5004    
5005                            Session session = null;
5006    
5007                            try {
5008                                    session = openSession();
5009    
5010                                    Query q = session.createQuery(sql);
5011    
5012                                    QueryPos qPos = QueryPos.getInstance(q);
5013    
5014                                    qPos.add(repositoryId);
5015    
5016                                    qPos.add(mountPoint);
5017    
5018                                    count = (Long)q.uniqueResult();
5019    
5020                                    finderCache.putResult(finderPath, finderArgs, count);
5021                            }
5022                            catch (Exception e) {
5023                                    finderCache.removeResult(finderPath, finderArgs);
5024    
5025                                    throw processException(e);
5026                            }
5027                            finally {
5028                                    closeSession(session);
5029                            }
5030                    }
5031    
5032                    return count.intValue();
5033            }
5034    
5035            private static final String _FINDER_COLUMN_R_M_REPOSITORYID_2 = "dlFolder.repositoryId = ? AND ";
5036            private static final String _FINDER_COLUMN_R_M_MOUNTPOINT_2 = "dlFolder.mountPoint = ?";
5037            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_R_P = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
5038                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
5039                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByR_P",
5040                            new String[] {
5041                                    Long.class.getName(), Long.class.getName(),
5042                                    
5043                            Integer.class.getName(), Integer.class.getName(),
5044                                    OrderByComparator.class.getName()
5045                            });
5046            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_P = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
5047                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
5048                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByR_P",
5049                            new String[] { Long.class.getName(), Long.class.getName() },
5050                            DLFolderModelImpl.REPOSITORYID_COLUMN_BITMASK |
5051                            DLFolderModelImpl.PARENTFOLDERID_COLUMN_BITMASK |
5052                            DLFolderModelImpl.NAME_COLUMN_BITMASK);
5053            public static final FinderPath FINDER_PATH_COUNT_BY_R_P = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
5054                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
5055                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByR_P",
5056                            new String[] { Long.class.getName(), Long.class.getName() });
5057    
5058            /**
5059             * Returns all the document library folders where repositoryId = &#63; and parentFolderId = &#63;.
5060             *
5061             * @param repositoryId the repository ID
5062             * @param parentFolderId the parent folder ID
5063             * @return the matching document library folders
5064             */
5065            @Override
5066            public List<DLFolder> findByR_P(long repositoryId, long parentFolderId) {
5067                    return findByR_P(repositoryId, parentFolderId, QueryUtil.ALL_POS,
5068                            QueryUtil.ALL_POS, null);
5069            }
5070    
5071            /**
5072             * Returns a range of all the document library folders where repositoryId = &#63; and parentFolderId = &#63;.
5073             *
5074             * <p>
5075             * 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.
5076             * </p>
5077             *
5078             * @param repositoryId the repository ID
5079             * @param parentFolderId the parent folder ID
5080             * @param start the lower bound of the range of document library folders
5081             * @param end the upper bound of the range of document library folders (not inclusive)
5082             * @return the range of matching document library folders
5083             */
5084            @Override
5085            public List<DLFolder> findByR_P(long repositoryId, long parentFolderId,
5086                    int start, int end) {
5087                    return findByR_P(repositoryId, parentFolderId, start, end, null);
5088            }
5089    
5090            /**
5091             * Returns an ordered range of all the document library folders where repositoryId = &#63; and parentFolderId = &#63;.
5092             *
5093             * <p>
5094             * 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.
5095             * </p>
5096             *
5097             * @param repositoryId the repository ID
5098             * @param parentFolderId the parent folder ID
5099             * @param start the lower bound of the range of document library folders
5100             * @param end the upper bound of the range of document library folders (not inclusive)
5101             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5102             * @return the ordered range of matching document library folders
5103             */
5104            @Override
5105            public List<DLFolder> findByR_P(long repositoryId, long parentFolderId,
5106                    int start, int end, OrderByComparator<DLFolder> orderByComparator) {
5107                    return findByR_P(repositoryId, parentFolderId, start, end,
5108                            orderByComparator, true);
5109            }
5110    
5111            /**
5112             * Returns an ordered range of all the document library folders where repositoryId = &#63; and parentFolderId = &#63;.
5113             *
5114             * <p>
5115             * 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.
5116             * </p>
5117             *
5118             * @param repositoryId the repository ID
5119             * @param parentFolderId the parent folder ID
5120             * @param start the lower bound of the range of document library folders
5121             * @param end the upper bound of the range of document library folders (not inclusive)
5122             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5123             * @param retrieveFromCache whether to retrieve from the finder cache
5124             * @return the ordered range of matching document library folders
5125             */
5126            @Override
5127            public List<DLFolder> findByR_P(long repositoryId, long parentFolderId,
5128                    int start, int end, OrderByComparator<DLFolder> orderByComparator,
5129                    boolean retrieveFromCache) {
5130                    boolean pagination = true;
5131                    FinderPath finderPath = null;
5132                    Object[] finderArgs = null;
5133    
5134                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5135                                    (orderByComparator == null)) {
5136                            pagination = false;
5137                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_P;
5138                            finderArgs = new Object[] { repositoryId, parentFolderId };
5139                    }
5140                    else {
5141                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_R_P;
5142                            finderArgs = new Object[] {
5143                                            repositoryId, parentFolderId,
5144                                            
5145                                            start, end, orderByComparator
5146                                    };
5147                    }
5148    
5149                    List<DLFolder> list = null;
5150    
5151                    if (retrieveFromCache) {
5152                            list = (List<DLFolder>)finderCache.getResult(finderPath,
5153                                            finderArgs, this);
5154    
5155                            if ((list != null) && !list.isEmpty()) {
5156                                    for (DLFolder dlFolder : list) {
5157                                            if ((repositoryId != dlFolder.getRepositoryId()) ||
5158                                                            (parentFolderId != dlFolder.getParentFolderId())) {
5159                                                    list = null;
5160    
5161                                                    break;
5162                                            }
5163                                    }
5164                            }
5165                    }
5166    
5167                    if (list == null) {
5168                            StringBundler query = null;
5169    
5170                            if (orderByComparator != null) {
5171                                    query = new StringBundler(4 +
5172                                                    (orderByComparator.getOrderByFields().length * 2));
5173                            }
5174                            else {
5175                                    query = new StringBundler(4);
5176                            }
5177    
5178                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
5179    
5180                            query.append(_FINDER_COLUMN_R_P_REPOSITORYID_2);
5181    
5182                            query.append(_FINDER_COLUMN_R_P_PARENTFOLDERID_2);
5183    
5184                            if (orderByComparator != null) {
5185                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5186                                            orderByComparator);
5187                            }
5188                            else
5189                             if (pagination) {
5190                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
5191                            }
5192    
5193                            String sql = query.toString();
5194    
5195                            Session session = null;
5196    
5197                            try {
5198                                    session = openSession();
5199    
5200                                    Query q = session.createQuery(sql);
5201    
5202                                    QueryPos qPos = QueryPos.getInstance(q);
5203    
5204                                    qPos.add(repositoryId);
5205    
5206                                    qPos.add(parentFolderId);
5207    
5208                                    if (!pagination) {
5209                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
5210                                                            start, end, false);
5211    
5212                                            Collections.sort(list);
5213    
5214                                            list = Collections.unmodifiableList(list);
5215                                    }
5216                                    else {
5217                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
5218                                                            start, end);
5219                                    }
5220    
5221                                    cacheResult(list);
5222    
5223                                    finderCache.putResult(finderPath, finderArgs, list);
5224                            }
5225                            catch (Exception e) {
5226                                    finderCache.removeResult(finderPath, finderArgs);
5227    
5228                                    throw processException(e);
5229                            }
5230                            finally {
5231                                    closeSession(session);
5232                            }
5233                    }
5234    
5235                    return list;
5236            }
5237    
5238            /**
5239             * Returns the first document library folder in the ordered set where repositoryId = &#63; and parentFolderId = &#63;.
5240             *
5241             * @param repositoryId the repository ID
5242             * @param parentFolderId the parent folder ID
5243             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5244             * @return the first matching document library folder
5245             * @throws NoSuchFolderException if a matching document library folder could not be found
5246             */
5247            @Override
5248            public DLFolder findByR_P_First(long repositoryId, long parentFolderId,
5249                    OrderByComparator<DLFolder> orderByComparator)
5250                    throws NoSuchFolderException {
5251                    DLFolder dlFolder = fetchByR_P_First(repositoryId, parentFolderId,
5252                                    orderByComparator);
5253    
5254                    if (dlFolder != null) {
5255                            return dlFolder;
5256                    }
5257    
5258                    StringBundler msg = new StringBundler(6);
5259    
5260                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5261    
5262                    msg.append("repositoryId=");
5263                    msg.append(repositoryId);
5264    
5265                    msg.append(", parentFolderId=");
5266                    msg.append(parentFolderId);
5267    
5268                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5269    
5270                    throw new NoSuchFolderException(msg.toString());
5271            }
5272    
5273            /**
5274             * Returns the first document library folder in the ordered set where repositoryId = &#63; and parentFolderId = &#63;.
5275             *
5276             * @param repositoryId the repository ID
5277             * @param parentFolderId the parent folder ID
5278             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5279             * @return the first matching document library folder, or <code>null</code> if a matching document library folder could not be found
5280             */
5281            @Override
5282            public DLFolder fetchByR_P_First(long repositoryId, long parentFolderId,
5283                    OrderByComparator<DLFolder> orderByComparator) {
5284                    List<DLFolder> list = findByR_P(repositoryId, parentFolderId, 0, 1,
5285                                    orderByComparator);
5286    
5287                    if (!list.isEmpty()) {
5288                            return list.get(0);
5289                    }
5290    
5291                    return null;
5292            }
5293    
5294            /**
5295             * Returns the last document library folder in the ordered set where repositoryId = &#63; and parentFolderId = &#63;.
5296             *
5297             * @param repositoryId the repository ID
5298             * @param parentFolderId the parent folder ID
5299             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5300             * @return the last matching document library folder
5301             * @throws NoSuchFolderException if a matching document library folder could not be found
5302             */
5303            @Override
5304            public DLFolder findByR_P_Last(long repositoryId, long parentFolderId,
5305                    OrderByComparator<DLFolder> orderByComparator)
5306                    throws NoSuchFolderException {
5307                    DLFolder dlFolder = fetchByR_P_Last(repositoryId, parentFolderId,
5308                                    orderByComparator);
5309    
5310                    if (dlFolder != null) {
5311                            return dlFolder;
5312                    }
5313    
5314                    StringBundler msg = new StringBundler(6);
5315    
5316                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5317    
5318                    msg.append("repositoryId=");
5319                    msg.append(repositoryId);
5320    
5321                    msg.append(", parentFolderId=");
5322                    msg.append(parentFolderId);
5323    
5324                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5325    
5326                    throw new NoSuchFolderException(msg.toString());
5327            }
5328    
5329            /**
5330             * Returns the last document library folder in the ordered set where repositoryId = &#63; and parentFolderId = &#63;.
5331             *
5332             * @param repositoryId the repository ID
5333             * @param parentFolderId the parent folder ID
5334             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5335             * @return the last matching document library folder, or <code>null</code> if a matching document library folder could not be found
5336             */
5337            @Override
5338            public DLFolder fetchByR_P_Last(long repositoryId, long parentFolderId,
5339                    OrderByComparator<DLFolder> orderByComparator) {
5340                    int count = countByR_P(repositoryId, parentFolderId);
5341    
5342                    if (count == 0) {
5343                            return null;
5344                    }
5345    
5346                    List<DLFolder> list = findByR_P(repositoryId, parentFolderId,
5347                                    count - 1, count, orderByComparator);
5348    
5349                    if (!list.isEmpty()) {
5350                            return list.get(0);
5351                    }
5352    
5353                    return null;
5354            }
5355    
5356            /**
5357             * Returns the document library folders before and after the current document library folder in the ordered set where repositoryId = &#63; and parentFolderId = &#63;.
5358             *
5359             * @param folderId the primary key of the current document library folder
5360             * @param repositoryId the repository ID
5361             * @param parentFolderId the parent folder ID
5362             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5363             * @return the previous, current, and next document library folder
5364             * @throws NoSuchFolderException if a document library folder with the primary key could not be found
5365             */
5366            @Override
5367            public DLFolder[] findByR_P_PrevAndNext(long folderId, long repositoryId,
5368                    long parentFolderId, OrderByComparator<DLFolder> orderByComparator)
5369                    throws NoSuchFolderException {
5370                    DLFolder dlFolder = findByPrimaryKey(folderId);
5371    
5372                    Session session = null;
5373    
5374                    try {
5375                            session = openSession();
5376    
5377                            DLFolder[] array = new DLFolderImpl[3];
5378    
5379                            array[0] = getByR_P_PrevAndNext(session, dlFolder, repositoryId,
5380                                            parentFolderId, orderByComparator, true);
5381    
5382                            array[1] = dlFolder;
5383    
5384                            array[2] = getByR_P_PrevAndNext(session, dlFolder, repositoryId,
5385                                            parentFolderId, orderByComparator, false);
5386    
5387                            return array;
5388                    }
5389                    catch (Exception e) {
5390                            throw processException(e);
5391                    }
5392                    finally {
5393                            closeSession(session);
5394                    }
5395            }
5396    
5397            protected DLFolder getByR_P_PrevAndNext(Session session, DLFolder dlFolder,
5398                    long repositoryId, long parentFolderId,
5399                    OrderByComparator<DLFolder> orderByComparator, boolean previous) {
5400                    StringBundler query = null;
5401    
5402                    if (orderByComparator != null) {
5403                            query = new StringBundler(5 +
5404                                            (orderByComparator.getOrderByConditionFields().length * 3) +
5405                                            (orderByComparator.getOrderByFields().length * 3));
5406                    }
5407                    else {
5408                            query = new StringBundler(4);
5409                    }
5410    
5411                    query.append(_SQL_SELECT_DLFOLDER_WHERE);
5412    
5413                    query.append(_FINDER_COLUMN_R_P_REPOSITORYID_2);
5414    
5415                    query.append(_FINDER_COLUMN_R_P_PARENTFOLDERID_2);
5416    
5417                    if (orderByComparator != null) {
5418                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5419    
5420                            if (orderByConditionFields.length > 0) {
5421                                    query.append(WHERE_AND);
5422                            }
5423    
5424                            for (int i = 0; i < orderByConditionFields.length; i++) {
5425                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5426                                    query.append(orderByConditionFields[i]);
5427    
5428                                    if ((i + 1) < orderByConditionFields.length) {
5429                                            if (orderByComparator.isAscending() ^ previous) {
5430                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5431                                            }
5432                                            else {
5433                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5434                                            }
5435                                    }
5436                                    else {
5437                                            if (orderByComparator.isAscending() ^ previous) {
5438                                                    query.append(WHERE_GREATER_THAN);
5439                                            }
5440                                            else {
5441                                                    query.append(WHERE_LESSER_THAN);
5442                                            }
5443                                    }
5444                            }
5445    
5446                            query.append(ORDER_BY_CLAUSE);
5447    
5448                            String[] orderByFields = orderByComparator.getOrderByFields();
5449    
5450                            for (int i = 0; i < orderByFields.length; i++) {
5451                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5452                                    query.append(orderByFields[i]);
5453    
5454                                    if ((i + 1) < orderByFields.length) {
5455                                            if (orderByComparator.isAscending() ^ previous) {
5456                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5457                                            }
5458                                            else {
5459                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5460                                            }
5461                                    }
5462                                    else {
5463                                            if (orderByComparator.isAscending() ^ previous) {
5464                                                    query.append(ORDER_BY_ASC);
5465                                            }
5466                                            else {
5467                                                    query.append(ORDER_BY_DESC);
5468                                            }
5469                                    }
5470                            }
5471                    }
5472                    else {
5473                            query.append(DLFolderModelImpl.ORDER_BY_JPQL);
5474                    }
5475    
5476                    String sql = query.toString();
5477    
5478                    Query q = session.createQuery(sql);
5479    
5480                    q.setFirstResult(0);
5481                    q.setMaxResults(2);
5482    
5483                    QueryPos qPos = QueryPos.getInstance(q);
5484    
5485                    qPos.add(repositoryId);
5486    
5487                    qPos.add(parentFolderId);
5488    
5489                    if (orderByComparator != null) {
5490                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
5491    
5492                            for (Object value : values) {
5493                                    qPos.add(value);
5494                            }
5495                    }
5496    
5497                    List<DLFolder> list = q.list();
5498    
5499                    if (list.size() == 2) {
5500                            return list.get(1);
5501                    }
5502                    else {
5503                            return null;
5504                    }
5505            }
5506    
5507            /**
5508             * Removes all the document library folders where repositoryId = &#63; and parentFolderId = &#63; from the database.
5509             *
5510             * @param repositoryId the repository ID
5511             * @param parentFolderId the parent folder ID
5512             */
5513            @Override
5514            public void removeByR_P(long repositoryId, long parentFolderId) {
5515                    for (DLFolder dlFolder : findByR_P(repositoryId, parentFolderId,
5516                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
5517                            remove(dlFolder);
5518                    }
5519            }
5520    
5521            /**
5522             * Returns the number of document library folders where repositoryId = &#63; and parentFolderId = &#63;.
5523             *
5524             * @param repositoryId the repository ID
5525             * @param parentFolderId the parent folder ID
5526             * @return the number of matching document library folders
5527             */
5528            @Override
5529            public int countByR_P(long repositoryId, long parentFolderId) {
5530                    FinderPath finderPath = FINDER_PATH_COUNT_BY_R_P;
5531    
5532                    Object[] finderArgs = new Object[] { repositoryId, parentFolderId };
5533    
5534                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
5535    
5536                    if (count == null) {
5537                            StringBundler query = new StringBundler(3);
5538    
5539                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
5540    
5541                            query.append(_FINDER_COLUMN_R_P_REPOSITORYID_2);
5542    
5543                            query.append(_FINDER_COLUMN_R_P_PARENTFOLDERID_2);
5544    
5545                            String sql = query.toString();
5546    
5547                            Session session = null;
5548    
5549                            try {
5550                                    session = openSession();
5551    
5552                                    Query q = session.createQuery(sql);
5553    
5554                                    QueryPos qPos = QueryPos.getInstance(q);
5555    
5556                                    qPos.add(repositoryId);
5557    
5558                                    qPos.add(parentFolderId);
5559    
5560                                    count = (Long)q.uniqueResult();
5561    
5562                                    finderCache.putResult(finderPath, finderArgs, count);
5563                            }
5564                            catch (Exception e) {
5565                                    finderCache.removeResult(finderPath, finderArgs);
5566    
5567                                    throw processException(e);
5568                            }
5569                            finally {
5570                                    closeSession(session);
5571                            }
5572                    }
5573    
5574                    return count.intValue();
5575            }
5576    
5577            private static final String _FINDER_COLUMN_R_P_REPOSITORYID_2 = "dlFolder.repositoryId = ? AND ";
5578            private static final String _FINDER_COLUMN_R_P_PARENTFOLDERID_2 = "dlFolder.parentFolderId = ?";
5579            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_P_N = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
5580                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
5581                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByP_N",
5582                            new String[] {
5583                                    Long.class.getName(), String.class.getName(),
5584                                    
5585                            Integer.class.getName(), Integer.class.getName(),
5586                                    OrderByComparator.class.getName()
5587                            });
5588            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_N = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
5589                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
5590                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByP_N",
5591                            new String[] { Long.class.getName(), String.class.getName() },
5592                            DLFolderModelImpl.PARENTFOLDERID_COLUMN_BITMASK |
5593                            DLFolderModelImpl.NAME_COLUMN_BITMASK);
5594            public static final FinderPath FINDER_PATH_COUNT_BY_P_N = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
5595                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
5596                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByP_N",
5597                            new String[] { Long.class.getName(), String.class.getName() });
5598    
5599            /**
5600             * Returns all the document library folders where parentFolderId = &#63; and name = &#63;.
5601             *
5602             * @param parentFolderId the parent folder ID
5603             * @param name the name
5604             * @return the matching document library folders
5605             */
5606            @Override
5607            public List<DLFolder> findByP_N(long parentFolderId, String name) {
5608                    return findByP_N(parentFolderId, name, QueryUtil.ALL_POS,
5609                            QueryUtil.ALL_POS, null);
5610            }
5611    
5612            /**
5613             * Returns a range of all the document library folders where parentFolderId = &#63; and name = &#63;.
5614             *
5615             * <p>
5616             * 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.
5617             * </p>
5618             *
5619             * @param parentFolderId the parent folder ID
5620             * @param name the name
5621             * @param start the lower bound of the range of document library folders
5622             * @param end the upper bound of the range of document library folders (not inclusive)
5623             * @return the range of matching document library folders
5624             */
5625            @Override
5626            public List<DLFolder> findByP_N(long parentFolderId, String name,
5627                    int start, int end) {
5628                    return findByP_N(parentFolderId, name, start, end, null);
5629            }
5630    
5631            /**
5632             * Returns an ordered range of all the document library folders where parentFolderId = &#63; and name = &#63;.
5633             *
5634             * <p>
5635             * 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.
5636             * </p>
5637             *
5638             * @param parentFolderId the parent folder ID
5639             * @param name the name
5640             * @param start the lower bound of the range of document library folders
5641             * @param end the upper bound of the range of document library folders (not inclusive)
5642             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5643             * @return the ordered range of matching document library folders
5644             */
5645            @Override
5646            public List<DLFolder> findByP_N(long parentFolderId, String name,
5647                    int start, int end, OrderByComparator<DLFolder> orderByComparator) {
5648                    return findByP_N(parentFolderId, name, start, end, orderByComparator,
5649                            true);
5650            }
5651    
5652            /**
5653             * Returns an ordered range of all the document library folders where parentFolderId = &#63; and name = &#63;.
5654             *
5655             * <p>
5656             * 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.
5657             * </p>
5658             *
5659             * @param parentFolderId the parent folder ID
5660             * @param name the name
5661             * @param start the lower bound of the range of document library folders
5662             * @param end the upper bound of the range of document library folders (not inclusive)
5663             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5664             * @param retrieveFromCache whether to retrieve from the finder cache
5665             * @return the ordered range of matching document library folders
5666             */
5667            @Override
5668            public List<DLFolder> findByP_N(long parentFolderId, String name,
5669                    int start, int end, OrderByComparator<DLFolder> orderByComparator,
5670                    boolean retrieveFromCache) {
5671                    boolean pagination = true;
5672                    FinderPath finderPath = null;
5673                    Object[] finderArgs = null;
5674    
5675                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5676                                    (orderByComparator == null)) {
5677                            pagination = false;
5678                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_N;
5679                            finderArgs = new Object[] { parentFolderId, name };
5680                    }
5681                    else {
5682                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_P_N;
5683                            finderArgs = new Object[] {
5684                                            parentFolderId, name,
5685                                            
5686                                            start, end, orderByComparator
5687                                    };
5688                    }
5689    
5690                    List<DLFolder> list = null;
5691    
5692                    if (retrieveFromCache) {
5693                            list = (List<DLFolder>)finderCache.getResult(finderPath,
5694                                            finderArgs, this);
5695    
5696                            if ((list != null) && !list.isEmpty()) {
5697                                    for (DLFolder dlFolder : list) {
5698                                            if ((parentFolderId != dlFolder.getParentFolderId()) ||
5699                                                            !Validator.equals(name, dlFolder.getName())) {
5700                                                    list = null;
5701    
5702                                                    break;
5703                                            }
5704                                    }
5705                            }
5706                    }
5707    
5708                    if (list == null) {
5709                            StringBundler query = null;
5710    
5711                            if (orderByComparator != null) {
5712                                    query = new StringBundler(4 +
5713                                                    (orderByComparator.getOrderByFields().length * 2));
5714                            }
5715                            else {
5716                                    query = new StringBundler(4);
5717                            }
5718    
5719                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
5720    
5721                            query.append(_FINDER_COLUMN_P_N_PARENTFOLDERID_2);
5722    
5723                            boolean bindName = false;
5724    
5725                            if (name == null) {
5726                                    query.append(_FINDER_COLUMN_P_N_NAME_1);
5727                            }
5728                            else if (name.equals(StringPool.BLANK)) {
5729                                    query.append(_FINDER_COLUMN_P_N_NAME_3);
5730                            }
5731                            else {
5732                                    bindName = true;
5733    
5734                                    query.append(_FINDER_COLUMN_P_N_NAME_2);
5735                            }
5736    
5737                            if (orderByComparator != null) {
5738                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5739                                            orderByComparator);
5740                            }
5741                            else
5742                             if (pagination) {
5743                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
5744                            }
5745    
5746                            String sql = query.toString();
5747    
5748                            Session session = null;
5749    
5750                            try {
5751                                    session = openSession();
5752    
5753                                    Query q = session.createQuery(sql);
5754    
5755                                    QueryPos qPos = QueryPos.getInstance(q);
5756    
5757                                    qPos.add(parentFolderId);
5758    
5759                                    if (bindName) {
5760                                            qPos.add(name);
5761                                    }
5762    
5763                                    if (!pagination) {
5764                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
5765                                                            start, end, false);
5766    
5767                                            Collections.sort(list);
5768    
5769                                            list = Collections.unmodifiableList(list);
5770                                    }
5771                                    else {
5772                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
5773                                                            start, end);
5774                                    }
5775    
5776                                    cacheResult(list);
5777    
5778                                    finderCache.putResult(finderPath, finderArgs, list);
5779                            }
5780                            catch (Exception e) {
5781                                    finderCache.removeResult(finderPath, finderArgs);
5782    
5783                                    throw processException(e);
5784                            }
5785                            finally {
5786                                    closeSession(session);
5787                            }
5788                    }
5789    
5790                    return list;
5791            }
5792    
5793            /**
5794             * Returns the first document library folder in the ordered set where parentFolderId = &#63; and name = &#63;.
5795             *
5796             * @param parentFolderId the parent folder ID
5797             * @param name the name
5798             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5799             * @return the first matching document library folder
5800             * @throws NoSuchFolderException if a matching document library folder could not be found
5801             */
5802            @Override
5803            public DLFolder findByP_N_First(long parentFolderId, String name,
5804                    OrderByComparator<DLFolder> orderByComparator)
5805                    throws NoSuchFolderException {
5806                    DLFolder dlFolder = fetchByP_N_First(parentFolderId, name,
5807                                    orderByComparator);
5808    
5809                    if (dlFolder != null) {
5810                            return dlFolder;
5811                    }
5812    
5813                    StringBundler msg = new StringBundler(6);
5814    
5815                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5816    
5817                    msg.append("parentFolderId=");
5818                    msg.append(parentFolderId);
5819    
5820                    msg.append(", name=");
5821                    msg.append(name);
5822    
5823                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5824    
5825                    throw new NoSuchFolderException(msg.toString());
5826            }
5827    
5828            /**
5829             * Returns the first document library folder in the ordered set where parentFolderId = &#63; and name = &#63;.
5830             *
5831             * @param parentFolderId the parent folder ID
5832             * @param name the name
5833             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5834             * @return the first matching document library folder, or <code>null</code> if a matching document library folder could not be found
5835             */
5836            @Override
5837            public DLFolder fetchByP_N_First(long parentFolderId, String name,
5838                    OrderByComparator<DLFolder> orderByComparator) {
5839                    List<DLFolder> list = findByP_N(parentFolderId, name, 0, 1,
5840                                    orderByComparator);
5841    
5842                    if (!list.isEmpty()) {
5843                            return list.get(0);
5844                    }
5845    
5846                    return null;
5847            }
5848    
5849            /**
5850             * Returns the last document library folder in the ordered set where parentFolderId = &#63; and name = &#63;.
5851             *
5852             * @param parentFolderId the parent folder ID
5853             * @param name the name
5854             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5855             * @return the last matching document library folder
5856             * @throws NoSuchFolderException if a matching document library folder could not be found
5857             */
5858            @Override
5859            public DLFolder findByP_N_Last(long parentFolderId, String name,
5860                    OrderByComparator<DLFolder> orderByComparator)
5861                    throws NoSuchFolderException {
5862                    DLFolder dlFolder = fetchByP_N_Last(parentFolderId, name,
5863                                    orderByComparator);
5864    
5865                    if (dlFolder != null) {
5866                            return dlFolder;
5867                    }
5868    
5869                    StringBundler msg = new StringBundler(6);
5870    
5871                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5872    
5873                    msg.append("parentFolderId=");
5874                    msg.append(parentFolderId);
5875    
5876                    msg.append(", name=");
5877                    msg.append(name);
5878    
5879                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5880    
5881                    throw new NoSuchFolderException(msg.toString());
5882            }
5883    
5884            /**
5885             * Returns the last document library folder in the ordered set where parentFolderId = &#63; and name = &#63;.
5886             *
5887             * @param parentFolderId the parent folder ID
5888             * @param name the name
5889             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5890             * @return the last matching document library folder, or <code>null</code> if a matching document library folder could not be found
5891             */
5892            @Override
5893            public DLFolder fetchByP_N_Last(long parentFolderId, String name,
5894                    OrderByComparator<DLFolder> orderByComparator) {
5895                    int count = countByP_N(parentFolderId, name);
5896    
5897                    if (count == 0) {
5898                            return null;
5899                    }
5900    
5901                    List<DLFolder> list = findByP_N(parentFolderId, name, count - 1, count,
5902                                    orderByComparator);
5903    
5904                    if (!list.isEmpty()) {
5905                            return list.get(0);
5906                    }
5907    
5908                    return null;
5909            }
5910    
5911            /**
5912             * Returns the document library folders before and after the current document library folder in the ordered set where parentFolderId = &#63; and name = &#63;.
5913             *
5914             * @param folderId the primary key of the current document library folder
5915             * @param parentFolderId the parent folder ID
5916             * @param name the name
5917             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5918             * @return the previous, current, and next document library folder
5919             * @throws NoSuchFolderException if a document library folder with the primary key could not be found
5920             */
5921            @Override
5922            public DLFolder[] findByP_N_PrevAndNext(long folderId, long parentFolderId,
5923                    String name, OrderByComparator<DLFolder> orderByComparator)
5924                    throws NoSuchFolderException {
5925                    DLFolder dlFolder = findByPrimaryKey(folderId);
5926    
5927                    Session session = null;
5928    
5929                    try {
5930                            session = openSession();
5931    
5932                            DLFolder[] array = new DLFolderImpl[3];
5933    
5934                            array[0] = getByP_N_PrevAndNext(session, dlFolder, parentFolderId,
5935                                            name, orderByComparator, true);
5936    
5937                            array[1] = dlFolder;
5938    
5939                            array[2] = getByP_N_PrevAndNext(session, dlFolder, parentFolderId,
5940                                            name, orderByComparator, false);
5941    
5942                            return array;
5943                    }
5944                    catch (Exception e) {
5945                            throw processException(e);
5946                    }
5947                    finally {
5948                            closeSession(session);
5949                    }
5950            }
5951    
5952            protected DLFolder getByP_N_PrevAndNext(Session session, DLFolder dlFolder,
5953                    long parentFolderId, String name,
5954                    OrderByComparator<DLFolder> orderByComparator, boolean previous) {
5955                    StringBundler query = null;
5956    
5957                    if (orderByComparator != null) {
5958                            query = new StringBundler(5 +
5959                                            (orderByComparator.getOrderByConditionFields().length * 3) +
5960                                            (orderByComparator.getOrderByFields().length * 3));
5961                    }
5962                    else {
5963                            query = new StringBundler(4);
5964                    }
5965    
5966                    query.append(_SQL_SELECT_DLFOLDER_WHERE);
5967    
5968                    query.append(_FINDER_COLUMN_P_N_PARENTFOLDERID_2);
5969    
5970                    boolean bindName = false;
5971    
5972                    if (name == null) {
5973                            query.append(_FINDER_COLUMN_P_N_NAME_1);
5974                    }
5975                    else if (name.equals(StringPool.BLANK)) {
5976                            query.append(_FINDER_COLUMN_P_N_NAME_3);
5977                    }
5978                    else {
5979                            bindName = true;
5980    
5981                            query.append(_FINDER_COLUMN_P_N_NAME_2);
5982                    }
5983    
5984                    if (orderByComparator != null) {
5985                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5986    
5987                            if (orderByConditionFields.length > 0) {
5988                                    query.append(WHERE_AND);
5989                            }
5990    
5991                            for (int i = 0; i < orderByConditionFields.length; i++) {
5992                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5993                                    query.append(orderByConditionFields[i]);
5994    
5995                                    if ((i + 1) < orderByConditionFields.length) {
5996                                            if (orderByComparator.isAscending() ^ previous) {
5997                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5998                                            }
5999                                            else {
6000                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6001                                            }
6002                                    }
6003                                    else {
6004                                            if (orderByComparator.isAscending() ^ previous) {
6005                                                    query.append(WHERE_GREATER_THAN);
6006                                            }
6007                                            else {
6008                                                    query.append(WHERE_LESSER_THAN);
6009                                            }
6010                                    }
6011                            }
6012    
6013                            query.append(ORDER_BY_CLAUSE);
6014    
6015                            String[] orderByFields = orderByComparator.getOrderByFields();
6016    
6017                            for (int i = 0; i < orderByFields.length; i++) {
6018                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6019                                    query.append(orderByFields[i]);
6020    
6021                                    if ((i + 1) < orderByFields.length) {
6022                                            if (orderByComparator.isAscending() ^ previous) {
6023                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6024                                            }
6025                                            else {
6026                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6027                                            }
6028                                    }
6029                                    else {
6030                                            if (orderByComparator.isAscending() ^ previous) {
6031                                                    query.append(ORDER_BY_ASC);
6032                                            }
6033                                            else {
6034                                                    query.append(ORDER_BY_DESC);
6035                                            }
6036                                    }
6037                            }
6038                    }
6039                    else {
6040                            query.append(DLFolderModelImpl.ORDER_BY_JPQL);
6041                    }
6042    
6043                    String sql = query.toString();
6044    
6045                    Query q = session.createQuery(sql);
6046    
6047                    q.setFirstResult(0);
6048                    q.setMaxResults(2);
6049    
6050                    QueryPos qPos = QueryPos.getInstance(q);
6051    
6052                    qPos.add(parentFolderId);
6053    
6054                    if (bindName) {
6055                            qPos.add(name);
6056                    }
6057    
6058                    if (orderByComparator != null) {
6059                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
6060    
6061                            for (Object value : values) {
6062                                    qPos.add(value);
6063                            }
6064                    }
6065    
6066                    List<DLFolder> list = q.list();
6067    
6068                    if (list.size() == 2) {
6069                            return list.get(1);
6070                    }
6071                    else {
6072                            return null;
6073                    }
6074            }
6075    
6076            /**
6077             * Removes all the document library folders where parentFolderId = &#63; and name = &#63; from the database.
6078             *
6079             * @param parentFolderId the parent folder ID
6080             * @param name the name
6081             */
6082            @Override
6083            public void removeByP_N(long parentFolderId, String name) {
6084                    for (DLFolder dlFolder : findByP_N(parentFolderId, name,
6085                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
6086                            remove(dlFolder);
6087                    }
6088            }
6089    
6090            /**
6091             * Returns the number of document library folders where parentFolderId = &#63; and name = &#63;.
6092             *
6093             * @param parentFolderId the parent folder ID
6094             * @param name the name
6095             * @return the number of matching document library folders
6096             */
6097            @Override
6098            public int countByP_N(long parentFolderId, String name) {
6099                    FinderPath finderPath = FINDER_PATH_COUNT_BY_P_N;
6100    
6101                    Object[] finderArgs = new Object[] { parentFolderId, name };
6102    
6103                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
6104    
6105                    if (count == null) {
6106                            StringBundler query = new StringBundler(3);
6107    
6108                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
6109    
6110                            query.append(_FINDER_COLUMN_P_N_PARENTFOLDERID_2);
6111    
6112                            boolean bindName = false;
6113    
6114                            if (name == null) {
6115                                    query.append(_FINDER_COLUMN_P_N_NAME_1);
6116                            }
6117                            else if (name.equals(StringPool.BLANK)) {
6118                                    query.append(_FINDER_COLUMN_P_N_NAME_3);
6119                            }
6120                            else {
6121                                    bindName = true;
6122    
6123                                    query.append(_FINDER_COLUMN_P_N_NAME_2);
6124                            }
6125    
6126                            String sql = query.toString();
6127    
6128                            Session session = null;
6129    
6130                            try {
6131                                    session = openSession();
6132    
6133                                    Query q = session.createQuery(sql);
6134    
6135                                    QueryPos qPos = QueryPos.getInstance(q);
6136    
6137                                    qPos.add(parentFolderId);
6138    
6139                                    if (bindName) {
6140                                            qPos.add(name);
6141                                    }
6142    
6143                                    count = (Long)q.uniqueResult();
6144    
6145                                    finderCache.putResult(finderPath, finderArgs, count);
6146                            }
6147                            catch (Exception e) {
6148                                    finderCache.removeResult(finderPath, finderArgs);
6149    
6150                                    throw processException(e);
6151                            }
6152                            finally {
6153                                    closeSession(session);
6154                            }
6155                    }
6156    
6157                    return count.intValue();
6158            }
6159    
6160            private static final String _FINDER_COLUMN_P_N_PARENTFOLDERID_2 = "dlFolder.parentFolderId = ? AND ";
6161            private static final String _FINDER_COLUMN_P_N_NAME_1 = "dlFolder.name IS NULL";
6162            private static final String _FINDER_COLUMN_P_N_NAME_2 = "dlFolder.name = ?";
6163            private static final String _FINDER_COLUMN_P_N_NAME_3 = "(dlFolder.name IS NULL OR dlFolder.name = '')";
6164            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_M_P = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
6165                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
6166                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_M_P",
6167                            new String[] {
6168                                    Long.class.getName(), Boolean.class.getName(),
6169                                    Long.class.getName(),
6170                                    
6171                            Integer.class.getName(), Integer.class.getName(),
6172                                    OrderByComparator.class.getName()
6173                            });
6174            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
6175                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
6176                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_M_P",
6177                            new String[] {
6178                                    Long.class.getName(), Boolean.class.getName(),
6179                                    Long.class.getName()
6180                            },
6181                            DLFolderModelImpl.GROUPID_COLUMN_BITMASK |
6182                            DLFolderModelImpl.MOUNTPOINT_COLUMN_BITMASK |
6183                            DLFolderModelImpl.PARENTFOLDERID_COLUMN_BITMASK |
6184                            DLFolderModelImpl.NAME_COLUMN_BITMASK);
6185            public static final FinderPath FINDER_PATH_COUNT_BY_G_M_P = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
6186                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
6187                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_M_P",
6188                            new String[] {
6189                                    Long.class.getName(), Boolean.class.getName(),
6190                                    Long.class.getName()
6191                            });
6192    
6193            /**
6194             * Returns all the document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63;.
6195             *
6196             * @param groupId the group ID
6197             * @param mountPoint the mount point
6198             * @param parentFolderId the parent folder ID
6199             * @return the matching document library folders
6200             */
6201            @Override
6202            public List<DLFolder> findByG_M_P(long groupId, boolean mountPoint,
6203                    long parentFolderId) {
6204                    return findByG_M_P(groupId, mountPoint, parentFolderId,
6205                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
6206            }
6207    
6208            /**
6209             * Returns a range of all the document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63;.
6210             *
6211             * <p>
6212             * 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.
6213             * </p>
6214             *
6215             * @param groupId the group ID
6216             * @param mountPoint the mount point
6217             * @param parentFolderId the parent folder ID
6218             * @param start the lower bound of the range of document library folders
6219             * @param end the upper bound of the range of document library folders (not inclusive)
6220             * @return the range of matching document library folders
6221             */
6222            @Override
6223            public List<DLFolder> findByG_M_P(long groupId, boolean mountPoint,
6224                    long parentFolderId, int start, int end) {
6225                    return findByG_M_P(groupId, mountPoint, parentFolderId, start, end, null);
6226            }
6227    
6228            /**
6229             * Returns an ordered range of all the document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63;.
6230             *
6231             * <p>
6232             * 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.
6233             * </p>
6234             *
6235             * @param groupId the group ID
6236             * @param mountPoint the mount point
6237             * @param parentFolderId the parent folder ID
6238             * @param start the lower bound of the range of document library folders
6239             * @param end the upper bound of the range of document library folders (not inclusive)
6240             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6241             * @return the ordered range of matching document library folders
6242             */
6243            @Override
6244            public List<DLFolder> findByG_M_P(long groupId, boolean mountPoint,
6245                    long parentFolderId, int start, int end,
6246                    OrderByComparator<DLFolder> orderByComparator) {
6247                    return findByG_M_P(groupId, mountPoint, parentFolderId, start, end,
6248                            orderByComparator, true);
6249            }
6250    
6251            /**
6252             * Returns an ordered range of all the document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63;.
6253             *
6254             * <p>
6255             * 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.
6256             * </p>
6257             *
6258             * @param groupId the group ID
6259             * @param mountPoint the mount point
6260             * @param parentFolderId the parent folder ID
6261             * @param start the lower bound of the range of document library folders
6262             * @param end the upper bound of the range of document library folders (not inclusive)
6263             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6264             * @param retrieveFromCache whether to retrieve from the finder cache
6265             * @return the ordered range of matching document library folders
6266             */
6267            @Override
6268            public List<DLFolder> findByG_M_P(long groupId, boolean mountPoint,
6269                    long parentFolderId, int start, int end,
6270                    OrderByComparator<DLFolder> orderByComparator, boolean retrieveFromCache) {
6271                    boolean pagination = true;
6272                    FinderPath finderPath = null;
6273                    Object[] finderArgs = null;
6274    
6275                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6276                                    (orderByComparator == null)) {
6277                            pagination = false;
6278                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P;
6279                            finderArgs = new Object[] { groupId, mountPoint, parentFolderId };
6280                    }
6281                    else {
6282                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_M_P;
6283                            finderArgs = new Object[] {
6284                                            groupId, mountPoint, parentFolderId,
6285                                            
6286                                            start, end, orderByComparator
6287                                    };
6288                    }
6289    
6290                    List<DLFolder> list = null;
6291    
6292                    if (retrieveFromCache) {
6293                            list = (List<DLFolder>)finderCache.getResult(finderPath,
6294                                            finderArgs, this);
6295    
6296                            if ((list != null) && !list.isEmpty()) {
6297                                    for (DLFolder dlFolder : list) {
6298                                            if ((groupId != dlFolder.getGroupId()) ||
6299                                                            (mountPoint != dlFolder.getMountPoint()) ||
6300                                                            (parentFolderId != dlFolder.getParentFolderId())) {
6301                                                    list = null;
6302    
6303                                                    break;
6304                                            }
6305                                    }
6306                            }
6307                    }
6308    
6309                    if (list == null) {
6310                            StringBundler query = null;
6311    
6312                            if (orderByComparator != null) {
6313                                    query = new StringBundler(5 +
6314                                                    (orderByComparator.getOrderByFields().length * 2));
6315                            }
6316                            else {
6317                                    query = new StringBundler(5);
6318                            }
6319    
6320                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
6321    
6322                            query.append(_FINDER_COLUMN_G_M_P_GROUPID_2);
6323    
6324                            query.append(_FINDER_COLUMN_G_M_P_MOUNTPOINT_2);
6325    
6326                            query.append(_FINDER_COLUMN_G_M_P_PARENTFOLDERID_2);
6327    
6328                            if (orderByComparator != null) {
6329                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6330                                            orderByComparator);
6331                            }
6332                            else
6333                             if (pagination) {
6334                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
6335                            }
6336    
6337                            String sql = query.toString();
6338    
6339                            Session session = null;
6340    
6341                            try {
6342                                    session = openSession();
6343    
6344                                    Query q = session.createQuery(sql);
6345    
6346                                    QueryPos qPos = QueryPos.getInstance(q);
6347    
6348                                    qPos.add(groupId);
6349    
6350                                    qPos.add(mountPoint);
6351    
6352                                    qPos.add(parentFolderId);
6353    
6354                                    if (!pagination) {
6355                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
6356                                                            start, end, false);
6357    
6358                                            Collections.sort(list);
6359    
6360                                            list = Collections.unmodifiableList(list);
6361                                    }
6362                                    else {
6363                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
6364                                                            start, end);
6365                                    }
6366    
6367                                    cacheResult(list);
6368    
6369                                    finderCache.putResult(finderPath, finderArgs, list);
6370                            }
6371                            catch (Exception e) {
6372                                    finderCache.removeResult(finderPath, finderArgs);
6373    
6374                                    throw processException(e);
6375                            }
6376                            finally {
6377                                    closeSession(session);
6378                            }
6379                    }
6380    
6381                    return list;
6382            }
6383    
6384            /**
6385             * Returns the first document library folder in the ordered set where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63;.
6386             *
6387             * @param groupId the group ID
6388             * @param mountPoint the mount point
6389             * @param parentFolderId the parent folder ID
6390             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6391             * @return the first matching document library folder
6392             * @throws NoSuchFolderException if a matching document library folder could not be found
6393             */
6394            @Override
6395            public DLFolder findByG_M_P_First(long groupId, boolean mountPoint,
6396                    long parentFolderId, OrderByComparator<DLFolder> orderByComparator)
6397                    throws NoSuchFolderException {
6398                    DLFolder dlFolder = fetchByG_M_P_First(groupId, mountPoint,
6399                                    parentFolderId, orderByComparator);
6400    
6401                    if (dlFolder != null) {
6402                            return dlFolder;
6403                    }
6404    
6405                    StringBundler msg = new StringBundler(8);
6406    
6407                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6408    
6409                    msg.append("groupId=");
6410                    msg.append(groupId);
6411    
6412                    msg.append(", mountPoint=");
6413                    msg.append(mountPoint);
6414    
6415                    msg.append(", parentFolderId=");
6416                    msg.append(parentFolderId);
6417    
6418                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6419    
6420                    throw new NoSuchFolderException(msg.toString());
6421            }
6422    
6423            /**
6424             * Returns the first document library folder in the ordered set where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63;.
6425             *
6426             * @param groupId the group ID
6427             * @param mountPoint the mount point
6428             * @param parentFolderId the parent folder ID
6429             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6430             * @return the first matching document library folder, or <code>null</code> if a matching document library folder could not be found
6431             */
6432            @Override
6433            public DLFolder fetchByG_M_P_First(long groupId, boolean mountPoint,
6434                    long parentFolderId, OrderByComparator<DLFolder> orderByComparator) {
6435                    List<DLFolder> list = findByG_M_P(groupId, mountPoint, parentFolderId,
6436                                    0, 1, orderByComparator);
6437    
6438                    if (!list.isEmpty()) {
6439                            return list.get(0);
6440                    }
6441    
6442                    return null;
6443            }
6444    
6445            /**
6446             * Returns the last document library folder in the ordered set where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63;.
6447             *
6448             * @param groupId the group ID
6449             * @param mountPoint the mount point
6450             * @param parentFolderId the parent folder ID
6451             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6452             * @return the last matching document library folder
6453             * @throws NoSuchFolderException if a matching document library folder could not be found
6454             */
6455            @Override
6456            public DLFolder findByG_M_P_Last(long groupId, boolean mountPoint,
6457                    long parentFolderId, OrderByComparator<DLFolder> orderByComparator)
6458                    throws NoSuchFolderException {
6459                    DLFolder dlFolder = fetchByG_M_P_Last(groupId, mountPoint,
6460                                    parentFolderId, orderByComparator);
6461    
6462                    if (dlFolder != null) {
6463                            return dlFolder;
6464                    }
6465    
6466                    StringBundler msg = new StringBundler(8);
6467    
6468                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6469    
6470                    msg.append("groupId=");
6471                    msg.append(groupId);
6472    
6473                    msg.append(", mountPoint=");
6474                    msg.append(mountPoint);
6475    
6476                    msg.append(", parentFolderId=");
6477                    msg.append(parentFolderId);
6478    
6479                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6480    
6481                    throw new NoSuchFolderException(msg.toString());
6482            }
6483    
6484            /**
6485             * Returns the last document library folder in the ordered set where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63;.
6486             *
6487             * @param groupId the group ID
6488             * @param mountPoint the mount point
6489             * @param parentFolderId the parent folder ID
6490             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6491             * @return the last matching document library folder, or <code>null</code> if a matching document library folder could not be found
6492             */
6493            @Override
6494            public DLFolder fetchByG_M_P_Last(long groupId, boolean mountPoint,
6495                    long parentFolderId, OrderByComparator<DLFolder> orderByComparator) {
6496                    int count = countByG_M_P(groupId, mountPoint, parentFolderId);
6497    
6498                    if (count == 0) {
6499                            return null;
6500                    }
6501    
6502                    List<DLFolder> list = findByG_M_P(groupId, mountPoint, parentFolderId,
6503                                    count - 1, count, orderByComparator);
6504    
6505                    if (!list.isEmpty()) {
6506                            return list.get(0);
6507                    }
6508    
6509                    return null;
6510            }
6511    
6512            /**
6513             * 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;.
6514             *
6515             * @param folderId the primary key of the current document library folder
6516             * @param groupId the group ID
6517             * @param mountPoint the mount point
6518             * @param parentFolderId the parent folder ID
6519             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6520             * @return the previous, current, and next document library folder
6521             * @throws NoSuchFolderException if a document library folder with the primary key could not be found
6522             */
6523            @Override
6524            public DLFolder[] findByG_M_P_PrevAndNext(long folderId, long groupId,
6525                    boolean mountPoint, long parentFolderId,
6526                    OrderByComparator<DLFolder> orderByComparator)
6527                    throws NoSuchFolderException {
6528                    DLFolder dlFolder = findByPrimaryKey(folderId);
6529    
6530                    Session session = null;
6531    
6532                    try {
6533                            session = openSession();
6534    
6535                            DLFolder[] array = new DLFolderImpl[3];
6536    
6537                            array[0] = getByG_M_P_PrevAndNext(session, dlFolder, groupId,
6538                                            mountPoint, parentFolderId, orderByComparator, true);
6539    
6540                            array[1] = dlFolder;
6541    
6542                            array[2] = getByG_M_P_PrevAndNext(session, dlFolder, groupId,
6543                                            mountPoint, parentFolderId, orderByComparator, false);
6544    
6545                            return array;
6546                    }
6547                    catch (Exception e) {
6548                            throw processException(e);
6549                    }
6550                    finally {
6551                            closeSession(session);
6552                    }
6553            }
6554    
6555            protected DLFolder getByG_M_P_PrevAndNext(Session session,
6556                    DLFolder dlFolder, long groupId, boolean mountPoint,
6557                    long parentFolderId, OrderByComparator<DLFolder> orderByComparator,
6558                    boolean previous) {
6559                    StringBundler query = null;
6560    
6561                    if (orderByComparator != null) {
6562                            query = new StringBundler(6 +
6563                                            (orderByComparator.getOrderByConditionFields().length * 3) +
6564                                            (orderByComparator.getOrderByFields().length * 3));
6565                    }
6566                    else {
6567                            query = new StringBundler(5);
6568                    }
6569    
6570                    query.append(_SQL_SELECT_DLFOLDER_WHERE);
6571    
6572                    query.append(_FINDER_COLUMN_G_M_P_GROUPID_2);
6573    
6574                    query.append(_FINDER_COLUMN_G_M_P_MOUNTPOINT_2);
6575    
6576                    query.append(_FINDER_COLUMN_G_M_P_PARENTFOLDERID_2);
6577    
6578                    if (orderByComparator != null) {
6579                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6580    
6581                            if (orderByConditionFields.length > 0) {
6582                                    query.append(WHERE_AND);
6583                            }
6584    
6585                            for (int i = 0; i < orderByConditionFields.length; i++) {
6586                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6587                                    query.append(orderByConditionFields[i]);
6588    
6589                                    if ((i + 1) < orderByConditionFields.length) {
6590                                            if (orderByComparator.isAscending() ^ previous) {
6591                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6592                                            }
6593                                            else {
6594                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6595                                            }
6596                                    }
6597                                    else {
6598                                            if (orderByComparator.isAscending() ^ previous) {
6599                                                    query.append(WHERE_GREATER_THAN);
6600                                            }
6601                                            else {
6602                                                    query.append(WHERE_LESSER_THAN);
6603                                            }
6604                                    }
6605                            }
6606    
6607                            query.append(ORDER_BY_CLAUSE);
6608    
6609                            String[] orderByFields = orderByComparator.getOrderByFields();
6610    
6611                            for (int i = 0; i < orderByFields.length; i++) {
6612                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6613                                    query.append(orderByFields[i]);
6614    
6615                                    if ((i + 1) < orderByFields.length) {
6616                                            if (orderByComparator.isAscending() ^ previous) {
6617                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6618                                            }
6619                                            else {
6620                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6621                                            }
6622                                    }
6623                                    else {
6624                                            if (orderByComparator.isAscending() ^ previous) {
6625                                                    query.append(ORDER_BY_ASC);
6626                                            }
6627                                            else {
6628                                                    query.append(ORDER_BY_DESC);
6629                                            }
6630                                    }
6631                            }
6632                    }
6633                    else {
6634                            query.append(DLFolderModelImpl.ORDER_BY_JPQL);
6635                    }
6636    
6637                    String sql = query.toString();
6638    
6639                    Query q = session.createQuery(sql);
6640    
6641                    q.setFirstResult(0);
6642                    q.setMaxResults(2);
6643    
6644                    QueryPos qPos = QueryPos.getInstance(q);
6645    
6646                    qPos.add(groupId);
6647    
6648                    qPos.add(mountPoint);
6649    
6650                    qPos.add(parentFolderId);
6651    
6652                    if (orderByComparator != null) {
6653                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
6654    
6655                            for (Object value : values) {
6656                                    qPos.add(value);
6657                            }
6658                    }
6659    
6660                    List<DLFolder> list = q.list();
6661    
6662                    if (list.size() == 2) {
6663                            return list.get(1);
6664                    }
6665                    else {
6666                            return null;
6667                    }
6668            }
6669    
6670            /**
6671             * Returns all the document library folders that the user has permission to view where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63;.
6672             *
6673             * @param groupId the group ID
6674             * @param mountPoint the mount point
6675             * @param parentFolderId the parent folder ID
6676             * @return the matching document library folders that the user has permission to view
6677             */
6678            @Override
6679            public List<DLFolder> filterFindByG_M_P(long groupId, boolean mountPoint,
6680                    long parentFolderId) {
6681                    return filterFindByG_M_P(groupId, mountPoint, parentFolderId,
6682                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
6683            }
6684    
6685            /**
6686             * 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;.
6687             *
6688             * <p>
6689             * 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.
6690             * </p>
6691             *
6692             * @param groupId the group ID
6693             * @param mountPoint the mount point
6694             * @param parentFolderId the parent folder ID
6695             * @param start the lower bound of the range of document library folders
6696             * @param end the upper bound of the range of document library folders (not inclusive)
6697             * @return the range of matching document library folders that the user has permission to view
6698             */
6699            @Override
6700            public List<DLFolder> filterFindByG_M_P(long groupId, boolean mountPoint,
6701                    long parentFolderId, int start, int end) {
6702                    return filterFindByG_M_P(groupId, mountPoint, parentFolderId, start,
6703                            end, null);
6704            }
6705    
6706            /**
6707             * 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;.
6708             *
6709             * <p>
6710             * 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.
6711             * </p>
6712             *
6713             * @param groupId the group ID
6714             * @param mountPoint the mount point
6715             * @param parentFolderId the parent folder ID
6716             * @param start the lower bound of the range of document library folders
6717             * @param end the upper bound of the range of document library folders (not inclusive)
6718             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6719             * @return the ordered range of matching document library folders that the user has permission to view
6720             */
6721            @Override
6722            public List<DLFolder> filterFindByG_M_P(long groupId, boolean mountPoint,
6723                    long parentFolderId, int start, int end,
6724                    OrderByComparator<DLFolder> orderByComparator) {
6725                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6726                            return findByG_M_P(groupId, mountPoint, parentFolderId, start, end,
6727                                    orderByComparator);
6728                    }
6729    
6730                    StringBundler query = null;
6731    
6732                    if (orderByComparator != null) {
6733                            query = new StringBundler(5 +
6734                                            (orderByComparator.getOrderByFields().length * 2));
6735                    }
6736                    else {
6737                            query = new StringBundler(6);
6738                    }
6739    
6740                    if (getDB().isSupportsInlineDistinct()) {
6741                            query.append(_FILTER_SQL_SELECT_DLFOLDER_WHERE);
6742                    }
6743                    else {
6744                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1);
6745                    }
6746    
6747                    query.append(_FINDER_COLUMN_G_M_P_GROUPID_2);
6748    
6749                    query.append(_FINDER_COLUMN_G_M_P_MOUNTPOINT_2);
6750    
6751                    query.append(_FINDER_COLUMN_G_M_P_PARENTFOLDERID_2);
6752    
6753                    if (!getDB().isSupportsInlineDistinct()) {
6754                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2);
6755                    }
6756    
6757                    if (orderByComparator != null) {
6758                            if (getDB().isSupportsInlineDistinct()) {
6759                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6760                                            orderByComparator, true);
6761                            }
6762                            else {
6763                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
6764                                            orderByComparator, true);
6765                            }
6766                    }
6767                    else {
6768                            if (getDB().isSupportsInlineDistinct()) {
6769                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
6770                            }
6771                            else {
6772                                    query.append(DLFolderModelImpl.ORDER_BY_SQL);
6773                            }
6774                    }
6775    
6776                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6777                                    DLFolder.class.getName(),
6778                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6779    
6780                    Session session = null;
6781    
6782                    try {
6783                            session = openSession();
6784    
6785                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
6786    
6787                            if (getDB().isSupportsInlineDistinct()) {
6788                                    q.addEntity(_FILTER_ENTITY_ALIAS, DLFolderImpl.class);
6789                            }
6790                            else {
6791                                    q.addEntity(_FILTER_ENTITY_TABLE, DLFolderImpl.class);
6792                            }
6793    
6794                            QueryPos qPos = QueryPos.getInstance(q);
6795    
6796                            qPos.add(groupId);
6797    
6798                            qPos.add(mountPoint);
6799    
6800                            qPos.add(parentFolderId);
6801    
6802                            return (List<DLFolder>)QueryUtil.list(q, getDialect(), start, end);
6803                    }
6804                    catch (Exception e) {
6805                            throw processException(e);
6806                    }
6807                    finally {
6808                            closeSession(session);
6809                    }
6810            }
6811    
6812            /**
6813             * 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;.
6814             *
6815             * @param folderId the primary key of the current document library folder
6816             * @param groupId the group ID
6817             * @param mountPoint the mount point
6818             * @param parentFolderId the parent folder ID
6819             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6820             * @return the previous, current, and next document library folder
6821             * @throws NoSuchFolderException if a document library folder with the primary key could not be found
6822             */
6823            @Override
6824            public DLFolder[] filterFindByG_M_P_PrevAndNext(long folderId,
6825                    long groupId, boolean mountPoint, long parentFolderId,
6826                    OrderByComparator<DLFolder> orderByComparator)
6827                    throws NoSuchFolderException {
6828                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6829                            return findByG_M_P_PrevAndNext(folderId, groupId, mountPoint,
6830                                    parentFolderId, orderByComparator);
6831                    }
6832    
6833                    DLFolder dlFolder = findByPrimaryKey(folderId);
6834    
6835                    Session session = null;
6836    
6837                    try {
6838                            session = openSession();
6839    
6840                            DLFolder[] array = new DLFolderImpl[3];
6841    
6842                            array[0] = filterGetByG_M_P_PrevAndNext(session, dlFolder, groupId,
6843                                            mountPoint, parentFolderId, orderByComparator, true);
6844    
6845                            array[1] = dlFolder;
6846    
6847                            array[2] = filterGetByG_M_P_PrevAndNext(session, dlFolder, groupId,
6848                                            mountPoint, parentFolderId, orderByComparator, false);
6849    
6850                            return array;
6851                    }
6852                    catch (Exception e) {
6853                            throw processException(e);
6854                    }
6855                    finally {
6856                            closeSession(session);
6857                    }
6858            }
6859    
6860            protected DLFolder filterGetByG_M_P_PrevAndNext(Session session,
6861                    DLFolder dlFolder, long groupId, boolean mountPoint,
6862                    long parentFolderId, OrderByComparator<DLFolder> orderByComparator,
6863                    boolean previous) {
6864                    StringBundler query = null;
6865    
6866                    if (orderByComparator != null) {
6867                            query = new StringBundler(7 +
6868                                            (orderByComparator.getOrderByConditionFields().length * 3) +
6869                                            (orderByComparator.getOrderByFields().length * 3));
6870                    }
6871                    else {
6872                            query = new StringBundler(6);
6873                    }
6874    
6875                    if (getDB().isSupportsInlineDistinct()) {
6876                            query.append(_FILTER_SQL_SELECT_DLFOLDER_WHERE);
6877                    }
6878                    else {
6879                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1);
6880                    }
6881    
6882                    query.append(_FINDER_COLUMN_G_M_P_GROUPID_2);
6883    
6884                    query.append(_FINDER_COLUMN_G_M_P_MOUNTPOINT_2);
6885    
6886                    query.append(_FINDER_COLUMN_G_M_P_PARENTFOLDERID_2);
6887    
6888                    if (!getDB().isSupportsInlineDistinct()) {
6889                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2);
6890                    }
6891    
6892                    if (orderByComparator != null) {
6893                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6894    
6895                            if (orderByConditionFields.length > 0) {
6896                                    query.append(WHERE_AND);
6897                            }
6898    
6899                            for (int i = 0; i < orderByConditionFields.length; i++) {
6900                                    if (getDB().isSupportsInlineDistinct()) {
6901                                            query.append(_ORDER_BY_ENTITY_ALIAS);
6902                                    }
6903                                    else {
6904                                            query.append(_ORDER_BY_ENTITY_TABLE);
6905                                    }
6906    
6907                                    query.append(orderByConditionFields[i]);
6908    
6909                                    if ((i + 1) < orderByConditionFields.length) {
6910                                            if (orderByComparator.isAscending() ^ previous) {
6911                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6912                                            }
6913                                            else {
6914                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6915                                            }
6916                                    }
6917                                    else {
6918                                            if (orderByComparator.isAscending() ^ previous) {
6919                                                    query.append(WHERE_GREATER_THAN);
6920                                            }
6921                                            else {
6922                                                    query.append(WHERE_LESSER_THAN);
6923                                            }
6924                                    }
6925                            }
6926    
6927                            query.append(ORDER_BY_CLAUSE);
6928    
6929                            String[] orderByFields = orderByComparator.getOrderByFields();
6930    
6931                            for (int i = 0; i < orderByFields.length; i++) {
6932                                    if (getDB().isSupportsInlineDistinct()) {
6933                                            query.append(_ORDER_BY_ENTITY_ALIAS);
6934                                    }
6935                                    else {
6936                                            query.append(_ORDER_BY_ENTITY_TABLE);
6937                                    }
6938    
6939                                    query.append(orderByFields[i]);
6940    
6941                                    if ((i + 1) < orderByFields.length) {
6942                                            if (orderByComparator.isAscending() ^ previous) {
6943                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6944                                            }
6945                                            else {
6946                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6947                                            }
6948                                    }
6949                                    else {
6950                                            if (orderByComparator.isAscending() ^ previous) {
6951                                                    query.append(ORDER_BY_ASC);
6952                                            }
6953                                            else {
6954                                                    query.append(ORDER_BY_DESC);
6955                                            }
6956                                    }
6957                            }
6958                    }
6959                    else {
6960                            if (getDB().isSupportsInlineDistinct()) {
6961                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
6962                            }
6963                            else {
6964                                    query.append(DLFolderModelImpl.ORDER_BY_SQL);
6965                            }
6966                    }
6967    
6968                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6969                                    DLFolder.class.getName(),
6970                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6971    
6972                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
6973    
6974                    q.setFirstResult(0);
6975                    q.setMaxResults(2);
6976    
6977                    if (getDB().isSupportsInlineDistinct()) {
6978                            q.addEntity(_FILTER_ENTITY_ALIAS, DLFolderImpl.class);
6979                    }
6980                    else {
6981                            q.addEntity(_FILTER_ENTITY_TABLE, DLFolderImpl.class);
6982                    }
6983    
6984                    QueryPos qPos = QueryPos.getInstance(q);
6985    
6986                    qPos.add(groupId);
6987    
6988                    qPos.add(mountPoint);
6989    
6990                    qPos.add(parentFolderId);
6991    
6992                    if (orderByComparator != null) {
6993                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
6994    
6995                            for (Object value : values) {
6996                                    qPos.add(value);
6997                            }
6998                    }
6999    
7000                    List<DLFolder> list = q.list();
7001    
7002                    if (list.size() == 2) {
7003                            return list.get(1);
7004                    }
7005                    else {
7006                            return null;
7007                    }
7008            }
7009    
7010            /**
7011             * Removes all the document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; from the database.
7012             *
7013             * @param groupId the group ID
7014             * @param mountPoint the mount point
7015             * @param parentFolderId the parent folder ID
7016             */
7017            @Override
7018            public void removeByG_M_P(long groupId, boolean mountPoint,
7019                    long parentFolderId) {
7020                    for (DLFolder dlFolder : findByG_M_P(groupId, mountPoint,
7021                                    parentFolderId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
7022                            remove(dlFolder);
7023                    }
7024            }
7025    
7026            /**
7027             * Returns the number of document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63;.
7028             *
7029             * @param groupId the group ID
7030             * @param mountPoint the mount point
7031             * @param parentFolderId the parent folder ID
7032             * @return the number of matching document library folders
7033             */
7034            @Override
7035            public int countByG_M_P(long groupId, boolean mountPoint,
7036                    long parentFolderId) {
7037                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_M_P;
7038    
7039                    Object[] finderArgs = new Object[] { groupId, mountPoint, parentFolderId };
7040    
7041                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
7042    
7043                    if (count == null) {
7044                            StringBundler query = new StringBundler(4);
7045    
7046                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
7047    
7048                            query.append(_FINDER_COLUMN_G_M_P_GROUPID_2);
7049    
7050                            query.append(_FINDER_COLUMN_G_M_P_MOUNTPOINT_2);
7051    
7052                            query.append(_FINDER_COLUMN_G_M_P_PARENTFOLDERID_2);
7053    
7054                            String sql = query.toString();
7055    
7056                            Session session = null;
7057    
7058                            try {
7059                                    session = openSession();
7060    
7061                                    Query q = session.createQuery(sql);
7062    
7063                                    QueryPos qPos = QueryPos.getInstance(q);
7064    
7065                                    qPos.add(groupId);
7066    
7067                                    qPos.add(mountPoint);
7068    
7069                                    qPos.add(parentFolderId);
7070    
7071                                    count = (Long)q.uniqueResult();
7072    
7073                                    finderCache.putResult(finderPath, finderArgs, count);
7074                            }
7075                            catch (Exception e) {
7076                                    finderCache.removeResult(finderPath, finderArgs);
7077    
7078                                    throw processException(e);
7079                            }
7080                            finally {
7081                                    closeSession(session);
7082                            }
7083                    }
7084    
7085                    return count.intValue();
7086            }
7087    
7088            /**
7089             * Returns the number of document library folders that the user has permission to view where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63;.
7090             *
7091             * @param groupId the group ID
7092             * @param mountPoint the mount point
7093             * @param parentFolderId the parent folder ID
7094             * @return the number of matching document library folders that the user has permission to view
7095             */
7096            @Override
7097            public int filterCountByG_M_P(long groupId, boolean mountPoint,
7098                    long parentFolderId) {
7099                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7100                            return countByG_M_P(groupId, mountPoint, parentFolderId);
7101                    }
7102    
7103                    StringBundler query = new StringBundler(4);
7104    
7105                    query.append(_FILTER_SQL_COUNT_DLFOLDER_WHERE);
7106    
7107                    query.append(_FINDER_COLUMN_G_M_P_GROUPID_2);
7108    
7109                    query.append(_FINDER_COLUMN_G_M_P_MOUNTPOINT_2);
7110    
7111                    query.append(_FINDER_COLUMN_G_M_P_PARENTFOLDERID_2);
7112    
7113                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7114                                    DLFolder.class.getName(),
7115                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7116    
7117                    Session session = null;
7118    
7119                    try {
7120                            session = openSession();
7121    
7122                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
7123    
7124                            q.addScalar(COUNT_COLUMN_NAME,
7125                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
7126    
7127                            QueryPos qPos = QueryPos.getInstance(q);
7128    
7129                            qPos.add(groupId);
7130    
7131                            qPos.add(mountPoint);
7132    
7133                            qPos.add(parentFolderId);
7134    
7135                            Long count = (Long)q.uniqueResult();
7136    
7137                            return count.intValue();
7138                    }
7139                    catch (Exception e) {
7140                            throw processException(e);
7141                    }
7142                    finally {
7143                            closeSession(session);
7144                    }
7145            }
7146    
7147            private static final String _FINDER_COLUMN_G_M_P_GROUPID_2 = "dlFolder.groupId = ? AND ";
7148            private static final String _FINDER_COLUMN_G_M_P_MOUNTPOINT_2 = "dlFolder.mountPoint = ? AND ";
7149            private static final String _FINDER_COLUMN_G_M_P_PARENTFOLDERID_2 = "dlFolder.parentFolderId = ?";
7150            public static final FinderPath FINDER_PATH_FETCH_BY_G_P_N = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
7151                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
7152                            FINDER_CLASS_NAME_ENTITY, "fetchByG_P_N",
7153                            new String[] {
7154                                    Long.class.getName(), Long.class.getName(),
7155                                    String.class.getName()
7156                            },
7157                            DLFolderModelImpl.GROUPID_COLUMN_BITMASK |
7158                            DLFolderModelImpl.PARENTFOLDERID_COLUMN_BITMASK |
7159                            DLFolderModelImpl.NAME_COLUMN_BITMASK);
7160            public static final FinderPath FINDER_PATH_COUNT_BY_G_P_N = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
7161                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
7162                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P_N",
7163                            new String[] {
7164                                    Long.class.getName(), Long.class.getName(),
7165                                    String.class.getName()
7166                            });
7167    
7168            /**
7169             * 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.
7170             *
7171             * @param groupId the group ID
7172             * @param parentFolderId the parent folder ID
7173             * @param name the name
7174             * @return the matching document library folder
7175             * @throws NoSuchFolderException if a matching document library folder could not be found
7176             */
7177            @Override
7178            public DLFolder findByG_P_N(long groupId, long parentFolderId, String name)
7179                    throws NoSuchFolderException {
7180                    DLFolder dlFolder = fetchByG_P_N(groupId, parentFolderId, name);
7181    
7182                    if (dlFolder == null) {
7183                            StringBundler msg = new StringBundler(8);
7184    
7185                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7186    
7187                            msg.append("groupId=");
7188                            msg.append(groupId);
7189    
7190                            msg.append(", parentFolderId=");
7191                            msg.append(parentFolderId);
7192    
7193                            msg.append(", name=");
7194                            msg.append(name);
7195    
7196                            msg.append(StringPool.CLOSE_CURLY_BRACE);
7197    
7198                            if (_log.isWarnEnabled()) {
7199                                    _log.warn(msg.toString());
7200                            }
7201    
7202                            throw new NoSuchFolderException(msg.toString());
7203                    }
7204    
7205                    return dlFolder;
7206            }
7207    
7208            /**
7209             * 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.
7210             *
7211             * @param groupId the group ID
7212             * @param parentFolderId the parent folder ID
7213             * @param name the name
7214             * @return the matching document library folder, or <code>null</code> if a matching document library folder could not be found
7215             */
7216            @Override
7217            public DLFolder fetchByG_P_N(long groupId, long parentFolderId, String name) {
7218                    return fetchByG_P_N(groupId, parentFolderId, name, true);
7219            }
7220    
7221            /**
7222             * 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.
7223             *
7224             * @param groupId the group ID
7225             * @param parentFolderId the parent folder ID
7226             * @param name the name
7227             * @param retrieveFromCache whether to retrieve from the finder cache
7228             * @return the matching document library folder, or <code>null</code> if a matching document library folder could not be found
7229             */
7230            @Override
7231            public DLFolder fetchByG_P_N(long groupId, long parentFolderId,
7232                    String name, boolean retrieveFromCache) {
7233                    Object[] finderArgs = new Object[] { groupId, parentFolderId, name };
7234    
7235                    Object result = null;
7236    
7237                    if (retrieveFromCache) {
7238                            result = finderCache.getResult(FINDER_PATH_FETCH_BY_G_P_N,
7239                                            finderArgs, this);
7240                    }
7241    
7242                    if (result instanceof DLFolder) {
7243                            DLFolder dlFolder = (DLFolder)result;
7244    
7245                            if ((groupId != dlFolder.getGroupId()) ||
7246                                            (parentFolderId != dlFolder.getParentFolderId()) ||
7247                                            !Validator.equals(name, dlFolder.getName())) {
7248                                    result = null;
7249                            }
7250                    }
7251    
7252                    if (result == null) {
7253                            StringBundler query = new StringBundler(5);
7254    
7255                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
7256    
7257                            query.append(_FINDER_COLUMN_G_P_N_GROUPID_2);
7258    
7259                            query.append(_FINDER_COLUMN_G_P_N_PARENTFOLDERID_2);
7260    
7261                            boolean bindName = false;
7262    
7263                            if (name == null) {
7264                                    query.append(_FINDER_COLUMN_G_P_N_NAME_1);
7265                            }
7266                            else if (name.equals(StringPool.BLANK)) {
7267                                    query.append(_FINDER_COLUMN_G_P_N_NAME_3);
7268                            }
7269                            else {
7270                                    bindName = true;
7271    
7272                                    query.append(_FINDER_COLUMN_G_P_N_NAME_2);
7273                            }
7274    
7275                            String sql = query.toString();
7276    
7277                            Session session = null;
7278    
7279                            try {
7280                                    session = openSession();
7281    
7282                                    Query q = session.createQuery(sql);
7283    
7284                                    QueryPos qPos = QueryPos.getInstance(q);
7285    
7286                                    qPos.add(groupId);
7287    
7288                                    qPos.add(parentFolderId);
7289    
7290                                    if (bindName) {
7291                                            qPos.add(name);
7292                                    }
7293    
7294                                    List<DLFolder> list = q.list();
7295    
7296                                    if (list.isEmpty()) {
7297                                            finderCache.putResult(FINDER_PATH_FETCH_BY_G_P_N,
7298                                                    finderArgs, list);
7299                                    }
7300                                    else {
7301                                            DLFolder dlFolder = list.get(0);
7302    
7303                                            result = dlFolder;
7304    
7305                                            cacheResult(dlFolder);
7306    
7307                                            if ((dlFolder.getGroupId() != groupId) ||
7308                                                            (dlFolder.getParentFolderId() != parentFolderId) ||
7309                                                            (dlFolder.getName() == null) ||
7310                                                            !dlFolder.getName().equals(name)) {
7311                                                    finderCache.putResult(FINDER_PATH_FETCH_BY_G_P_N,
7312                                                            finderArgs, dlFolder);
7313                                            }
7314                                    }
7315                            }
7316                            catch (Exception e) {
7317                                    finderCache.removeResult(FINDER_PATH_FETCH_BY_G_P_N, finderArgs);
7318    
7319                                    throw processException(e);
7320                            }
7321                            finally {
7322                                    closeSession(session);
7323                            }
7324                    }
7325    
7326                    if (result instanceof List<?>) {
7327                            return null;
7328                    }
7329                    else {
7330                            return (DLFolder)result;
7331                    }
7332            }
7333    
7334            /**
7335             * Removes the document library folder where groupId = &#63; and parentFolderId = &#63; and name = &#63; from the database.
7336             *
7337             * @param groupId the group ID
7338             * @param parentFolderId the parent folder ID
7339             * @param name the name
7340             * @return the document library folder that was removed
7341             */
7342            @Override
7343            public DLFolder removeByG_P_N(long groupId, long parentFolderId, String name)
7344                    throws NoSuchFolderException {
7345                    DLFolder dlFolder = findByG_P_N(groupId, parentFolderId, name);
7346    
7347                    return remove(dlFolder);
7348            }
7349    
7350            /**
7351             * Returns the number of document library folders where groupId = &#63; and parentFolderId = &#63; and name = &#63;.
7352             *
7353             * @param groupId the group ID
7354             * @param parentFolderId the parent folder ID
7355             * @param name the name
7356             * @return the number of matching document library folders
7357             */
7358            @Override
7359            public int countByG_P_N(long groupId, long parentFolderId, String name) {
7360                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_P_N;
7361    
7362                    Object[] finderArgs = new Object[] { groupId, parentFolderId, name };
7363    
7364                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
7365    
7366                    if (count == null) {
7367                            StringBundler query = new StringBundler(4);
7368    
7369                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
7370    
7371                            query.append(_FINDER_COLUMN_G_P_N_GROUPID_2);
7372    
7373                            query.append(_FINDER_COLUMN_G_P_N_PARENTFOLDERID_2);
7374    
7375                            boolean bindName = false;
7376    
7377                            if (name == null) {
7378                                    query.append(_FINDER_COLUMN_G_P_N_NAME_1);
7379                            }
7380                            else if (name.equals(StringPool.BLANK)) {
7381                                    query.append(_FINDER_COLUMN_G_P_N_NAME_3);
7382                            }
7383                            else {
7384                                    bindName = true;
7385    
7386                                    query.append(_FINDER_COLUMN_G_P_N_NAME_2);
7387                            }
7388    
7389                            String sql = query.toString();
7390    
7391                            Session session = null;
7392    
7393                            try {
7394                                    session = openSession();
7395    
7396                                    Query q = session.createQuery(sql);
7397    
7398                                    QueryPos qPos = QueryPos.getInstance(q);
7399    
7400                                    qPos.add(groupId);
7401    
7402                                    qPos.add(parentFolderId);
7403    
7404                                    if (bindName) {
7405                                            qPos.add(name);
7406                                    }
7407    
7408                                    count = (Long)q.uniqueResult();
7409    
7410                                    finderCache.putResult(finderPath, finderArgs, count);
7411                            }
7412                            catch (Exception e) {
7413                                    finderCache.removeResult(finderPath, finderArgs);
7414    
7415                                    throw processException(e);
7416                            }
7417                            finally {
7418                                    closeSession(session);
7419                            }
7420                    }
7421    
7422                    return count.intValue();
7423            }
7424    
7425            private static final String _FINDER_COLUMN_G_P_N_GROUPID_2 = "dlFolder.groupId = ? AND ";
7426            private static final String _FINDER_COLUMN_G_P_N_PARENTFOLDERID_2 = "dlFolder.parentFolderId = ? AND ";
7427            private static final String _FINDER_COLUMN_G_P_N_NAME_1 = "dlFolder.name IS NULL";
7428            private static final String _FINDER_COLUMN_G_P_N_NAME_2 = "dlFolder.name = ?";
7429            private static final String _FINDER_COLUMN_G_P_N_NAME_3 = "(dlFolder.name IS NULL OR dlFolder.name = '')";
7430            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_F_C_P_NOTS =
7431                    new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
7432                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
7433                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByF_C_P_NotS",
7434                            new String[] {
7435                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
7436                                    Integer.class.getName(),
7437                                    
7438                            Integer.class.getName(), Integer.class.getName(),
7439                                    OrderByComparator.class.getName()
7440                            });
7441            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_F_C_P_NOTS =
7442                    new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
7443                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
7444                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByF_C_P_NotS",
7445                            new String[] {
7446                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
7447                                    Integer.class.getName()
7448                            });
7449    
7450            /**
7451             * Returns all the document library folders where folderId &gt; &#63; and companyId = &#63; and parentFolderId = &#63; and status &ne; &#63;.
7452             *
7453             * @param folderId the folder ID
7454             * @param companyId the company ID
7455             * @param parentFolderId the parent folder ID
7456             * @param status the status
7457             * @return the matching document library folders
7458             */
7459            @Override
7460            public List<DLFolder> findByF_C_P_NotS(long folderId, long companyId,
7461                    long parentFolderId, int status) {
7462                    return findByF_C_P_NotS(folderId, companyId, parentFolderId, status,
7463                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
7464            }
7465    
7466            /**
7467             * Returns a range of all the document library folders where folderId &gt; &#63; and companyId = &#63; and parentFolderId = &#63; and status &ne; &#63;.
7468             *
7469             * <p>
7470             * 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.
7471             * </p>
7472             *
7473             * @param folderId the folder ID
7474             * @param companyId the company ID
7475             * @param parentFolderId the parent folder ID
7476             * @param status the status
7477             * @param start the lower bound of the range of document library folders
7478             * @param end the upper bound of the range of document library folders (not inclusive)
7479             * @return the range of matching document library folders
7480             */
7481            @Override
7482            public List<DLFolder> findByF_C_P_NotS(long folderId, long companyId,
7483                    long parentFolderId, int status, int start, int end) {
7484                    return findByF_C_P_NotS(folderId, companyId, parentFolderId, status,
7485                            start, end, null);
7486            }
7487    
7488            /**
7489             * Returns an ordered range of all the document library folders where folderId &gt; &#63; and companyId = &#63; and parentFolderId = &#63; and status &ne; &#63;.
7490             *
7491             * <p>
7492             * 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.
7493             * </p>
7494             *
7495             * @param folderId the folder ID
7496             * @param companyId the company ID
7497             * @param parentFolderId the parent folder ID
7498             * @param status the status
7499             * @param start the lower bound of the range of document library folders
7500             * @param end the upper bound of the range of document library folders (not inclusive)
7501             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7502             * @return the ordered range of matching document library folders
7503             */
7504            @Override
7505            public List<DLFolder> findByF_C_P_NotS(long folderId, long companyId,
7506                    long parentFolderId, int status, int start, int end,
7507                    OrderByComparator<DLFolder> orderByComparator) {
7508                    return findByF_C_P_NotS(folderId, companyId, parentFolderId, status,
7509                            start, end, orderByComparator, true);
7510            }
7511    
7512            /**
7513             * Returns an ordered range of all the document library folders where folderId &gt; &#63; and companyId = &#63; and parentFolderId = &#63; and status &ne; &#63;.
7514             *
7515             * <p>
7516             * 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.
7517             * </p>
7518             *
7519             * @param folderId the folder ID
7520             * @param companyId the company ID
7521             * @param parentFolderId the parent folder ID
7522             * @param status the status
7523             * @param start the lower bound of the range of document library folders
7524             * @param end the upper bound of the range of document library folders (not inclusive)
7525             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7526             * @param retrieveFromCache whether to retrieve from the finder cache
7527             * @return the ordered range of matching document library folders
7528             */
7529            @Override
7530            public List<DLFolder> findByF_C_P_NotS(long folderId, long companyId,
7531                    long parentFolderId, int status, int start, int end,
7532                    OrderByComparator<DLFolder> orderByComparator, boolean retrieveFromCache) {
7533                    boolean pagination = true;
7534                    FinderPath finderPath = null;
7535                    Object[] finderArgs = null;
7536    
7537                    finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_F_C_P_NOTS;
7538                    finderArgs = new Object[] {
7539                                    folderId, companyId, parentFolderId, status,
7540                                    
7541                                    start, end, orderByComparator
7542                            };
7543    
7544                    List<DLFolder> list = null;
7545    
7546                    if (retrieveFromCache) {
7547                            list = (List<DLFolder>)finderCache.getResult(finderPath,
7548                                            finderArgs, this);
7549    
7550                            if ((list != null) && !list.isEmpty()) {
7551                                    for (DLFolder dlFolder : list) {
7552                                            if ((folderId >= dlFolder.getFolderId()) ||
7553                                                            (companyId != dlFolder.getCompanyId()) ||
7554                                                            (parentFolderId != dlFolder.getParentFolderId()) ||
7555                                                            (status == dlFolder.getStatus())) {
7556                                                    list = null;
7557    
7558                                                    break;
7559                                            }
7560                                    }
7561                            }
7562                    }
7563    
7564                    if (list == null) {
7565                            StringBundler query = null;
7566    
7567                            if (orderByComparator != null) {
7568                                    query = new StringBundler(6 +
7569                                                    (orderByComparator.getOrderByFields().length * 2));
7570                            }
7571                            else {
7572                                    query = new StringBundler(6);
7573                            }
7574    
7575                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
7576    
7577                            query.append(_FINDER_COLUMN_F_C_P_NOTS_FOLDERID_2);
7578    
7579                            query.append(_FINDER_COLUMN_F_C_P_NOTS_COMPANYID_2);
7580    
7581                            query.append(_FINDER_COLUMN_F_C_P_NOTS_PARENTFOLDERID_2);
7582    
7583                            query.append(_FINDER_COLUMN_F_C_P_NOTS_STATUS_2);
7584    
7585                            if (orderByComparator != null) {
7586                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7587                                            orderByComparator);
7588                            }
7589                            else
7590                             if (pagination) {
7591                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
7592                            }
7593    
7594                            String sql = query.toString();
7595    
7596                            Session session = null;
7597    
7598                            try {
7599                                    session = openSession();
7600    
7601                                    Query q = session.createQuery(sql);
7602    
7603                                    QueryPos qPos = QueryPos.getInstance(q);
7604    
7605                                    qPos.add(folderId);
7606    
7607                                    qPos.add(companyId);
7608    
7609                                    qPos.add(parentFolderId);
7610    
7611                                    qPos.add(status);
7612    
7613                                    if (!pagination) {
7614                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
7615                                                            start, end, false);
7616    
7617                                            Collections.sort(list);
7618    
7619                                            list = Collections.unmodifiableList(list);
7620                                    }
7621                                    else {
7622                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
7623                                                            start, end);
7624                                    }
7625    
7626                                    cacheResult(list);
7627    
7628                                    finderCache.putResult(finderPath, finderArgs, list);
7629                            }
7630                            catch (Exception e) {
7631                                    finderCache.removeResult(finderPath, finderArgs);
7632    
7633                                    throw processException(e);
7634                            }
7635                            finally {
7636                                    closeSession(session);
7637                            }
7638                    }
7639    
7640                    return list;
7641            }
7642    
7643            /**
7644             * Returns the first document library folder in the ordered set where folderId &gt; &#63; and companyId = &#63; and parentFolderId = &#63; and status &ne; &#63;.
7645             *
7646             * @param folderId the folder ID
7647             * @param companyId the company ID
7648             * @param parentFolderId the parent folder ID
7649             * @param status the status
7650             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7651             * @return the first matching document library folder
7652             * @throws NoSuchFolderException if a matching document library folder could not be found
7653             */
7654            @Override
7655            public DLFolder findByF_C_P_NotS_First(long folderId, long companyId,
7656                    long parentFolderId, int status,
7657                    OrderByComparator<DLFolder> orderByComparator)
7658                    throws NoSuchFolderException {
7659                    DLFolder dlFolder = fetchByF_C_P_NotS_First(folderId, companyId,
7660                                    parentFolderId, status, orderByComparator);
7661    
7662                    if (dlFolder != null) {
7663                            return dlFolder;
7664                    }
7665    
7666                    StringBundler msg = new StringBundler(10);
7667    
7668                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7669    
7670                    msg.append("folderId=");
7671                    msg.append(folderId);
7672    
7673                    msg.append(", companyId=");
7674                    msg.append(companyId);
7675    
7676                    msg.append(", parentFolderId=");
7677                    msg.append(parentFolderId);
7678    
7679                    msg.append(", status=");
7680                    msg.append(status);
7681    
7682                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7683    
7684                    throw new NoSuchFolderException(msg.toString());
7685            }
7686    
7687            /**
7688             * Returns the first document library folder in the ordered set where folderId &gt; &#63; and companyId = &#63; and parentFolderId = &#63; and status &ne; &#63;.
7689             *
7690             * @param folderId the folder ID
7691             * @param companyId the company ID
7692             * @param parentFolderId the parent folder ID
7693             * @param status the status
7694             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7695             * @return the first matching document library folder, or <code>null</code> if a matching document library folder could not be found
7696             */
7697            @Override
7698            public DLFolder fetchByF_C_P_NotS_First(long folderId, long companyId,
7699                    long parentFolderId, int status,
7700                    OrderByComparator<DLFolder> orderByComparator) {
7701                    List<DLFolder> list = findByF_C_P_NotS(folderId, companyId,
7702                                    parentFolderId, status, 0, 1, orderByComparator);
7703    
7704                    if (!list.isEmpty()) {
7705                            return list.get(0);
7706                    }
7707    
7708                    return null;
7709            }
7710    
7711            /**
7712             * Returns the last document library folder in the ordered set where folderId &gt; &#63; and companyId = &#63; and parentFolderId = &#63; and status &ne; &#63;.
7713             *
7714             * @param folderId the folder ID
7715             * @param companyId the company ID
7716             * @param parentFolderId the parent folder ID
7717             * @param status the status
7718             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7719             * @return the last matching document library folder
7720             * @throws NoSuchFolderException if a matching document library folder could not be found
7721             */
7722            @Override
7723            public DLFolder findByF_C_P_NotS_Last(long folderId, long companyId,
7724                    long parentFolderId, int status,
7725                    OrderByComparator<DLFolder> orderByComparator)
7726                    throws NoSuchFolderException {
7727                    DLFolder dlFolder = fetchByF_C_P_NotS_Last(folderId, companyId,
7728                                    parentFolderId, status, orderByComparator);
7729    
7730                    if (dlFolder != null) {
7731                            return dlFolder;
7732                    }
7733    
7734                    StringBundler msg = new StringBundler(10);
7735    
7736                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7737    
7738                    msg.append("folderId=");
7739                    msg.append(folderId);
7740    
7741                    msg.append(", companyId=");
7742                    msg.append(companyId);
7743    
7744                    msg.append(", parentFolderId=");
7745                    msg.append(parentFolderId);
7746    
7747                    msg.append(", status=");
7748                    msg.append(status);
7749    
7750                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7751    
7752                    throw new NoSuchFolderException(msg.toString());
7753            }
7754    
7755            /**
7756             * Returns the last document library folder in the ordered set where folderId &gt; &#63; and companyId = &#63; and parentFolderId = &#63; and status &ne; &#63;.
7757             *
7758             * @param folderId the folder ID
7759             * @param companyId the company ID
7760             * @param parentFolderId the parent folder ID
7761             * @param status the status
7762             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7763             * @return the last matching document library folder, or <code>null</code> if a matching document library folder could not be found
7764             */
7765            @Override
7766            public DLFolder fetchByF_C_P_NotS_Last(long folderId, long companyId,
7767                    long parentFolderId, int status,
7768                    OrderByComparator<DLFolder> orderByComparator) {
7769                    int count = countByF_C_P_NotS(folderId, companyId, parentFolderId,
7770                                    status);
7771    
7772                    if (count == 0) {
7773                            return null;
7774                    }
7775    
7776                    List<DLFolder> list = findByF_C_P_NotS(folderId, companyId,
7777                                    parentFolderId, status, count - 1, count, orderByComparator);
7778    
7779                    if (!list.isEmpty()) {
7780                            return list.get(0);
7781                    }
7782    
7783                    return null;
7784            }
7785    
7786            /**
7787             * Removes all the document library folders where folderId &gt; &#63; and companyId = &#63; and parentFolderId = &#63; and status &ne; &#63; from the database.
7788             *
7789             * @param folderId the folder ID
7790             * @param companyId the company ID
7791             * @param parentFolderId the parent folder ID
7792             * @param status the status
7793             */
7794            @Override
7795            public void removeByF_C_P_NotS(long folderId, long companyId,
7796                    long parentFolderId, int status) {
7797                    for (DLFolder dlFolder : findByF_C_P_NotS(folderId, companyId,
7798                                    parentFolderId, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
7799                                    null)) {
7800                            remove(dlFolder);
7801                    }
7802            }
7803    
7804            /**
7805             * Returns the number of document library folders where folderId &gt; &#63; and companyId = &#63; and parentFolderId = &#63; and status &ne; &#63;.
7806             *
7807             * @param folderId the folder ID
7808             * @param companyId the company ID
7809             * @param parentFolderId the parent folder ID
7810             * @param status the status
7811             * @return the number of matching document library folders
7812             */
7813            @Override
7814            public int countByF_C_P_NotS(long folderId, long companyId,
7815                    long parentFolderId, int status) {
7816                    FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_F_C_P_NOTS;
7817    
7818                    Object[] finderArgs = new Object[] {
7819                                    folderId, companyId, parentFolderId, status
7820                            };
7821    
7822                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
7823    
7824                    if (count == null) {
7825                            StringBundler query = new StringBundler(5);
7826    
7827                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
7828    
7829                            query.append(_FINDER_COLUMN_F_C_P_NOTS_FOLDERID_2);
7830    
7831                            query.append(_FINDER_COLUMN_F_C_P_NOTS_COMPANYID_2);
7832    
7833                            query.append(_FINDER_COLUMN_F_C_P_NOTS_PARENTFOLDERID_2);
7834    
7835                            query.append(_FINDER_COLUMN_F_C_P_NOTS_STATUS_2);
7836    
7837                            String sql = query.toString();
7838    
7839                            Session session = null;
7840    
7841                            try {
7842                                    session = openSession();
7843    
7844                                    Query q = session.createQuery(sql);
7845    
7846                                    QueryPos qPos = QueryPos.getInstance(q);
7847    
7848                                    qPos.add(folderId);
7849    
7850                                    qPos.add(companyId);
7851    
7852                                    qPos.add(parentFolderId);
7853    
7854                                    qPos.add(status);
7855    
7856                                    count = (Long)q.uniqueResult();
7857    
7858                                    finderCache.putResult(finderPath, finderArgs, count);
7859                            }
7860                            catch (Exception e) {
7861                                    finderCache.removeResult(finderPath, finderArgs);
7862    
7863                                    throw processException(e);
7864                            }
7865                            finally {
7866                                    closeSession(session);
7867                            }
7868                    }
7869    
7870                    return count.intValue();
7871            }
7872    
7873            private static final String _FINDER_COLUMN_F_C_P_NOTS_FOLDERID_2 = "dlFolder.folderId > ? AND ";
7874            private static final String _FINDER_COLUMN_F_C_P_NOTS_COMPANYID_2 = "dlFolder.companyId = ? AND ";
7875            private static final String _FINDER_COLUMN_F_C_P_NOTS_PARENTFOLDERID_2 = "dlFolder.parentFolderId = ? AND ";
7876            private static final String _FINDER_COLUMN_F_C_P_NOTS_STATUS_2 = "dlFolder.status != ?";
7877            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_M_P_H = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
7878                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
7879                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_M_P_H",
7880                            new String[] {
7881                                    Long.class.getName(), Boolean.class.getName(),
7882                                    Long.class.getName(), Boolean.class.getName(),
7883                                    
7884                            Integer.class.getName(), Integer.class.getName(),
7885                                    OrderByComparator.class.getName()
7886                            });
7887            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P_H =
7888                    new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
7889                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
7890                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_M_P_H",
7891                            new String[] {
7892                                    Long.class.getName(), Boolean.class.getName(),
7893                                    Long.class.getName(), Boolean.class.getName()
7894                            },
7895                            DLFolderModelImpl.GROUPID_COLUMN_BITMASK |
7896                            DLFolderModelImpl.MOUNTPOINT_COLUMN_BITMASK |
7897                            DLFolderModelImpl.PARENTFOLDERID_COLUMN_BITMASK |
7898                            DLFolderModelImpl.HIDDEN_COLUMN_BITMASK |
7899                            DLFolderModelImpl.NAME_COLUMN_BITMASK);
7900            public static final FinderPath FINDER_PATH_COUNT_BY_G_M_P_H = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
7901                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
7902                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_M_P_H",
7903                            new String[] {
7904                                    Long.class.getName(), Boolean.class.getName(),
7905                                    Long.class.getName(), Boolean.class.getName()
7906                            });
7907    
7908            /**
7909             * Returns all the document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63;.
7910             *
7911             * @param groupId the group ID
7912             * @param mountPoint the mount point
7913             * @param parentFolderId the parent folder ID
7914             * @param hidden the hidden
7915             * @return the matching document library folders
7916             */
7917            @Override
7918            public List<DLFolder> findByG_M_P_H(long groupId, boolean mountPoint,
7919                    long parentFolderId, boolean hidden) {
7920                    return findByG_M_P_H(groupId, mountPoint, parentFolderId, hidden,
7921                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
7922            }
7923    
7924            /**
7925             * Returns a range of all the document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63;.
7926             *
7927             * <p>
7928             * 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.
7929             * </p>
7930             *
7931             * @param groupId the group ID
7932             * @param mountPoint the mount point
7933             * @param parentFolderId the parent folder ID
7934             * @param hidden the hidden
7935             * @param start the lower bound of the range of document library folders
7936             * @param end the upper bound of the range of document library folders (not inclusive)
7937             * @return the range of matching document library folders
7938             */
7939            @Override
7940            public List<DLFolder> findByG_M_P_H(long groupId, boolean mountPoint,
7941                    long parentFolderId, boolean hidden, int start, int end) {
7942                    return findByG_M_P_H(groupId, mountPoint, parentFolderId, hidden,
7943                            start, end, null);
7944            }
7945    
7946            /**
7947             * Returns an ordered range of all the document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63;.
7948             *
7949             * <p>
7950             * 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.
7951             * </p>
7952             *
7953             * @param groupId the group ID
7954             * @param mountPoint the mount point
7955             * @param parentFolderId the parent folder ID
7956             * @param hidden the hidden
7957             * @param start the lower bound of the range of document library folders
7958             * @param end the upper bound of the range of document library folders (not inclusive)
7959             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7960             * @return the ordered range of matching document library folders
7961             */
7962            @Override
7963            public List<DLFolder> findByG_M_P_H(long groupId, boolean mountPoint,
7964                    long parentFolderId, boolean hidden, int start, int end,
7965                    OrderByComparator<DLFolder> orderByComparator) {
7966                    return findByG_M_P_H(groupId, mountPoint, parentFolderId, hidden,
7967                            start, end, orderByComparator, true);
7968            }
7969    
7970            /**
7971             * Returns an ordered range of all the document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63;.
7972             *
7973             * <p>
7974             * 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.
7975             * </p>
7976             *
7977             * @param groupId the group ID
7978             * @param mountPoint the mount point
7979             * @param parentFolderId the parent folder ID
7980             * @param hidden the hidden
7981             * @param start the lower bound of the range of document library folders
7982             * @param end the upper bound of the range of document library folders (not inclusive)
7983             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7984             * @param retrieveFromCache whether to retrieve from the finder cache
7985             * @return the ordered range of matching document library folders
7986             */
7987            @Override
7988            public List<DLFolder> findByG_M_P_H(long groupId, boolean mountPoint,
7989                    long parentFolderId, boolean hidden, int start, int end,
7990                    OrderByComparator<DLFolder> orderByComparator, boolean retrieveFromCache) {
7991                    boolean pagination = true;
7992                    FinderPath finderPath = null;
7993                    Object[] finderArgs = null;
7994    
7995                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7996                                    (orderByComparator == null)) {
7997                            pagination = false;
7998                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P_H;
7999                            finderArgs = new Object[] {
8000                                            groupId, mountPoint, parentFolderId, hidden
8001                                    };
8002                    }
8003                    else {
8004                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_M_P_H;
8005                            finderArgs = new Object[] {
8006                                            groupId, mountPoint, parentFolderId, hidden,
8007                                            
8008                                            start, end, orderByComparator
8009                                    };
8010                    }
8011    
8012                    List<DLFolder> list = null;
8013    
8014                    if (retrieveFromCache) {
8015                            list = (List<DLFolder>)finderCache.getResult(finderPath,
8016                                            finderArgs, this);
8017    
8018                            if ((list != null) && !list.isEmpty()) {
8019                                    for (DLFolder dlFolder : list) {
8020                                            if ((groupId != dlFolder.getGroupId()) ||
8021                                                            (mountPoint != dlFolder.getMountPoint()) ||
8022                                                            (parentFolderId != dlFolder.getParentFolderId()) ||
8023                                                            (hidden != dlFolder.getHidden())) {
8024                                                    list = null;
8025    
8026                                                    break;
8027                                            }
8028                                    }
8029                            }
8030                    }
8031    
8032                    if (list == null) {
8033                            StringBundler query = null;
8034    
8035                            if (orderByComparator != null) {
8036                                    query = new StringBundler(6 +
8037                                                    (orderByComparator.getOrderByFields().length * 2));
8038                            }
8039                            else {
8040                                    query = new StringBundler(6);
8041                            }
8042    
8043                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
8044    
8045                            query.append(_FINDER_COLUMN_G_M_P_H_GROUPID_2);
8046    
8047                            query.append(_FINDER_COLUMN_G_M_P_H_MOUNTPOINT_2);
8048    
8049                            query.append(_FINDER_COLUMN_G_M_P_H_PARENTFOLDERID_2);
8050    
8051                            query.append(_FINDER_COLUMN_G_M_P_H_HIDDEN_2);
8052    
8053                            if (orderByComparator != null) {
8054                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8055                                            orderByComparator);
8056                            }
8057                            else
8058                             if (pagination) {
8059                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
8060                            }
8061    
8062                            String sql = query.toString();
8063    
8064                            Session session = null;
8065    
8066                            try {
8067                                    session = openSession();
8068    
8069                                    Query q = session.createQuery(sql);
8070    
8071                                    QueryPos qPos = QueryPos.getInstance(q);
8072    
8073                                    qPos.add(groupId);
8074    
8075                                    qPos.add(mountPoint);
8076    
8077                                    qPos.add(parentFolderId);
8078    
8079                                    qPos.add(hidden);
8080    
8081                                    if (!pagination) {
8082                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
8083                                                            start, end, false);
8084    
8085                                            Collections.sort(list);
8086    
8087                                            list = Collections.unmodifiableList(list);
8088                                    }
8089                                    else {
8090                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
8091                                                            start, end);
8092                                    }
8093    
8094                                    cacheResult(list);
8095    
8096                                    finderCache.putResult(finderPath, finderArgs, list);
8097                            }
8098                            catch (Exception e) {
8099                                    finderCache.removeResult(finderPath, finderArgs);
8100    
8101                                    throw processException(e);
8102                            }
8103                            finally {
8104                                    closeSession(session);
8105                            }
8106                    }
8107    
8108                    return list;
8109            }
8110    
8111            /**
8112             * Returns the first document library folder in the ordered set where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63;.
8113             *
8114             * @param groupId the group ID
8115             * @param mountPoint the mount point
8116             * @param parentFolderId the parent folder ID
8117             * @param hidden the hidden
8118             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8119             * @return the first matching document library folder
8120             * @throws NoSuchFolderException if a matching document library folder could not be found
8121             */
8122            @Override
8123            public DLFolder findByG_M_P_H_First(long groupId, boolean mountPoint,
8124                    long parentFolderId, boolean hidden,
8125                    OrderByComparator<DLFolder> orderByComparator)
8126                    throws NoSuchFolderException {
8127                    DLFolder dlFolder = fetchByG_M_P_H_First(groupId, mountPoint,
8128                                    parentFolderId, hidden, orderByComparator);
8129    
8130                    if (dlFolder != null) {
8131                            return dlFolder;
8132                    }
8133    
8134                    StringBundler msg = new StringBundler(10);
8135    
8136                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8137    
8138                    msg.append("groupId=");
8139                    msg.append(groupId);
8140    
8141                    msg.append(", mountPoint=");
8142                    msg.append(mountPoint);
8143    
8144                    msg.append(", parentFolderId=");
8145                    msg.append(parentFolderId);
8146    
8147                    msg.append(", hidden=");
8148                    msg.append(hidden);
8149    
8150                    msg.append(StringPool.CLOSE_CURLY_BRACE);
8151    
8152                    throw new NoSuchFolderException(msg.toString());
8153            }
8154    
8155            /**
8156             * Returns the first document library folder in the ordered set where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63;.
8157             *
8158             * @param groupId the group ID
8159             * @param mountPoint the mount point
8160             * @param parentFolderId the parent folder ID
8161             * @param hidden the hidden
8162             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8163             * @return the first matching document library folder, or <code>null</code> if a matching document library folder could not be found
8164             */
8165            @Override
8166            public DLFolder fetchByG_M_P_H_First(long groupId, boolean mountPoint,
8167                    long parentFolderId, boolean hidden,
8168                    OrderByComparator<DLFolder> orderByComparator) {
8169                    List<DLFolder> list = findByG_M_P_H(groupId, mountPoint,
8170                                    parentFolderId, hidden, 0, 1, orderByComparator);
8171    
8172                    if (!list.isEmpty()) {
8173                            return list.get(0);
8174                    }
8175    
8176                    return null;
8177            }
8178    
8179            /**
8180             * Returns the last document library folder in the ordered set where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63;.
8181             *
8182             * @param groupId the group ID
8183             * @param mountPoint the mount point
8184             * @param parentFolderId the parent folder ID
8185             * @param hidden the hidden
8186             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8187             * @return the last matching document library folder
8188             * @throws NoSuchFolderException if a matching document library folder could not be found
8189             */
8190            @Override
8191            public DLFolder findByG_M_P_H_Last(long groupId, boolean mountPoint,
8192                    long parentFolderId, boolean hidden,
8193                    OrderByComparator<DLFolder> orderByComparator)
8194                    throws NoSuchFolderException {
8195                    DLFolder dlFolder = fetchByG_M_P_H_Last(groupId, mountPoint,
8196                                    parentFolderId, hidden, orderByComparator);
8197    
8198                    if (dlFolder != null) {
8199                            return dlFolder;
8200                    }
8201    
8202                    StringBundler msg = new StringBundler(10);
8203    
8204                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8205    
8206                    msg.append("groupId=");
8207                    msg.append(groupId);
8208    
8209                    msg.append(", mountPoint=");
8210                    msg.append(mountPoint);
8211    
8212                    msg.append(", parentFolderId=");
8213                    msg.append(parentFolderId);
8214    
8215                    msg.append(", hidden=");
8216                    msg.append(hidden);
8217    
8218                    msg.append(StringPool.CLOSE_CURLY_BRACE);
8219    
8220                    throw new NoSuchFolderException(msg.toString());
8221            }
8222    
8223            /**
8224             * Returns the last document library folder in the ordered set where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63;.
8225             *
8226             * @param groupId the group ID
8227             * @param mountPoint the mount point
8228             * @param parentFolderId the parent folder ID
8229             * @param hidden the hidden
8230             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8231             * @return the last matching document library folder, or <code>null</code> if a matching document library folder could not be found
8232             */
8233            @Override
8234            public DLFolder fetchByG_M_P_H_Last(long groupId, boolean mountPoint,
8235                    long parentFolderId, boolean hidden,
8236                    OrderByComparator<DLFolder> orderByComparator) {
8237                    int count = countByG_M_P_H(groupId, mountPoint, parentFolderId, hidden);
8238    
8239                    if (count == 0) {
8240                            return null;
8241                    }
8242    
8243                    List<DLFolder> list = findByG_M_P_H(groupId, mountPoint,
8244                                    parentFolderId, hidden, count - 1, count, orderByComparator);
8245    
8246                    if (!list.isEmpty()) {
8247                            return list.get(0);
8248                    }
8249    
8250                    return null;
8251            }
8252    
8253            /**
8254             * 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;.
8255             *
8256             * @param folderId the primary key of the current document library folder
8257             * @param groupId the group ID
8258             * @param mountPoint the mount point
8259             * @param parentFolderId the parent folder ID
8260             * @param hidden the hidden
8261             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8262             * @return the previous, current, and next document library folder
8263             * @throws NoSuchFolderException if a document library folder with the primary key could not be found
8264             */
8265            @Override
8266            public DLFolder[] findByG_M_P_H_PrevAndNext(long folderId, long groupId,
8267                    boolean mountPoint, long parentFolderId, boolean hidden,
8268                    OrderByComparator<DLFolder> orderByComparator)
8269                    throws NoSuchFolderException {
8270                    DLFolder dlFolder = findByPrimaryKey(folderId);
8271    
8272                    Session session = null;
8273    
8274                    try {
8275                            session = openSession();
8276    
8277                            DLFolder[] array = new DLFolderImpl[3];
8278    
8279                            array[0] = getByG_M_P_H_PrevAndNext(session, dlFolder, groupId,
8280                                            mountPoint, parentFolderId, hidden, orderByComparator, true);
8281    
8282                            array[1] = dlFolder;
8283    
8284                            array[2] = getByG_M_P_H_PrevAndNext(session, dlFolder, groupId,
8285                                            mountPoint, parentFolderId, hidden, orderByComparator, false);
8286    
8287                            return array;
8288                    }
8289                    catch (Exception e) {
8290                            throw processException(e);
8291                    }
8292                    finally {
8293                            closeSession(session);
8294                    }
8295            }
8296    
8297            protected DLFolder getByG_M_P_H_PrevAndNext(Session session,
8298                    DLFolder dlFolder, long groupId, boolean mountPoint,
8299                    long parentFolderId, boolean hidden,
8300                    OrderByComparator<DLFolder> orderByComparator, boolean previous) {
8301                    StringBundler query = null;
8302    
8303                    if (orderByComparator != null) {
8304                            query = new StringBundler(7 +
8305                                            (orderByComparator.getOrderByConditionFields().length * 3) +
8306                                            (orderByComparator.getOrderByFields().length * 3));
8307                    }
8308                    else {
8309                            query = new StringBundler(6);
8310                    }
8311    
8312                    query.append(_SQL_SELECT_DLFOLDER_WHERE);
8313    
8314                    query.append(_FINDER_COLUMN_G_M_P_H_GROUPID_2);
8315    
8316                    query.append(_FINDER_COLUMN_G_M_P_H_MOUNTPOINT_2);
8317    
8318                    query.append(_FINDER_COLUMN_G_M_P_H_PARENTFOLDERID_2);
8319    
8320                    query.append(_FINDER_COLUMN_G_M_P_H_HIDDEN_2);
8321    
8322                    if (orderByComparator != null) {
8323                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
8324    
8325                            if (orderByConditionFields.length > 0) {
8326                                    query.append(WHERE_AND);
8327                            }
8328    
8329                            for (int i = 0; i < orderByConditionFields.length; i++) {
8330                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8331                                    query.append(orderByConditionFields[i]);
8332    
8333                                    if ((i + 1) < orderByConditionFields.length) {
8334                                            if (orderByComparator.isAscending() ^ previous) {
8335                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
8336                                            }
8337                                            else {
8338                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
8339                                            }
8340                                    }
8341                                    else {
8342                                            if (orderByComparator.isAscending() ^ previous) {
8343                                                    query.append(WHERE_GREATER_THAN);
8344                                            }
8345                                            else {
8346                                                    query.append(WHERE_LESSER_THAN);
8347                                            }
8348                                    }
8349                            }
8350    
8351                            query.append(ORDER_BY_CLAUSE);
8352    
8353                            String[] orderByFields = orderByComparator.getOrderByFields();
8354    
8355                            for (int i = 0; i < orderByFields.length; i++) {
8356                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8357                                    query.append(orderByFields[i]);
8358    
8359                                    if ((i + 1) < orderByFields.length) {
8360                                            if (orderByComparator.isAscending() ^ previous) {
8361                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
8362                                            }
8363                                            else {
8364                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
8365                                            }
8366                                    }
8367                                    else {
8368                                            if (orderByComparator.isAscending() ^ previous) {
8369                                                    query.append(ORDER_BY_ASC);
8370                                            }
8371                                            else {
8372                                                    query.append(ORDER_BY_DESC);
8373                                            }
8374                                    }
8375                            }
8376                    }
8377                    else {
8378                            query.append(DLFolderModelImpl.ORDER_BY_JPQL);
8379                    }
8380    
8381                    String sql = query.toString();
8382    
8383                    Query q = session.createQuery(sql);
8384    
8385                    q.setFirstResult(0);
8386                    q.setMaxResults(2);
8387    
8388                    QueryPos qPos = QueryPos.getInstance(q);
8389    
8390                    qPos.add(groupId);
8391    
8392                    qPos.add(mountPoint);
8393    
8394                    qPos.add(parentFolderId);
8395    
8396                    qPos.add(hidden);
8397    
8398                    if (orderByComparator != null) {
8399                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
8400    
8401                            for (Object value : values) {
8402                                    qPos.add(value);
8403                            }
8404                    }
8405    
8406                    List<DLFolder> list = q.list();
8407    
8408                    if (list.size() == 2) {
8409                            return list.get(1);
8410                    }
8411                    else {
8412                            return null;
8413                    }
8414            }
8415    
8416            /**
8417             * 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;.
8418             *
8419             * @param groupId the group ID
8420             * @param mountPoint the mount point
8421             * @param parentFolderId the parent folder ID
8422             * @param hidden the hidden
8423             * @return the matching document library folders that the user has permission to view
8424             */
8425            @Override
8426            public List<DLFolder> filterFindByG_M_P_H(long groupId, boolean mountPoint,
8427                    long parentFolderId, boolean hidden) {
8428                    return filterFindByG_M_P_H(groupId, mountPoint, parentFolderId, hidden,
8429                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
8430            }
8431    
8432            /**
8433             * 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;.
8434             *
8435             * <p>
8436             * 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.
8437             * </p>
8438             *
8439             * @param groupId the group ID
8440             * @param mountPoint the mount point
8441             * @param parentFolderId the parent folder ID
8442             * @param hidden the hidden
8443             * @param start the lower bound of the range of document library folders
8444             * @param end the upper bound of the range of document library folders (not inclusive)
8445             * @return the range of matching document library folders that the user has permission to view
8446             */
8447            @Override
8448            public List<DLFolder> filterFindByG_M_P_H(long groupId, boolean mountPoint,
8449                    long parentFolderId, boolean hidden, int start, int end) {
8450                    return filterFindByG_M_P_H(groupId, mountPoint, parentFolderId, hidden,
8451                            start, end, null);
8452            }
8453    
8454            /**
8455             * 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;.
8456             *
8457             * <p>
8458             * 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.
8459             * </p>
8460             *
8461             * @param groupId the group ID
8462             * @param mountPoint the mount point
8463             * @param parentFolderId the parent folder ID
8464             * @param hidden the hidden
8465             * @param start the lower bound of the range of document library folders
8466             * @param end the upper bound of the range of document library folders (not inclusive)
8467             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8468             * @return the ordered range of matching document library folders that the user has permission to view
8469             */
8470            @Override
8471            public List<DLFolder> filterFindByG_M_P_H(long groupId, boolean mountPoint,
8472                    long parentFolderId, boolean hidden, int start, int end,
8473                    OrderByComparator<DLFolder> orderByComparator) {
8474                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8475                            return findByG_M_P_H(groupId, mountPoint, parentFolderId, hidden,
8476                                    start, end, orderByComparator);
8477                    }
8478    
8479                    StringBundler query = null;
8480    
8481                    if (orderByComparator != null) {
8482                            query = new StringBundler(6 +
8483                                            (orderByComparator.getOrderByFields().length * 2));
8484                    }
8485                    else {
8486                            query = new StringBundler(7);
8487                    }
8488    
8489                    if (getDB().isSupportsInlineDistinct()) {
8490                            query.append(_FILTER_SQL_SELECT_DLFOLDER_WHERE);
8491                    }
8492                    else {
8493                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1);
8494                    }
8495    
8496                    query.append(_FINDER_COLUMN_G_M_P_H_GROUPID_2);
8497    
8498                    query.append(_FINDER_COLUMN_G_M_P_H_MOUNTPOINT_2);
8499    
8500                    query.append(_FINDER_COLUMN_G_M_P_H_PARENTFOLDERID_2);
8501    
8502                    query.append(_FINDER_COLUMN_G_M_P_H_HIDDEN_2_SQL);
8503    
8504                    if (!getDB().isSupportsInlineDistinct()) {
8505                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2);
8506                    }
8507    
8508                    if (orderByComparator != null) {
8509                            if (getDB().isSupportsInlineDistinct()) {
8510                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8511                                            orderByComparator, true);
8512                            }
8513                            else {
8514                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
8515                                            orderByComparator, true);
8516                            }
8517                    }
8518                    else {
8519                            if (getDB().isSupportsInlineDistinct()) {
8520                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
8521                            }
8522                            else {
8523                                    query.append(DLFolderModelImpl.ORDER_BY_SQL);
8524                            }
8525                    }
8526    
8527                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8528                                    DLFolder.class.getName(),
8529                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8530    
8531                    Session session = null;
8532    
8533                    try {
8534                            session = openSession();
8535    
8536                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
8537    
8538                            if (getDB().isSupportsInlineDistinct()) {
8539                                    q.addEntity(_FILTER_ENTITY_ALIAS, DLFolderImpl.class);
8540                            }
8541                            else {
8542                                    q.addEntity(_FILTER_ENTITY_TABLE, DLFolderImpl.class);
8543                            }
8544    
8545                            QueryPos qPos = QueryPos.getInstance(q);
8546    
8547                            qPos.add(groupId);
8548    
8549                            qPos.add(mountPoint);
8550    
8551                            qPos.add(parentFolderId);
8552    
8553                            qPos.add(hidden);
8554    
8555                            return (List<DLFolder>)QueryUtil.list(q, getDialect(), start, end);
8556                    }
8557                    catch (Exception e) {
8558                            throw processException(e);
8559                    }
8560                    finally {
8561                            closeSession(session);
8562                    }
8563            }
8564    
8565            /**
8566             * 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;.
8567             *
8568             * @param folderId the primary key of the current document library folder
8569             * @param groupId the group ID
8570             * @param mountPoint the mount point
8571             * @param parentFolderId the parent folder ID
8572             * @param hidden the hidden
8573             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8574             * @return the previous, current, and next document library folder
8575             * @throws NoSuchFolderException if a document library folder with the primary key could not be found
8576             */
8577            @Override
8578            public DLFolder[] filterFindByG_M_P_H_PrevAndNext(long folderId,
8579                    long groupId, boolean mountPoint, long parentFolderId, boolean hidden,
8580                    OrderByComparator<DLFolder> orderByComparator)
8581                    throws NoSuchFolderException {
8582                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8583                            return findByG_M_P_H_PrevAndNext(folderId, groupId, mountPoint,
8584                                    parentFolderId, hidden, orderByComparator);
8585                    }
8586    
8587                    DLFolder dlFolder = findByPrimaryKey(folderId);
8588    
8589                    Session session = null;
8590    
8591                    try {
8592                            session = openSession();
8593    
8594                            DLFolder[] array = new DLFolderImpl[3];
8595    
8596                            array[0] = filterGetByG_M_P_H_PrevAndNext(session, dlFolder,
8597                                            groupId, mountPoint, parentFolderId, hidden,
8598                                            orderByComparator, true);
8599    
8600                            array[1] = dlFolder;
8601    
8602                            array[2] = filterGetByG_M_P_H_PrevAndNext(session, dlFolder,
8603                                            groupId, mountPoint, parentFolderId, hidden,
8604                                            orderByComparator, false);
8605    
8606                            return array;
8607                    }
8608                    catch (Exception e) {
8609                            throw processException(e);
8610                    }
8611                    finally {
8612                            closeSession(session);
8613                    }
8614            }
8615    
8616            protected DLFolder filterGetByG_M_P_H_PrevAndNext(Session session,
8617                    DLFolder dlFolder, long groupId, boolean mountPoint,
8618                    long parentFolderId, boolean hidden,
8619                    OrderByComparator<DLFolder> orderByComparator, boolean previous) {
8620                    StringBundler query = null;
8621    
8622                    if (orderByComparator != null) {
8623                            query = new StringBundler(8 +
8624                                            (orderByComparator.getOrderByConditionFields().length * 3) +
8625                                            (orderByComparator.getOrderByFields().length * 3));
8626                    }
8627                    else {
8628                            query = new StringBundler(7);
8629                    }
8630    
8631                    if (getDB().isSupportsInlineDistinct()) {
8632                            query.append(_FILTER_SQL_SELECT_DLFOLDER_WHERE);
8633                    }
8634                    else {
8635                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1);
8636                    }
8637    
8638                    query.append(_FINDER_COLUMN_G_M_P_H_GROUPID_2);
8639    
8640                    query.append(_FINDER_COLUMN_G_M_P_H_MOUNTPOINT_2);
8641    
8642                    query.append(_FINDER_COLUMN_G_M_P_H_PARENTFOLDERID_2);
8643    
8644                    query.append(_FINDER_COLUMN_G_M_P_H_HIDDEN_2_SQL);
8645    
8646                    if (!getDB().isSupportsInlineDistinct()) {
8647                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2);
8648                    }
8649    
8650                    if (orderByComparator != null) {
8651                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
8652    
8653                            if (orderByConditionFields.length > 0) {
8654                                    query.append(WHERE_AND);
8655                            }
8656    
8657                            for (int i = 0; i < orderByConditionFields.length; i++) {
8658                                    if (getDB().isSupportsInlineDistinct()) {
8659                                            query.append(_ORDER_BY_ENTITY_ALIAS);
8660                                    }
8661                                    else {
8662                                            query.append(_ORDER_BY_ENTITY_TABLE);
8663                                    }
8664    
8665                                    query.append(orderByConditionFields[i]);
8666    
8667                                    if ((i + 1) < orderByConditionFields.length) {
8668                                            if (orderByComparator.isAscending() ^ previous) {
8669                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
8670                                            }
8671                                            else {
8672                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
8673                                            }
8674                                    }
8675                                    else {
8676                                            if (orderByComparator.isAscending() ^ previous) {
8677                                                    query.append(WHERE_GREATER_THAN);
8678                                            }
8679                                            else {
8680                                                    query.append(WHERE_LESSER_THAN);
8681                                            }
8682                                    }
8683                            }
8684    
8685                            query.append(ORDER_BY_CLAUSE);
8686    
8687                            String[] orderByFields = orderByComparator.getOrderByFields();
8688    
8689                            for (int i = 0; i < orderByFields.length; i++) {
8690                                    if (getDB().isSupportsInlineDistinct()) {
8691                                            query.append(_ORDER_BY_ENTITY_ALIAS);
8692                                    }
8693                                    else {
8694                                            query.append(_ORDER_BY_ENTITY_TABLE);
8695                                    }
8696    
8697                                    query.append(orderByFields[i]);
8698    
8699                                    if ((i + 1) < orderByFields.length) {
8700                                            if (orderByComparator.isAscending() ^ previous) {
8701                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
8702                                            }
8703                                            else {
8704                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
8705                                            }
8706                                    }
8707                                    else {
8708                                            if (orderByComparator.isAscending() ^ previous) {
8709                                                    query.append(ORDER_BY_ASC);
8710                                            }
8711                                            else {
8712                                                    query.append(ORDER_BY_DESC);
8713                                            }
8714                                    }
8715                            }
8716                    }
8717                    else {
8718                            if (getDB().isSupportsInlineDistinct()) {
8719                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
8720                            }
8721                            else {
8722                                    query.append(DLFolderModelImpl.ORDER_BY_SQL);
8723                            }
8724                    }
8725    
8726                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8727                                    DLFolder.class.getName(),
8728                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8729    
8730                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
8731    
8732                    q.setFirstResult(0);
8733                    q.setMaxResults(2);
8734    
8735                    if (getDB().isSupportsInlineDistinct()) {
8736                            q.addEntity(_FILTER_ENTITY_ALIAS, DLFolderImpl.class);
8737                    }
8738                    else {
8739                            q.addEntity(_FILTER_ENTITY_TABLE, DLFolderImpl.class);
8740                    }
8741    
8742                    QueryPos qPos = QueryPos.getInstance(q);
8743    
8744                    qPos.add(groupId);
8745    
8746                    qPos.add(mountPoint);
8747    
8748                    qPos.add(parentFolderId);
8749    
8750                    qPos.add(hidden);
8751    
8752                    if (orderByComparator != null) {
8753                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
8754    
8755                            for (Object value : values) {
8756                                    qPos.add(value);
8757                            }
8758                    }
8759    
8760                    List<DLFolder> list = q.list();
8761    
8762                    if (list.size() == 2) {
8763                            return list.get(1);
8764                    }
8765                    else {
8766                            return null;
8767                    }
8768            }
8769    
8770            /**
8771             * Removes all the document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63; from the database.
8772             *
8773             * @param groupId the group ID
8774             * @param mountPoint the mount point
8775             * @param parentFolderId the parent folder ID
8776             * @param hidden the hidden
8777             */
8778            @Override
8779            public void removeByG_M_P_H(long groupId, boolean mountPoint,
8780                    long parentFolderId, boolean hidden) {
8781                    for (DLFolder dlFolder : findByG_M_P_H(groupId, mountPoint,
8782                                    parentFolderId, hidden, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
8783                                    null)) {
8784                            remove(dlFolder);
8785                    }
8786            }
8787    
8788            /**
8789             * Returns the number of document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63;.
8790             *
8791             * @param groupId the group ID
8792             * @param mountPoint the mount point
8793             * @param parentFolderId the parent folder ID
8794             * @param hidden the hidden
8795             * @return the number of matching document library folders
8796             */
8797            @Override
8798            public int countByG_M_P_H(long groupId, boolean mountPoint,
8799                    long parentFolderId, boolean hidden) {
8800                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_M_P_H;
8801    
8802                    Object[] finderArgs = new Object[] {
8803                                    groupId, mountPoint, parentFolderId, hidden
8804                            };
8805    
8806                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
8807    
8808                    if (count == null) {
8809                            StringBundler query = new StringBundler(5);
8810    
8811                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
8812    
8813                            query.append(_FINDER_COLUMN_G_M_P_H_GROUPID_2);
8814    
8815                            query.append(_FINDER_COLUMN_G_M_P_H_MOUNTPOINT_2);
8816    
8817                            query.append(_FINDER_COLUMN_G_M_P_H_PARENTFOLDERID_2);
8818    
8819                            query.append(_FINDER_COLUMN_G_M_P_H_HIDDEN_2);
8820    
8821                            String sql = query.toString();
8822    
8823                            Session session = null;
8824    
8825                            try {
8826                                    session = openSession();
8827    
8828                                    Query q = session.createQuery(sql);
8829    
8830                                    QueryPos qPos = QueryPos.getInstance(q);
8831    
8832                                    qPos.add(groupId);
8833    
8834                                    qPos.add(mountPoint);
8835    
8836                                    qPos.add(parentFolderId);
8837    
8838                                    qPos.add(hidden);
8839    
8840                                    count = (Long)q.uniqueResult();
8841    
8842                                    finderCache.putResult(finderPath, finderArgs, count);
8843                            }
8844                            catch (Exception e) {
8845                                    finderCache.removeResult(finderPath, finderArgs);
8846    
8847                                    throw processException(e);
8848                            }
8849                            finally {
8850                                    closeSession(session);
8851                            }
8852                    }
8853    
8854                    return count.intValue();
8855            }
8856    
8857            /**
8858             * 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;.
8859             *
8860             * @param groupId the group ID
8861             * @param mountPoint the mount point
8862             * @param parentFolderId the parent folder ID
8863             * @param hidden the hidden
8864             * @return the number of matching document library folders that the user has permission to view
8865             */
8866            @Override
8867            public int filterCountByG_M_P_H(long groupId, boolean mountPoint,
8868                    long parentFolderId, boolean hidden) {
8869                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8870                            return countByG_M_P_H(groupId, mountPoint, parentFolderId, hidden);
8871                    }
8872    
8873                    StringBundler query = new StringBundler(5);
8874    
8875                    query.append(_FILTER_SQL_COUNT_DLFOLDER_WHERE);
8876    
8877                    query.append(_FINDER_COLUMN_G_M_P_H_GROUPID_2);
8878    
8879                    query.append(_FINDER_COLUMN_G_M_P_H_MOUNTPOINT_2);
8880    
8881                    query.append(_FINDER_COLUMN_G_M_P_H_PARENTFOLDERID_2);
8882    
8883                    query.append(_FINDER_COLUMN_G_M_P_H_HIDDEN_2_SQL);
8884    
8885                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8886                                    DLFolder.class.getName(),
8887                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8888    
8889                    Session session = null;
8890    
8891                    try {
8892                            session = openSession();
8893    
8894                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
8895    
8896                            q.addScalar(COUNT_COLUMN_NAME,
8897                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
8898    
8899                            QueryPos qPos = QueryPos.getInstance(q);
8900    
8901                            qPos.add(groupId);
8902    
8903                            qPos.add(mountPoint);
8904    
8905                            qPos.add(parentFolderId);
8906    
8907                            qPos.add(hidden);
8908    
8909                            Long count = (Long)q.uniqueResult();
8910    
8911                            return count.intValue();
8912                    }
8913                    catch (Exception e) {
8914                            throw processException(e);
8915                    }
8916                    finally {
8917                            closeSession(session);
8918                    }
8919            }
8920    
8921            private static final String _FINDER_COLUMN_G_M_P_H_GROUPID_2 = "dlFolder.groupId = ? AND ";
8922            private static final String _FINDER_COLUMN_G_M_P_H_MOUNTPOINT_2 = "dlFolder.mountPoint = ? AND ";
8923            private static final String _FINDER_COLUMN_G_M_P_H_PARENTFOLDERID_2 = "dlFolder.parentFolderId = ? AND ";
8924            private static final String _FINDER_COLUMN_G_M_P_H_HIDDEN_2 = "dlFolder.hidden = ?";
8925            private static final String _FINDER_COLUMN_G_M_P_H_HIDDEN_2_SQL = "dlFolder.hidden_ = ?";
8926            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_M_T_H = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
8927                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
8928                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_M_T_H",
8929                            new String[] {
8930                                    Long.class.getName(), Boolean.class.getName(),
8931                                    String.class.getName(), Boolean.class.getName(),
8932                                    
8933                            Integer.class.getName(), Integer.class.getName(),
8934                                    OrderByComparator.class.getName()
8935                            });
8936            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_M_T_H = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
8937                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
8938                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_M_T_H",
8939                            new String[] {
8940                                    Long.class.getName(), Boolean.class.getName(),
8941                                    String.class.getName(), Boolean.class.getName()
8942                            });
8943    
8944            /**
8945             * Returns all the document library folders where groupId = &#63; and mountPoint = &#63; and treePath LIKE &#63; and hidden = &#63;.
8946             *
8947             * @param groupId the group ID
8948             * @param mountPoint the mount point
8949             * @param treePath the tree path
8950             * @param hidden the hidden
8951             * @return the matching document library folders
8952             */
8953            @Override
8954            public List<DLFolder> findByG_M_T_H(long groupId, boolean mountPoint,
8955                    String treePath, boolean hidden) {
8956                    return findByG_M_T_H(groupId, mountPoint, treePath, hidden,
8957                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
8958            }
8959    
8960            /**
8961             * Returns a range of all the document library folders where groupId = &#63; and mountPoint = &#63; and treePath LIKE &#63; and hidden = &#63;.
8962             *
8963             * <p>
8964             * 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.
8965             * </p>
8966             *
8967             * @param groupId the group ID
8968             * @param mountPoint the mount point
8969             * @param treePath the tree path
8970             * @param hidden the hidden
8971             * @param start the lower bound of the range of document library folders
8972             * @param end the upper bound of the range of document library folders (not inclusive)
8973             * @return the range of matching document library folders
8974             */
8975            @Override
8976            public List<DLFolder> findByG_M_T_H(long groupId, boolean mountPoint,
8977                    String treePath, boolean hidden, int start, int end) {
8978                    return findByG_M_T_H(groupId, mountPoint, treePath, hidden, start, end,
8979                            null);
8980            }
8981    
8982            /**
8983             * Returns an ordered range of all the document library folders where groupId = &#63; and mountPoint = &#63; and treePath LIKE &#63; and hidden = &#63;.
8984             *
8985             * <p>
8986             * 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.
8987             * </p>
8988             *
8989             * @param groupId the group ID
8990             * @param mountPoint the mount point
8991             * @param treePath the tree path
8992             * @param hidden the hidden
8993             * @param start the lower bound of the range of document library folders
8994             * @param end the upper bound of the range of document library folders (not inclusive)
8995             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8996             * @return the ordered range of matching document library folders
8997             */
8998            @Override
8999            public List<DLFolder> findByG_M_T_H(long groupId, boolean mountPoint,
9000                    String treePath, boolean hidden, int start, int end,
9001                    OrderByComparator<DLFolder> orderByComparator) {
9002                    return findByG_M_T_H(groupId, mountPoint, treePath, hidden, start, end,
9003                            orderByComparator, true);
9004            }
9005    
9006            /**
9007             * Returns an ordered range of all the document library folders where groupId = &#63; and mountPoint = &#63; and treePath LIKE &#63; and hidden = &#63;.
9008             *
9009             * <p>
9010             * 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.
9011             * </p>
9012             *
9013             * @param groupId the group ID
9014             * @param mountPoint the mount point
9015             * @param treePath the tree path
9016             * @param hidden the hidden
9017             * @param start the lower bound of the range of document library folders
9018             * @param end the upper bound of the range of document library folders (not inclusive)
9019             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9020             * @param retrieveFromCache whether to retrieve from the finder cache
9021             * @return the ordered range of matching document library folders
9022             */
9023            @Override
9024            public List<DLFolder> findByG_M_T_H(long groupId, boolean mountPoint,
9025                    String treePath, boolean hidden, int start, int end,
9026                    OrderByComparator<DLFolder> orderByComparator, boolean retrieveFromCache) {
9027                    boolean pagination = true;
9028                    FinderPath finderPath = null;
9029                    Object[] finderArgs = null;
9030    
9031                    finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_M_T_H;
9032                    finderArgs = new Object[] {
9033                                    groupId, mountPoint, treePath, hidden,
9034                                    
9035                                    start, end, orderByComparator
9036                            };
9037    
9038                    List<DLFolder> list = null;
9039    
9040                    if (retrieveFromCache) {
9041                            list = (List<DLFolder>)finderCache.getResult(finderPath,
9042                                            finderArgs, this);
9043    
9044                            if ((list != null) && !list.isEmpty()) {
9045                                    for (DLFolder dlFolder : list) {
9046                                            if ((groupId != dlFolder.getGroupId()) ||
9047                                                            (mountPoint != dlFolder.getMountPoint()) ||
9048                                                            !StringUtil.wildcardMatches(
9049                                                                    dlFolder.getTreePath(), treePath,
9050                                                                    CharPool.UNDERLINE, CharPool.PERCENT,
9051                                                                    CharPool.BACK_SLASH, true) ||
9052                                                            (hidden != dlFolder.getHidden())) {
9053                                                    list = null;
9054    
9055                                                    break;
9056                                            }
9057                                    }
9058                            }
9059                    }
9060    
9061                    if (list == null) {
9062                            StringBundler query = null;
9063    
9064                            if (orderByComparator != null) {
9065                                    query = new StringBundler(6 +
9066                                                    (orderByComparator.getOrderByFields().length * 2));
9067                            }
9068                            else {
9069                                    query = new StringBundler(6);
9070                            }
9071    
9072                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
9073    
9074                            query.append(_FINDER_COLUMN_G_M_T_H_GROUPID_2);
9075    
9076                            query.append(_FINDER_COLUMN_G_M_T_H_MOUNTPOINT_2);
9077    
9078                            boolean bindTreePath = false;
9079    
9080                            if (treePath == null) {
9081                                    query.append(_FINDER_COLUMN_G_M_T_H_TREEPATH_1);
9082                            }
9083                            else if (treePath.equals(StringPool.BLANK)) {
9084                                    query.append(_FINDER_COLUMN_G_M_T_H_TREEPATH_3);
9085                            }
9086                            else {
9087                                    bindTreePath = true;
9088    
9089                                    query.append(_FINDER_COLUMN_G_M_T_H_TREEPATH_2);
9090                            }
9091    
9092                            query.append(_FINDER_COLUMN_G_M_T_H_HIDDEN_2);
9093    
9094                            if (orderByComparator != null) {
9095                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9096                                            orderByComparator);
9097                            }
9098                            else
9099                             if (pagination) {
9100                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
9101                            }
9102    
9103                            String sql = query.toString();
9104    
9105                            Session session = null;
9106    
9107                            try {
9108                                    session = openSession();
9109    
9110                                    Query q = session.createQuery(sql);
9111    
9112                                    QueryPos qPos = QueryPos.getInstance(q);
9113    
9114                                    qPos.add(groupId);
9115    
9116                                    qPos.add(mountPoint);
9117    
9118                                    if (bindTreePath) {
9119                                            qPos.add(treePath);
9120                                    }
9121    
9122                                    qPos.add(hidden);
9123    
9124                                    if (!pagination) {
9125                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
9126                                                            start, end, false);
9127    
9128                                            Collections.sort(list);
9129    
9130                                            list = Collections.unmodifiableList(list);
9131                                    }
9132                                    else {
9133                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
9134                                                            start, end);
9135                                    }
9136    
9137                                    cacheResult(list);
9138    
9139                                    finderCache.putResult(finderPath, finderArgs, list);
9140                            }
9141                            catch (Exception e) {
9142                                    finderCache.removeResult(finderPath, finderArgs);
9143    
9144                                    throw processException(e);
9145                            }
9146                            finally {
9147                                    closeSession(session);
9148                            }
9149                    }
9150    
9151                    return list;
9152            }
9153    
9154            /**
9155             * Returns the first document library folder in the ordered set where groupId = &#63; and mountPoint = &#63; and treePath LIKE &#63; and hidden = &#63;.
9156             *
9157             * @param groupId the group ID
9158             * @param mountPoint the mount point
9159             * @param treePath the tree path
9160             * @param hidden the hidden
9161             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9162             * @return the first matching document library folder
9163             * @throws NoSuchFolderException if a matching document library folder could not be found
9164             */
9165            @Override
9166            public DLFolder findByG_M_T_H_First(long groupId, boolean mountPoint,
9167                    String treePath, boolean hidden,
9168                    OrderByComparator<DLFolder> orderByComparator)
9169                    throws NoSuchFolderException {
9170                    DLFolder dlFolder = fetchByG_M_T_H_First(groupId, mountPoint, treePath,
9171                                    hidden, orderByComparator);
9172    
9173                    if (dlFolder != null) {
9174                            return dlFolder;
9175                    }
9176    
9177                    StringBundler msg = new StringBundler(10);
9178    
9179                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9180    
9181                    msg.append("groupId=");
9182                    msg.append(groupId);
9183    
9184                    msg.append(", mountPoint=");
9185                    msg.append(mountPoint);
9186    
9187                    msg.append(", treePath=");
9188                    msg.append(treePath);
9189    
9190                    msg.append(", hidden=");
9191                    msg.append(hidden);
9192    
9193                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9194    
9195                    throw new NoSuchFolderException(msg.toString());
9196            }
9197    
9198            /**
9199             * Returns the first document library folder in the ordered set where groupId = &#63; and mountPoint = &#63; and treePath LIKE &#63; and hidden = &#63;.
9200             *
9201             * @param groupId the group ID
9202             * @param mountPoint the mount point
9203             * @param treePath the tree path
9204             * @param hidden the hidden
9205             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9206             * @return the first matching document library folder, or <code>null</code> if a matching document library folder could not be found
9207             */
9208            @Override
9209            public DLFolder fetchByG_M_T_H_First(long groupId, boolean mountPoint,
9210                    String treePath, boolean hidden,
9211                    OrderByComparator<DLFolder> orderByComparator) {
9212                    List<DLFolder> list = findByG_M_T_H(groupId, mountPoint, treePath,
9213                                    hidden, 0, 1, orderByComparator);
9214    
9215                    if (!list.isEmpty()) {
9216                            return list.get(0);
9217                    }
9218    
9219                    return null;
9220            }
9221    
9222            /**
9223             * Returns the last document library folder in the ordered set where groupId = &#63; and mountPoint = &#63; and treePath LIKE &#63; and hidden = &#63;.
9224             *
9225             * @param groupId the group ID
9226             * @param mountPoint the mount point
9227             * @param treePath the tree path
9228             * @param hidden the hidden
9229             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9230             * @return the last matching document library folder
9231             * @throws NoSuchFolderException if a matching document library folder could not be found
9232             */
9233            @Override
9234            public DLFolder findByG_M_T_H_Last(long groupId, boolean mountPoint,
9235                    String treePath, boolean hidden,
9236                    OrderByComparator<DLFolder> orderByComparator)
9237                    throws NoSuchFolderException {
9238                    DLFolder dlFolder = fetchByG_M_T_H_Last(groupId, mountPoint, treePath,
9239                                    hidden, orderByComparator);
9240    
9241                    if (dlFolder != null) {
9242                            return dlFolder;
9243                    }
9244    
9245                    StringBundler msg = new StringBundler(10);
9246    
9247                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9248    
9249                    msg.append("groupId=");
9250                    msg.append(groupId);
9251    
9252                    msg.append(", mountPoint=");
9253                    msg.append(mountPoint);
9254    
9255                    msg.append(", treePath=");
9256                    msg.append(treePath);
9257    
9258                    msg.append(", hidden=");
9259                    msg.append(hidden);
9260    
9261                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9262    
9263                    throw new NoSuchFolderException(msg.toString());
9264            }
9265    
9266            /**
9267             * Returns the last document library folder in the ordered set where groupId = &#63; and mountPoint = &#63; and treePath LIKE &#63; and hidden = &#63;.
9268             *
9269             * @param groupId the group ID
9270             * @param mountPoint the mount point
9271             * @param treePath the tree path
9272             * @param hidden the hidden
9273             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9274             * @return the last matching document library folder, or <code>null</code> if a matching document library folder could not be found
9275             */
9276            @Override
9277            public DLFolder fetchByG_M_T_H_Last(long groupId, boolean mountPoint,
9278                    String treePath, boolean hidden,
9279                    OrderByComparator<DLFolder> orderByComparator) {
9280                    int count = countByG_M_T_H(groupId, mountPoint, treePath, hidden);
9281    
9282                    if (count == 0) {
9283                            return null;
9284                    }
9285    
9286                    List<DLFolder> list = findByG_M_T_H(groupId, mountPoint, treePath,
9287                                    hidden, count - 1, count, orderByComparator);
9288    
9289                    if (!list.isEmpty()) {
9290                            return list.get(0);
9291                    }
9292    
9293                    return null;
9294            }
9295    
9296            /**
9297             * 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;.
9298             *
9299             * @param folderId the primary key of the current document library folder
9300             * @param groupId the group ID
9301             * @param mountPoint the mount point
9302             * @param treePath the tree path
9303             * @param hidden the hidden
9304             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9305             * @return the previous, current, and next document library folder
9306             * @throws NoSuchFolderException if a document library folder with the primary key could not be found
9307             */
9308            @Override
9309            public DLFolder[] findByG_M_T_H_PrevAndNext(long folderId, long groupId,
9310                    boolean mountPoint, String treePath, boolean hidden,
9311                    OrderByComparator<DLFolder> orderByComparator)
9312                    throws NoSuchFolderException {
9313                    DLFolder dlFolder = findByPrimaryKey(folderId);
9314    
9315                    Session session = null;
9316    
9317                    try {
9318                            session = openSession();
9319    
9320                            DLFolder[] array = new DLFolderImpl[3];
9321    
9322                            array[0] = getByG_M_T_H_PrevAndNext(session, dlFolder, groupId,
9323                                            mountPoint, treePath, hidden, orderByComparator, true);
9324    
9325                            array[1] = dlFolder;
9326    
9327                            array[2] = getByG_M_T_H_PrevAndNext(session, dlFolder, groupId,
9328                                            mountPoint, treePath, hidden, orderByComparator, false);
9329    
9330                            return array;
9331                    }
9332                    catch (Exception e) {
9333                            throw processException(e);
9334                    }
9335                    finally {
9336                            closeSession(session);
9337                    }
9338            }
9339    
9340            protected DLFolder getByG_M_T_H_PrevAndNext(Session session,
9341                    DLFolder dlFolder, long groupId, boolean mountPoint, String treePath,
9342                    boolean hidden, OrderByComparator<DLFolder> orderByComparator,
9343                    boolean previous) {
9344                    StringBundler query = null;
9345    
9346                    if (orderByComparator != null) {
9347                            query = new StringBundler(7 +
9348                                            (orderByComparator.getOrderByConditionFields().length * 3) +
9349                                            (orderByComparator.getOrderByFields().length * 3));
9350                    }
9351                    else {
9352                            query = new StringBundler(6);
9353                    }
9354    
9355                    query.append(_SQL_SELECT_DLFOLDER_WHERE);
9356    
9357                    query.append(_FINDER_COLUMN_G_M_T_H_GROUPID_2);
9358    
9359                    query.append(_FINDER_COLUMN_G_M_T_H_MOUNTPOINT_2);
9360    
9361                    boolean bindTreePath = false;
9362    
9363                    if (treePath == null) {
9364                            query.append(_FINDER_COLUMN_G_M_T_H_TREEPATH_1);
9365                    }
9366                    else if (treePath.equals(StringPool.BLANK)) {
9367                            query.append(_FINDER_COLUMN_G_M_T_H_TREEPATH_3);
9368                    }
9369                    else {
9370                            bindTreePath = true;
9371    
9372                            query.append(_FINDER_COLUMN_G_M_T_H_TREEPATH_2);
9373                    }
9374    
9375                    query.append(_FINDER_COLUMN_G_M_T_H_HIDDEN_2);
9376    
9377                    if (orderByComparator != null) {
9378                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
9379    
9380                            if (orderByConditionFields.length > 0) {
9381                                    query.append(WHERE_AND);
9382                            }
9383    
9384                            for (int i = 0; i < orderByConditionFields.length; i++) {
9385                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9386                                    query.append(orderByConditionFields[i]);
9387    
9388                                    if ((i + 1) < orderByConditionFields.length) {
9389                                            if (orderByComparator.isAscending() ^ previous) {
9390                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
9391                                            }
9392                                            else {
9393                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
9394                                            }
9395                                    }
9396                                    else {
9397                                            if (orderByComparator.isAscending() ^ previous) {
9398                                                    query.append(WHERE_GREATER_THAN);
9399                                            }
9400                                            else {
9401                                                    query.append(WHERE_LESSER_THAN);
9402                                            }
9403                                    }
9404                            }
9405    
9406                            query.append(ORDER_BY_CLAUSE);
9407    
9408                            String[] orderByFields = orderByComparator.getOrderByFields();
9409    
9410                            for (int i = 0; i < orderByFields.length; i++) {
9411                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9412                                    query.append(orderByFields[i]);
9413    
9414                                    if ((i + 1) < orderByFields.length) {
9415                                            if (orderByComparator.isAscending() ^ previous) {
9416                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
9417                                            }
9418                                            else {
9419                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
9420                                            }
9421                                    }
9422                                    else {
9423                                            if (orderByComparator.isAscending() ^ previous) {
9424                                                    query.append(ORDER_BY_ASC);
9425                                            }
9426                                            else {
9427                                                    query.append(ORDER_BY_DESC);
9428                                            }
9429                                    }
9430                            }
9431                    }
9432                    else {
9433                            query.append(DLFolderModelImpl.ORDER_BY_JPQL);
9434                    }
9435    
9436                    String sql = query.toString();
9437    
9438                    Query q = session.createQuery(sql);
9439    
9440                    q.setFirstResult(0);
9441                    q.setMaxResults(2);
9442    
9443                    QueryPos qPos = QueryPos.getInstance(q);
9444    
9445                    qPos.add(groupId);
9446    
9447                    qPos.add(mountPoint);
9448    
9449                    if (bindTreePath) {
9450                            qPos.add(treePath);
9451                    }
9452    
9453                    qPos.add(hidden);
9454    
9455                    if (orderByComparator != null) {
9456                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
9457    
9458                            for (Object value : values) {
9459                                    qPos.add(value);
9460                            }
9461                    }
9462    
9463                    List<DLFolder> list = q.list();
9464    
9465                    if (list.size() == 2) {
9466                            return list.get(1);
9467                    }
9468                    else {
9469                            return null;
9470                    }
9471            }
9472    
9473            /**
9474             * 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;.
9475             *
9476             * @param groupId the group ID
9477             * @param mountPoint the mount point
9478             * @param treePath the tree path
9479             * @param hidden the hidden
9480             * @return the matching document library folders that the user has permission to view
9481             */
9482            @Override
9483            public List<DLFolder> filterFindByG_M_T_H(long groupId, boolean mountPoint,
9484                    String treePath, boolean hidden) {
9485                    return filterFindByG_M_T_H(groupId, mountPoint, treePath, hidden,
9486                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
9487            }
9488    
9489            /**
9490             * 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;.
9491             *
9492             * <p>
9493             * 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.
9494             * </p>
9495             *
9496             * @param groupId the group ID
9497             * @param mountPoint the mount point
9498             * @param treePath the tree path
9499             * @param hidden the hidden
9500             * @param start the lower bound of the range of document library folders
9501             * @param end the upper bound of the range of document library folders (not inclusive)
9502             * @return the range of matching document library folders that the user has permission to view
9503             */
9504            @Override
9505            public List<DLFolder> filterFindByG_M_T_H(long groupId, boolean mountPoint,
9506                    String treePath, boolean hidden, int start, int end) {
9507                    return filterFindByG_M_T_H(groupId, mountPoint, treePath, hidden,
9508                            start, end, null);
9509            }
9510    
9511            /**
9512             * 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;.
9513             *
9514             * <p>
9515             * 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.
9516             * </p>
9517             *
9518             * @param groupId the group ID
9519             * @param mountPoint the mount point
9520             * @param treePath the tree path
9521             * @param hidden the hidden
9522             * @param start the lower bound of the range of document library folders
9523             * @param end the upper bound of the range of document library folders (not inclusive)
9524             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9525             * @return the ordered range of matching document library folders that the user has permission to view
9526             */
9527            @Override
9528            public List<DLFolder> filterFindByG_M_T_H(long groupId, boolean mountPoint,
9529                    String treePath, boolean hidden, int start, int end,
9530                    OrderByComparator<DLFolder> orderByComparator) {
9531                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
9532                            return findByG_M_T_H(groupId, mountPoint, treePath, hidden, start,
9533                                    end, orderByComparator);
9534                    }
9535    
9536                    StringBundler query = null;
9537    
9538                    if (orderByComparator != null) {
9539                            query = new StringBundler(6 +
9540                                            (orderByComparator.getOrderByFields().length * 2));
9541                    }
9542                    else {
9543                            query = new StringBundler(7);
9544                    }
9545    
9546                    if (getDB().isSupportsInlineDistinct()) {
9547                            query.append(_FILTER_SQL_SELECT_DLFOLDER_WHERE);
9548                    }
9549                    else {
9550                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1);
9551                    }
9552    
9553                    query.append(_FINDER_COLUMN_G_M_T_H_GROUPID_2);
9554    
9555                    query.append(_FINDER_COLUMN_G_M_T_H_MOUNTPOINT_2);
9556    
9557                    boolean bindTreePath = false;
9558    
9559                    if (treePath == null) {
9560                            query.append(_FINDER_COLUMN_G_M_T_H_TREEPATH_1);
9561                    }
9562                    else if (treePath.equals(StringPool.BLANK)) {
9563                            query.append(_FINDER_COLUMN_G_M_T_H_TREEPATH_3);
9564                    }
9565                    else {
9566                            bindTreePath = true;
9567    
9568                            query.append(_FINDER_COLUMN_G_M_T_H_TREEPATH_2);
9569                    }
9570    
9571                    query.append(_FINDER_COLUMN_G_M_T_H_HIDDEN_2_SQL);
9572    
9573                    if (!getDB().isSupportsInlineDistinct()) {
9574                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2);
9575                    }
9576    
9577                    if (orderByComparator != null) {
9578                            if (getDB().isSupportsInlineDistinct()) {
9579                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9580                                            orderByComparator, true);
9581                            }
9582                            else {
9583                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
9584                                            orderByComparator, true);
9585                            }
9586                    }
9587                    else {
9588                            if (getDB().isSupportsInlineDistinct()) {
9589                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
9590                            }
9591                            else {
9592                                    query.append(DLFolderModelImpl.ORDER_BY_SQL);
9593                            }
9594                    }
9595    
9596                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
9597                                    DLFolder.class.getName(),
9598                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
9599    
9600                    Session session = null;
9601    
9602                    try {
9603                            session = openSession();
9604    
9605                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
9606    
9607                            if (getDB().isSupportsInlineDistinct()) {
9608                                    q.addEntity(_FILTER_ENTITY_ALIAS, DLFolderImpl.class);
9609                            }
9610                            else {
9611                                    q.addEntity(_FILTER_ENTITY_TABLE, DLFolderImpl.class);
9612                            }
9613    
9614                            QueryPos qPos = QueryPos.getInstance(q);
9615    
9616                            qPos.add(groupId);
9617    
9618                            qPos.add(mountPoint);
9619    
9620                            if (bindTreePath) {
9621                                    qPos.add(treePath);
9622                            }
9623    
9624                            qPos.add(hidden);
9625    
9626                            return (List<DLFolder>)QueryUtil.list(q, getDialect(), start, end);
9627                    }
9628                    catch (Exception e) {
9629                            throw processException(e);
9630                    }
9631                    finally {
9632                            closeSession(session);
9633                    }
9634            }
9635    
9636            /**
9637             * 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;.
9638             *
9639             * @param folderId the primary key of the current document library folder
9640             * @param groupId the group ID
9641             * @param mountPoint the mount point
9642             * @param treePath the tree path
9643             * @param hidden the hidden
9644             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9645             * @return the previous, current, and next document library folder
9646             * @throws NoSuchFolderException if a document library folder with the primary key could not be found
9647             */
9648            @Override
9649            public DLFolder[] filterFindByG_M_T_H_PrevAndNext(long folderId,
9650                    long groupId, boolean mountPoint, String treePath, boolean hidden,
9651                    OrderByComparator<DLFolder> orderByComparator)
9652                    throws NoSuchFolderException {
9653                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
9654                            return findByG_M_T_H_PrevAndNext(folderId, groupId, mountPoint,
9655                                    treePath, hidden, orderByComparator);
9656                    }
9657    
9658                    DLFolder dlFolder = findByPrimaryKey(folderId);
9659    
9660                    Session session = null;
9661    
9662                    try {
9663                            session = openSession();
9664    
9665                            DLFolder[] array = new DLFolderImpl[3];
9666    
9667                            array[0] = filterGetByG_M_T_H_PrevAndNext(session, dlFolder,
9668                                            groupId, mountPoint, treePath, hidden, orderByComparator,
9669                                            true);
9670    
9671                            array[1] = dlFolder;
9672    
9673                            array[2] = filterGetByG_M_T_H_PrevAndNext(session, dlFolder,
9674                                            groupId, mountPoint, treePath, hidden, orderByComparator,
9675                                            false);
9676    
9677                            return array;
9678                    }
9679                    catch (Exception e) {
9680                            throw processException(e);
9681                    }
9682                    finally {
9683                            closeSession(session);
9684                    }
9685            }
9686    
9687            protected DLFolder filterGetByG_M_T_H_PrevAndNext(Session session,
9688                    DLFolder dlFolder, long groupId, boolean mountPoint, String treePath,
9689                    boolean hidden, OrderByComparator<DLFolder> orderByComparator,
9690                    boolean previous) {
9691                    StringBundler query = null;
9692    
9693                    if (orderByComparator != null) {
9694                            query = new StringBundler(8 +
9695                                            (orderByComparator.getOrderByConditionFields().length * 3) +
9696                                            (orderByComparator.getOrderByFields().length * 3));
9697                    }
9698                    else {
9699                            query = new StringBundler(7);
9700                    }
9701    
9702                    if (getDB().isSupportsInlineDistinct()) {
9703                            query.append(_FILTER_SQL_SELECT_DLFOLDER_WHERE);
9704                    }
9705                    else {
9706                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1);
9707                    }
9708    
9709                    query.append(_FINDER_COLUMN_G_M_T_H_GROUPID_2);
9710    
9711                    query.append(_FINDER_COLUMN_G_M_T_H_MOUNTPOINT_2);
9712    
9713                    boolean bindTreePath = false;
9714    
9715                    if (treePath == null) {
9716                            query.append(_FINDER_COLUMN_G_M_T_H_TREEPATH_1);
9717                    }
9718                    else if (treePath.equals(StringPool.BLANK)) {
9719                            query.append(_FINDER_COLUMN_G_M_T_H_TREEPATH_3);
9720                    }
9721                    else {
9722                            bindTreePath = true;
9723    
9724                            query.append(_FINDER_COLUMN_G_M_T_H_TREEPATH_2);
9725                    }
9726    
9727                    query.append(_FINDER_COLUMN_G_M_T_H_HIDDEN_2_SQL);
9728    
9729                    if (!getDB().isSupportsInlineDistinct()) {
9730                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2);
9731                    }
9732    
9733                    if (orderByComparator != null) {
9734                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
9735    
9736                            if (orderByConditionFields.length > 0) {
9737                                    query.append(WHERE_AND);
9738                            }
9739    
9740                            for (int i = 0; i < orderByConditionFields.length; i++) {
9741                                    if (getDB().isSupportsInlineDistinct()) {
9742                                            query.append(_ORDER_BY_ENTITY_ALIAS);
9743                                    }
9744                                    else {
9745                                            query.append(_ORDER_BY_ENTITY_TABLE);
9746                                    }
9747    
9748                                    query.append(orderByConditionFields[i]);
9749    
9750                                    if ((i + 1) < orderByConditionFields.length) {
9751                                            if (orderByComparator.isAscending() ^ previous) {
9752                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
9753                                            }
9754                                            else {
9755                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
9756                                            }
9757                                    }
9758                                    else {
9759                                            if (orderByComparator.isAscending() ^ previous) {
9760                                                    query.append(WHERE_GREATER_THAN);
9761                                            }
9762                                            else {
9763                                                    query.append(WHERE_LESSER_THAN);
9764                                            }
9765                                    }
9766                            }
9767    
9768                            query.append(ORDER_BY_CLAUSE);
9769    
9770                            String[] orderByFields = orderByComparator.getOrderByFields();
9771    
9772                            for (int i = 0; i < orderByFields.length; i++) {
9773                                    if (getDB().isSupportsInlineDistinct()) {
9774                                            query.append(_ORDER_BY_ENTITY_ALIAS);
9775                                    }
9776                                    else {
9777                                            query.append(_ORDER_BY_ENTITY_TABLE);
9778                                    }
9779    
9780                                    query.append(orderByFields[i]);
9781    
9782                                    if ((i + 1) < orderByFields.length) {
9783                                            if (orderByComparator.isAscending() ^ previous) {
9784                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
9785                                            }
9786                                            else {
9787                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
9788                                            }
9789                                    }
9790                                    else {
9791                                            if (orderByComparator.isAscending() ^ previous) {
9792                                                    query.append(ORDER_BY_ASC);
9793                                            }
9794                                            else {
9795                                                    query.append(ORDER_BY_DESC);
9796                                            }
9797                                    }
9798                            }
9799                    }
9800                    else {
9801                            if (getDB().isSupportsInlineDistinct()) {
9802                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
9803                            }
9804                            else {
9805                                    query.append(DLFolderModelImpl.ORDER_BY_SQL);
9806                            }
9807                    }
9808    
9809                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
9810                                    DLFolder.class.getName(),
9811                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
9812    
9813                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
9814    
9815                    q.setFirstResult(0);
9816                    q.setMaxResults(2);
9817    
9818                    if (getDB().isSupportsInlineDistinct()) {
9819                            q.addEntity(_FILTER_ENTITY_ALIAS, DLFolderImpl.class);
9820                    }
9821                    else {
9822                            q.addEntity(_FILTER_ENTITY_TABLE, DLFolderImpl.class);
9823                    }
9824    
9825                    QueryPos qPos = QueryPos.getInstance(q);
9826    
9827                    qPos.add(groupId);
9828    
9829                    qPos.add(mountPoint);
9830    
9831                    if (bindTreePath) {
9832                            qPos.add(treePath);
9833                    }
9834    
9835                    qPos.add(hidden);
9836    
9837                    if (orderByComparator != null) {
9838                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
9839    
9840                            for (Object value : values) {
9841                                    qPos.add(value);
9842                            }
9843                    }
9844    
9845                    List<DLFolder> list = q.list();
9846    
9847                    if (list.size() == 2) {
9848                            return list.get(1);
9849                    }
9850                    else {
9851                            return null;
9852                    }
9853            }
9854    
9855            /**
9856             * Removes all the document library folders where groupId = &#63; and mountPoint = &#63; and treePath LIKE &#63; and hidden = &#63; from the database.
9857             *
9858             * @param groupId the group ID
9859             * @param mountPoint the mount point
9860             * @param treePath the tree path
9861             * @param hidden the hidden
9862             */
9863            @Override
9864            public void removeByG_M_T_H(long groupId, boolean mountPoint,
9865                    String treePath, boolean hidden) {
9866                    for (DLFolder dlFolder : findByG_M_T_H(groupId, mountPoint, treePath,
9867                                    hidden, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
9868                            remove(dlFolder);
9869                    }
9870            }
9871    
9872            /**
9873             * Returns the number of document library folders where groupId = &#63; and mountPoint = &#63; and treePath LIKE &#63; and hidden = &#63;.
9874             *
9875             * @param groupId the group ID
9876             * @param mountPoint the mount point
9877             * @param treePath the tree path
9878             * @param hidden the hidden
9879             * @return the number of matching document library folders
9880             */
9881            @Override
9882            public int countByG_M_T_H(long groupId, boolean mountPoint,
9883                    String treePath, boolean hidden) {
9884                    FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_M_T_H;
9885    
9886                    Object[] finderArgs = new Object[] { groupId, mountPoint, treePath, hidden };
9887    
9888                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
9889    
9890                    if (count == null) {
9891                            StringBundler query = new StringBundler(5);
9892    
9893                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
9894    
9895                            query.append(_FINDER_COLUMN_G_M_T_H_GROUPID_2);
9896    
9897                            query.append(_FINDER_COLUMN_G_M_T_H_MOUNTPOINT_2);
9898    
9899                            boolean bindTreePath = false;
9900    
9901                            if (treePath == null) {
9902                                    query.append(_FINDER_COLUMN_G_M_T_H_TREEPATH_1);
9903                            }
9904                            else if (treePath.equals(StringPool.BLANK)) {
9905                                    query.append(_FINDER_COLUMN_G_M_T_H_TREEPATH_3);
9906                            }
9907                            else {
9908                                    bindTreePath = true;
9909    
9910                                    query.append(_FINDER_COLUMN_G_M_T_H_TREEPATH_2);
9911                            }
9912    
9913                            query.append(_FINDER_COLUMN_G_M_T_H_HIDDEN_2);
9914    
9915                            String sql = query.toString();
9916    
9917                            Session session = null;
9918    
9919                            try {
9920                                    session = openSession();
9921    
9922                                    Query q = session.createQuery(sql);
9923    
9924                                    QueryPos qPos = QueryPos.getInstance(q);
9925    
9926                                    qPos.add(groupId);
9927    
9928                                    qPos.add(mountPoint);
9929    
9930                                    if (bindTreePath) {
9931                                            qPos.add(treePath);
9932                                    }
9933    
9934                                    qPos.add(hidden);
9935    
9936                                    count = (Long)q.uniqueResult();
9937    
9938                                    finderCache.putResult(finderPath, finderArgs, count);
9939                            }
9940                            catch (Exception e) {
9941                                    finderCache.removeResult(finderPath, finderArgs);
9942    
9943                                    throw processException(e);
9944                            }
9945                            finally {
9946                                    closeSession(session);
9947                            }
9948                    }
9949    
9950                    return count.intValue();
9951            }
9952    
9953            /**
9954             * 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;.
9955             *
9956             * @param groupId the group ID
9957             * @param mountPoint the mount point
9958             * @param treePath the tree path
9959             * @param hidden the hidden
9960             * @return the number of matching document library folders that the user has permission to view
9961             */
9962            @Override
9963            public int filterCountByG_M_T_H(long groupId, boolean mountPoint,
9964                    String treePath, boolean hidden) {
9965                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
9966                            return countByG_M_T_H(groupId, mountPoint, treePath, hidden);
9967                    }
9968    
9969                    StringBundler query = new StringBundler(5);
9970    
9971                    query.append(_FILTER_SQL_COUNT_DLFOLDER_WHERE);
9972    
9973                    query.append(_FINDER_COLUMN_G_M_T_H_GROUPID_2);
9974    
9975                    query.append(_FINDER_COLUMN_G_M_T_H_MOUNTPOINT_2);
9976    
9977                    boolean bindTreePath = false;
9978    
9979                    if (treePath == null) {
9980                            query.append(_FINDER_COLUMN_G_M_T_H_TREEPATH_1);
9981                    }
9982                    else if (treePath.equals(StringPool.BLANK)) {
9983                            query.append(_FINDER_COLUMN_G_M_T_H_TREEPATH_3);
9984                    }
9985                    else {
9986                            bindTreePath = true;
9987    
9988                            query.append(_FINDER_COLUMN_G_M_T_H_TREEPATH_2);
9989                    }
9990    
9991                    query.append(_FINDER_COLUMN_G_M_T_H_HIDDEN_2_SQL);
9992    
9993                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
9994                                    DLFolder.class.getName(),
9995                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
9996    
9997                    Session session = null;
9998    
9999                    try {
10000                            session = openSession();
10001    
10002                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
10003    
10004                            q.addScalar(COUNT_COLUMN_NAME,
10005                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
10006    
10007                            QueryPos qPos = QueryPos.getInstance(q);
10008    
10009                            qPos.add(groupId);
10010    
10011                            qPos.add(mountPoint);
10012    
10013                            if (bindTreePath) {
10014                                    qPos.add(treePath);
10015                            }
10016    
10017                            qPos.add(hidden);
10018    
10019                            Long count = (Long)q.uniqueResult();
10020    
10021                            return count.intValue();
10022                    }
10023                    catch (Exception e) {
10024                            throw processException(e);
10025                    }
10026                    finally {
10027                            closeSession(session);
10028                    }
10029            }
10030    
10031            private static final String _FINDER_COLUMN_G_M_T_H_GROUPID_2 = "dlFolder.groupId = ? AND ";
10032            private static final String _FINDER_COLUMN_G_M_T_H_MOUNTPOINT_2 = "dlFolder.mountPoint = ? AND ";
10033            private static final String _FINDER_COLUMN_G_M_T_H_TREEPATH_1 = "dlFolder.treePath IS NULL AND ";
10034            private static final String _FINDER_COLUMN_G_M_T_H_TREEPATH_2 = "dlFolder.treePath LIKE ? AND ";
10035            private static final String _FINDER_COLUMN_G_M_T_H_TREEPATH_3 = "(dlFolder.treePath IS NULL OR dlFolder.treePath LIKE '') AND ";
10036            private static final String _FINDER_COLUMN_G_M_T_H_HIDDEN_2 = "dlFolder.hidden = ?";
10037            private static final String _FINDER_COLUMN_G_M_T_H_HIDDEN_2_SQL = "dlFolder.hidden_ = ?";
10038            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_H_S = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
10039                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
10040                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_P_H_S",
10041                            new String[] {
10042                                    Long.class.getName(), Long.class.getName(),
10043                                    Boolean.class.getName(), Integer.class.getName(),
10044                                    
10045                            Integer.class.getName(), Integer.class.getName(),
10046                                    OrderByComparator.class.getName()
10047                            });
10048            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_H_S =
10049                    new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
10050                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
10051                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_P_H_S",
10052                            new String[] {
10053                                    Long.class.getName(), Long.class.getName(),
10054                                    Boolean.class.getName(), Integer.class.getName()
10055                            },
10056                            DLFolderModelImpl.GROUPID_COLUMN_BITMASK |
10057                            DLFolderModelImpl.PARENTFOLDERID_COLUMN_BITMASK |
10058                            DLFolderModelImpl.HIDDEN_COLUMN_BITMASK |
10059                            DLFolderModelImpl.STATUS_COLUMN_BITMASK |
10060                            DLFolderModelImpl.NAME_COLUMN_BITMASK);
10061            public static final FinderPath FINDER_PATH_COUNT_BY_G_P_H_S = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
10062                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
10063                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P_H_S",
10064                            new String[] {
10065                                    Long.class.getName(), Long.class.getName(),
10066                                    Boolean.class.getName(), Integer.class.getName()
10067                            });
10068    
10069            /**
10070             * Returns all the document library folders where groupId = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
10071             *
10072             * @param groupId the group ID
10073             * @param parentFolderId the parent folder ID
10074             * @param hidden the hidden
10075             * @param status the status
10076             * @return the matching document library folders
10077             */
10078            @Override
10079            public List<DLFolder> findByG_P_H_S(long groupId, long parentFolderId,
10080                    boolean hidden, int status) {
10081                    return findByG_P_H_S(groupId, parentFolderId, hidden, status,
10082                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
10083            }
10084    
10085            /**
10086             * Returns a range of all the document library folders where groupId = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
10087             *
10088             * <p>
10089             * 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.
10090             * </p>
10091             *
10092             * @param groupId the group ID
10093             * @param parentFolderId the parent folder ID
10094             * @param hidden the hidden
10095             * @param status the status
10096             * @param start the lower bound of the range of document library folders
10097             * @param end the upper bound of the range of document library folders (not inclusive)
10098             * @return the range of matching document library folders
10099             */
10100            @Override
10101            public List<DLFolder> findByG_P_H_S(long groupId, long parentFolderId,
10102                    boolean hidden, int status, int start, int end) {
10103                    return findByG_P_H_S(groupId, parentFolderId, hidden, status, start,
10104                            end, null);
10105            }
10106    
10107            /**
10108             * Returns an ordered range of all the document library folders where groupId = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
10109             *
10110             * <p>
10111             * 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.
10112             * </p>
10113             *
10114             * @param groupId the group ID
10115             * @param parentFolderId the parent folder ID
10116             * @param hidden the hidden
10117             * @param status the status
10118             * @param start the lower bound of the range of document library folders
10119             * @param end the upper bound of the range of document library folders (not inclusive)
10120             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10121             * @return the ordered range of matching document library folders
10122             */
10123            @Override
10124            public List<DLFolder> findByG_P_H_S(long groupId, long parentFolderId,
10125                    boolean hidden, int status, int start, int end,
10126                    OrderByComparator<DLFolder> orderByComparator) {
10127                    return findByG_P_H_S(groupId, parentFolderId, hidden, status, start,
10128                            end, orderByComparator, true);
10129            }
10130    
10131            /**
10132             * Returns an ordered range of all the document library folders where groupId = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
10133             *
10134             * <p>
10135             * 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.
10136             * </p>
10137             *
10138             * @param groupId the group ID
10139             * @param parentFolderId the parent folder ID
10140             * @param hidden the hidden
10141             * @param status the status
10142             * @param start the lower bound of the range of document library folders
10143             * @param end the upper bound of the range of document library folders (not inclusive)
10144             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10145             * @param retrieveFromCache whether to retrieve from the finder cache
10146             * @return the ordered range of matching document library folders
10147             */
10148            @Override
10149            public List<DLFolder> findByG_P_H_S(long groupId, long parentFolderId,
10150                    boolean hidden, int status, int start, int end,
10151                    OrderByComparator<DLFolder> orderByComparator, boolean retrieveFromCache) {
10152                    boolean pagination = true;
10153                    FinderPath finderPath = null;
10154                    Object[] finderArgs = null;
10155    
10156                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
10157                                    (orderByComparator == null)) {
10158                            pagination = false;
10159                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_H_S;
10160                            finderArgs = new Object[] { groupId, parentFolderId, hidden, status };
10161                    }
10162                    else {
10163                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_H_S;
10164                            finderArgs = new Object[] {
10165                                            groupId, parentFolderId, hidden, status,
10166                                            
10167                                            start, end, orderByComparator
10168                                    };
10169                    }
10170    
10171                    List<DLFolder> list = null;
10172    
10173                    if (retrieveFromCache) {
10174                            list = (List<DLFolder>)finderCache.getResult(finderPath,
10175                                            finderArgs, this);
10176    
10177                            if ((list != null) && !list.isEmpty()) {
10178                                    for (DLFolder dlFolder : list) {
10179                                            if ((groupId != dlFolder.getGroupId()) ||
10180                                                            (parentFolderId != dlFolder.getParentFolderId()) ||
10181                                                            (hidden != dlFolder.getHidden()) ||
10182                                                            (status != dlFolder.getStatus())) {
10183                                                    list = null;
10184    
10185                                                    break;
10186                                            }
10187                                    }
10188                            }
10189                    }
10190    
10191                    if (list == null) {
10192                            StringBundler query = null;
10193    
10194                            if (orderByComparator != null) {
10195                                    query = new StringBundler(6 +
10196                                                    (orderByComparator.getOrderByFields().length * 2));
10197                            }
10198                            else {
10199                                    query = new StringBundler(6);
10200                            }
10201    
10202                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
10203    
10204                            query.append(_FINDER_COLUMN_G_P_H_S_GROUPID_2);
10205    
10206                            query.append(_FINDER_COLUMN_G_P_H_S_PARENTFOLDERID_2);
10207    
10208                            query.append(_FINDER_COLUMN_G_P_H_S_HIDDEN_2);
10209    
10210                            query.append(_FINDER_COLUMN_G_P_H_S_STATUS_2);
10211    
10212                            if (orderByComparator != null) {
10213                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10214                                            orderByComparator);
10215                            }
10216                            else
10217                             if (pagination) {
10218                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
10219                            }
10220    
10221                            String sql = query.toString();
10222    
10223                            Session session = null;
10224    
10225                            try {
10226                                    session = openSession();
10227    
10228                                    Query q = session.createQuery(sql);
10229    
10230                                    QueryPos qPos = QueryPos.getInstance(q);
10231    
10232                                    qPos.add(groupId);
10233    
10234                                    qPos.add(parentFolderId);
10235    
10236                                    qPos.add(hidden);
10237    
10238                                    qPos.add(status);
10239    
10240                                    if (!pagination) {
10241                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
10242                                                            start, end, false);
10243    
10244                                            Collections.sort(list);
10245    
10246                                            list = Collections.unmodifiableList(list);
10247                                    }
10248                                    else {
10249                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
10250                                                            start, end);
10251                                    }
10252    
10253                                    cacheResult(list);
10254    
10255                                    finderCache.putResult(finderPath, finderArgs, list);
10256                            }
10257                            catch (Exception e) {
10258                                    finderCache.removeResult(finderPath, finderArgs);
10259    
10260                                    throw processException(e);
10261                            }
10262                            finally {
10263                                    closeSession(session);
10264                            }
10265                    }
10266    
10267                    return list;
10268            }
10269    
10270            /**
10271             * Returns the first document library folder in the ordered set where groupId = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
10272             *
10273             * @param groupId the group ID
10274             * @param parentFolderId the parent folder ID
10275             * @param hidden the hidden
10276             * @param status the status
10277             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10278             * @return the first matching document library folder
10279             * @throws NoSuchFolderException if a matching document library folder could not be found
10280             */
10281            @Override
10282            public DLFolder findByG_P_H_S_First(long groupId, long parentFolderId,
10283                    boolean hidden, int status,
10284                    OrderByComparator<DLFolder> orderByComparator)
10285                    throws NoSuchFolderException {
10286                    DLFolder dlFolder = fetchByG_P_H_S_First(groupId, parentFolderId,
10287                                    hidden, status, orderByComparator);
10288    
10289                    if (dlFolder != null) {
10290                            return dlFolder;
10291                    }
10292    
10293                    StringBundler msg = new StringBundler(10);
10294    
10295                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10296    
10297                    msg.append("groupId=");
10298                    msg.append(groupId);
10299    
10300                    msg.append(", parentFolderId=");
10301                    msg.append(parentFolderId);
10302    
10303                    msg.append(", hidden=");
10304                    msg.append(hidden);
10305    
10306                    msg.append(", status=");
10307                    msg.append(status);
10308    
10309                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10310    
10311                    throw new NoSuchFolderException(msg.toString());
10312            }
10313    
10314            /**
10315             * Returns the first document library folder in the ordered set where groupId = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
10316             *
10317             * @param groupId the group ID
10318             * @param parentFolderId the parent folder ID
10319             * @param hidden the hidden
10320             * @param status the status
10321             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10322             * @return the first matching document library folder, or <code>null</code> if a matching document library folder could not be found
10323             */
10324            @Override
10325            public DLFolder fetchByG_P_H_S_First(long groupId, long parentFolderId,
10326                    boolean hidden, int status,
10327                    OrderByComparator<DLFolder> orderByComparator) {
10328                    List<DLFolder> list = findByG_P_H_S(groupId, parentFolderId, hidden,
10329                                    status, 0, 1, orderByComparator);
10330    
10331                    if (!list.isEmpty()) {
10332                            return list.get(0);
10333                    }
10334    
10335                    return null;
10336            }
10337    
10338            /**
10339             * Returns the last document library folder in the ordered set where groupId = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
10340             *
10341             * @param groupId the group ID
10342             * @param parentFolderId the parent folder ID
10343             * @param hidden the hidden
10344             * @param status the status
10345             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10346             * @return the last matching document library folder
10347             * @throws NoSuchFolderException if a matching document library folder could not be found
10348             */
10349            @Override
10350            public DLFolder findByG_P_H_S_Last(long groupId, long parentFolderId,
10351                    boolean hidden, int status,
10352                    OrderByComparator<DLFolder> orderByComparator)
10353                    throws NoSuchFolderException {
10354                    DLFolder dlFolder = fetchByG_P_H_S_Last(groupId, parentFolderId,
10355                                    hidden, status, orderByComparator);
10356    
10357                    if (dlFolder != null) {
10358                            return dlFolder;
10359                    }
10360    
10361                    StringBundler msg = new StringBundler(10);
10362    
10363                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10364    
10365                    msg.append("groupId=");
10366                    msg.append(groupId);
10367    
10368                    msg.append(", parentFolderId=");
10369                    msg.append(parentFolderId);
10370    
10371                    msg.append(", hidden=");
10372                    msg.append(hidden);
10373    
10374                    msg.append(", status=");
10375                    msg.append(status);
10376    
10377                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10378    
10379                    throw new NoSuchFolderException(msg.toString());
10380            }
10381    
10382            /**
10383             * Returns the last document library folder in the ordered set where groupId = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
10384             *
10385             * @param groupId the group ID
10386             * @param parentFolderId the parent folder ID
10387             * @param hidden the hidden
10388             * @param status the status
10389             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10390             * @return the last matching document library folder, or <code>null</code> if a matching document library folder could not be found
10391             */
10392            @Override
10393            public DLFolder fetchByG_P_H_S_Last(long groupId, long parentFolderId,
10394                    boolean hidden, int status,
10395                    OrderByComparator<DLFolder> orderByComparator) {
10396                    int count = countByG_P_H_S(groupId, parentFolderId, hidden, status);
10397    
10398                    if (count == 0) {
10399                            return null;
10400                    }
10401    
10402                    List<DLFolder> list = findByG_P_H_S(groupId, parentFolderId, hidden,
10403                                    status, count - 1, count, orderByComparator);
10404    
10405                    if (!list.isEmpty()) {
10406                            return list.get(0);
10407                    }
10408    
10409                    return null;
10410            }
10411    
10412            /**
10413             * 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;.
10414             *
10415             * @param folderId the primary key of the current document library folder
10416             * @param groupId the group ID
10417             * @param parentFolderId the parent folder ID
10418             * @param hidden the hidden
10419             * @param status the status
10420             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10421             * @return the previous, current, and next document library folder
10422             * @throws NoSuchFolderException if a document library folder with the primary key could not be found
10423             */
10424            @Override
10425            public DLFolder[] findByG_P_H_S_PrevAndNext(long folderId, long groupId,
10426                    long parentFolderId, boolean hidden, int status,
10427                    OrderByComparator<DLFolder> orderByComparator)
10428                    throws NoSuchFolderException {
10429                    DLFolder dlFolder = findByPrimaryKey(folderId);
10430    
10431                    Session session = null;
10432    
10433                    try {
10434                            session = openSession();
10435    
10436                            DLFolder[] array = new DLFolderImpl[3];
10437    
10438                            array[0] = getByG_P_H_S_PrevAndNext(session, dlFolder, groupId,
10439                                            parentFolderId, hidden, status, orderByComparator, true);
10440    
10441                            array[1] = dlFolder;
10442    
10443                            array[2] = getByG_P_H_S_PrevAndNext(session, dlFolder, groupId,
10444                                            parentFolderId, hidden, status, orderByComparator, false);
10445    
10446                            return array;
10447                    }
10448                    catch (Exception e) {
10449                            throw processException(e);
10450                    }
10451                    finally {
10452                            closeSession(session);
10453                    }
10454            }
10455    
10456            protected DLFolder getByG_P_H_S_PrevAndNext(Session session,
10457                    DLFolder dlFolder, long groupId, long parentFolderId, boolean hidden,
10458                    int status, OrderByComparator<DLFolder> orderByComparator,
10459                    boolean previous) {
10460                    StringBundler query = null;
10461    
10462                    if (orderByComparator != null) {
10463                            query = new StringBundler(7 +
10464                                            (orderByComparator.getOrderByConditionFields().length * 3) +
10465                                            (orderByComparator.getOrderByFields().length * 3));
10466                    }
10467                    else {
10468                            query = new StringBundler(6);
10469                    }
10470    
10471                    query.append(_SQL_SELECT_DLFOLDER_WHERE);
10472    
10473                    query.append(_FINDER_COLUMN_G_P_H_S_GROUPID_2);
10474    
10475                    query.append(_FINDER_COLUMN_G_P_H_S_PARENTFOLDERID_2);
10476    
10477                    query.append(_FINDER_COLUMN_G_P_H_S_HIDDEN_2);
10478    
10479                    query.append(_FINDER_COLUMN_G_P_H_S_STATUS_2);
10480    
10481                    if (orderByComparator != null) {
10482                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
10483    
10484                            if (orderByConditionFields.length > 0) {
10485                                    query.append(WHERE_AND);
10486                            }
10487    
10488                            for (int i = 0; i < orderByConditionFields.length; i++) {
10489                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10490                                    query.append(orderByConditionFields[i]);
10491    
10492                                    if ((i + 1) < orderByConditionFields.length) {
10493                                            if (orderByComparator.isAscending() ^ previous) {
10494                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
10495                                            }
10496                                            else {
10497                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
10498                                            }
10499                                    }
10500                                    else {
10501                                            if (orderByComparator.isAscending() ^ previous) {
10502                                                    query.append(WHERE_GREATER_THAN);
10503                                            }
10504                                            else {
10505                                                    query.append(WHERE_LESSER_THAN);
10506                                            }
10507                                    }
10508                            }
10509    
10510                            query.append(ORDER_BY_CLAUSE);
10511    
10512                            String[] orderByFields = orderByComparator.getOrderByFields();
10513    
10514                            for (int i = 0; i < orderByFields.length; i++) {
10515                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10516                                    query.append(orderByFields[i]);
10517    
10518                                    if ((i + 1) < orderByFields.length) {
10519                                            if (orderByComparator.isAscending() ^ previous) {
10520                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
10521                                            }
10522                                            else {
10523                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
10524                                            }
10525                                    }
10526                                    else {
10527                                            if (orderByComparator.isAscending() ^ previous) {
10528                                                    query.append(ORDER_BY_ASC);
10529                                            }
10530                                            else {
10531                                                    query.append(ORDER_BY_DESC);
10532                                            }
10533                                    }
10534                            }
10535                    }
10536                    else {
10537                            query.append(DLFolderModelImpl.ORDER_BY_JPQL);
10538                    }
10539    
10540                    String sql = query.toString();
10541    
10542                    Query q = session.createQuery(sql);
10543    
10544                    q.setFirstResult(0);
10545                    q.setMaxResults(2);
10546    
10547                    QueryPos qPos = QueryPos.getInstance(q);
10548    
10549                    qPos.add(groupId);
10550    
10551                    qPos.add(parentFolderId);
10552    
10553                    qPos.add(hidden);
10554    
10555                    qPos.add(status);
10556    
10557                    if (orderByComparator != null) {
10558                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
10559    
10560                            for (Object value : values) {
10561                                    qPos.add(value);
10562                            }
10563                    }
10564    
10565                    List<DLFolder> list = q.list();
10566    
10567                    if (list.size() == 2) {
10568                            return list.get(1);
10569                    }
10570                    else {
10571                            return null;
10572                    }
10573            }
10574    
10575            /**
10576             * 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;.
10577             *
10578             * @param groupId the group ID
10579             * @param parentFolderId the parent folder ID
10580             * @param hidden the hidden
10581             * @param status the status
10582             * @return the matching document library folders that the user has permission to view
10583             */
10584            @Override
10585            public List<DLFolder> filterFindByG_P_H_S(long groupId,
10586                    long parentFolderId, boolean hidden, int status) {
10587                    return filterFindByG_P_H_S(groupId, parentFolderId, hidden, status,
10588                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
10589            }
10590    
10591            /**
10592             * 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;.
10593             *
10594             * <p>
10595             * 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.
10596             * </p>
10597             *
10598             * @param groupId the group ID
10599             * @param parentFolderId the parent folder ID
10600             * @param hidden the hidden
10601             * @param status the status
10602             * @param start the lower bound of the range of document library folders
10603             * @param end the upper bound of the range of document library folders (not inclusive)
10604             * @return the range of matching document library folders that the user has permission to view
10605             */
10606            @Override
10607            public List<DLFolder> filterFindByG_P_H_S(long groupId,
10608                    long parentFolderId, boolean hidden, int status, int start, int end) {
10609                    return filterFindByG_P_H_S(groupId, parentFolderId, hidden, status,
10610                            start, end, null);
10611            }
10612    
10613            /**
10614             * 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;.
10615             *
10616             * <p>
10617             * 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.
10618             * </p>
10619             *
10620             * @param groupId the group ID
10621             * @param parentFolderId the parent folder ID
10622             * @param hidden the hidden
10623             * @param status the status
10624             * @param start the lower bound of the range of document library folders
10625             * @param end the upper bound of the range of document library folders (not inclusive)
10626             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10627             * @return the ordered range of matching document library folders that the user has permission to view
10628             */
10629            @Override
10630            public List<DLFolder> filterFindByG_P_H_S(long groupId,
10631                    long parentFolderId, boolean hidden, int status, int start, int end,
10632                    OrderByComparator<DLFolder> orderByComparator) {
10633                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
10634                            return findByG_P_H_S(groupId, parentFolderId, hidden, status,
10635                                    start, end, orderByComparator);
10636                    }
10637    
10638                    StringBundler query = null;
10639    
10640                    if (orderByComparator != null) {
10641                            query = new StringBundler(6 +
10642                                            (orderByComparator.getOrderByFields().length * 2));
10643                    }
10644                    else {
10645                            query = new StringBundler(7);
10646                    }
10647    
10648                    if (getDB().isSupportsInlineDistinct()) {
10649                            query.append(_FILTER_SQL_SELECT_DLFOLDER_WHERE);
10650                    }
10651                    else {
10652                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1);
10653                    }
10654    
10655                    query.append(_FINDER_COLUMN_G_P_H_S_GROUPID_2);
10656    
10657                    query.append(_FINDER_COLUMN_G_P_H_S_PARENTFOLDERID_2);
10658    
10659                    query.append(_FINDER_COLUMN_G_P_H_S_HIDDEN_2_SQL);
10660    
10661                    query.append(_FINDER_COLUMN_G_P_H_S_STATUS_2);
10662    
10663                    if (!getDB().isSupportsInlineDistinct()) {
10664                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2);
10665                    }
10666    
10667                    if (orderByComparator != null) {
10668                            if (getDB().isSupportsInlineDistinct()) {
10669                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10670                                            orderByComparator, true);
10671                            }
10672                            else {
10673                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
10674                                            orderByComparator, true);
10675                            }
10676                    }
10677                    else {
10678                            if (getDB().isSupportsInlineDistinct()) {
10679                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
10680                            }
10681                            else {
10682                                    query.append(DLFolderModelImpl.ORDER_BY_SQL);
10683                            }
10684                    }
10685    
10686                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
10687                                    DLFolder.class.getName(),
10688                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
10689    
10690                    Session session = null;
10691    
10692                    try {
10693                            session = openSession();
10694    
10695                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
10696    
10697                            if (getDB().isSupportsInlineDistinct()) {
10698                                    q.addEntity(_FILTER_ENTITY_ALIAS, DLFolderImpl.class);
10699                            }
10700                            else {
10701                                    q.addEntity(_FILTER_ENTITY_TABLE, DLFolderImpl.class);
10702                            }
10703    
10704                            QueryPos qPos = QueryPos.getInstance(q);
10705    
10706                            qPos.add(groupId);
10707    
10708                            qPos.add(parentFolderId);
10709    
10710                            qPos.add(hidden);
10711    
10712                            qPos.add(status);
10713    
10714                            return (List<DLFolder>)QueryUtil.list(q, getDialect(), start, end);
10715                    }
10716                    catch (Exception e) {
10717                            throw processException(e);
10718                    }
10719                    finally {
10720                            closeSession(session);
10721                    }
10722            }
10723    
10724            /**
10725             * 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;.
10726             *
10727             * @param folderId the primary key of the current document library folder
10728             * @param groupId the group ID
10729             * @param parentFolderId the parent folder ID
10730             * @param hidden the hidden
10731             * @param status the status
10732             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10733             * @return the previous, current, and next document library folder
10734             * @throws NoSuchFolderException if a document library folder with the primary key could not be found
10735             */
10736            @Override
10737            public DLFolder[] filterFindByG_P_H_S_PrevAndNext(long folderId,
10738                    long groupId, long parentFolderId, boolean hidden, int status,
10739                    OrderByComparator<DLFolder> orderByComparator)
10740                    throws NoSuchFolderException {
10741                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
10742                            return findByG_P_H_S_PrevAndNext(folderId, groupId, parentFolderId,
10743                                    hidden, status, orderByComparator);
10744                    }
10745    
10746                    DLFolder dlFolder = findByPrimaryKey(folderId);
10747    
10748                    Session session = null;
10749    
10750                    try {
10751                            session = openSession();
10752    
10753                            DLFolder[] array = new DLFolderImpl[3];
10754    
10755                            array[0] = filterGetByG_P_H_S_PrevAndNext(session, dlFolder,
10756                                            groupId, parentFolderId, hidden, status, orderByComparator,
10757                                            true);
10758    
10759                            array[1] = dlFolder;
10760    
10761                            array[2] = filterGetByG_P_H_S_PrevAndNext(session, dlFolder,
10762                                            groupId, parentFolderId, hidden, status, orderByComparator,
10763                                            false);
10764    
10765                            return array;
10766                    }
10767                    catch (Exception e) {
10768                            throw processException(e);
10769                    }
10770                    finally {
10771                            closeSession(session);
10772                    }
10773            }
10774    
10775            protected DLFolder filterGetByG_P_H_S_PrevAndNext(Session session,
10776                    DLFolder dlFolder, long groupId, long parentFolderId, boolean hidden,
10777                    int status, OrderByComparator<DLFolder> orderByComparator,
10778                    boolean previous) {
10779                    StringBundler query = null;
10780    
10781                    if (orderByComparator != null) {
10782                            query = new StringBundler(8 +
10783                                            (orderByComparator.getOrderByConditionFields().length * 3) +
10784                                            (orderByComparator.getOrderByFields().length * 3));
10785                    }
10786                    else {
10787                            query = new StringBundler(7);
10788                    }
10789    
10790                    if (getDB().isSupportsInlineDistinct()) {
10791                            query.append(_FILTER_SQL_SELECT_DLFOLDER_WHERE);
10792                    }
10793                    else {
10794                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1);
10795                    }
10796    
10797                    query.append(_FINDER_COLUMN_G_P_H_S_GROUPID_2);
10798    
10799                    query.append(_FINDER_COLUMN_G_P_H_S_PARENTFOLDERID_2);
10800    
10801                    query.append(_FINDER_COLUMN_G_P_H_S_HIDDEN_2_SQL);
10802    
10803                    query.append(_FINDER_COLUMN_G_P_H_S_STATUS_2);
10804    
10805                    if (!getDB().isSupportsInlineDistinct()) {
10806                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2);
10807                    }
10808    
10809                    if (orderByComparator != null) {
10810                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
10811    
10812                            if (orderByConditionFields.length > 0) {
10813                                    query.append(WHERE_AND);
10814                            }
10815    
10816                            for (int i = 0; i < orderByConditionFields.length; i++) {
10817                                    if (getDB().isSupportsInlineDistinct()) {
10818                                            query.append(_ORDER_BY_ENTITY_ALIAS);
10819                                    }
10820                                    else {
10821                                            query.append(_ORDER_BY_ENTITY_TABLE);
10822                                    }
10823    
10824                                    query.append(orderByConditionFields[i]);
10825    
10826                                    if ((i + 1) < orderByConditionFields.length) {
10827                                            if (orderByComparator.isAscending() ^ previous) {
10828                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
10829                                            }
10830                                            else {
10831                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
10832                                            }
10833                                    }
10834                                    else {
10835                                            if (orderByComparator.isAscending() ^ previous) {
10836                                                    query.append(WHERE_GREATER_THAN);
10837                                            }
10838                                            else {
10839                                                    query.append(WHERE_LESSER_THAN);
10840                                            }
10841                                    }
10842                            }
10843    
10844                            query.append(ORDER_BY_CLAUSE);
10845    
10846                            String[] orderByFields = orderByComparator.getOrderByFields();
10847    
10848                            for (int i = 0; i < orderByFields.length; i++) {
10849                                    if (getDB().isSupportsInlineDistinct()) {
10850                                            query.append(_ORDER_BY_ENTITY_ALIAS);
10851                                    }
10852                                    else {
10853                                            query.append(_ORDER_BY_ENTITY_TABLE);
10854                                    }
10855    
10856                                    query.append(orderByFields[i]);
10857    
10858                                    if ((i + 1) < orderByFields.length) {
10859                                            if (orderByComparator.isAscending() ^ previous) {
10860                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
10861                                            }
10862                                            else {
10863                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
10864                                            }
10865                                    }
10866                                    else {
10867                                            if (orderByComparator.isAscending() ^ previous) {
10868                                                    query.append(ORDER_BY_ASC);
10869                                            }
10870                                            else {
10871                                                    query.append(ORDER_BY_DESC);
10872                                            }
10873                                    }
10874                            }
10875                    }
10876                    else {
10877                            if (getDB().isSupportsInlineDistinct()) {
10878                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
10879                            }
10880                            else {
10881                                    query.append(DLFolderModelImpl.ORDER_BY_SQL);
10882                            }
10883                    }
10884    
10885                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
10886                                    DLFolder.class.getName(),
10887                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
10888    
10889                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
10890    
10891                    q.setFirstResult(0);
10892                    q.setMaxResults(2);
10893    
10894                    if (getDB().isSupportsInlineDistinct()) {
10895                            q.addEntity(_FILTER_ENTITY_ALIAS, DLFolderImpl.class);
10896                    }
10897                    else {
10898                            q.addEntity(_FILTER_ENTITY_TABLE, DLFolderImpl.class);
10899                    }
10900    
10901                    QueryPos qPos = QueryPos.getInstance(q);
10902    
10903                    qPos.add(groupId);
10904    
10905                    qPos.add(parentFolderId);
10906    
10907                    qPos.add(hidden);
10908    
10909                    qPos.add(status);
10910    
10911                    if (orderByComparator != null) {
10912                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
10913    
10914                            for (Object value : values) {
10915                                    qPos.add(value);
10916                            }
10917                    }
10918    
10919                    List<DLFolder> list = q.list();
10920    
10921                    if (list.size() == 2) {
10922                            return list.get(1);
10923                    }
10924                    else {
10925                            return null;
10926                    }
10927            }
10928    
10929            /**
10930             * Removes all the document library folders where groupId = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63; from the database.
10931             *
10932             * @param groupId the group ID
10933             * @param parentFolderId the parent folder ID
10934             * @param hidden the hidden
10935             * @param status the status
10936             */
10937            @Override
10938            public void removeByG_P_H_S(long groupId, long parentFolderId,
10939                    boolean hidden, int status) {
10940                    for (DLFolder dlFolder : findByG_P_H_S(groupId, parentFolderId, hidden,
10941                                    status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
10942                            remove(dlFolder);
10943                    }
10944            }
10945    
10946            /**
10947             * Returns the number of document library folders where groupId = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
10948             *
10949             * @param groupId the group ID
10950             * @param parentFolderId the parent folder ID
10951             * @param hidden the hidden
10952             * @param status the status
10953             * @return the number of matching document library folders
10954             */
10955            @Override
10956            public int countByG_P_H_S(long groupId, long parentFolderId,
10957                    boolean hidden, int status) {
10958                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_P_H_S;
10959    
10960                    Object[] finderArgs = new Object[] {
10961                                    groupId, parentFolderId, hidden, status
10962                            };
10963    
10964                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
10965    
10966                    if (count == null) {
10967                            StringBundler query = new StringBundler(5);
10968    
10969                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
10970    
10971                            query.append(_FINDER_COLUMN_G_P_H_S_GROUPID_2);
10972    
10973                            query.append(_FINDER_COLUMN_G_P_H_S_PARENTFOLDERID_2);
10974    
10975                            query.append(_FINDER_COLUMN_G_P_H_S_HIDDEN_2);
10976    
10977                            query.append(_FINDER_COLUMN_G_P_H_S_STATUS_2);
10978    
10979                            String sql = query.toString();
10980    
10981                            Session session = null;
10982    
10983                            try {
10984                                    session = openSession();
10985    
10986                                    Query q = session.createQuery(sql);
10987    
10988                                    QueryPos qPos = QueryPos.getInstance(q);
10989    
10990                                    qPos.add(groupId);
10991    
10992                                    qPos.add(parentFolderId);
10993    
10994                                    qPos.add(hidden);
10995    
10996                                    qPos.add(status);
10997    
10998                                    count = (Long)q.uniqueResult();
10999    
11000                                    finderCache.putResult(finderPath, finderArgs, count);
11001                            }
11002                            catch (Exception e) {
11003                                    finderCache.removeResult(finderPath, finderArgs);
11004    
11005                                    throw processException(e);
11006                            }
11007                            finally {
11008                                    closeSession(session);
11009                            }
11010                    }
11011    
11012                    return count.intValue();
11013            }
11014    
11015            /**
11016             * 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;.
11017             *
11018             * @param groupId the group ID
11019             * @param parentFolderId the parent folder ID
11020             * @param hidden the hidden
11021             * @param status the status
11022             * @return the number of matching document library folders that the user has permission to view
11023             */
11024            @Override
11025            public int filterCountByG_P_H_S(long groupId, long parentFolderId,
11026                    boolean hidden, int status) {
11027                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
11028                            return countByG_P_H_S(groupId, parentFolderId, hidden, status);
11029                    }
11030    
11031                    StringBundler query = new StringBundler(5);
11032    
11033                    query.append(_FILTER_SQL_COUNT_DLFOLDER_WHERE);
11034    
11035                    query.append(_FINDER_COLUMN_G_P_H_S_GROUPID_2);
11036    
11037                    query.append(_FINDER_COLUMN_G_P_H_S_PARENTFOLDERID_2);
11038    
11039                    query.append(_FINDER_COLUMN_G_P_H_S_HIDDEN_2_SQL);
11040    
11041                    query.append(_FINDER_COLUMN_G_P_H_S_STATUS_2);
11042    
11043                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
11044                                    DLFolder.class.getName(),
11045                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
11046    
11047                    Session session = null;
11048    
11049                    try {
11050                            session = openSession();
11051    
11052                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
11053    
11054                            q.addScalar(COUNT_COLUMN_NAME,
11055                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
11056    
11057                            QueryPos qPos = QueryPos.getInstance(q);
11058    
11059                            qPos.add(groupId);
11060    
11061                            qPos.add(parentFolderId);
11062    
11063                            qPos.add(hidden);
11064    
11065                            qPos.add(status);
11066    
11067                            Long count = (Long)q.uniqueResult();
11068    
11069                            return count.intValue();
11070                    }
11071                    catch (Exception e) {
11072                            throw processException(e);
11073                    }
11074                    finally {
11075                            closeSession(session);
11076                    }
11077            }
11078    
11079            private static final String _FINDER_COLUMN_G_P_H_S_GROUPID_2 = "dlFolder.groupId = ? AND ";
11080            private static final String _FINDER_COLUMN_G_P_H_S_PARENTFOLDERID_2 = "dlFolder.parentFolderId = ? AND ";
11081            private static final String _FINDER_COLUMN_G_P_H_S_HIDDEN_2 = "dlFolder.hidden = ? AND ";
11082            private static final String _FINDER_COLUMN_G_P_H_S_HIDDEN_2_SQL = "dlFolder.hidden_ = ? AND ";
11083            private static final String _FINDER_COLUMN_G_P_H_S_STATUS_2 = "dlFolder.status = ?";
11084            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_M_P_H_S =
11085                    new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
11086                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
11087                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_M_P_H_S",
11088                            new String[] {
11089                                    Long.class.getName(), Boolean.class.getName(),
11090                                    Long.class.getName(), Boolean.class.getName(),
11091                                    Integer.class.getName(),
11092                                    
11093                            Integer.class.getName(), Integer.class.getName(),
11094                                    OrderByComparator.class.getName()
11095                            });
11096            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P_H_S =
11097                    new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
11098                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
11099                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_M_P_H_S",
11100                            new String[] {
11101                                    Long.class.getName(), Boolean.class.getName(),
11102                                    Long.class.getName(), Boolean.class.getName(),
11103                                    Integer.class.getName()
11104                            },
11105                            DLFolderModelImpl.GROUPID_COLUMN_BITMASK |
11106                            DLFolderModelImpl.MOUNTPOINT_COLUMN_BITMASK |
11107                            DLFolderModelImpl.PARENTFOLDERID_COLUMN_BITMASK |
11108                            DLFolderModelImpl.HIDDEN_COLUMN_BITMASK |
11109                            DLFolderModelImpl.STATUS_COLUMN_BITMASK |
11110                            DLFolderModelImpl.NAME_COLUMN_BITMASK);
11111            public static final FinderPath FINDER_PATH_COUNT_BY_G_M_P_H_S = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
11112                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
11113                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_M_P_H_S",
11114                            new String[] {
11115                                    Long.class.getName(), Boolean.class.getName(),
11116                                    Long.class.getName(), Boolean.class.getName(),
11117                                    Integer.class.getName()
11118                            });
11119    
11120            /**
11121             * Returns all the document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
11122             *
11123             * @param groupId the group ID
11124             * @param mountPoint the mount point
11125             * @param parentFolderId the parent folder ID
11126             * @param hidden the hidden
11127             * @param status the status
11128             * @return the matching document library folders
11129             */
11130            @Override
11131            public List<DLFolder> findByG_M_P_H_S(long groupId, boolean mountPoint,
11132                    long parentFolderId, boolean hidden, int status) {
11133                    return findByG_M_P_H_S(groupId, mountPoint, parentFolderId, hidden,
11134                            status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
11135            }
11136    
11137            /**
11138             * Returns a range of all the document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
11139             *
11140             * <p>
11141             * 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.
11142             * </p>
11143             *
11144             * @param groupId the group ID
11145             * @param mountPoint the mount point
11146             * @param parentFolderId the parent folder ID
11147             * @param hidden the hidden
11148             * @param status the status
11149             * @param start the lower bound of the range of document library folders
11150             * @param end the upper bound of the range of document library folders (not inclusive)
11151             * @return the range of matching document library folders
11152             */
11153            @Override
11154            public List<DLFolder> findByG_M_P_H_S(long groupId, boolean mountPoint,
11155                    long parentFolderId, boolean hidden, int status, int start, int end) {
11156                    return findByG_M_P_H_S(groupId, mountPoint, parentFolderId, hidden,
11157                            status, start, end, null);
11158            }
11159    
11160            /**
11161             * 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;.
11162             *
11163             * <p>
11164             * 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.
11165             * </p>
11166             *
11167             * @param groupId the group ID
11168             * @param mountPoint the mount point
11169             * @param parentFolderId the parent folder ID
11170             * @param hidden the hidden
11171             * @param status the status
11172             * @param start the lower bound of the range of document library folders
11173             * @param end the upper bound of the range of document library folders (not inclusive)
11174             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
11175             * @return the ordered range of matching document library folders
11176             */
11177            @Override
11178            public List<DLFolder> findByG_M_P_H_S(long groupId, boolean mountPoint,
11179                    long parentFolderId, boolean hidden, int status, int start, int end,
11180                    OrderByComparator<DLFolder> orderByComparator) {
11181                    return findByG_M_P_H_S(groupId, mountPoint, parentFolderId, hidden,
11182                            status, start, end, orderByComparator, true);
11183            }
11184    
11185            /**
11186             * 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;.
11187             *
11188             * <p>
11189             * 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.
11190             * </p>
11191             *
11192             * @param groupId the group ID
11193             * @param mountPoint the mount point
11194             * @param parentFolderId the parent folder ID
11195             * @param hidden the hidden
11196             * @param status the status
11197             * @param start the lower bound of the range of document library folders
11198             * @param end the upper bound of the range of document library folders (not inclusive)
11199             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
11200             * @param retrieveFromCache whether to retrieve from the finder cache
11201             * @return the ordered range of matching document library folders
11202             */
11203            @Override
11204            public List<DLFolder> findByG_M_P_H_S(long groupId, boolean mountPoint,
11205                    long parentFolderId, boolean hidden, int status, int start, int end,
11206                    OrderByComparator<DLFolder> orderByComparator, boolean retrieveFromCache) {
11207                    boolean pagination = true;
11208                    FinderPath finderPath = null;
11209                    Object[] finderArgs = null;
11210    
11211                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
11212                                    (orderByComparator == null)) {
11213                            pagination = false;
11214                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P_H_S;
11215                            finderArgs = new Object[] {
11216                                            groupId, mountPoint, parentFolderId, hidden, status
11217                                    };
11218                    }
11219                    else {
11220                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_M_P_H_S;
11221                            finderArgs = new Object[] {
11222                                            groupId, mountPoint, parentFolderId, hidden, status,
11223                                            
11224                                            start, end, orderByComparator
11225                                    };
11226                    }
11227    
11228                    List<DLFolder> list = null;
11229    
11230                    if (retrieveFromCache) {
11231                            list = (List<DLFolder>)finderCache.getResult(finderPath,
11232                                            finderArgs, this);
11233    
11234                            if ((list != null) && !list.isEmpty()) {
11235                                    for (DLFolder dlFolder : list) {
11236                                            if ((groupId != dlFolder.getGroupId()) ||
11237                                                            (mountPoint != dlFolder.getMountPoint()) ||
11238                                                            (parentFolderId != dlFolder.getParentFolderId()) ||
11239                                                            (hidden != dlFolder.getHidden()) ||
11240                                                            (status != dlFolder.getStatus())) {
11241                                                    list = null;
11242    
11243                                                    break;
11244                                            }
11245                                    }
11246                            }
11247                    }
11248    
11249                    if (list == null) {
11250                            StringBundler query = null;
11251    
11252                            if (orderByComparator != null) {
11253                                    query = new StringBundler(7 +
11254                                                    (orderByComparator.getOrderByFields().length * 2));
11255                            }
11256                            else {
11257                                    query = new StringBundler(7);
11258                            }
11259    
11260                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
11261    
11262                            query.append(_FINDER_COLUMN_G_M_P_H_S_GROUPID_2);
11263    
11264                            query.append(_FINDER_COLUMN_G_M_P_H_S_MOUNTPOINT_2);
11265    
11266                            query.append(_FINDER_COLUMN_G_M_P_H_S_PARENTFOLDERID_2);
11267    
11268                            query.append(_FINDER_COLUMN_G_M_P_H_S_HIDDEN_2);
11269    
11270                            query.append(_FINDER_COLUMN_G_M_P_H_S_STATUS_2);
11271    
11272                            if (orderByComparator != null) {
11273                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
11274                                            orderByComparator);
11275                            }
11276                            else
11277                             if (pagination) {
11278                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
11279                            }
11280    
11281                            String sql = query.toString();
11282    
11283                            Session session = null;
11284    
11285                            try {
11286                                    session = openSession();
11287    
11288                                    Query q = session.createQuery(sql);
11289    
11290                                    QueryPos qPos = QueryPos.getInstance(q);
11291    
11292                                    qPos.add(groupId);
11293    
11294                                    qPos.add(mountPoint);
11295    
11296                                    qPos.add(parentFolderId);
11297    
11298                                    qPos.add(hidden);
11299    
11300                                    qPos.add(status);
11301    
11302                                    if (!pagination) {
11303                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
11304                                                            start, end, false);
11305    
11306                                            Collections.sort(list);
11307    
11308                                            list = Collections.unmodifiableList(list);
11309                                    }
11310                                    else {
11311                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
11312                                                            start, end);
11313                                    }
11314    
11315                                    cacheResult(list);
11316    
11317                                    finderCache.putResult(finderPath, finderArgs, list);
11318                            }
11319                            catch (Exception e) {
11320                                    finderCache.removeResult(finderPath, finderArgs);
11321    
11322                                    throw processException(e);
11323                            }
11324                            finally {
11325                                    closeSession(session);
11326                            }
11327                    }
11328    
11329                    return list;
11330            }
11331    
11332            /**
11333             * 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;.
11334             *
11335             * @param groupId the group ID
11336             * @param mountPoint the mount point
11337             * @param parentFolderId the parent folder ID
11338             * @param hidden the hidden
11339             * @param status the status
11340             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11341             * @return the first matching document library folder
11342             * @throws NoSuchFolderException if a matching document library folder could not be found
11343             */
11344            @Override
11345            public DLFolder findByG_M_P_H_S_First(long groupId, boolean mountPoint,
11346                    long parentFolderId, boolean hidden, int status,
11347                    OrderByComparator<DLFolder> orderByComparator)
11348                    throws NoSuchFolderException {
11349                    DLFolder dlFolder = fetchByG_M_P_H_S_First(groupId, mountPoint,
11350                                    parentFolderId, hidden, status, orderByComparator);
11351    
11352                    if (dlFolder != null) {
11353                            return dlFolder;
11354                    }
11355    
11356                    StringBundler msg = new StringBundler(12);
11357    
11358                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
11359    
11360                    msg.append("groupId=");
11361                    msg.append(groupId);
11362    
11363                    msg.append(", mountPoint=");
11364                    msg.append(mountPoint);
11365    
11366                    msg.append(", parentFolderId=");
11367                    msg.append(parentFolderId);
11368    
11369                    msg.append(", hidden=");
11370                    msg.append(hidden);
11371    
11372                    msg.append(", status=");
11373                    msg.append(status);
11374    
11375                    msg.append(StringPool.CLOSE_CURLY_BRACE);
11376    
11377                    throw new NoSuchFolderException(msg.toString());
11378            }
11379    
11380            /**
11381             * 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;.
11382             *
11383             * @param groupId the group ID
11384             * @param mountPoint the mount point
11385             * @param parentFolderId the parent folder ID
11386             * @param hidden the hidden
11387             * @param status the status
11388             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11389             * @return the first matching document library folder, or <code>null</code> if a matching document library folder could not be found
11390             */
11391            @Override
11392            public DLFolder fetchByG_M_P_H_S_First(long groupId, boolean mountPoint,
11393                    long parentFolderId, boolean hidden, int status,
11394                    OrderByComparator<DLFolder> orderByComparator) {
11395                    List<DLFolder> list = findByG_M_P_H_S(groupId, mountPoint,
11396                                    parentFolderId, hidden, status, 0, 1, orderByComparator);
11397    
11398                    if (!list.isEmpty()) {
11399                            return list.get(0);
11400                    }
11401    
11402                    return null;
11403            }
11404    
11405            /**
11406             * 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;.
11407             *
11408             * @param groupId the group ID
11409             * @param mountPoint the mount point
11410             * @param parentFolderId the parent folder ID
11411             * @param hidden the hidden
11412             * @param status the status
11413             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11414             * @return the last matching document library folder
11415             * @throws NoSuchFolderException if a matching document library folder could not be found
11416             */
11417            @Override
11418            public DLFolder findByG_M_P_H_S_Last(long groupId, boolean mountPoint,
11419                    long parentFolderId, boolean hidden, int status,
11420                    OrderByComparator<DLFolder> orderByComparator)
11421                    throws NoSuchFolderException {
11422                    DLFolder dlFolder = fetchByG_M_P_H_S_Last(groupId, mountPoint,
11423                                    parentFolderId, hidden, status, orderByComparator);
11424    
11425                    if (dlFolder != null) {
11426                            return dlFolder;
11427                    }
11428    
11429                    StringBundler msg = new StringBundler(12);
11430    
11431                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
11432    
11433                    msg.append("groupId=");
11434                    msg.append(groupId);
11435    
11436                    msg.append(", mountPoint=");
11437                    msg.append(mountPoint);
11438    
11439                    msg.append(", parentFolderId=");
11440                    msg.append(parentFolderId);
11441    
11442                    msg.append(", hidden=");
11443                    msg.append(hidden);
11444    
11445                    msg.append(", status=");
11446                    msg.append(status);
11447    
11448                    msg.append(StringPool.CLOSE_CURLY_BRACE);
11449    
11450                    throw new NoSuchFolderException(msg.toString());
11451            }
11452    
11453            /**
11454             * 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;.
11455             *
11456             * @param groupId the group ID
11457             * @param mountPoint the mount point
11458             * @param parentFolderId the parent folder ID
11459             * @param hidden the hidden
11460             * @param status the status
11461             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11462             * @return the last matching document library folder, or <code>null</code> if a matching document library folder could not be found
11463             */
11464            @Override
11465            public DLFolder fetchByG_M_P_H_S_Last(long groupId, boolean mountPoint,
11466                    long parentFolderId, boolean hidden, int status,
11467                    OrderByComparator<DLFolder> orderByComparator) {
11468                    int count = countByG_M_P_H_S(groupId, mountPoint, parentFolderId,
11469                                    hidden, status);
11470    
11471                    if (count == 0) {
11472                            return null;
11473                    }
11474    
11475                    List<DLFolder> list = findByG_M_P_H_S(groupId, mountPoint,
11476                                    parentFolderId, hidden, status, count - 1, count,
11477                                    orderByComparator);
11478    
11479                    if (!list.isEmpty()) {
11480                            return list.get(0);
11481                    }
11482    
11483                    return null;
11484            }
11485    
11486            /**
11487             * 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;.
11488             *
11489             * @param folderId the primary key of the current document library folder
11490             * @param groupId the group ID
11491             * @param mountPoint the mount point
11492             * @param parentFolderId the parent folder ID
11493             * @param hidden the hidden
11494             * @param status the status
11495             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11496             * @return the previous, current, and next document library folder
11497             * @throws NoSuchFolderException if a document library folder with the primary key could not be found
11498             */
11499            @Override
11500            public DLFolder[] findByG_M_P_H_S_PrevAndNext(long folderId, long groupId,
11501                    boolean mountPoint, long parentFolderId, boolean hidden, int status,
11502                    OrderByComparator<DLFolder> orderByComparator)
11503                    throws NoSuchFolderException {
11504                    DLFolder dlFolder = findByPrimaryKey(folderId);
11505    
11506                    Session session = null;
11507    
11508                    try {
11509                            session = openSession();
11510    
11511                            DLFolder[] array = new DLFolderImpl[3];
11512    
11513                            array[0] = getByG_M_P_H_S_PrevAndNext(session, dlFolder, groupId,
11514                                            mountPoint, parentFolderId, hidden, status,
11515                                            orderByComparator, true);
11516    
11517                            array[1] = dlFolder;
11518    
11519                            array[2] = getByG_M_P_H_S_PrevAndNext(session, dlFolder, groupId,
11520                                            mountPoint, parentFolderId, hidden, status,
11521                                            orderByComparator, false);
11522    
11523                            return array;
11524                    }
11525                    catch (Exception e) {
11526                            throw processException(e);
11527                    }
11528                    finally {
11529                            closeSession(session);
11530                    }
11531            }
11532    
11533            protected DLFolder getByG_M_P_H_S_PrevAndNext(Session session,
11534                    DLFolder dlFolder, long groupId, boolean mountPoint,
11535                    long parentFolderId, boolean hidden, int status,
11536                    OrderByComparator<DLFolder> orderByComparator, boolean previous) {
11537                    StringBundler query = null;
11538    
11539                    if (orderByComparator != null) {
11540                            query = new StringBundler(8 +
11541                                            (orderByComparator.getOrderByConditionFields().length * 3) +
11542                                            (orderByComparator.getOrderByFields().length * 3));
11543                    }
11544                    else {
11545                            query = new StringBundler(7);
11546                    }
11547    
11548                    query.append(_SQL_SELECT_DLFOLDER_WHERE);
11549    
11550                    query.append(_FINDER_COLUMN_G_M_P_H_S_GROUPID_2);
11551    
11552                    query.append(_FINDER_COLUMN_G_M_P_H_S_MOUNTPOINT_2);
11553    
11554                    query.append(_FINDER_COLUMN_G_M_P_H_S_PARENTFOLDERID_2);
11555    
11556                    query.append(_FINDER_COLUMN_G_M_P_H_S_HIDDEN_2);
11557    
11558                    query.append(_FINDER_COLUMN_G_M_P_H_S_STATUS_2);
11559    
11560                    if (orderByComparator != null) {
11561                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
11562    
11563                            if (orderByConditionFields.length > 0) {
11564                                    query.append(WHERE_AND);
11565                            }
11566    
11567                            for (int i = 0; i < orderByConditionFields.length; i++) {
11568                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11569                                    query.append(orderByConditionFields[i]);
11570    
11571                                    if ((i + 1) < orderByConditionFields.length) {
11572                                            if (orderByComparator.isAscending() ^ previous) {
11573                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
11574                                            }
11575                                            else {
11576                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
11577                                            }
11578                                    }
11579                                    else {
11580                                            if (orderByComparator.isAscending() ^ previous) {
11581                                                    query.append(WHERE_GREATER_THAN);
11582                                            }
11583                                            else {
11584                                                    query.append(WHERE_LESSER_THAN);
11585                                            }
11586                                    }
11587                            }
11588    
11589                            query.append(ORDER_BY_CLAUSE);
11590    
11591                            String[] orderByFields = orderByComparator.getOrderByFields();
11592    
11593                            for (int i = 0; i < orderByFields.length; i++) {
11594                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11595                                    query.append(orderByFields[i]);
11596    
11597                                    if ((i + 1) < orderByFields.length) {
11598                                            if (orderByComparator.isAscending() ^ previous) {
11599                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
11600                                            }
11601                                            else {
11602                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
11603                                            }
11604                                    }
11605                                    else {
11606                                            if (orderByComparator.isAscending() ^ previous) {
11607                                                    query.append(ORDER_BY_ASC);
11608                                            }
11609                                            else {
11610                                                    query.append(ORDER_BY_DESC);
11611                                            }
11612                                    }
11613                            }
11614                    }
11615                    else {
11616                            query.append(DLFolderModelImpl.ORDER_BY_JPQL);
11617                    }
11618    
11619                    String sql = query.toString();
11620    
11621                    Query q = session.createQuery(sql);
11622    
11623                    q.setFirstResult(0);
11624                    q.setMaxResults(2);
11625    
11626                    QueryPos qPos = QueryPos.getInstance(q);
11627    
11628                    qPos.add(groupId);
11629    
11630                    qPos.add(mountPoint);
11631    
11632                    qPos.add(parentFolderId);
11633    
11634                    qPos.add(hidden);
11635    
11636                    qPos.add(status);
11637    
11638                    if (orderByComparator != null) {
11639                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
11640    
11641                            for (Object value : values) {
11642                                    qPos.add(value);
11643                            }
11644                    }
11645    
11646                    List<DLFolder> list = q.list();
11647    
11648                    if (list.size() == 2) {
11649                            return list.get(1);
11650                    }
11651                    else {
11652                            return null;
11653                    }
11654            }
11655    
11656            /**
11657             * 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;.
11658             *
11659             * @param groupId the group ID
11660             * @param mountPoint the mount point
11661             * @param parentFolderId the parent folder ID
11662             * @param hidden the hidden
11663             * @param status the status
11664             * @return the matching document library folders that the user has permission to view
11665             */
11666            @Override
11667            public List<DLFolder> filterFindByG_M_P_H_S(long groupId,
11668                    boolean mountPoint, long parentFolderId, boolean hidden, int status) {
11669                    return filterFindByG_M_P_H_S(groupId, mountPoint, parentFolderId,
11670                            hidden, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
11671            }
11672    
11673            /**
11674             * 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;.
11675             *
11676             * <p>
11677             * 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.
11678             * </p>
11679             *
11680             * @param groupId the group ID
11681             * @param mountPoint the mount point
11682             * @param parentFolderId the parent folder ID
11683             * @param hidden the hidden
11684             * @param status the status
11685             * @param start the lower bound of the range of document library folders
11686             * @param end the upper bound of the range of document library folders (not inclusive)
11687             * @return the range of matching document library folders that the user has permission to view
11688             */
11689            @Override
11690            public List<DLFolder> filterFindByG_M_P_H_S(long groupId,
11691                    boolean mountPoint, long parentFolderId, boolean hidden, int status,
11692                    int start, int end) {
11693                    return filterFindByG_M_P_H_S(groupId, mountPoint, parentFolderId,
11694                            hidden, status, start, end, null);
11695            }
11696    
11697            /**
11698             * 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;.
11699             *
11700             * <p>
11701             * 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.
11702             * </p>
11703             *
11704             * @param groupId the group ID
11705             * @param mountPoint the mount point
11706             * @param parentFolderId the parent folder ID
11707             * @param hidden the hidden
11708             * @param status the status
11709             * @param start the lower bound of the range of document library folders
11710             * @param end the upper bound of the range of document library folders (not inclusive)
11711             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
11712             * @return the ordered range of matching document library folders that the user has permission to view
11713             */
11714            @Override
11715            public List<DLFolder> filterFindByG_M_P_H_S(long groupId,
11716                    boolean mountPoint, long parentFolderId, boolean hidden, int status,
11717                    int start, int end, OrderByComparator<DLFolder> orderByComparator) {
11718                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
11719                            return findByG_M_P_H_S(groupId, mountPoint, parentFolderId, hidden,
11720                                    status, start, end, orderByComparator);
11721                    }
11722    
11723                    StringBundler query = null;
11724    
11725                    if (orderByComparator != null) {
11726                            query = new StringBundler(7 +
11727                                            (orderByComparator.getOrderByFields().length * 2));
11728                    }
11729                    else {
11730                            query = new StringBundler(8);
11731                    }
11732    
11733                    if (getDB().isSupportsInlineDistinct()) {
11734                            query.append(_FILTER_SQL_SELECT_DLFOLDER_WHERE);
11735                    }
11736                    else {
11737                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1);
11738                    }
11739    
11740                    query.append(_FINDER_COLUMN_G_M_P_H_S_GROUPID_2);
11741    
11742                    query.append(_FINDER_COLUMN_G_M_P_H_S_MOUNTPOINT_2);
11743    
11744                    query.append(_FINDER_COLUMN_G_M_P_H_S_PARENTFOLDERID_2);
11745    
11746                    query.append(_FINDER_COLUMN_G_M_P_H_S_HIDDEN_2_SQL);
11747    
11748                    query.append(_FINDER_COLUMN_G_M_P_H_S_STATUS_2);
11749    
11750                    if (!getDB().isSupportsInlineDistinct()) {
11751                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2);
11752                    }
11753    
11754                    if (orderByComparator != null) {
11755                            if (getDB().isSupportsInlineDistinct()) {
11756                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
11757                                            orderByComparator, true);
11758                            }
11759                            else {
11760                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
11761                                            orderByComparator, true);
11762                            }
11763                    }
11764                    else {
11765                            if (getDB().isSupportsInlineDistinct()) {
11766                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
11767                            }
11768                            else {
11769                                    query.append(DLFolderModelImpl.ORDER_BY_SQL);
11770                            }
11771                    }
11772    
11773                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
11774                                    DLFolder.class.getName(),
11775                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
11776    
11777                    Session session = null;
11778    
11779                    try {
11780                            session = openSession();
11781    
11782                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
11783    
11784                            if (getDB().isSupportsInlineDistinct()) {
11785                                    q.addEntity(_FILTER_ENTITY_ALIAS, DLFolderImpl.class);
11786                            }
11787                            else {
11788                                    q.addEntity(_FILTER_ENTITY_TABLE, DLFolderImpl.class);
11789                            }
11790    
11791                            QueryPos qPos = QueryPos.getInstance(q);
11792    
11793                            qPos.add(groupId);
11794    
11795                            qPos.add(mountPoint);
11796    
11797                            qPos.add(parentFolderId);
11798    
11799                            qPos.add(hidden);
11800    
11801                            qPos.add(status);
11802    
11803                            return (List<DLFolder>)QueryUtil.list(q, getDialect(), start, end);
11804                    }
11805                    catch (Exception e) {
11806                            throw processException(e);
11807                    }
11808                    finally {
11809                            closeSession(session);
11810                    }
11811            }
11812    
11813            /**
11814             * 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;.
11815             *
11816             * @param folderId the primary key of the current document library folder
11817             * @param groupId the group ID
11818             * @param mountPoint the mount point
11819             * @param parentFolderId the parent folder ID
11820             * @param hidden the hidden
11821             * @param status the status
11822             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11823             * @return the previous, current, and next document library folder
11824             * @throws NoSuchFolderException if a document library folder with the primary key could not be found
11825             */
11826            @Override
11827            public DLFolder[] filterFindByG_M_P_H_S_PrevAndNext(long folderId,
11828                    long groupId, boolean mountPoint, long parentFolderId, boolean hidden,
11829                    int status, OrderByComparator<DLFolder> orderByComparator)
11830                    throws NoSuchFolderException {
11831                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
11832                            return findByG_M_P_H_S_PrevAndNext(folderId, groupId, mountPoint,
11833                                    parentFolderId, hidden, status, orderByComparator);
11834                    }
11835    
11836                    DLFolder dlFolder = findByPrimaryKey(folderId);
11837    
11838                    Session session = null;
11839    
11840                    try {
11841                            session = openSession();
11842    
11843                            DLFolder[] array = new DLFolderImpl[3];
11844    
11845                            array[0] = filterGetByG_M_P_H_S_PrevAndNext(session, dlFolder,
11846                                            groupId, mountPoint, parentFolderId, hidden, status,
11847                                            orderByComparator, true);
11848    
11849                            array[1] = dlFolder;
11850    
11851                            array[2] = filterGetByG_M_P_H_S_PrevAndNext(session, dlFolder,
11852                                            groupId, mountPoint, parentFolderId, hidden, status,
11853                                            orderByComparator, false);
11854    
11855                            return array;
11856                    }
11857                    catch (Exception e) {
11858                            throw processException(e);
11859                    }
11860                    finally {
11861                            closeSession(session);
11862                    }
11863            }
11864    
11865            protected DLFolder filterGetByG_M_P_H_S_PrevAndNext(Session session,
11866                    DLFolder dlFolder, long groupId, boolean mountPoint,
11867                    long parentFolderId, boolean hidden, int status,
11868                    OrderByComparator<DLFolder> orderByComparator, boolean previous) {
11869                    StringBundler query = null;
11870    
11871                    if (orderByComparator != null) {
11872                            query = new StringBundler(9 +
11873                                            (orderByComparator.getOrderByConditionFields().length * 3) +
11874                                            (orderByComparator.getOrderByFields().length * 3));
11875                    }
11876                    else {
11877                            query = new StringBundler(8);
11878                    }
11879    
11880                    if (getDB().isSupportsInlineDistinct()) {
11881                            query.append(_FILTER_SQL_SELECT_DLFOLDER_WHERE);
11882                    }
11883                    else {
11884                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1);
11885                    }
11886    
11887                    query.append(_FINDER_COLUMN_G_M_P_H_S_GROUPID_2);
11888    
11889                    query.append(_FINDER_COLUMN_G_M_P_H_S_MOUNTPOINT_2);
11890    
11891                    query.append(_FINDER_COLUMN_G_M_P_H_S_PARENTFOLDERID_2);
11892    
11893                    query.append(_FINDER_COLUMN_G_M_P_H_S_HIDDEN_2_SQL);
11894    
11895                    query.append(_FINDER_COLUMN_G_M_P_H_S_STATUS_2);
11896    
11897                    if (!getDB().isSupportsInlineDistinct()) {
11898                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2);
11899                    }
11900    
11901                    if (orderByComparator != null) {
11902                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
11903    
11904                            if (orderByConditionFields.length > 0) {
11905                                    query.append(WHERE_AND);
11906                            }
11907    
11908                            for (int i = 0; i < orderByConditionFields.length; i++) {
11909                                    if (getDB().isSupportsInlineDistinct()) {
11910                                            query.append(_ORDER_BY_ENTITY_ALIAS);
11911                                    }
11912                                    else {
11913                                            query.append(_ORDER_BY_ENTITY_TABLE);
11914                                    }
11915    
11916                                    query.append(orderByConditionFields[i]);
11917    
11918                                    if ((i + 1) < orderByConditionFields.length) {
11919                                            if (orderByComparator.isAscending() ^ previous) {
11920                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
11921                                            }
11922                                            else {
11923                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
11924                                            }
11925                                    }
11926                                    else {
11927                                            if (orderByComparator.isAscending() ^ previous) {
11928                                                    query.append(WHERE_GREATER_THAN);
11929                                            }
11930                                            else {
11931                                                    query.append(WHERE_LESSER_THAN);
11932                                            }
11933                                    }
11934                            }
11935    
11936                            query.append(ORDER_BY_CLAUSE);
11937    
11938                            String[] orderByFields = orderByComparator.getOrderByFields();
11939    
11940                            for (int i = 0; i < orderByFields.length; i++) {
11941                                    if (getDB().isSupportsInlineDistinct()) {
11942                                            query.append(_ORDER_BY_ENTITY_ALIAS);
11943                                    }
11944                                    else {
11945                                            query.append(_ORDER_BY_ENTITY_TABLE);
11946                                    }
11947    
11948                                    query.append(orderByFields[i]);
11949    
11950                                    if ((i + 1) < orderByFields.length) {
11951                                            if (orderByComparator.isAscending() ^ previous) {
11952                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
11953                                            }
11954                                            else {
11955                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
11956                                            }
11957                                    }
11958                                    else {
11959                                            if (orderByComparator.isAscending() ^ previous) {
11960                                                    query.append(ORDER_BY_ASC);
11961                                            }
11962                                            else {
11963                                                    query.append(ORDER_BY_DESC);
11964                                            }
11965                                    }
11966                            }
11967                    }
11968                    else {
11969                            if (getDB().isSupportsInlineDistinct()) {
11970                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
11971                            }
11972                            else {
11973                                    query.append(DLFolderModelImpl.ORDER_BY_SQL);
11974                            }
11975                    }
11976    
11977                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
11978                                    DLFolder.class.getName(),
11979                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
11980    
11981                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
11982    
11983                    q.setFirstResult(0);
11984                    q.setMaxResults(2);
11985    
11986                    if (getDB().isSupportsInlineDistinct()) {
11987                            q.addEntity(_FILTER_ENTITY_ALIAS, DLFolderImpl.class);
11988                    }
11989                    else {
11990                            q.addEntity(_FILTER_ENTITY_TABLE, DLFolderImpl.class);
11991                    }
11992    
11993                    QueryPos qPos = QueryPos.getInstance(q);
11994    
11995                    qPos.add(groupId);
11996    
11997                    qPos.add(mountPoint);
11998    
11999                    qPos.add(parentFolderId);
12000    
12001                    qPos.add(hidden);
12002    
12003                    qPos.add(status);
12004    
12005                    if (orderByComparator != null) {
12006                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
12007    
12008                            for (Object value : values) {
12009                                    qPos.add(value);
12010                            }
12011                    }
12012    
12013                    List<DLFolder> list = q.list();
12014    
12015                    if (list.size() == 2) {
12016                            return list.get(1);
12017                    }
12018                    else {
12019                            return null;
12020                    }
12021            }
12022    
12023            /**
12024             * Removes all the document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63; from the database.
12025             *
12026             * @param groupId the group ID
12027             * @param mountPoint the mount point
12028             * @param parentFolderId the parent folder ID
12029             * @param hidden the hidden
12030             * @param status the status
12031             */
12032            @Override
12033            public void removeByG_M_P_H_S(long groupId, boolean mountPoint,
12034                    long parentFolderId, boolean hidden, int status) {
12035                    for (DLFolder dlFolder : findByG_M_P_H_S(groupId, mountPoint,
12036                                    parentFolderId, hidden, status, QueryUtil.ALL_POS,
12037                                    QueryUtil.ALL_POS, null)) {
12038                            remove(dlFolder);
12039                    }
12040            }
12041    
12042            /**
12043             * Returns the number of document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
12044             *
12045             * @param groupId the group ID
12046             * @param mountPoint the mount point
12047             * @param parentFolderId the parent folder ID
12048             * @param hidden the hidden
12049             * @param status the status
12050             * @return the number of matching document library folders
12051             */
12052            @Override
12053            public int countByG_M_P_H_S(long groupId, boolean mountPoint,
12054                    long parentFolderId, boolean hidden, int status) {
12055                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_M_P_H_S;
12056    
12057                    Object[] finderArgs = new Object[] {
12058                                    groupId, mountPoint, parentFolderId, hidden, status
12059                            };
12060    
12061                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
12062    
12063                    if (count == null) {
12064                            StringBundler query = new StringBundler(6);
12065    
12066                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
12067    
12068                            query.append(_FINDER_COLUMN_G_M_P_H_S_GROUPID_2);
12069    
12070                            query.append(_FINDER_COLUMN_G_M_P_H_S_MOUNTPOINT_2);
12071    
12072                            query.append(_FINDER_COLUMN_G_M_P_H_S_PARENTFOLDERID_2);
12073    
12074                            query.append(_FINDER_COLUMN_G_M_P_H_S_HIDDEN_2);
12075    
12076                            query.append(_FINDER_COLUMN_G_M_P_H_S_STATUS_2);
12077    
12078                            String sql = query.toString();
12079    
12080                            Session session = null;
12081    
12082                            try {
12083                                    session = openSession();
12084    
12085                                    Query q = session.createQuery(sql);
12086    
12087                                    QueryPos qPos = QueryPos.getInstance(q);
12088    
12089                                    qPos.add(groupId);
12090    
12091                                    qPos.add(mountPoint);
12092    
12093                                    qPos.add(parentFolderId);
12094    
12095                                    qPos.add(hidden);
12096    
12097                                    qPos.add(status);
12098    
12099                                    count = (Long)q.uniqueResult();
12100    
12101                                    finderCache.putResult(finderPath, finderArgs, count);
12102                            }
12103                            catch (Exception e) {
12104                                    finderCache.removeResult(finderPath, finderArgs);
12105    
12106                                    throw processException(e);
12107                            }
12108                            finally {
12109                                    closeSession(session);
12110                            }
12111                    }
12112    
12113                    return count.intValue();
12114            }
12115    
12116            /**
12117             * 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;.
12118             *
12119             * @param groupId the group ID
12120             * @param mountPoint the mount point
12121             * @param parentFolderId the parent folder ID
12122             * @param hidden the hidden
12123             * @param status the status
12124             * @return the number of matching document library folders that the user has permission to view
12125             */
12126            @Override
12127            public int filterCountByG_M_P_H_S(long groupId, boolean mountPoint,
12128                    long parentFolderId, boolean hidden, int status) {
12129                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
12130                            return countByG_M_P_H_S(groupId, mountPoint, parentFolderId,
12131                                    hidden, status);
12132                    }
12133    
12134                    StringBundler query = new StringBundler(6);
12135    
12136                    query.append(_FILTER_SQL_COUNT_DLFOLDER_WHERE);
12137    
12138                    query.append(_FINDER_COLUMN_G_M_P_H_S_GROUPID_2);
12139    
12140                    query.append(_FINDER_COLUMN_G_M_P_H_S_MOUNTPOINT_2);
12141    
12142                    query.append(_FINDER_COLUMN_G_M_P_H_S_PARENTFOLDERID_2);
12143    
12144                    query.append(_FINDER_COLUMN_G_M_P_H_S_HIDDEN_2_SQL);
12145    
12146                    query.append(_FINDER_COLUMN_G_M_P_H_S_STATUS_2);
12147    
12148                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
12149                                    DLFolder.class.getName(),
12150                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
12151    
12152                    Session session = null;
12153    
12154                    try {
12155                            session = openSession();
12156    
12157                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
12158    
12159                            q.addScalar(COUNT_COLUMN_NAME,
12160                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
12161    
12162                            QueryPos qPos = QueryPos.getInstance(q);
12163    
12164                            qPos.add(groupId);
12165    
12166                            qPos.add(mountPoint);
12167    
12168                            qPos.add(parentFolderId);
12169    
12170                            qPos.add(hidden);
12171    
12172                            qPos.add(status);
12173    
12174                            Long count = (Long)q.uniqueResult();
12175    
12176                            return count.intValue();
12177                    }
12178                    catch (Exception e) {
12179                            throw processException(e);
12180                    }
12181                    finally {
12182                            closeSession(session);
12183                    }
12184            }
12185    
12186            private static final String _FINDER_COLUMN_G_M_P_H_S_GROUPID_2 = "dlFolder.groupId = ? AND ";
12187            private static final String _FINDER_COLUMN_G_M_P_H_S_MOUNTPOINT_2 = "dlFolder.mountPoint = ? AND ";
12188            private static final String _FINDER_COLUMN_G_M_P_H_S_PARENTFOLDERID_2 = "dlFolder.parentFolderId = ? AND ";
12189            private static final String _FINDER_COLUMN_G_M_P_H_S_HIDDEN_2 = "dlFolder.hidden = ? AND ";
12190            private static final String _FINDER_COLUMN_G_M_P_H_S_HIDDEN_2_SQL = "dlFolder.hidden_ = ? AND ";
12191            private static final String _FINDER_COLUMN_G_M_P_H_S_STATUS_2 = "dlFolder.status = ?";
12192    
12193            public DLFolderPersistenceImpl() {
12194                    setModelClass(DLFolder.class);
12195            }
12196    
12197            /**
12198             * Caches the document library folder in the entity cache if it is enabled.
12199             *
12200             * @param dlFolder the document library folder
12201             */
12202            @Override
12203            public void cacheResult(DLFolder dlFolder) {
12204                    entityCache.putResult(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
12205                            DLFolderImpl.class, dlFolder.getPrimaryKey(), dlFolder);
12206    
12207                    finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G,
12208                            new Object[] { dlFolder.getUuid(), dlFolder.getGroupId() }, dlFolder);
12209    
12210                    finderCache.putResult(FINDER_PATH_FETCH_BY_R_M,
12211                            new Object[] { dlFolder.getRepositoryId(), dlFolder.getMountPoint() },
12212                            dlFolder);
12213    
12214                    finderCache.putResult(FINDER_PATH_FETCH_BY_G_P_N,
12215                            new Object[] {
12216                                    dlFolder.getGroupId(), dlFolder.getParentFolderId(),
12217                                    dlFolder.getName()
12218                            }, dlFolder);
12219    
12220                    dlFolder.resetOriginalValues();
12221            }
12222    
12223            /**
12224             * Caches the document library folders in the entity cache if it is enabled.
12225             *
12226             * @param dlFolders the document library folders
12227             */
12228            @Override
12229            public void cacheResult(List<DLFolder> dlFolders) {
12230                    for (DLFolder dlFolder : dlFolders) {
12231                            if (entityCache.getResult(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
12232                                                    DLFolderImpl.class, dlFolder.getPrimaryKey()) == null) {
12233                                    cacheResult(dlFolder);
12234                            }
12235                            else {
12236                                    dlFolder.resetOriginalValues();
12237                            }
12238                    }
12239            }
12240    
12241            /**
12242             * Clears the cache for all document library folders.
12243             *
12244             * <p>
12245             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
12246             * </p>
12247             */
12248            @Override
12249            public void clearCache() {
12250                    entityCache.clearCache(DLFolderImpl.class);
12251    
12252                    finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
12253                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
12254                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
12255            }
12256    
12257            /**
12258             * Clears the cache for the document library folder.
12259             *
12260             * <p>
12261             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
12262             * </p>
12263             */
12264            @Override
12265            public void clearCache(DLFolder dlFolder) {
12266                    entityCache.removeResult(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
12267                            DLFolderImpl.class, dlFolder.getPrimaryKey());
12268    
12269                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
12270                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
12271    
12272                    clearUniqueFindersCache((DLFolderModelImpl)dlFolder);
12273            }
12274    
12275            @Override
12276            public void clearCache(List<DLFolder> dlFolders) {
12277                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
12278                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
12279    
12280                    for (DLFolder dlFolder : dlFolders) {
12281                            entityCache.removeResult(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
12282                                    DLFolderImpl.class, dlFolder.getPrimaryKey());
12283    
12284                            clearUniqueFindersCache((DLFolderModelImpl)dlFolder);
12285                    }
12286            }
12287    
12288            protected void cacheUniqueFindersCache(
12289                    DLFolderModelImpl dlFolderModelImpl, boolean isNew) {
12290                    if (isNew) {
12291                            Object[] args = new Object[] {
12292                                            dlFolderModelImpl.getUuid(), dlFolderModelImpl.getGroupId()
12293                                    };
12294    
12295                            finderCache.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
12296                                    Long.valueOf(1));
12297                            finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
12298                                    dlFolderModelImpl);
12299    
12300                            args = new Object[] {
12301                                            dlFolderModelImpl.getRepositoryId(),
12302                                            dlFolderModelImpl.getMountPoint()
12303                                    };
12304    
12305                            finderCache.putResult(FINDER_PATH_COUNT_BY_R_M, args,
12306                                    Long.valueOf(1));
12307                            finderCache.putResult(FINDER_PATH_FETCH_BY_R_M, args,
12308                                    dlFolderModelImpl);
12309    
12310                            args = new Object[] {
12311                                            dlFolderModelImpl.getGroupId(),
12312                                            dlFolderModelImpl.getParentFolderId(),
12313                                            dlFolderModelImpl.getName()
12314                                    };
12315    
12316                            finderCache.putResult(FINDER_PATH_COUNT_BY_G_P_N, args,
12317                                    Long.valueOf(1));
12318                            finderCache.putResult(FINDER_PATH_FETCH_BY_G_P_N, args,
12319                                    dlFolderModelImpl);
12320                    }
12321                    else {
12322                            if ((dlFolderModelImpl.getColumnBitmask() &
12323                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
12324                                    Object[] args = new Object[] {
12325                                                    dlFolderModelImpl.getUuid(),
12326                                                    dlFolderModelImpl.getGroupId()
12327                                            };
12328    
12329                                    finderCache.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
12330                                            Long.valueOf(1));
12331                                    finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
12332                                            dlFolderModelImpl);
12333                            }
12334    
12335                            if ((dlFolderModelImpl.getColumnBitmask() &
12336                                            FINDER_PATH_FETCH_BY_R_M.getColumnBitmask()) != 0) {
12337                                    Object[] args = new Object[] {
12338                                                    dlFolderModelImpl.getRepositoryId(),
12339                                                    dlFolderModelImpl.getMountPoint()
12340                                            };
12341    
12342                                    finderCache.putResult(FINDER_PATH_COUNT_BY_R_M, args,
12343                                            Long.valueOf(1));
12344                                    finderCache.putResult(FINDER_PATH_FETCH_BY_R_M, args,
12345                                            dlFolderModelImpl);
12346                            }
12347    
12348                            if ((dlFolderModelImpl.getColumnBitmask() &
12349                                            FINDER_PATH_FETCH_BY_G_P_N.getColumnBitmask()) != 0) {
12350                                    Object[] args = new Object[] {
12351                                                    dlFolderModelImpl.getGroupId(),
12352                                                    dlFolderModelImpl.getParentFolderId(),
12353                                                    dlFolderModelImpl.getName()
12354                                            };
12355    
12356                                    finderCache.putResult(FINDER_PATH_COUNT_BY_G_P_N, args,
12357                                            Long.valueOf(1));
12358                                    finderCache.putResult(FINDER_PATH_FETCH_BY_G_P_N, args,
12359                                            dlFolderModelImpl);
12360                            }
12361                    }
12362            }
12363    
12364            protected void clearUniqueFindersCache(DLFolderModelImpl dlFolderModelImpl) {
12365                    Object[] args = new Object[] {
12366                                    dlFolderModelImpl.getUuid(), dlFolderModelImpl.getGroupId()
12367                            };
12368    
12369                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
12370                    finderCache.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
12371    
12372                    if ((dlFolderModelImpl.getColumnBitmask() &
12373                                    FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
12374                            args = new Object[] {
12375                                            dlFolderModelImpl.getOriginalUuid(),
12376                                            dlFolderModelImpl.getOriginalGroupId()
12377                                    };
12378    
12379                            finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
12380                            finderCache.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
12381                    }
12382    
12383                    args = new Object[] {
12384                                    dlFolderModelImpl.getRepositoryId(),
12385                                    dlFolderModelImpl.getMountPoint()
12386                            };
12387    
12388                    finderCache.removeResult(FINDER_PATH_COUNT_BY_R_M, args);
12389                    finderCache.removeResult(FINDER_PATH_FETCH_BY_R_M, args);
12390    
12391                    if ((dlFolderModelImpl.getColumnBitmask() &
12392                                    FINDER_PATH_FETCH_BY_R_M.getColumnBitmask()) != 0) {
12393                            args = new Object[] {
12394                                            dlFolderModelImpl.getOriginalRepositoryId(),
12395                                            dlFolderModelImpl.getOriginalMountPoint()
12396                                    };
12397    
12398                            finderCache.removeResult(FINDER_PATH_COUNT_BY_R_M, args);
12399                            finderCache.removeResult(FINDER_PATH_FETCH_BY_R_M, args);
12400                    }
12401    
12402                    args = new Object[] {
12403                                    dlFolderModelImpl.getGroupId(),
12404                                    dlFolderModelImpl.getParentFolderId(),
12405                                    dlFolderModelImpl.getName()
12406                            };
12407    
12408                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_P_N, args);
12409                    finderCache.removeResult(FINDER_PATH_FETCH_BY_G_P_N, args);
12410    
12411                    if ((dlFolderModelImpl.getColumnBitmask() &
12412                                    FINDER_PATH_FETCH_BY_G_P_N.getColumnBitmask()) != 0) {
12413                            args = new Object[] {
12414                                            dlFolderModelImpl.getOriginalGroupId(),
12415                                            dlFolderModelImpl.getOriginalParentFolderId(),
12416                                            dlFolderModelImpl.getOriginalName()
12417                                    };
12418    
12419                            finderCache.removeResult(FINDER_PATH_COUNT_BY_G_P_N, args);
12420                            finderCache.removeResult(FINDER_PATH_FETCH_BY_G_P_N, args);
12421                    }
12422            }
12423    
12424            /**
12425             * Creates a new document library folder with the primary key. Does not add the document library folder to the database.
12426             *
12427             * @param folderId the primary key for the new document library folder
12428             * @return the new document library folder
12429             */
12430            @Override
12431            public DLFolder create(long folderId) {
12432                    DLFolder dlFolder = new DLFolderImpl();
12433    
12434                    dlFolder.setNew(true);
12435                    dlFolder.setPrimaryKey(folderId);
12436    
12437                    String uuid = PortalUUIDUtil.generate();
12438    
12439                    dlFolder.setUuid(uuid);
12440    
12441                    dlFolder.setCompanyId(companyProvider.getCompanyId());
12442    
12443                    return dlFolder;
12444            }
12445    
12446            /**
12447             * Removes the document library folder with the primary key from the database. Also notifies the appropriate model listeners.
12448             *
12449             * @param folderId the primary key of the document library folder
12450             * @return the document library folder that was removed
12451             * @throws NoSuchFolderException if a document library folder with the primary key could not be found
12452             */
12453            @Override
12454            public DLFolder remove(long folderId) throws NoSuchFolderException {
12455                    return remove((Serializable)folderId);
12456            }
12457    
12458            /**
12459             * Removes the document library folder with the primary key from the database. Also notifies the appropriate model listeners.
12460             *
12461             * @param primaryKey the primary key of the document library folder
12462             * @return the document library folder that was removed
12463             * @throws NoSuchFolderException if a document library folder with the primary key could not be found
12464             */
12465            @Override
12466            public DLFolder remove(Serializable primaryKey)
12467                    throws NoSuchFolderException {
12468                    Session session = null;
12469    
12470                    try {
12471                            session = openSession();
12472    
12473                            DLFolder dlFolder = (DLFolder)session.get(DLFolderImpl.class,
12474                                            primaryKey);
12475    
12476                            if (dlFolder == null) {
12477                                    if (_log.isWarnEnabled()) {
12478                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
12479                                    }
12480    
12481                                    throw new NoSuchFolderException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
12482                                            primaryKey);
12483                            }
12484    
12485                            return remove(dlFolder);
12486                    }
12487                    catch (NoSuchFolderException nsee) {
12488                            throw nsee;
12489                    }
12490                    catch (Exception e) {
12491                            throw processException(e);
12492                    }
12493                    finally {
12494                            closeSession(session);
12495                    }
12496            }
12497    
12498            @Override
12499            protected DLFolder removeImpl(DLFolder dlFolder) {
12500                    dlFolder = toUnwrappedModel(dlFolder);
12501    
12502                    dlFolderToDLFileEntryTypeTableMapper.deleteLeftPrimaryKeyTableMappings(dlFolder.getPrimaryKey());
12503    
12504                    Session session = null;
12505    
12506                    try {
12507                            session = openSession();
12508    
12509                            if (!session.contains(dlFolder)) {
12510                                    dlFolder = (DLFolder)session.get(DLFolderImpl.class,
12511                                                    dlFolder.getPrimaryKeyObj());
12512                            }
12513    
12514                            if (dlFolder != null) {
12515                                    session.delete(dlFolder);
12516                            }
12517                    }
12518                    catch (Exception e) {
12519                            throw processException(e);
12520                    }
12521                    finally {
12522                            closeSession(session);
12523                    }
12524    
12525                    if (dlFolder != null) {
12526                            clearCache(dlFolder);
12527                    }
12528    
12529                    return dlFolder;
12530            }
12531    
12532            @Override
12533            public DLFolder updateImpl(DLFolder dlFolder) {
12534                    dlFolder = toUnwrappedModel(dlFolder);
12535    
12536                    boolean isNew = dlFolder.isNew();
12537    
12538                    DLFolderModelImpl dlFolderModelImpl = (DLFolderModelImpl)dlFolder;
12539    
12540                    if (Validator.isNull(dlFolder.getUuid())) {
12541                            String uuid = PortalUUIDUtil.generate();
12542    
12543                            dlFolder.setUuid(uuid);
12544                    }
12545    
12546                    ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();
12547    
12548                    Date now = new Date();
12549    
12550                    if (isNew && (dlFolder.getCreateDate() == null)) {
12551                            if (serviceContext == null) {
12552                                    dlFolder.setCreateDate(now);
12553                            }
12554                            else {
12555                                    dlFolder.setCreateDate(serviceContext.getCreateDate(now));
12556                            }
12557                    }
12558    
12559                    if (!dlFolderModelImpl.hasSetModifiedDate()) {
12560                            if (serviceContext == null) {
12561                                    dlFolder.setModifiedDate(now);
12562                            }
12563                            else {
12564                                    dlFolder.setModifiedDate(serviceContext.getModifiedDate(now));
12565                            }
12566                    }
12567    
12568                    Session session = null;
12569    
12570                    try {
12571                            session = openSession();
12572    
12573                            if (dlFolder.isNew()) {
12574                                    session.save(dlFolder);
12575    
12576                                    dlFolder.setNew(false);
12577                            }
12578                            else {
12579                                    dlFolder = (DLFolder)session.merge(dlFolder);
12580                            }
12581                    }
12582                    catch (Exception e) {
12583                            throw processException(e);
12584                    }
12585                    finally {
12586                            closeSession(session);
12587                    }
12588    
12589                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
12590    
12591                    if (isNew || !DLFolderModelImpl.COLUMN_BITMASK_ENABLED) {
12592                            finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
12593                    }
12594    
12595                    else {
12596                            if ((dlFolderModelImpl.getColumnBitmask() &
12597                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
12598                                    Object[] args = new Object[] { dlFolderModelImpl.getOriginalUuid() };
12599    
12600                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
12601                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
12602                                            args);
12603    
12604                                    args = new Object[] { dlFolderModelImpl.getUuid() };
12605    
12606                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
12607                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
12608                                            args);
12609                            }
12610    
12611                            if ((dlFolderModelImpl.getColumnBitmask() &
12612                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
12613                                    Object[] args = new Object[] {
12614                                                    dlFolderModelImpl.getOriginalUuid(),
12615                                                    dlFolderModelImpl.getOriginalCompanyId()
12616                                            };
12617    
12618                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
12619                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
12620                                            args);
12621    
12622                                    args = new Object[] {
12623                                                    dlFolderModelImpl.getUuid(),
12624                                                    dlFolderModelImpl.getCompanyId()
12625                                            };
12626    
12627                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
12628                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
12629                                            args);
12630                            }
12631    
12632                            if ((dlFolderModelImpl.getColumnBitmask() &
12633                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
12634                                    Object[] args = new Object[] {
12635                                                    dlFolderModelImpl.getOriginalGroupId()
12636                                            };
12637    
12638                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
12639                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
12640                                            args);
12641    
12642                                    args = new Object[] { dlFolderModelImpl.getGroupId() };
12643    
12644                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
12645                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
12646                                            args);
12647                            }
12648    
12649                            if ((dlFolderModelImpl.getColumnBitmask() &
12650                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
12651                                    Object[] args = new Object[] {
12652                                                    dlFolderModelImpl.getOriginalCompanyId()
12653                                            };
12654    
12655                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_COMPANYID, args);
12656                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
12657                                            args);
12658    
12659                                    args = new Object[] { dlFolderModelImpl.getCompanyId() };
12660    
12661                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_COMPANYID, args);
12662                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
12663                                            args);
12664                            }
12665    
12666                            if ((dlFolderModelImpl.getColumnBitmask() &
12667                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_REPOSITORYID.getColumnBitmask()) != 0) {
12668                                    Object[] args = new Object[] {
12669                                                    dlFolderModelImpl.getOriginalRepositoryId()
12670                                            };
12671    
12672                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_REPOSITORYID, args);
12673                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_REPOSITORYID,
12674                                            args);
12675    
12676                                    args = new Object[] { dlFolderModelImpl.getRepositoryId() };
12677    
12678                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_REPOSITORYID, args);
12679                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_REPOSITORYID,
12680                                            args);
12681                            }
12682    
12683                            if ((dlFolderModelImpl.getColumnBitmask() &
12684                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P.getColumnBitmask()) != 0) {
12685                                    Object[] args = new Object[] {
12686                                                    dlFolderModelImpl.getOriginalGroupId(),
12687                                                    dlFolderModelImpl.getOriginalParentFolderId()
12688                                            };
12689    
12690                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_P, args);
12691                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P,
12692                                            args);
12693    
12694                                    args = new Object[] {
12695                                                    dlFolderModelImpl.getGroupId(),
12696                                                    dlFolderModelImpl.getParentFolderId()
12697                                            };
12698    
12699                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_P, args);
12700                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P,
12701                                            args);
12702                            }
12703    
12704                            if ((dlFolderModelImpl.getColumnBitmask() &
12705                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_P.getColumnBitmask()) != 0) {
12706                                    Object[] args = new Object[] {
12707                                                    dlFolderModelImpl.getOriginalRepositoryId(),
12708                                                    dlFolderModelImpl.getOriginalParentFolderId()
12709                                            };
12710    
12711                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_R_P, args);
12712                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_P,
12713                                            args);
12714    
12715                                    args = new Object[] {
12716                                                    dlFolderModelImpl.getRepositoryId(),
12717                                                    dlFolderModelImpl.getParentFolderId()
12718                                            };
12719    
12720                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_R_P, args);
12721                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_P,
12722                                            args);
12723                            }
12724    
12725                            if ((dlFolderModelImpl.getColumnBitmask() &
12726                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_N.getColumnBitmask()) != 0) {
12727                                    Object[] args = new Object[] {
12728                                                    dlFolderModelImpl.getOriginalParentFolderId(),
12729                                                    dlFolderModelImpl.getOriginalName()
12730                                            };
12731    
12732                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_P_N, args);
12733                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_N,
12734                                            args);
12735    
12736                                    args = new Object[] {
12737                                                    dlFolderModelImpl.getParentFolderId(),
12738                                                    dlFolderModelImpl.getName()
12739                                            };
12740    
12741                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_P_N, args);
12742                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_N,
12743                                            args);
12744                            }
12745    
12746                            if ((dlFolderModelImpl.getColumnBitmask() &
12747                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P.getColumnBitmask()) != 0) {
12748                                    Object[] args = new Object[] {
12749                                                    dlFolderModelImpl.getOriginalGroupId(),
12750                                                    dlFolderModelImpl.getOriginalMountPoint(),
12751                                                    dlFolderModelImpl.getOriginalParentFolderId()
12752                                            };
12753    
12754                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_M_P, args);
12755                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P,
12756                                            args);
12757    
12758                                    args = new Object[] {
12759                                                    dlFolderModelImpl.getGroupId(),
12760                                                    dlFolderModelImpl.getMountPoint(),
12761                                                    dlFolderModelImpl.getParentFolderId()
12762                                            };
12763    
12764                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_M_P, args);
12765                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P,
12766                                            args);
12767                            }
12768    
12769                            if ((dlFolderModelImpl.getColumnBitmask() &
12770                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P_H.getColumnBitmask()) != 0) {
12771                                    Object[] args = new Object[] {
12772                                                    dlFolderModelImpl.getOriginalGroupId(),
12773                                                    dlFolderModelImpl.getOriginalMountPoint(),
12774                                                    dlFolderModelImpl.getOriginalParentFolderId(),
12775                                                    dlFolderModelImpl.getOriginalHidden()
12776                                            };
12777    
12778                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_M_P_H, args);
12779                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P_H,
12780                                            args);
12781    
12782                                    args = new Object[] {
12783                                                    dlFolderModelImpl.getGroupId(),
12784                                                    dlFolderModelImpl.getMountPoint(),
12785                                                    dlFolderModelImpl.getParentFolderId(),
12786                                                    dlFolderModelImpl.getHidden()
12787                                            };
12788    
12789                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_M_P_H, args);
12790                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P_H,
12791                                            args);
12792                            }
12793    
12794                            if ((dlFolderModelImpl.getColumnBitmask() &
12795                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_H_S.getColumnBitmask()) != 0) {
12796                                    Object[] args = new Object[] {
12797                                                    dlFolderModelImpl.getOriginalGroupId(),
12798                                                    dlFolderModelImpl.getOriginalParentFolderId(),
12799                                                    dlFolderModelImpl.getOriginalHidden(),
12800                                                    dlFolderModelImpl.getOriginalStatus()
12801                                            };
12802    
12803                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_P_H_S, args);
12804                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_H_S,
12805                                            args);
12806    
12807                                    args = new Object[] {
12808                                                    dlFolderModelImpl.getGroupId(),
12809                                                    dlFolderModelImpl.getParentFolderId(),
12810                                                    dlFolderModelImpl.getHidden(),
12811                                                    dlFolderModelImpl.getStatus()
12812                                            };
12813    
12814                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_P_H_S, args);
12815                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_H_S,
12816                                            args);
12817                            }
12818    
12819                            if ((dlFolderModelImpl.getColumnBitmask() &
12820                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P_H_S.getColumnBitmask()) != 0) {
12821                                    Object[] args = new Object[] {
12822                                                    dlFolderModelImpl.getOriginalGroupId(),
12823                                                    dlFolderModelImpl.getOriginalMountPoint(),
12824                                                    dlFolderModelImpl.getOriginalParentFolderId(),
12825                                                    dlFolderModelImpl.getOriginalHidden(),
12826                                                    dlFolderModelImpl.getOriginalStatus()
12827                                            };
12828    
12829                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_M_P_H_S, args);
12830                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P_H_S,
12831                                            args);
12832    
12833                                    args = new Object[] {
12834                                                    dlFolderModelImpl.getGroupId(),
12835                                                    dlFolderModelImpl.getMountPoint(),
12836                                                    dlFolderModelImpl.getParentFolderId(),
12837                                                    dlFolderModelImpl.getHidden(),
12838                                                    dlFolderModelImpl.getStatus()
12839                                            };
12840    
12841                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_M_P_H_S, args);
12842                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P_H_S,
12843                                            args);
12844                            }
12845                    }
12846    
12847                    entityCache.putResult(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
12848                            DLFolderImpl.class, dlFolder.getPrimaryKey(), dlFolder, false);
12849    
12850                    clearUniqueFindersCache(dlFolderModelImpl);
12851                    cacheUniqueFindersCache(dlFolderModelImpl, isNew);
12852    
12853                    dlFolder.resetOriginalValues();
12854    
12855                    return dlFolder;
12856            }
12857    
12858            protected DLFolder toUnwrappedModel(DLFolder dlFolder) {
12859                    if (dlFolder instanceof DLFolderImpl) {
12860                            return dlFolder;
12861                    }
12862    
12863                    DLFolderImpl dlFolderImpl = new DLFolderImpl();
12864    
12865                    dlFolderImpl.setNew(dlFolder.isNew());
12866                    dlFolderImpl.setPrimaryKey(dlFolder.getPrimaryKey());
12867    
12868                    dlFolderImpl.setUuid(dlFolder.getUuid());
12869                    dlFolderImpl.setFolderId(dlFolder.getFolderId());
12870                    dlFolderImpl.setGroupId(dlFolder.getGroupId());
12871                    dlFolderImpl.setCompanyId(dlFolder.getCompanyId());
12872                    dlFolderImpl.setUserId(dlFolder.getUserId());
12873                    dlFolderImpl.setUserName(dlFolder.getUserName());
12874                    dlFolderImpl.setCreateDate(dlFolder.getCreateDate());
12875                    dlFolderImpl.setModifiedDate(dlFolder.getModifiedDate());
12876                    dlFolderImpl.setRepositoryId(dlFolder.getRepositoryId());
12877                    dlFolderImpl.setMountPoint(dlFolder.isMountPoint());
12878                    dlFolderImpl.setParentFolderId(dlFolder.getParentFolderId());
12879                    dlFolderImpl.setTreePath(dlFolder.getTreePath());
12880                    dlFolderImpl.setName(dlFolder.getName());
12881                    dlFolderImpl.setDescription(dlFolder.getDescription());
12882                    dlFolderImpl.setLastPostDate(dlFolder.getLastPostDate());
12883                    dlFolderImpl.setDefaultFileEntryTypeId(dlFolder.getDefaultFileEntryTypeId());
12884                    dlFolderImpl.setHidden(dlFolder.isHidden());
12885                    dlFolderImpl.setRestrictionType(dlFolder.getRestrictionType());
12886                    dlFolderImpl.setLastPublishDate(dlFolder.getLastPublishDate());
12887                    dlFolderImpl.setStatus(dlFolder.getStatus());
12888                    dlFolderImpl.setStatusByUserId(dlFolder.getStatusByUserId());
12889                    dlFolderImpl.setStatusByUserName(dlFolder.getStatusByUserName());
12890                    dlFolderImpl.setStatusDate(dlFolder.getStatusDate());
12891    
12892                    return dlFolderImpl;
12893            }
12894    
12895            /**
12896             * Returns the document library folder with the primary key or throws a {@link com.liferay.portal.kernel.exception.NoSuchModelException} if it could not be found.
12897             *
12898             * @param primaryKey the primary key of the document library folder
12899             * @return the document library folder
12900             * @throws NoSuchFolderException if a document library folder with the primary key could not be found
12901             */
12902            @Override
12903            public DLFolder findByPrimaryKey(Serializable primaryKey)
12904                    throws NoSuchFolderException {
12905                    DLFolder dlFolder = fetchByPrimaryKey(primaryKey);
12906    
12907                    if (dlFolder == null) {
12908                            if (_log.isWarnEnabled()) {
12909                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
12910                            }
12911    
12912                            throw new NoSuchFolderException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
12913                                    primaryKey);
12914                    }
12915    
12916                    return dlFolder;
12917            }
12918    
12919            /**
12920             * Returns the document library folder with the primary key or throws a {@link NoSuchFolderException} if it could not be found.
12921             *
12922             * @param folderId the primary key of the document library folder
12923             * @return the document library folder
12924             * @throws NoSuchFolderException if a document library folder with the primary key could not be found
12925             */
12926            @Override
12927            public DLFolder findByPrimaryKey(long folderId)
12928                    throws NoSuchFolderException {
12929                    return findByPrimaryKey((Serializable)folderId);
12930            }
12931    
12932            /**
12933             * Returns the document library folder with the primary key or returns <code>null</code> if it could not be found.
12934             *
12935             * @param primaryKey the primary key of the document library folder
12936             * @return the document library folder, or <code>null</code> if a document library folder with the primary key could not be found
12937             */
12938            @Override
12939            public DLFolder fetchByPrimaryKey(Serializable primaryKey) {
12940                    DLFolder dlFolder = (DLFolder)entityCache.getResult(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
12941                                    DLFolderImpl.class, primaryKey);
12942    
12943                    if (dlFolder == _nullDLFolder) {
12944                            return null;
12945                    }
12946    
12947                    if (dlFolder == null) {
12948                            Session session = null;
12949    
12950                            try {
12951                                    session = openSession();
12952    
12953                                    dlFolder = (DLFolder)session.get(DLFolderImpl.class, primaryKey);
12954    
12955                                    if (dlFolder != null) {
12956                                            cacheResult(dlFolder);
12957                                    }
12958                                    else {
12959                                            entityCache.putResult(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
12960                                                    DLFolderImpl.class, primaryKey, _nullDLFolder);
12961                                    }
12962                            }
12963                            catch (Exception e) {
12964                                    entityCache.removeResult(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
12965                                            DLFolderImpl.class, primaryKey);
12966    
12967                                    throw processException(e);
12968                            }
12969                            finally {
12970                                    closeSession(session);
12971                            }
12972                    }
12973    
12974                    return dlFolder;
12975            }
12976    
12977            /**
12978             * Returns the document library folder with the primary key or returns <code>null</code> if it could not be found.
12979             *
12980             * @param folderId the primary key of the document library folder
12981             * @return the document library folder, or <code>null</code> if a document library folder with the primary key could not be found
12982             */
12983            @Override
12984            public DLFolder fetchByPrimaryKey(long folderId) {
12985                    return fetchByPrimaryKey((Serializable)folderId);
12986            }
12987    
12988            @Override
12989            public Map<Serializable, DLFolder> fetchByPrimaryKeys(
12990                    Set<Serializable> primaryKeys) {
12991                    if (primaryKeys.isEmpty()) {
12992                            return Collections.emptyMap();
12993                    }
12994    
12995                    Map<Serializable, DLFolder> map = new HashMap<Serializable, DLFolder>();
12996    
12997                    if (primaryKeys.size() == 1) {
12998                            Iterator<Serializable> iterator = primaryKeys.iterator();
12999    
13000                            Serializable primaryKey = iterator.next();
13001    
13002                            DLFolder dlFolder = fetchByPrimaryKey(primaryKey);
13003    
13004                            if (dlFolder != null) {
13005                                    map.put(primaryKey, dlFolder);
13006                            }
13007    
13008                            return map;
13009                    }
13010    
13011                    Set<Serializable> uncachedPrimaryKeys = null;
13012    
13013                    for (Serializable primaryKey : primaryKeys) {
13014                            DLFolder dlFolder = (DLFolder)entityCache.getResult(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
13015                                            DLFolderImpl.class, primaryKey);
13016    
13017                            if (dlFolder == null) {
13018                                    if (uncachedPrimaryKeys == null) {
13019                                            uncachedPrimaryKeys = new HashSet<Serializable>();
13020                                    }
13021    
13022                                    uncachedPrimaryKeys.add(primaryKey);
13023                            }
13024                            else {
13025                                    map.put(primaryKey, dlFolder);
13026                            }
13027                    }
13028    
13029                    if (uncachedPrimaryKeys == null) {
13030                            return map;
13031                    }
13032    
13033                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
13034                                    1);
13035    
13036                    query.append(_SQL_SELECT_DLFOLDER_WHERE_PKS_IN);
13037    
13038                    for (Serializable primaryKey : uncachedPrimaryKeys) {
13039                            query.append(String.valueOf(primaryKey));
13040    
13041                            query.append(StringPool.COMMA);
13042                    }
13043    
13044                    query.setIndex(query.index() - 1);
13045    
13046                    query.append(StringPool.CLOSE_PARENTHESIS);
13047    
13048                    String sql = query.toString();
13049    
13050                    Session session = null;
13051    
13052                    try {
13053                            session = openSession();
13054    
13055                            Query q = session.createQuery(sql);
13056    
13057                            for (DLFolder dlFolder : (List<DLFolder>)q.list()) {
13058                                    map.put(dlFolder.getPrimaryKeyObj(), dlFolder);
13059    
13060                                    cacheResult(dlFolder);
13061    
13062                                    uncachedPrimaryKeys.remove(dlFolder.getPrimaryKeyObj());
13063                            }
13064    
13065                            for (Serializable primaryKey : uncachedPrimaryKeys) {
13066                                    entityCache.putResult(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
13067                                            DLFolderImpl.class, primaryKey, _nullDLFolder);
13068                            }
13069                    }
13070                    catch (Exception e) {
13071                            throw processException(e);
13072                    }
13073                    finally {
13074                            closeSession(session);
13075                    }
13076    
13077                    return map;
13078            }
13079    
13080            /**
13081             * Returns all the document library folders.
13082             *
13083             * @return the document library folders
13084             */
13085            @Override
13086            public List<DLFolder> findAll() {
13087                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
13088            }
13089    
13090            /**
13091             * Returns a range of all the document library folders.
13092             *
13093             * <p>
13094             * 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.
13095             * </p>
13096             *
13097             * @param start the lower bound of the range of document library folders
13098             * @param end the upper bound of the range of document library folders (not inclusive)
13099             * @return the range of document library folders
13100             */
13101            @Override
13102            public List<DLFolder> findAll(int start, int end) {
13103                    return findAll(start, end, null);
13104            }
13105    
13106            /**
13107             * Returns an ordered range of all the document library folders.
13108             *
13109             * <p>
13110             * 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.
13111             * </p>
13112             *
13113             * @param start the lower bound of the range of document library folders
13114             * @param end the upper bound of the range of document library folders (not inclusive)
13115             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
13116             * @return the ordered range of document library folders
13117             */
13118            @Override
13119            public List<DLFolder> findAll(int start, int end,
13120                    OrderByComparator<DLFolder> orderByComparator) {
13121                    return findAll(start, end, orderByComparator, true);
13122            }
13123    
13124            /**
13125             * Returns an ordered range of all the document library folders.
13126             *
13127             * <p>
13128             * 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.
13129             * </p>
13130             *
13131             * @param start the lower bound of the range of document library folders
13132             * @param end the upper bound of the range of document library folders (not inclusive)
13133             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
13134             * @param retrieveFromCache whether to retrieve from the finder cache
13135             * @return the ordered range of document library folders
13136             */
13137            @Override
13138            public List<DLFolder> findAll(int start, int end,
13139                    OrderByComparator<DLFolder> orderByComparator, boolean retrieveFromCache) {
13140                    boolean pagination = true;
13141                    FinderPath finderPath = null;
13142                    Object[] finderArgs = null;
13143    
13144                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
13145                                    (orderByComparator == null)) {
13146                            pagination = false;
13147                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
13148                            finderArgs = FINDER_ARGS_EMPTY;
13149                    }
13150                    else {
13151                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
13152                            finderArgs = new Object[] { start, end, orderByComparator };
13153                    }
13154    
13155                    List<DLFolder> list = null;
13156    
13157                    if (retrieveFromCache) {
13158                            list = (List<DLFolder>)finderCache.getResult(finderPath,
13159                                            finderArgs, this);
13160                    }
13161    
13162                    if (list == null) {
13163                            StringBundler query = null;
13164                            String sql = null;
13165    
13166                            if (orderByComparator != null) {
13167                                    query = new StringBundler(2 +
13168                                                    (orderByComparator.getOrderByFields().length * 2));
13169    
13170                                    query.append(_SQL_SELECT_DLFOLDER);
13171    
13172                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
13173                                            orderByComparator);
13174    
13175                                    sql = query.toString();
13176                            }
13177                            else {
13178                                    sql = _SQL_SELECT_DLFOLDER;
13179    
13180                                    if (pagination) {
13181                                            sql = sql.concat(DLFolderModelImpl.ORDER_BY_JPQL);
13182                                    }
13183                            }
13184    
13185                            Session session = null;
13186    
13187                            try {
13188                                    session = openSession();
13189    
13190                                    Query q = session.createQuery(sql);
13191    
13192                                    if (!pagination) {
13193                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
13194                                                            start, end, false);
13195    
13196                                            Collections.sort(list);
13197    
13198                                            list = Collections.unmodifiableList(list);
13199                                    }
13200                                    else {
13201                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
13202                                                            start, end);
13203                                    }
13204    
13205                                    cacheResult(list);
13206    
13207                                    finderCache.putResult(finderPath, finderArgs, list);
13208                            }
13209                            catch (Exception e) {
13210                                    finderCache.removeResult(finderPath, finderArgs);
13211    
13212                                    throw processException(e);
13213                            }
13214                            finally {
13215                                    closeSession(session);
13216                            }
13217                    }
13218    
13219                    return list;
13220            }
13221    
13222            /**
13223             * Removes all the document library folders from the database.
13224             *
13225             */
13226            @Override
13227            public void removeAll() {
13228                    for (DLFolder dlFolder : findAll()) {
13229                            remove(dlFolder);
13230                    }
13231            }
13232    
13233            /**
13234             * Returns the number of document library folders.
13235             *
13236             * @return the number of document library folders
13237             */
13238            @Override
13239            public int countAll() {
13240                    Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
13241                                    FINDER_ARGS_EMPTY, this);
13242    
13243                    if (count == null) {
13244                            Session session = null;
13245    
13246                            try {
13247                                    session = openSession();
13248    
13249                                    Query q = session.createQuery(_SQL_COUNT_DLFOLDER);
13250    
13251                                    count = (Long)q.uniqueResult();
13252    
13253                                    finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
13254                                            count);
13255                            }
13256                            catch (Exception e) {
13257                                    finderCache.removeResult(FINDER_PATH_COUNT_ALL,
13258                                            FINDER_ARGS_EMPTY);
13259    
13260                                    throw processException(e);
13261                            }
13262                            finally {
13263                                    closeSession(session);
13264                            }
13265                    }
13266    
13267                    return count.intValue();
13268            }
13269    
13270            /**
13271             * Returns the primaryKeys of document library file entry types associated with the document library folder.
13272             *
13273             * @param pk the primary key of the document library folder
13274             * @return long[] of the primaryKeys of document library file entry types associated with the document library folder
13275             */
13276            @Override
13277            public long[] getDLFileEntryTypePrimaryKeys(long pk) {
13278                    long[] pks = dlFolderToDLFileEntryTypeTableMapper.getRightPrimaryKeys(pk);
13279    
13280                    return pks.clone();
13281            }
13282    
13283            /**
13284             * Returns all the document library file entry types associated with the document library folder.
13285             *
13286             * @param pk the primary key of the document library folder
13287             * @return the document library file entry types associated with the document library folder
13288             */
13289            @Override
13290            public List<com.liferay.document.library.kernel.model.DLFileEntryType> getDLFileEntryTypes(
13291                    long pk) {
13292                    return getDLFileEntryTypes(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
13293            }
13294    
13295            /**
13296             * Returns a range of all the document library file entry types associated with the document library folder.
13297             *
13298             * <p>
13299             * 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.
13300             * </p>
13301             *
13302             * @param pk the primary key of the document library folder
13303             * @param start the lower bound of the range of document library folders
13304             * @param end the upper bound of the range of document library folders (not inclusive)
13305             * @return the range of document library file entry types associated with the document library folder
13306             */
13307            @Override
13308            public List<com.liferay.document.library.kernel.model.DLFileEntryType> getDLFileEntryTypes(
13309                    long pk, int start, int end) {
13310                    return getDLFileEntryTypes(pk, start, end, null);
13311            }
13312    
13313            /**
13314             * Returns an ordered range of all the document library file entry types associated with the document library folder.
13315             *
13316             * <p>
13317             * 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.
13318             * </p>
13319             *
13320             * @param pk the primary key of the document library folder
13321             * @param start the lower bound of the range of document library folders
13322             * @param end the upper bound of the range of document library folders (not inclusive)
13323             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
13324             * @return the ordered range of document library file entry types associated with the document library folder
13325             */
13326            @Override
13327            public List<com.liferay.document.library.kernel.model.DLFileEntryType> getDLFileEntryTypes(
13328                    long pk, int start, int end,
13329                    OrderByComparator<com.liferay.document.library.kernel.model.DLFileEntryType> orderByComparator) {
13330                    return dlFolderToDLFileEntryTypeTableMapper.getRightBaseModels(pk,
13331                            start, end, orderByComparator);
13332            }
13333    
13334            /**
13335             * Returns the number of document library file entry types associated with the document library folder.
13336             *
13337             * @param pk the primary key of the document library folder
13338             * @return the number of document library file entry types associated with the document library folder
13339             */
13340            @Override
13341            public int getDLFileEntryTypesSize(long pk) {
13342                    long[] pks = dlFolderToDLFileEntryTypeTableMapper.getRightPrimaryKeys(pk);
13343    
13344                    return pks.length;
13345            }
13346    
13347            /**
13348             * Returns <code>true</code> if the document library file entry type is associated with the document library folder.
13349             *
13350             * @param pk the primary key of the document library folder
13351             * @param dlFileEntryTypePK the primary key of the document library file entry type
13352             * @return <code>true</code> if the document library file entry type is associated with the document library folder; <code>false</code> otherwise
13353             */
13354            @Override
13355            public boolean containsDLFileEntryType(long pk, long dlFileEntryTypePK) {
13356                    return dlFolderToDLFileEntryTypeTableMapper.containsTableMapping(pk,
13357                            dlFileEntryTypePK);
13358            }
13359    
13360            /**
13361             * Returns <code>true</code> if the document library folder has any document library file entry types associated with it.
13362             *
13363             * @param pk the primary key of the document library folder to check for associations with document library file entry types
13364             * @return <code>true</code> if the document library folder has any document library file entry types associated with it; <code>false</code> otherwise
13365             */
13366            @Override
13367            public boolean containsDLFileEntryTypes(long pk) {
13368                    if (getDLFileEntryTypesSize(pk) > 0) {
13369                            return true;
13370                    }
13371                    else {
13372                            return false;
13373                    }
13374            }
13375    
13376            /**
13377             * 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.
13378             *
13379             * @param pk the primary key of the document library folder
13380             * @param dlFileEntryTypePK the primary key of the document library file entry type
13381             */
13382            @Override
13383            public void addDLFileEntryType(long pk, long dlFileEntryTypePK) {
13384                    DLFolder dlFolder = fetchByPrimaryKey(pk);
13385    
13386                    if (dlFolder == null) {
13387                            dlFolderToDLFileEntryTypeTableMapper.addTableMapping(companyProvider.getCompanyId(),
13388                                    pk, dlFileEntryTypePK);
13389                    }
13390                    else {
13391                            dlFolderToDLFileEntryTypeTableMapper.addTableMapping(dlFolder.getCompanyId(),
13392                                    pk, dlFileEntryTypePK);
13393                    }
13394            }
13395    
13396            /**
13397             * 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.
13398             *
13399             * @param pk the primary key of the document library folder
13400             * @param dlFileEntryType the document library file entry type
13401             */
13402            @Override
13403            public void addDLFileEntryType(long pk,
13404                    com.liferay.document.library.kernel.model.DLFileEntryType dlFileEntryType) {
13405                    DLFolder dlFolder = fetchByPrimaryKey(pk);
13406    
13407                    if (dlFolder == null) {
13408                            dlFolderToDLFileEntryTypeTableMapper.addTableMapping(companyProvider.getCompanyId(),
13409                                    pk, dlFileEntryType.getPrimaryKey());
13410                    }
13411                    else {
13412                            dlFolderToDLFileEntryTypeTableMapper.addTableMapping(dlFolder.getCompanyId(),
13413                                    pk, dlFileEntryType.getPrimaryKey());
13414                    }
13415            }
13416    
13417            /**
13418             * 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.
13419             *
13420             * @param pk the primary key of the document library folder
13421             * @param dlFileEntryTypePKs the primary keys of the document library file entry types
13422             */
13423            @Override
13424            public void addDLFileEntryTypes(long pk, long[] dlFileEntryTypePKs) {
13425                    long companyId = 0;
13426    
13427                    DLFolder dlFolder = fetchByPrimaryKey(pk);
13428    
13429                    if (dlFolder == null) {
13430                            companyId = companyProvider.getCompanyId();
13431                    }
13432                    else {
13433                            companyId = dlFolder.getCompanyId();
13434                    }
13435    
13436                    for (long dlFileEntryTypePK : dlFileEntryTypePKs) {
13437                            dlFolderToDLFileEntryTypeTableMapper.addTableMapping(companyId, pk,
13438                                    dlFileEntryTypePK);
13439                    }
13440            }
13441    
13442            /**
13443             * 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.
13444             *
13445             * @param pk the primary key of the document library folder
13446             * @param dlFileEntryTypes the document library file entry types
13447             */
13448            @Override
13449            public void addDLFileEntryTypes(long pk,
13450                    List<com.liferay.document.library.kernel.model.DLFileEntryType> dlFileEntryTypes) {
13451                    long companyId = 0;
13452    
13453                    DLFolder dlFolder = fetchByPrimaryKey(pk);
13454    
13455                    if (dlFolder == null) {
13456                            companyId = companyProvider.getCompanyId();
13457                    }
13458                    else {
13459                            companyId = dlFolder.getCompanyId();
13460                    }
13461    
13462                    for (com.liferay.document.library.kernel.model.DLFileEntryType dlFileEntryType : dlFileEntryTypes) {
13463                            dlFolderToDLFileEntryTypeTableMapper.addTableMapping(companyId, pk,
13464                                    dlFileEntryType.getPrimaryKey());
13465                    }
13466            }
13467    
13468            /**
13469             * 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.
13470             *
13471             * @param pk the primary key of the document library folder to clear the associated document library file entry types from
13472             */
13473            @Override
13474            public void clearDLFileEntryTypes(long pk) {
13475                    dlFolderToDLFileEntryTypeTableMapper.deleteLeftPrimaryKeyTableMappings(pk);
13476            }
13477    
13478            /**
13479             * 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.
13480             *
13481             * @param pk the primary key of the document library folder
13482             * @param dlFileEntryTypePK the primary key of the document library file entry type
13483             */
13484            @Override
13485            public void removeDLFileEntryType(long pk, long dlFileEntryTypePK) {
13486                    dlFolderToDLFileEntryTypeTableMapper.deleteTableMapping(pk,
13487                            dlFileEntryTypePK);
13488            }
13489    
13490            /**
13491             * 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.
13492             *
13493             * @param pk the primary key of the document library folder
13494             * @param dlFileEntryType the document library file entry type
13495             */
13496            @Override
13497            public void removeDLFileEntryType(long pk,
13498                    com.liferay.document.library.kernel.model.DLFileEntryType dlFileEntryType) {
13499                    dlFolderToDLFileEntryTypeTableMapper.deleteTableMapping(pk,
13500                            dlFileEntryType.getPrimaryKey());
13501            }
13502    
13503            /**
13504             * 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.
13505             *
13506             * @param pk the primary key of the document library folder
13507             * @param dlFileEntryTypePKs the primary keys of the document library file entry types
13508             */
13509            @Override
13510            public void removeDLFileEntryTypes(long pk, long[] dlFileEntryTypePKs) {
13511                    for (long dlFileEntryTypePK : dlFileEntryTypePKs) {
13512                            dlFolderToDLFileEntryTypeTableMapper.deleteTableMapping(pk,
13513                                    dlFileEntryTypePK);
13514                    }
13515            }
13516    
13517            /**
13518             * 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.
13519             *
13520             * @param pk the primary key of the document library folder
13521             * @param dlFileEntryTypes the document library file entry types
13522             */
13523            @Override
13524            public void removeDLFileEntryTypes(long pk,
13525                    List<com.liferay.document.library.kernel.model.DLFileEntryType> dlFileEntryTypes) {
13526                    for (com.liferay.document.library.kernel.model.DLFileEntryType dlFileEntryType : dlFileEntryTypes) {
13527                            dlFolderToDLFileEntryTypeTableMapper.deleteTableMapping(pk,
13528                                    dlFileEntryType.getPrimaryKey());
13529                    }
13530            }
13531    
13532            /**
13533             * 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.
13534             *
13535             * @param pk the primary key of the document library folder
13536             * @param dlFileEntryTypePKs the primary keys of the document library file entry types to be associated with the document library folder
13537             */
13538            @Override
13539            public void setDLFileEntryTypes(long pk, long[] dlFileEntryTypePKs) {
13540                    Set<Long> newDLFileEntryTypePKsSet = SetUtil.fromArray(dlFileEntryTypePKs);
13541                    Set<Long> oldDLFileEntryTypePKsSet = SetUtil.fromArray(dlFolderToDLFileEntryTypeTableMapper.getRightPrimaryKeys(
13542                                            pk));
13543    
13544                    Set<Long> removeDLFileEntryTypePKsSet = new HashSet<Long>(oldDLFileEntryTypePKsSet);
13545    
13546                    removeDLFileEntryTypePKsSet.removeAll(newDLFileEntryTypePKsSet);
13547    
13548                    for (long removeDLFileEntryTypePK : removeDLFileEntryTypePKsSet) {
13549                            dlFolderToDLFileEntryTypeTableMapper.deleteTableMapping(pk,
13550                                    removeDLFileEntryTypePK);
13551                    }
13552    
13553                    newDLFileEntryTypePKsSet.removeAll(oldDLFileEntryTypePKsSet);
13554    
13555                    long companyId = 0;
13556    
13557                    DLFolder dlFolder = fetchByPrimaryKey(pk);
13558    
13559                    if (dlFolder == null) {
13560                            companyId = companyProvider.getCompanyId();
13561                    }
13562                    else {
13563                            companyId = dlFolder.getCompanyId();
13564                    }
13565    
13566                    for (long newDLFileEntryTypePK : newDLFileEntryTypePKsSet) {
13567                            dlFolderToDLFileEntryTypeTableMapper.addTableMapping(companyId, pk,
13568                                    newDLFileEntryTypePK);
13569                    }
13570            }
13571    
13572            /**
13573             * 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.
13574             *
13575             * @param pk the primary key of the document library folder
13576             * @param dlFileEntryTypes the document library file entry types to be associated with the document library folder
13577             */
13578            @Override
13579            public void setDLFileEntryTypes(long pk,
13580                    List<com.liferay.document.library.kernel.model.DLFileEntryType> dlFileEntryTypes) {
13581                    try {
13582                            long[] dlFileEntryTypePKs = new long[dlFileEntryTypes.size()];
13583    
13584                            for (int i = 0; i < dlFileEntryTypes.size(); i++) {
13585                                    com.liferay.document.library.kernel.model.DLFileEntryType dlFileEntryType =
13586                                            dlFileEntryTypes.get(i);
13587    
13588                                    dlFileEntryTypePKs[i] = dlFileEntryType.getPrimaryKey();
13589                            }
13590    
13591                            setDLFileEntryTypes(pk, dlFileEntryTypePKs);
13592                    }
13593                    catch (Exception e) {
13594                            throw processException(e);
13595                    }
13596            }
13597    
13598            @Override
13599            public Set<String> getBadColumnNames() {
13600                    return _badColumnNames;
13601            }
13602    
13603            @Override
13604            protected Map<String, Integer> getTableColumnsMap() {
13605                    return DLFolderModelImpl.TABLE_COLUMNS_MAP;
13606            }
13607    
13608            /**
13609             * Initializes the document library folder persistence.
13610             */
13611            public void afterPropertiesSet() {
13612                    dlFolderToDLFileEntryTypeTableMapper = TableMapperFactory.getTableMapper("DLFileEntryTypes_DLFolders",
13613                                    "companyId", "folderId", "fileEntryTypeId", this,
13614                                    dlFileEntryTypePersistence);
13615            }
13616    
13617            public void destroy() {
13618                    entityCache.removeCache(DLFolderImpl.class.getName());
13619                    finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
13620                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
13621                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
13622    
13623                    TableMapperFactory.removeTableMapper("DLFileEntryTypes_DLFolders");
13624            }
13625    
13626            @BeanReference(type = CompanyProviderWrapper.class)
13627            protected CompanyProvider companyProvider;
13628            protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
13629            protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
13630            @BeanReference(type = DLFileEntryTypePersistence.class)
13631            protected DLFileEntryTypePersistence dlFileEntryTypePersistence;
13632            protected TableMapper<DLFolder, com.liferay.document.library.kernel.model.DLFileEntryType> dlFolderToDLFileEntryTypeTableMapper;
13633            private static final String _SQL_SELECT_DLFOLDER = "SELECT dlFolder FROM DLFolder dlFolder";
13634            private static final String _SQL_SELECT_DLFOLDER_WHERE_PKS_IN = "SELECT dlFolder FROM DLFolder dlFolder WHERE folderId IN (";
13635            private static final String _SQL_SELECT_DLFOLDER_WHERE = "SELECT dlFolder FROM DLFolder dlFolder WHERE ";
13636            private static final String _SQL_COUNT_DLFOLDER = "SELECT COUNT(dlFolder) FROM DLFolder dlFolder";
13637            private static final String _SQL_COUNT_DLFOLDER_WHERE = "SELECT COUNT(dlFolder) FROM DLFolder dlFolder WHERE ";
13638            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "dlFolder.folderId";
13639            private static final String _FILTER_SQL_SELECT_DLFOLDER_WHERE = "SELECT DISTINCT {dlFolder.*} FROM DLFolder dlFolder WHERE ";
13640            private static final String _FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1 =
13641                    "SELECT {DLFolder.*} FROM (SELECT DISTINCT dlFolder.folderId FROM DLFolder dlFolder WHERE ";
13642            private static final String _FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2 =
13643                    ") TEMP_TABLE INNER JOIN DLFolder ON TEMP_TABLE.folderId = DLFolder.folderId";
13644            private static final String _FILTER_SQL_COUNT_DLFOLDER_WHERE = "SELECT COUNT(DISTINCT dlFolder.folderId) AS COUNT_VALUE FROM DLFolder dlFolder WHERE ";
13645            private static final String _FILTER_ENTITY_ALIAS = "dlFolder";
13646            private static final String _FILTER_ENTITY_TABLE = "DLFolder";
13647            private static final String _ORDER_BY_ENTITY_ALIAS = "dlFolder.";
13648            private static final String _ORDER_BY_ENTITY_TABLE = "DLFolder.";
13649            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No DLFolder exists with the primary key ";
13650            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No DLFolder exists with the key {";
13651            private static final Log _log = LogFactoryUtil.getLog(DLFolderPersistenceImpl.class);
13652            private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
13653                                    "uuid", "hidden"
13654                            });
13655            private static final DLFolder _nullDLFolder = new DLFolderImpl() {
13656                            @Override
13657                            public Object clone() {
13658                                    return this;
13659                            }
13660    
13661                            @Override
13662                            public CacheModel<DLFolder> toCacheModel() {
13663                                    return _nullDLFolderCacheModel;
13664                            }
13665                    };
13666    
13667            private static final CacheModel<DLFolder> _nullDLFolderCacheModel = new CacheModel<DLFolder>() {
13668                            @Override
13669                            public DLFolder toEntityModel() {
13670                                    return _nullDLFolder;
13671                            }
13672                    };
13673    }