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