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