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_R_P = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
4854                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
4855                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByR_P",
4856                            new String[] {
4857                                    Long.class.getName(), Long.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_R_P = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
4863                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
4864                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByR_P",
4865                            new String[] { Long.class.getName(), Long.class.getName() },
4866                            DLFolderModelImpl.REPOSITORYID_COLUMN_BITMASK |
4867                            DLFolderModelImpl.PARENTFOLDERID_COLUMN_BITMASK |
4868                            DLFolderModelImpl.NAME_COLUMN_BITMASK);
4869            public static final FinderPath FINDER_PATH_COUNT_BY_R_P = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
4870                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
4871                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByR_P",
4872                            new String[] { Long.class.getName(), Long.class.getName() });
4873    
4874            /**
4875             * Returns all the document library folders where repositoryId = &#63; and parentFolderId = &#63;.
4876             *
4877             * @param repositoryId the repository ID
4878             * @param parentFolderId the parent folder ID
4879             * @return the matching document library folders
4880             */
4881            @Override
4882            public List<DLFolder> findByR_P(long repositoryId, long parentFolderId) {
4883                    return findByR_P(repositoryId, parentFolderId, QueryUtil.ALL_POS,
4884                            QueryUtil.ALL_POS, null);
4885            }
4886    
4887            /**
4888             * Returns a range of all the document library folders where repositoryId = &#63; and parentFolderId = &#63;.
4889             *
4890             * <p>
4891             * 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.
4892             * </p>
4893             *
4894             * @param repositoryId the repository ID
4895             * @param parentFolderId the parent folder ID
4896             * @param start the lower bound of the range of document library folders
4897             * @param end the upper bound of the range of document library folders (not inclusive)
4898             * @return the range of matching document library folders
4899             */
4900            @Override
4901            public List<DLFolder> findByR_P(long repositoryId, long parentFolderId,
4902                    int start, int end) {
4903                    return findByR_P(repositoryId, parentFolderId, start, end, null);
4904            }
4905    
4906            /**
4907             * Returns an ordered range of all the document library folders where repositoryId = &#63; and parentFolderId = &#63;.
4908             *
4909             * <p>
4910             * 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.
4911             * </p>
4912             *
4913             * @param repositoryId the repository ID
4914             * @param parentFolderId the parent folder ID
4915             * @param start the lower bound of the range of document library folders
4916             * @param end the upper bound of the range of document library folders (not inclusive)
4917             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4918             * @return the ordered range of matching document library folders
4919             */
4920            @Override
4921            public List<DLFolder> findByR_P(long repositoryId, long parentFolderId,
4922                    int start, int end, OrderByComparator<DLFolder> orderByComparator) {
4923                    boolean pagination = true;
4924                    FinderPath finderPath = null;
4925                    Object[] finderArgs = null;
4926    
4927                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4928                                    (orderByComparator == null)) {
4929                            pagination = false;
4930                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_P;
4931                            finderArgs = new Object[] { repositoryId, parentFolderId };
4932                    }
4933                    else {
4934                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_R_P;
4935                            finderArgs = new Object[] {
4936                                            repositoryId, parentFolderId,
4937                                            
4938                                            start, end, orderByComparator
4939                                    };
4940                    }
4941    
4942                    List<DLFolder> list = (List<DLFolder>)FinderCacheUtil.getResult(finderPath,
4943                                    finderArgs, this);
4944    
4945                    if ((list != null) && !list.isEmpty()) {
4946                            for (DLFolder dlFolder : list) {
4947                                    if ((repositoryId != dlFolder.getRepositoryId()) ||
4948                                                    (parentFolderId != dlFolder.getParentFolderId())) {
4949                                            list = null;
4950    
4951                                            break;
4952                                    }
4953                            }
4954                    }
4955    
4956                    if (list == null) {
4957                            StringBundler query = null;
4958    
4959                            if (orderByComparator != null) {
4960                                    query = new StringBundler(4 +
4961                                                    (orderByComparator.getOrderByFields().length * 3));
4962                            }
4963                            else {
4964                                    query = new StringBundler(4);
4965                            }
4966    
4967                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
4968    
4969                            query.append(_FINDER_COLUMN_R_P_REPOSITORYID_2);
4970    
4971                            query.append(_FINDER_COLUMN_R_P_PARENTFOLDERID_2);
4972    
4973                            if (orderByComparator != null) {
4974                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4975                                            orderByComparator);
4976                            }
4977                            else
4978                             if (pagination) {
4979                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
4980                            }
4981    
4982                            String sql = query.toString();
4983    
4984                            Session session = null;
4985    
4986                            try {
4987                                    session = openSession();
4988    
4989                                    Query q = session.createQuery(sql);
4990    
4991                                    QueryPos qPos = QueryPos.getInstance(q);
4992    
4993                                    qPos.add(repositoryId);
4994    
4995                                    qPos.add(parentFolderId);
4996    
4997                                    if (!pagination) {
4998                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
4999                                                            start, end, false);
5000    
5001                                            Collections.sort(list);
5002    
5003                                            list = Collections.unmodifiableList(list);
5004                                    }
5005                                    else {
5006                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
5007                                                            start, end);
5008                                    }
5009    
5010                                    cacheResult(list);
5011    
5012                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
5013                            }
5014                            catch (Exception e) {
5015                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5016    
5017                                    throw processException(e);
5018                            }
5019                            finally {
5020                                    closeSession(session);
5021                            }
5022                    }
5023    
5024                    return list;
5025            }
5026    
5027            /**
5028             * Returns the first document library folder in the ordered set where repositoryId = &#63; and parentFolderId = &#63;.
5029             *
5030             * @param repositoryId the repository ID
5031             * @param parentFolderId the parent folder ID
5032             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5033             * @return the first matching document library folder
5034             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
5035             */
5036            @Override
5037            public DLFolder findByR_P_First(long repositoryId, long parentFolderId,
5038                    OrderByComparator<DLFolder> orderByComparator)
5039                    throws NoSuchFolderException {
5040                    DLFolder dlFolder = fetchByR_P_First(repositoryId, parentFolderId,
5041                                    orderByComparator);
5042    
5043                    if (dlFolder != null) {
5044                            return dlFolder;
5045                    }
5046    
5047                    StringBundler msg = new StringBundler(6);
5048    
5049                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5050    
5051                    msg.append("repositoryId=");
5052                    msg.append(repositoryId);
5053    
5054                    msg.append(", parentFolderId=");
5055                    msg.append(parentFolderId);
5056    
5057                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5058    
5059                    throw new NoSuchFolderException(msg.toString());
5060            }
5061    
5062            /**
5063             * Returns the first document library folder in the ordered set where repositoryId = &#63; and parentFolderId = &#63;.
5064             *
5065             * @param repositoryId the repository ID
5066             * @param parentFolderId the parent folder ID
5067             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5068             * @return the first matching document library folder, or <code>null</code> if a matching document library folder could not be found
5069             */
5070            @Override
5071            public DLFolder fetchByR_P_First(long repositoryId, long parentFolderId,
5072                    OrderByComparator<DLFolder> orderByComparator) {
5073                    List<DLFolder> list = findByR_P(repositoryId, parentFolderId, 0, 1,
5074                                    orderByComparator);
5075    
5076                    if (!list.isEmpty()) {
5077                            return list.get(0);
5078                    }
5079    
5080                    return null;
5081            }
5082    
5083            /**
5084             * Returns the last document library folder in the ordered set where repositoryId = &#63; and parentFolderId = &#63;.
5085             *
5086             * @param repositoryId the repository ID
5087             * @param parentFolderId the parent folder ID
5088             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5089             * @return the last matching document library folder
5090             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
5091             */
5092            @Override
5093            public DLFolder findByR_P_Last(long repositoryId, long parentFolderId,
5094                    OrderByComparator<DLFolder> orderByComparator)
5095                    throws NoSuchFolderException {
5096                    DLFolder dlFolder = fetchByR_P_Last(repositoryId, parentFolderId,
5097                                    orderByComparator);
5098    
5099                    if (dlFolder != null) {
5100                            return dlFolder;
5101                    }
5102    
5103                    StringBundler msg = new StringBundler(6);
5104    
5105                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5106    
5107                    msg.append("repositoryId=");
5108                    msg.append(repositoryId);
5109    
5110                    msg.append(", parentFolderId=");
5111                    msg.append(parentFolderId);
5112    
5113                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5114    
5115                    throw new NoSuchFolderException(msg.toString());
5116            }
5117    
5118            /**
5119             * Returns the last document library folder in the ordered set where repositoryId = &#63; and parentFolderId = &#63;.
5120             *
5121             * @param repositoryId the repository ID
5122             * @param parentFolderId the parent folder ID
5123             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5124             * @return the last matching document library folder, or <code>null</code> if a matching document library folder could not be found
5125             */
5126            @Override
5127            public DLFolder fetchByR_P_Last(long repositoryId, long parentFolderId,
5128                    OrderByComparator<DLFolder> orderByComparator) {
5129                    int count = countByR_P(repositoryId, parentFolderId);
5130    
5131                    if (count == 0) {
5132                            return null;
5133                    }
5134    
5135                    List<DLFolder> list = findByR_P(repositoryId, parentFolderId,
5136                                    count - 1, count, orderByComparator);
5137    
5138                    if (!list.isEmpty()) {
5139                            return list.get(0);
5140                    }
5141    
5142                    return null;
5143            }
5144    
5145            /**
5146             * Returns the document library folders before and after the current document library folder in the ordered set where repositoryId = &#63; and parentFolderId = &#63;.
5147             *
5148             * @param folderId the primary key of the current document library folder
5149             * @param repositoryId the repository ID
5150             * @param parentFolderId the parent folder ID
5151             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5152             * @return the previous, current, and next document library folder
5153             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
5154             */
5155            @Override
5156            public DLFolder[] findByR_P_PrevAndNext(long folderId, long repositoryId,
5157                    long parentFolderId, OrderByComparator<DLFolder> orderByComparator)
5158                    throws NoSuchFolderException {
5159                    DLFolder dlFolder = findByPrimaryKey(folderId);
5160    
5161                    Session session = null;
5162    
5163                    try {
5164                            session = openSession();
5165    
5166                            DLFolder[] array = new DLFolderImpl[3];
5167    
5168                            array[0] = getByR_P_PrevAndNext(session, dlFolder, repositoryId,
5169                                            parentFolderId, orderByComparator, true);
5170    
5171                            array[1] = dlFolder;
5172    
5173                            array[2] = getByR_P_PrevAndNext(session, dlFolder, repositoryId,
5174                                            parentFolderId, orderByComparator, false);
5175    
5176                            return array;
5177                    }
5178                    catch (Exception e) {
5179                            throw processException(e);
5180                    }
5181                    finally {
5182                            closeSession(session);
5183                    }
5184            }
5185    
5186            protected DLFolder getByR_P_PrevAndNext(Session session, DLFolder dlFolder,
5187                    long repositoryId, long parentFolderId,
5188                    OrderByComparator<DLFolder> orderByComparator, boolean previous) {
5189                    StringBundler query = null;
5190    
5191                    if (orderByComparator != null) {
5192                            query = new StringBundler(6 +
5193                                            (orderByComparator.getOrderByFields().length * 6));
5194                    }
5195                    else {
5196                            query = new StringBundler(3);
5197                    }
5198    
5199                    query.append(_SQL_SELECT_DLFOLDER_WHERE);
5200    
5201                    query.append(_FINDER_COLUMN_R_P_REPOSITORYID_2);
5202    
5203                    query.append(_FINDER_COLUMN_R_P_PARENTFOLDERID_2);
5204    
5205                    if (orderByComparator != null) {
5206                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5207    
5208                            if (orderByConditionFields.length > 0) {
5209                                    query.append(WHERE_AND);
5210                            }
5211    
5212                            for (int i = 0; i < orderByConditionFields.length; i++) {
5213                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5214                                    query.append(orderByConditionFields[i]);
5215    
5216                                    if ((i + 1) < orderByConditionFields.length) {
5217                                            if (orderByComparator.isAscending() ^ previous) {
5218                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5219                                            }
5220                                            else {
5221                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5222                                            }
5223                                    }
5224                                    else {
5225                                            if (orderByComparator.isAscending() ^ previous) {
5226                                                    query.append(WHERE_GREATER_THAN);
5227                                            }
5228                                            else {
5229                                                    query.append(WHERE_LESSER_THAN);
5230                                            }
5231                                    }
5232                            }
5233    
5234                            query.append(ORDER_BY_CLAUSE);
5235    
5236                            String[] orderByFields = orderByComparator.getOrderByFields();
5237    
5238                            for (int i = 0; i < orderByFields.length; i++) {
5239                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5240                                    query.append(orderByFields[i]);
5241    
5242                                    if ((i + 1) < orderByFields.length) {
5243                                            if (orderByComparator.isAscending() ^ previous) {
5244                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5245                                            }
5246                                            else {
5247                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5248                                            }
5249                                    }
5250                                    else {
5251                                            if (orderByComparator.isAscending() ^ previous) {
5252                                                    query.append(ORDER_BY_ASC);
5253                                            }
5254                                            else {
5255                                                    query.append(ORDER_BY_DESC);
5256                                            }
5257                                    }
5258                            }
5259                    }
5260                    else {
5261                            query.append(DLFolderModelImpl.ORDER_BY_JPQL);
5262                    }
5263    
5264                    String sql = query.toString();
5265    
5266                    Query q = session.createQuery(sql);
5267    
5268                    q.setFirstResult(0);
5269                    q.setMaxResults(2);
5270    
5271                    QueryPos qPos = QueryPos.getInstance(q);
5272    
5273                    qPos.add(repositoryId);
5274    
5275                    qPos.add(parentFolderId);
5276    
5277                    if (orderByComparator != null) {
5278                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
5279    
5280                            for (Object value : values) {
5281                                    qPos.add(value);
5282                            }
5283                    }
5284    
5285                    List<DLFolder> list = q.list();
5286    
5287                    if (list.size() == 2) {
5288                            return list.get(1);
5289                    }
5290                    else {
5291                            return null;
5292                    }
5293            }
5294    
5295            /**
5296             * Removes all the document library folders where repositoryId = &#63; and parentFolderId = &#63; from the database.
5297             *
5298             * @param repositoryId the repository ID
5299             * @param parentFolderId the parent folder ID
5300             */
5301            @Override
5302            public void removeByR_P(long repositoryId, long parentFolderId) {
5303                    for (DLFolder dlFolder : findByR_P(repositoryId, parentFolderId,
5304                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
5305                            remove(dlFolder);
5306                    }
5307            }
5308    
5309            /**
5310             * Returns the number of document library folders where repositoryId = &#63; and parentFolderId = &#63;.
5311             *
5312             * @param repositoryId the repository ID
5313             * @param parentFolderId the parent folder ID
5314             * @return the number of matching document library folders
5315             */
5316            @Override
5317            public int countByR_P(long repositoryId, long parentFolderId) {
5318                    FinderPath finderPath = FINDER_PATH_COUNT_BY_R_P;
5319    
5320                    Object[] finderArgs = new Object[] { repositoryId, parentFolderId };
5321    
5322                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5323                                    this);
5324    
5325                    if (count == null) {
5326                            StringBundler query = new StringBundler(3);
5327    
5328                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
5329    
5330                            query.append(_FINDER_COLUMN_R_P_REPOSITORYID_2);
5331    
5332                            query.append(_FINDER_COLUMN_R_P_PARENTFOLDERID_2);
5333    
5334                            String sql = query.toString();
5335    
5336                            Session session = null;
5337    
5338                            try {
5339                                    session = openSession();
5340    
5341                                    Query q = session.createQuery(sql);
5342    
5343                                    QueryPos qPos = QueryPos.getInstance(q);
5344    
5345                                    qPos.add(repositoryId);
5346    
5347                                    qPos.add(parentFolderId);
5348    
5349                                    count = (Long)q.uniqueResult();
5350    
5351                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
5352                            }
5353                            catch (Exception e) {
5354                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5355    
5356                                    throw processException(e);
5357                            }
5358                            finally {
5359                                    closeSession(session);
5360                            }
5361                    }
5362    
5363                    return count.intValue();
5364            }
5365    
5366            private static final String _FINDER_COLUMN_R_P_REPOSITORYID_2 = "dlFolder.repositoryId = ? AND ";
5367            private static final String _FINDER_COLUMN_R_P_PARENTFOLDERID_2 = "dlFolder.parentFolderId = ?";
5368            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_P_N = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
5369                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
5370                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByP_N",
5371                            new String[] {
5372                                    Long.class.getName(), String.class.getName(),
5373                                    
5374                            Integer.class.getName(), Integer.class.getName(),
5375                                    OrderByComparator.class.getName()
5376                            });
5377            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_N = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
5378                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
5379                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByP_N",
5380                            new String[] { Long.class.getName(), String.class.getName() },
5381                            DLFolderModelImpl.PARENTFOLDERID_COLUMN_BITMASK |
5382                            DLFolderModelImpl.NAME_COLUMN_BITMASK);
5383            public static final FinderPath FINDER_PATH_COUNT_BY_P_N = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
5384                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
5385                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByP_N",
5386                            new String[] { Long.class.getName(), String.class.getName() });
5387    
5388            /**
5389             * Returns all the document library folders where parentFolderId = &#63; and name = &#63;.
5390             *
5391             * @param parentFolderId the parent folder ID
5392             * @param name the name
5393             * @return the matching document library folders
5394             */
5395            @Override
5396            public List<DLFolder> findByP_N(long parentFolderId, String name) {
5397                    return findByP_N(parentFolderId, name, QueryUtil.ALL_POS,
5398                            QueryUtil.ALL_POS, null);
5399            }
5400    
5401            /**
5402             * Returns a range of all the document library folders where parentFolderId = &#63; and name = &#63;.
5403             *
5404             * <p>
5405             * 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.
5406             * </p>
5407             *
5408             * @param parentFolderId the parent folder ID
5409             * @param name the name
5410             * @param start the lower bound of the range of document library folders
5411             * @param end the upper bound of the range of document library folders (not inclusive)
5412             * @return the range of matching document library folders
5413             */
5414            @Override
5415            public List<DLFolder> findByP_N(long parentFolderId, String name,
5416                    int start, int end) {
5417                    return findByP_N(parentFolderId, name, start, end, null);
5418            }
5419    
5420            /**
5421             * Returns an ordered range of all the document library folders where parentFolderId = &#63; and name = &#63;.
5422             *
5423             * <p>
5424             * 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.
5425             * </p>
5426             *
5427             * @param parentFolderId the parent folder ID
5428             * @param name the name
5429             * @param start the lower bound of the range of document library folders
5430             * @param end the upper bound of the range of document library folders (not inclusive)
5431             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5432             * @return the ordered range of matching document library folders
5433             */
5434            @Override
5435            public List<DLFolder> findByP_N(long parentFolderId, String name,
5436                    int start, int end, OrderByComparator<DLFolder> orderByComparator) {
5437                    boolean pagination = true;
5438                    FinderPath finderPath = null;
5439                    Object[] finderArgs = null;
5440    
5441                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5442                                    (orderByComparator == null)) {
5443                            pagination = false;
5444                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_N;
5445                            finderArgs = new Object[] { parentFolderId, name };
5446                    }
5447                    else {
5448                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_P_N;
5449                            finderArgs = new Object[] {
5450                                            parentFolderId, name,
5451                                            
5452                                            start, end, orderByComparator
5453                                    };
5454                    }
5455    
5456                    List<DLFolder> list = (List<DLFolder>)FinderCacheUtil.getResult(finderPath,
5457                                    finderArgs, this);
5458    
5459                    if ((list != null) && !list.isEmpty()) {
5460                            for (DLFolder dlFolder : list) {
5461                                    if ((parentFolderId != dlFolder.getParentFolderId()) ||
5462                                                    !Validator.equals(name, dlFolder.getName())) {
5463                                            list = null;
5464    
5465                                            break;
5466                                    }
5467                            }
5468                    }
5469    
5470                    if (list == null) {
5471                            StringBundler query = null;
5472    
5473                            if (orderByComparator != null) {
5474                                    query = new StringBundler(4 +
5475                                                    (orderByComparator.getOrderByFields().length * 3));
5476                            }
5477                            else {
5478                                    query = new StringBundler(4);
5479                            }
5480    
5481                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
5482    
5483                            query.append(_FINDER_COLUMN_P_N_PARENTFOLDERID_2);
5484    
5485                            boolean bindName = false;
5486    
5487                            if (name == null) {
5488                                    query.append(_FINDER_COLUMN_P_N_NAME_1);
5489                            }
5490                            else if (name.equals(StringPool.BLANK)) {
5491                                    query.append(_FINDER_COLUMN_P_N_NAME_3);
5492                            }
5493                            else {
5494                                    bindName = true;
5495    
5496                                    query.append(_FINDER_COLUMN_P_N_NAME_2);
5497                            }
5498    
5499                            if (orderByComparator != null) {
5500                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5501                                            orderByComparator);
5502                            }
5503                            else
5504                             if (pagination) {
5505                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
5506                            }
5507    
5508                            String sql = query.toString();
5509    
5510                            Session session = null;
5511    
5512                            try {
5513                                    session = openSession();
5514    
5515                                    Query q = session.createQuery(sql);
5516    
5517                                    QueryPos qPos = QueryPos.getInstance(q);
5518    
5519                                    qPos.add(parentFolderId);
5520    
5521                                    if (bindName) {
5522                                            qPos.add(name);
5523                                    }
5524    
5525                                    if (!pagination) {
5526                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
5527                                                            start, end, false);
5528    
5529                                            Collections.sort(list);
5530    
5531                                            list = Collections.unmodifiableList(list);
5532                                    }
5533                                    else {
5534                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
5535                                                            start, end);
5536                                    }
5537    
5538                                    cacheResult(list);
5539    
5540                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
5541                            }
5542                            catch (Exception e) {
5543                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5544    
5545                                    throw processException(e);
5546                            }
5547                            finally {
5548                                    closeSession(session);
5549                            }
5550                    }
5551    
5552                    return list;
5553            }
5554    
5555            /**
5556             * Returns the first document library folder in the ordered set where parentFolderId = &#63; and name = &#63;.
5557             *
5558             * @param parentFolderId the parent folder ID
5559             * @param name the name
5560             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5561             * @return the first matching document library folder
5562             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
5563             */
5564            @Override
5565            public DLFolder findByP_N_First(long parentFolderId, String name,
5566                    OrderByComparator<DLFolder> orderByComparator)
5567                    throws NoSuchFolderException {
5568                    DLFolder dlFolder = fetchByP_N_First(parentFolderId, name,
5569                                    orderByComparator);
5570    
5571                    if (dlFolder != null) {
5572                            return dlFolder;
5573                    }
5574    
5575                    StringBundler msg = new StringBundler(6);
5576    
5577                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5578    
5579                    msg.append("parentFolderId=");
5580                    msg.append(parentFolderId);
5581    
5582                    msg.append(", name=");
5583                    msg.append(name);
5584    
5585                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5586    
5587                    throw new NoSuchFolderException(msg.toString());
5588            }
5589    
5590            /**
5591             * Returns the first document library folder in the ordered set where parentFolderId = &#63; and name = &#63;.
5592             *
5593             * @param parentFolderId the parent folder ID
5594             * @param name the name
5595             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5596             * @return the first matching document library folder, or <code>null</code> if a matching document library folder could not be found
5597             */
5598            @Override
5599            public DLFolder fetchByP_N_First(long parentFolderId, String name,
5600                    OrderByComparator<DLFolder> orderByComparator) {
5601                    List<DLFolder> list = findByP_N(parentFolderId, name, 0, 1,
5602                                    orderByComparator);
5603    
5604                    if (!list.isEmpty()) {
5605                            return list.get(0);
5606                    }
5607    
5608                    return null;
5609            }
5610    
5611            /**
5612             * Returns the last document library folder in the ordered set where parentFolderId = &#63; and name = &#63;.
5613             *
5614             * @param parentFolderId the parent folder ID
5615             * @param name the name
5616             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5617             * @return the last matching document library folder
5618             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
5619             */
5620            @Override
5621            public DLFolder findByP_N_Last(long parentFolderId, String name,
5622                    OrderByComparator<DLFolder> orderByComparator)
5623                    throws NoSuchFolderException {
5624                    DLFolder dlFolder = fetchByP_N_Last(parentFolderId, name,
5625                                    orderByComparator);
5626    
5627                    if (dlFolder != null) {
5628                            return dlFolder;
5629                    }
5630    
5631                    StringBundler msg = new StringBundler(6);
5632    
5633                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5634    
5635                    msg.append("parentFolderId=");
5636                    msg.append(parentFolderId);
5637    
5638                    msg.append(", name=");
5639                    msg.append(name);
5640    
5641                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5642    
5643                    throw new NoSuchFolderException(msg.toString());
5644            }
5645    
5646            /**
5647             * Returns the last document library folder in the ordered set where parentFolderId = &#63; and name = &#63;.
5648             *
5649             * @param parentFolderId the parent folder ID
5650             * @param name the name
5651             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5652             * @return the last matching document library folder, or <code>null</code> if a matching document library folder could not be found
5653             */
5654            @Override
5655            public DLFolder fetchByP_N_Last(long parentFolderId, String name,
5656                    OrderByComparator<DLFolder> orderByComparator) {
5657                    int count = countByP_N(parentFolderId, name);
5658    
5659                    if (count == 0) {
5660                            return null;
5661                    }
5662    
5663                    List<DLFolder> list = findByP_N(parentFolderId, name, count - 1, count,
5664                                    orderByComparator);
5665    
5666                    if (!list.isEmpty()) {
5667                            return list.get(0);
5668                    }
5669    
5670                    return null;
5671            }
5672    
5673            /**
5674             * Returns the document library folders before and after the current document library folder in the ordered set where parentFolderId = &#63; and name = &#63;.
5675             *
5676             * @param folderId the primary key of the current document library folder
5677             * @param parentFolderId the parent folder ID
5678             * @param name the name
5679             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5680             * @return the previous, current, and next document library folder
5681             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
5682             */
5683            @Override
5684            public DLFolder[] findByP_N_PrevAndNext(long folderId, long parentFolderId,
5685                    String name, OrderByComparator<DLFolder> orderByComparator)
5686                    throws NoSuchFolderException {
5687                    DLFolder dlFolder = findByPrimaryKey(folderId);
5688    
5689                    Session session = null;
5690    
5691                    try {
5692                            session = openSession();
5693    
5694                            DLFolder[] array = new DLFolderImpl[3];
5695    
5696                            array[0] = getByP_N_PrevAndNext(session, dlFolder, parentFolderId,
5697                                            name, orderByComparator, true);
5698    
5699                            array[1] = dlFolder;
5700    
5701                            array[2] = getByP_N_PrevAndNext(session, dlFolder, parentFolderId,
5702                                            name, orderByComparator, false);
5703    
5704                            return array;
5705                    }
5706                    catch (Exception e) {
5707                            throw processException(e);
5708                    }
5709                    finally {
5710                            closeSession(session);
5711                    }
5712            }
5713    
5714            protected DLFolder getByP_N_PrevAndNext(Session session, DLFolder dlFolder,
5715                    long parentFolderId, String name,
5716                    OrderByComparator<DLFolder> orderByComparator, boolean previous) {
5717                    StringBundler query = null;
5718    
5719                    if (orderByComparator != null) {
5720                            query = new StringBundler(6 +
5721                                            (orderByComparator.getOrderByFields().length * 6));
5722                    }
5723                    else {
5724                            query = new StringBundler(3);
5725                    }
5726    
5727                    query.append(_SQL_SELECT_DLFOLDER_WHERE);
5728    
5729                    query.append(_FINDER_COLUMN_P_N_PARENTFOLDERID_2);
5730    
5731                    boolean bindName = false;
5732    
5733                    if (name == null) {
5734                            query.append(_FINDER_COLUMN_P_N_NAME_1);
5735                    }
5736                    else if (name.equals(StringPool.BLANK)) {
5737                            query.append(_FINDER_COLUMN_P_N_NAME_3);
5738                    }
5739                    else {
5740                            bindName = true;
5741    
5742                            query.append(_FINDER_COLUMN_P_N_NAME_2);
5743                    }
5744    
5745                    if (orderByComparator != null) {
5746                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5747    
5748                            if (orderByConditionFields.length > 0) {
5749                                    query.append(WHERE_AND);
5750                            }
5751    
5752                            for (int i = 0; i < orderByConditionFields.length; i++) {
5753                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5754                                    query.append(orderByConditionFields[i]);
5755    
5756                                    if ((i + 1) < orderByConditionFields.length) {
5757                                            if (orderByComparator.isAscending() ^ previous) {
5758                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5759                                            }
5760                                            else {
5761                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5762                                            }
5763                                    }
5764                                    else {
5765                                            if (orderByComparator.isAscending() ^ previous) {
5766                                                    query.append(WHERE_GREATER_THAN);
5767                                            }
5768                                            else {
5769                                                    query.append(WHERE_LESSER_THAN);
5770                                            }
5771                                    }
5772                            }
5773    
5774                            query.append(ORDER_BY_CLAUSE);
5775    
5776                            String[] orderByFields = orderByComparator.getOrderByFields();
5777    
5778                            for (int i = 0; i < orderByFields.length; i++) {
5779                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5780                                    query.append(orderByFields[i]);
5781    
5782                                    if ((i + 1) < orderByFields.length) {
5783                                            if (orderByComparator.isAscending() ^ previous) {
5784                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5785                                            }
5786                                            else {
5787                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5788                                            }
5789                                    }
5790                                    else {
5791                                            if (orderByComparator.isAscending() ^ previous) {
5792                                                    query.append(ORDER_BY_ASC);
5793                                            }
5794                                            else {
5795                                                    query.append(ORDER_BY_DESC);
5796                                            }
5797                                    }
5798                            }
5799                    }
5800                    else {
5801                            query.append(DLFolderModelImpl.ORDER_BY_JPQL);
5802                    }
5803    
5804                    String sql = query.toString();
5805    
5806                    Query q = session.createQuery(sql);
5807    
5808                    q.setFirstResult(0);
5809                    q.setMaxResults(2);
5810    
5811                    QueryPos qPos = QueryPos.getInstance(q);
5812    
5813                    qPos.add(parentFolderId);
5814    
5815                    if (bindName) {
5816                            qPos.add(name);
5817                    }
5818    
5819                    if (orderByComparator != null) {
5820                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
5821    
5822                            for (Object value : values) {
5823                                    qPos.add(value);
5824                            }
5825                    }
5826    
5827                    List<DLFolder> list = q.list();
5828    
5829                    if (list.size() == 2) {
5830                            return list.get(1);
5831                    }
5832                    else {
5833                            return null;
5834                    }
5835            }
5836    
5837            /**
5838             * Removes all the document library folders where parentFolderId = &#63; and name = &#63; from the database.
5839             *
5840             * @param parentFolderId the parent folder ID
5841             * @param name the name
5842             */
5843            @Override
5844            public void removeByP_N(long parentFolderId, String name) {
5845                    for (DLFolder dlFolder : findByP_N(parentFolderId, name,
5846                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
5847                            remove(dlFolder);
5848                    }
5849            }
5850    
5851            /**
5852             * Returns the number of document library folders where parentFolderId = &#63; and name = &#63;.
5853             *
5854             * @param parentFolderId the parent folder ID
5855             * @param name the name
5856             * @return the number of matching document library folders
5857             */
5858            @Override
5859            public int countByP_N(long parentFolderId, String name) {
5860                    FinderPath finderPath = FINDER_PATH_COUNT_BY_P_N;
5861    
5862                    Object[] finderArgs = new Object[] { parentFolderId, name };
5863    
5864                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5865                                    this);
5866    
5867                    if (count == null) {
5868                            StringBundler query = new StringBundler(3);
5869    
5870                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
5871    
5872                            query.append(_FINDER_COLUMN_P_N_PARENTFOLDERID_2);
5873    
5874                            boolean bindName = false;
5875    
5876                            if (name == null) {
5877                                    query.append(_FINDER_COLUMN_P_N_NAME_1);
5878                            }
5879                            else if (name.equals(StringPool.BLANK)) {
5880                                    query.append(_FINDER_COLUMN_P_N_NAME_3);
5881                            }
5882                            else {
5883                                    bindName = true;
5884    
5885                                    query.append(_FINDER_COLUMN_P_N_NAME_2);
5886                            }
5887    
5888                            String sql = query.toString();
5889    
5890                            Session session = null;
5891    
5892                            try {
5893                                    session = openSession();
5894    
5895                                    Query q = session.createQuery(sql);
5896    
5897                                    QueryPos qPos = QueryPos.getInstance(q);
5898    
5899                                    qPos.add(parentFolderId);
5900    
5901                                    if (bindName) {
5902                                            qPos.add(name);
5903                                    }
5904    
5905                                    count = (Long)q.uniqueResult();
5906    
5907                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
5908                            }
5909                            catch (Exception e) {
5910                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5911    
5912                                    throw processException(e);
5913                            }
5914                            finally {
5915                                    closeSession(session);
5916                            }
5917                    }
5918    
5919                    return count.intValue();
5920            }
5921    
5922            private static final String _FINDER_COLUMN_P_N_PARENTFOLDERID_2 = "dlFolder.parentFolderId = ? AND ";
5923            private static final String _FINDER_COLUMN_P_N_NAME_1 = "dlFolder.name IS NULL";
5924            private static final String _FINDER_COLUMN_P_N_NAME_2 = "dlFolder.name = ?";
5925            private static final String _FINDER_COLUMN_P_N_NAME_3 = "(dlFolder.name IS NULL OR dlFolder.name = '')";
5926            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_M_P = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
5927                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
5928                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_M_P",
5929                            new String[] {
5930                                    Long.class.getName(), Boolean.class.getName(),
5931                                    Long.class.getName(),
5932                                    
5933                            Integer.class.getName(), Integer.class.getName(),
5934                                    OrderByComparator.class.getName()
5935                            });
5936            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
5937                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
5938                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_M_P",
5939                            new String[] {
5940                                    Long.class.getName(), Boolean.class.getName(),
5941                                    Long.class.getName()
5942                            },
5943                            DLFolderModelImpl.GROUPID_COLUMN_BITMASK |
5944                            DLFolderModelImpl.MOUNTPOINT_COLUMN_BITMASK |
5945                            DLFolderModelImpl.PARENTFOLDERID_COLUMN_BITMASK |
5946                            DLFolderModelImpl.NAME_COLUMN_BITMASK);
5947            public static final FinderPath FINDER_PATH_COUNT_BY_G_M_P = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
5948                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
5949                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_M_P",
5950                            new String[] {
5951                                    Long.class.getName(), Boolean.class.getName(),
5952                                    Long.class.getName()
5953                            });
5954    
5955            /**
5956             * Returns all the document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63;.
5957             *
5958             * @param groupId the group ID
5959             * @param mountPoint the mount point
5960             * @param parentFolderId the parent folder ID
5961             * @return the matching document library folders
5962             */
5963            @Override
5964            public List<DLFolder> findByG_M_P(long groupId, boolean mountPoint,
5965                    long parentFolderId) {
5966                    return findByG_M_P(groupId, mountPoint, parentFolderId,
5967                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
5968            }
5969    
5970            /**
5971             * Returns a range of all the document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63;.
5972             *
5973             * <p>
5974             * 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.
5975             * </p>
5976             *
5977             * @param groupId the group ID
5978             * @param mountPoint the mount point
5979             * @param parentFolderId the parent folder ID
5980             * @param start the lower bound of the range of document library folders
5981             * @param end the upper bound of the range of document library folders (not inclusive)
5982             * @return the range of matching document library folders
5983             */
5984            @Override
5985            public List<DLFolder> findByG_M_P(long groupId, boolean mountPoint,
5986                    long parentFolderId, int start, int end) {
5987                    return findByG_M_P(groupId, mountPoint, parentFolderId, start, end, null);
5988            }
5989    
5990            /**
5991             * Returns an ordered range of all the document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63;.
5992             *
5993             * <p>
5994             * 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.
5995             * </p>
5996             *
5997             * @param groupId the group ID
5998             * @param mountPoint the mount point
5999             * @param parentFolderId the parent folder ID
6000             * @param start the lower bound of the range of document library folders
6001             * @param end the upper bound of the range of document library folders (not inclusive)
6002             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6003             * @return the ordered range of matching document library folders
6004             */
6005            @Override
6006            public List<DLFolder> findByG_M_P(long groupId, boolean mountPoint,
6007                    long parentFolderId, int start, int end,
6008                    OrderByComparator<DLFolder> orderByComparator) {
6009                    boolean pagination = true;
6010                    FinderPath finderPath = null;
6011                    Object[] finderArgs = null;
6012    
6013                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6014                                    (orderByComparator == null)) {
6015                            pagination = false;
6016                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P;
6017                            finderArgs = new Object[] { groupId, mountPoint, parentFolderId };
6018                    }
6019                    else {
6020                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_M_P;
6021                            finderArgs = new Object[] {
6022                                            groupId, mountPoint, parentFolderId,
6023                                            
6024                                            start, end, orderByComparator
6025                                    };
6026                    }
6027    
6028                    List<DLFolder> list = (List<DLFolder>)FinderCacheUtil.getResult(finderPath,
6029                                    finderArgs, this);
6030    
6031                    if ((list != null) && !list.isEmpty()) {
6032                            for (DLFolder dlFolder : list) {
6033                                    if ((groupId != dlFolder.getGroupId()) ||
6034                                                    (mountPoint != dlFolder.getMountPoint()) ||
6035                                                    (parentFolderId != dlFolder.getParentFolderId())) {
6036                                            list = null;
6037    
6038                                            break;
6039                                    }
6040                            }
6041                    }
6042    
6043                    if (list == null) {
6044                            StringBundler query = null;
6045    
6046                            if (orderByComparator != null) {
6047                                    query = new StringBundler(5 +
6048                                                    (orderByComparator.getOrderByFields().length * 3));
6049                            }
6050                            else {
6051                                    query = new StringBundler(5);
6052                            }
6053    
6054                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
6055    
6056                            query.append(_FINDER_COLUMN_G_M_P_GROUPID_2);
6057    
6058                            query.append(_FINDER_COLUMN_G_M_P_MOUNTPOINT_2);
6059    
6060                            query.append(_FINDER_COLUMN_G_M_P_PARENTFOLDERID_2);
6061    
6062                            if (orderByComparator != null) {
6063                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6064                                            orderByComparator);
6065                            }
6066                            else
6067                             if (pagination) {
6068                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
6069                            }
6070    
6071                            String sql = query.toString();
6072    
6073                            Session session = null;
6074    
6075                            try {
6076                                    session = openSession();
6077    
6078                                    Query q = session.createQuery(sql);
6079    
6080                                    QueryPos qPos = QueryPos.getInstance(q);
6081    
6082                                    qPos.add(groupId);
6083    
6084                                    qPos.add(mountPoint);
6085    
6086                                    qPos.add(parentFolderId);
6087    
6088                                    if (!pagination) {
6089                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
6090                                                            start, end, false);
6091    
6092                                            Collections.sort(list);
6093    
6094                                            list = Collections.unmodifiableList(list);
6095                                    }
6096                                    else {
6097                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
6098                                                            start, end);
6099                                    }
6100    
6101                                    cacheResult(list);
6102    
6103                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
6104                            }
6105                            catch (Exception e) {
6106                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6107    
6108                                    throw processException(e);
6109                            }
6110                            finally {
6111                                    closeSession(session);
6112                            }
6113                    }
6114    
6115                    return list;
6116            }
6117    
6118            /**
6119             * Returns the first document library folder in the ordered set where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63;.
6120             *
6121             * @param groupId the group ID
6122             * @param mountPoint the mount point
6123             * @param parentFolderId the parent folder ID
6124             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6125             * @return the first matching document library folder
6126             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
6127             */
6128            @Override
6129            public DLFolder findByG_M_P_First(long groupId, boolean mountPoint,
6130                    long parentFolderId, OrderByComparator<DLFolder> orderByComparator)
6131                    throws NoSuchFolderException {
6132                    DLFolder dlFolder = fetchByG_M_P_First(groupId, mountPoint,
6133                                    parentFolderId, orderByComparator);
6134    
6135                    if (dlFolder != null) {
6136                            return dlFolder;
6137                    }
6138    
6139                    StringBundler msg = new StringBundler(8);
6140    
6141                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6142    
6143                    msg.append("groupId=");
6144                    msg.append(groupId);
6145    
6146                    msg.append(", mountPoint=");
6147                    msg.append(mountPoint);
6148    
6149                    msg.append(", parentFolderId=");
6150                    msg.append(parentFolderId);
6151    
6152                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6153    
6154                    throw new NoSuchFolderException(msg.toString());
6155            }
6156    
6157            /**
6158             * Returns the first document library folder in the ordered set where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63;.
6159             *
6160             * @param groupId the group ID
6161             * @param mountPoint the mount point
6162             * @param parentFolderId the parent folder ID
6163             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6164             * @return the first matching document library folder, or <code>null</code> if a matching document library folder could not be found
6165             */
6166            @Override
6167            public DLFolder fetchByG_M_P_First(long groupId, boolean mountPoint,
6168                    long parentFolderId, OrderByComparator<DLFolder> orderByComparator) {
6169                    List<DLFolder> list = findByG_M_P(groupId, mountPoint, parentFolderId,
6170                                    0, 1, orderByComparator);
6171    
6172                    if (!list.isEmpty()) {
6173                            return list.get(0);
6174                    }
6175    
6176                    return null;
6177            }
6178    
6179            /**
6180             * Returns the last document library folder in the ordered set where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63;.
6181             *
6182             * @param groupId the group ID
6183             * @param mountPoint the mount point
6184             * @param parentFolderId the parent folder ID
6185             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6186             * @return the last matching document library folder
6187             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
6188             */
6189            @Override
6190            public DLFolder findByG_M_P_Last(long groupId, boolean mountPoint,
6191                    long parentFolderId, OrderByComparator<DLFolder> orderByComparator)
6192                    throws NoSuchFolderException {
6193                    DLFolder dlFolder = fetchByG_M_P_Last(groupId, mountPoint,
6194                                    parentFolderId, orderByComparator);
6195    
6196                    if (dlFolder != null) {
6197                            return dlFolder;
6198                    }
6199    
6200                    StringBundler msg = new StringBundler(8);
6201    
6202                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6203    
6204                    msg.append("groupId=");
6205                    msg.append(groupId);
6206    
6207                    msg.append(", mountPoint=");
6208                    msg.append(mountPoint);
6209    
6210                    msg.append(", parentFolderId=");
6211                    msg.append(parentFolderId);
6212    
6213                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6214    
6215                    throw new NoSuchFolderException(msg.toString());
6216            }
6217    
6218            /**
6219             * Returns the last document library folder in the ordered set where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63;.
6220             *
6221             * @param groupId the group ID
6222             * @param mountPoint the mount point
6223             * @param parentFolderId the parent folder ID
6224             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6225             * @return the last matching document library folder, or <code>null</code> if a matching document library folder could not be found
6226             */
6227            @Override
6228            public DLFolder fetchByG_M_P_Last(long groupId, boolean mountPoint,
6229                    long parentFolderId, OrderByComparator<DLFolder> orderByComparator) {
6230                    int count = countByG_M_P(groupId, mountPoint, parentFolderId);
6231    
6232                    if (count == 0) {
6233                            return null;
6234                    }
6235    
6236                    List<DLFolder> list = findByG_M_P(groupId, mountPoint, parentFolderId,
6237                                    count - 1, count, orderByComparator);
6238    
6239                    if (!list.isEmpty()) {
6240                            return list.get(0);
6241                    }
6242    
6243                    return null;
6244            }
6245    
6246            /**
6247             * 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;.
6248             *
6249             * @param folderId the primary key of the current document library folder
6250             * @param groupId the group ID
6251             * @param mountPoint the mount point
6252             * @param parentFolderId the parent folder ID
6253             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6254             * @return the previous, current, and next document library folder
6255             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
6256             */
6257            @Override
6258            public DLFolder[] findByG_M_P_PrevAndNext(long folderId, long groupId,
6259                    boolean mountPoint, long parentFolderId,
6260                    OrderByComparator<DLFolder> orderByComparator)
6261                    throws NoSuchFolderException {
6262                    DLFolder dlFolder = findByPrimaryKey(folderId);
6263    
6264                    Session session = null;
6265    
6266                    try {
6267                            session = openSession();
6268    
6269                            DLFolder[] array = new DLFolderImpl[3];
6270    
6271                            array[0] = getByG_M_P_PrevAndNext(session, dlFolder, groupId,
6272                                            mountPoint, parentFolderId, orderByComparator, true);
6273    
6274                            array[1] = dlFolder;
6275    
6276                            array[2] = getByG_M_P_PrevAndNext(session, dlFolder, groupId,
6277                                            mountPoint, parentFolderId, orderByComparator, false);
6278    
6279                            return array;
6280                    }
6281                    catch (Exception e) {
6282                            throw processException(e);
6283                    }
6284                    finally {
6285                            closeSession(session);
6286                    }
6287            }
6288    
6289            protected DLFolder getByG_M_P_PrevAndNext(Session session,
6290                    DLFolder dlFolder, long groupId, boolean mountPoint,
6291                    long parentFolderId, OrderByComparator<DLFolder> orderByComparator,
6292                    boolean previous) {
6293                    StringBundler query = null;
6294    
6295                    if (orderByComparator != null) {
6296                            query = new StringBundler(6 +
6297                                            (orderByComparator.getOrderByFields().length * 6));
6298                    }
6299                    else {
6300                            query = new StringBundler(3);
6301                    }
6302    
6303                    query.append(_SQL_SELECT_DLFOLDER_WHERE);
6304    
6305                    query.append(_FINDER_COLUMN_G_M_P_GROUPID_2);
6306    
6307                    query.append(_FINDER_COLUMN_G_M_P_MOUNTPOINT_2);
6308    
6309                    query.append(_FINDER_COLUMN_G_M_P_PARENTFOLDERID_2);
6310    
6311                    if (orderByComparator != null) {
6312                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6313    
6314                            if (orderByConditionFields.length > 0) {
6315                                    query.append(WHERE_AND);
6316                            }
6317    
6318                            for (int i = 0; i < orderByConditionFields.length; i++) {
6319                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6320                                    query.append(orderByConditionFields[i]);
6321    
6322                                    if ((i + 1) < orderByConditionFields.length) {
6323                                            if (orderByComparator.isAscending() ^ previous) {
6324                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6325                                            }
6326                                            else {
6327                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6328                                            }
6329                                    }
6330                                    else {
6331                                            if (orderByComparator.isAscending() ^ previous) {
6332                                                    query.append(WHERE_GREATER_THAN);
6333                                            }
6334                                            else {
6335                                                    query.append(WHERE_LESSER_THAN);
6336                                            }
6337                                    }
6338                            }
6339    
6340                            query.append(ORDER_BY_CLAUSE);
6341    
6342                            String[] orderByFields = orderByComparator.getOrderByFields();
6343    
6344                            for (int i = 0; i < orderByFields.length; i++) {
6345                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6346                                    query.append(orderByFields[i]);
6347    
6348                                    if ((i + 1) < orderByFields.length) {
6349                                            if (orderByComparator.isAscending() ^ previous) {
6350                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6351                                            }
6352                                            else {
6353                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6354                                            }
6355                                    }
6356                                    else {
6357                                            if (orderByComparator.isAscending() ^ previous) {
6358                                                    query.append(ORDER_BY_ASC);
6359                                            }
6360                                            else {
6361                                                    query.append(ORDER_BY_DESC);
6362                                            }
6363                                    }
6364                            }
6365                    }
6366                    else {
6367                            query.append(DLFolderModelImpl.ORDER_BY_JPQL);
6368                    }
6369    
6370                    String sql = query.toString();
6371    
6372                    Query q = session.createQuery(sql);
6373    
6374                    q.setFirstResult(0);
6375                    q.setMaxResults(2);
6376    
6377                    QueryPos qPos = QueryPos.getInstance(q);
6378    
6379                    qPos.add(groupId);
6380    
6381                    qPos.add(mountPoint);
6382    
6383                    qPos.add(parentFolderId);
6384    
6385                    if (orderByComparator != null) {
6386                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
6387    
6388                            for (Object value : values) {
6389                                    qPos.add(value);
6390                            }
6391                    }
6392    
6393                    List<DLFolder> list = q.list();
6394    
6395                    if (list.size() == 2) {
6396                            return list.get(1);
6397                    }
6398                    else {
6399                            return null;
6400                    }
6401            }
6402    
6403            /**
6404             * Returns all the document library folders that the user has permission to view where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63;.
6405             *
6406             * @param groupId the group ID
6407             * @param mountPoint the mount point
6408             * @param parentFolderId the parent folder ID
6409             * @return the matching document library folders that the user has permission to view
6410             */
6411            @Override
6412            public List<DLFolder> filterFindByG_M_P(long groupId, boolean mountPoint,
6413                    long parentFolderId) {
6414                    return filterFindByG_M_P(groupId, mountPoint, parentFolderId,
6415                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
6416            }
6417    
6418            /**
6419             * 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;.
6420             *
6421             * <p>
6422             * 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.
6423             * </p>
6424             *
6425             * @param groupId the group ID
6426             * @param mountPoint the mount point
6427             * @param parentFolderId the parent folder ID
6428             * @param start the lower bound of the range of document library folders
6429             * @param end the upper bound of the range of document library folders (not inclusive)
6430             * @return the range of matching document library folders that the user has permission to view
6431             */
6432            @Override
6433            public List<DLFolder> filterFindByG_M_P(long groupId, boolean mountPoint,
6434                    long parentFolderId, int start, int end) {
6435                    return filterFindByG_M_P(groupId, mountPoint, parentFolderId, start,
6436                            end, null);
6437            }
6438    
6439            /**
6440             * 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;.
6441             *
6442             * <p>
6443             * 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.
6444             * </p>
6445             *
6446             * @param groupId the group ID
6447             * @param mountPoint the mount point
6448             * @param parentFolderId the parent folder ID
6449             * @param start the lower bound of the range of document library folders
6450             * @param end the upper bound of the range of document library folders (not inclusive)
6451             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6452             * @return the ordered range of matching document library folders that the user has permission to view
6453             */
6454            @Override
6455            public List<DLFolder> filterFindByG_M_P(long groupId, boolean mountPoint,
6456                    long parentFolderId, int start, int end,
6457                    OrderByComparator<DLFolder> orderByComparator) {
6458                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6459                            return findByG_M_P(groupId, mountPoint, parentFolderId, start, end,
6460                                    orderByComparator);
6461                    }
6462    
6463                    StringBundler query = null;
6464    
6465                    if (orderByComparator != null) {
6466                            query = new StringBundler(5 +
6467                                            (orderByComparator.getOrderByFields().length * 3));
6468                    }
6469                    else {
6470                            query = new StringBundler(5);
6471                    }
6472    
6473                    if (getDB().isSupportsInlineDistinct()) {
6474                            query.append(_FILTER_SQL_SELECT_DLFOLDER_WHERE);
6475                    }
6476                    else {
6477                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1);
6478                    }
6479    
6480                    query.append(_FINDER_COLUMN_G_M_P_GROUPID_2);
6481    
6482                    query.append(_FINDER_COLUMN_G_M_P_MOUNTPOINT_2);
6483    
6484                    query.append(_FINDER_COLUMN_G_M_P_PARENTFOLDERID_2);
6485    
6486                    if (!getDB().isSupportsInlineDistinct()) {
6487                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2);
6488                    }
6489    
6490                    if (orderByComparator != null) {
6491                            if (getDB().isSupportsInlineDistinct()) {
6492                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6493                                            orderByComparator, true);
6494                            }
6495                            else {
6496                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
6497                                            orderByComparator, true);
6498                            }
6499                    }
6500                    else {
6501                            if (getDB().isSupportsInlineDistinct()) {
6502                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
6503                            }
6504                            else {
6505                                    query.append(DLFolderModelImpl.ORDER_BY_SQL);
6506                            }
6507                    }
6508    
6509                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6510                                    DLFolder.class.getName(),
6511                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6512    
6513                    Session session = null;
6514    
6515                    try {
6516                            session = openSession();
6517    
6518                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
6519    
6520                            if (getDB().isSupportsInlineDistinct()) {
6521                                    q.addEntity(_FILTER_ENTITY_ALIAS, DLFolderImpl.class);
6522                            }
6523                            else {
6524                                    q.addEntity(_FILTER_ENTITY_TABLE, DLFolderImpl.class);
6525                            }
6526    
6527                            QueryPos qPos = QueryPos.getInstance(q);
6528    
6529                            qPos.add(groupId);
6530    
6531                            qPos.add(mountPoint);
6532    
6533                            qPos.add(parentFolderId);
6534    
6535                            return (List<DLFolder>)QueryUtil.list(q, getDialect(), start, end);
6536                    }
6537                    catch (Exception e) {
6538                            throw processException(e);
6539                    }
6540                    finally {
6541                            closeSession(session);
6542                    }
6543            }
6544    
6545            /**
6546             * 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;.
6547             *
6548             * @param folderId the primary key of the current document library folder
6549             * @param groupId the group ID
6550             * @param mountPoint the mount point
6551             * @param parentFolderId the parent folder ID
6552             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6553             * @return the previous, current, and next document library folder
6554             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
6555             */
6556            @Override
6557            public DLFolder[] filterFindByG_M_P_PrevAndNext(long folderId,
6558                    long groupId, boolean mountPoint, long parentFolderId,
6559                    OrderByComparator<DLFolder> orderByComparator)
6560                    throws NoSuchFolderException {
6561                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6562                            return findByG_M_P_PrevAndNext(folderId, groupId, mountPoint,
6563                                    parentFolderId, orderByComparator);
6564                    }
6565    
6566                    DLFolder dlFolder = findByPrimaryKey(folderId);
6567    
6568                    Session session = null;
6569    
6570                    try {
6571                            session = openSession();
6572    
6573                            DLFolder[] array = new DLFolderImpl[3];
6574    
6575                            array[0] = filterGetByG_M_P_PrevAndNext(session, dlFolder, groupId,
6576                                            mountPoint, parentFolderId, orderByComparator, true);
6577    
6578                            array[1] = dlFolder;
6579    
6580                            array[2] = filterGetByG_M_P_PrevAndNext(session, dlFolder, groupId,
6581                                            mountPoint, parentFolderId, orderByComparator, false);
6582    
6583                            return array;
6584                    }
6585                    catch (Exception e) {
6586                            throw processException(e);
6587                    }
6588                    finally {
6589                            closeSession(session);
6590                    }
6591            }
6592    
6593            protected DLFolder filterGetByG_M_P_PrevAndNext(Session session,
6594                    DLFolder dlFolder, long groupId, boolean mountPoint,
6595                    long parentFolderId, OrderByComparator<DLFolder> orderByComparator,
6596                    boolean previous) {
6597                    StringBundler query = null;
6598    
6599                    if (orderByComparator != null) {
6600                            query = new StringBundler(6 +
6601                                            (orderByComparator.getOrderByFields().length * 6));
6602                    }
6603                    else {
6604                            query = new StringBundler(3);
6605                    }
6606    
6607                    if (getDB().isSupportsInlineDistinct()) {
6608                            query.append(_FILTER_SQL_SELECT_DLFOLDER_WHERE);
6609                    }
6610                    else {
6611                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1);
6612                    }
6613    
6614                    query.append(_FINDER_COLUMN_G_M_P_GROUPID_2);
6615    
6616                    query.append(_FINDER_COLUMN_G_M_P_MOUNTPOINT_2);
6617    
6618                    query.append(_FINDER_COLUMN_G_M_P_PARENTFOLDERID_2);
6619    
6620                    if (!getDB().isSupportsInlineDistinct()) {
6621                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2);
6622                    }
6623    
6624                    if (orderByComparator != null) {
6625                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6626    
6627                            if (orderByConditionFields.length > 0) {
6628                                    query.append(WHERE_AND);
6629                            }
6630    
6631                            for (int i = 0; i < orderByConditionFields.length; i++) {
6632                                    if (getDB().isSupportsInlineDistinct()) {
6633                                            query.append(_ORDER_BY_ENTITY_ALIAS);
6634                                    }
6635                                    else {
6636                                            query.append(_ORDER_BY_ENTITY_TABLE);
6637                                    }
6638    
6639                                    query.append(orderByConditionFields[i]);
6640    
6641                                    if ((i + 1) < orderByConditionFields.length) {
6642                                            if (orderByComparator.isAscending() ^ previous) {
6643                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6644                                            }
6645                                            else {
6646                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6647                                            }
6648                                    }
6649                                    else {
6650                                            if (orderByComparator.isAscending() ^ previous) {
6651                                                    query.append(WHERE_GREATER_THAN);
6652                                            }
6653                                            else {
6654                                                    query.append(WHERE_LESSER_THAN);
6655                                            }
6656                                    }
6657                            }
6658    
6659                            query.append(ORDER_BY_CLAUSE);
6660    
6661                            String[] orderByFields = orderByComparator.getOrderByFields();
6662    
6663                            for (int i = 0; i < orderByFields.length; i++) {
6664                                    if (getDB().isSupportsInlineDistinct()) {
6665                                            query.append(_ORDER_BY_ENTITY_ALIAS);
6666                                    }
6667                                    else {
6668                                            query.append(_ORDER_BY_ENTITY_TABLE);
6669                                    }
6670    
6671                                    query.append(orderByFields[i]);
6672    
6673                                    if ((i + 1) < orderByFields.length) {
6674                                            if (orderByComparator.isAscending() ^ previous) {
6675                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6676                                            }
6677                                            else {
6678                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6679                                            }
6680                                    }
6681                                    else {
6682                                            if (orderByComparator.isAscending() ^ previous) {
6683                                                    query.append(ORDER_BY_ASC);
6684                                            }
6685                                            else {
6686                                                    query.append(ORDER_BY_DESC);
6687                                            }
6688                                    }
6689                            }
6690                    }
6691                    else {
6692                            if (getDB().isSupportsInlineDistinct()) {
6693                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
6694                            }
6695                            else {
6696                                    query.append(DLFolderModelImpl.ORDER_BY_SQL);
6697                            }
6698                    }
6699    
6700                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6701                                    DLFolder.class.getName(),
6702                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6703    
6704                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
6705    
6706                    q.setFirstResult(0);
6707                    q.setMaxResults(2);
6708    
6709                    if (getDB().isSupportsInlineDistinct()) {
6710                            q.addEntity(_FILTER_ENTITY_ALIAS, DLFolderImpl.class);
6711                    }
6712                    else {
6713                            q.addEntity(_FILTER_ENTITY_TABLE, DLFolderImpl.class);
6714                    }
6715    
6716                    QueryPos qPos = QueryPos.getInstance(q);
6717    
6718                    qPos.add(groupId);
6719    
6720                    qPos.add(mountPoint);
6721    
6722                    qPos.add(parentFolderId);
6723    
6724                    if (orderByComparator != null) {
6725                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
6726    
6727                            for (Object value : values) {
6728                                    qPos.add(value);
6729                            }
6730                    }
6731    
6732                    List<DLFolder> list = q.list();
6733    
6734                    if (list.size() == 2) {
6735                            return list.get(1);
6736                    }
6737                    else {
6738                            return null;
6739                    }
6740            }
6741    
6742            /**
6743             * Removes all the document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; from the database.
6744             *
6745             * @param groupId the group ID
6746             * @param mountPoint the mount point
6747             * @param parentFolderId the parent folder ID
6748             */
6749            @Override
6750            public void removeByG_M_P(long groupId, boolean mountPoint,
6751                    long parentFolderId) {
6752                    for (DLFolder dlFolder : findByG_M_P(groupId, mountPoint,
6753                                    parentFolderId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
6754                            remove(dlFolder);
6755                    }
6756            }
6757    
6758            /**
6759             * Returns the number of document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63;.
6760             *
6761             * @param groupId the group ID
6762             * @param mountPoint the mount point
6763             * @param parentFolderId the parent folder ID
6764             * @return the number of matching document library folders
6765             */
6766            @Override
6767            public int countByG_M_P(long groupId, boolean mountPoint,
6768                    long parentFolderId) {
6769                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_M_P;
6770    
6771                    Object[] finderArgs = new Object[] { groupId, mountPoint, parentFolderId };
6772    
6773                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
6774                                    this);
6775    
6776                    if (count == null) {
6777                            StringBundler query = new StringBundler(4);
6778    
6779                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
6780    
6781                            query.append(_FINDER_COLUMN_G_M_P_GROUPID_2);
6782    
6783                            query.append(_FINDER_COLUMN_G_M_P_MOUNTPOINT_2);
6784    
6785                            query.append(_FINDER_COLUMN_G_M_P_PARENTFOLDERID_2);
6786    
6787                            String sql = query.toString();
6788    
6789                            Session session = null;
6790    
6791                            try {
6792                                    session = openSession();
6793    
6794                                    Query q = session.createQuery(sql);
6795    
6796                                    QueryPos qPos = QueryPos.getInstance(q);
6797    
6798                                    qPos.add(groupId);
6799    
6800                                    qPos.add(mountPoint);
6801    
6802                                    qPos.add(parentFolderId);
6803    
6804                                    count = (Long)q.uniqueResult();
6805    
6806                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
6807                            }
6808                            catch (Exception e) {
6809                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6810    
6811                                    throw processException(e);
6812                            }
6813                            finally {
6814                                    closeSession(session);
6815                            }
6816                    }
6817    
6818                    return count.intValue();
6819            }
6820    
6821            /**
6822             * Returns the number of document library folders that the user has permission to view where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63;.
6823             *
6824             * @param groupId the group ID
6825             * @param mountPoint the mount point
6826             * @param parentFolderId the parent folder ID
6827             * @return the number of matching document library folders that the user has permission to view
6828             */
6829            @Override
6830            public int filterCountByG_M_P(long groupId, boolean mountPoint,
6831                    long parentFolderId) {
6832                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6833                            return countByG_M_P(groupId, mountPoint, parentFolderId);
6834                    }
6835    
6836                    StringBundler query = new StringBundler(4);
6837    
6838                    query.append(_FILTER_SQL_COUNT_DLFOLDER_WHERE);
6839    
6840                    query.append(_FINDER_COLUMN_G_M_P_GROUPID_2);
6841    
6842                    query.append(_FINDER_COLUMN_G_M_P_MOUNTPOINT_2);
6843    
6844                    query.append(_FINDER_COLUMN_G_M_P_PARENTFOLDERID_2);
6845    
6846                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6847                                    DLFolder.class.getName(),
6848                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6849    
6850                    Session session = null;
6851    
6852                    try {
6853                            session = openSession();
6854    
6855                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
6856    
6857                            q.addScalar(COUNT_COLUMN_NAME,
6858                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
6859    
6860                            QueryPos qPos = QueryPos.getInstance(q);
6861    
6862                            qPos.add(groupId);
6863    
6864                            qPos.add(mountPoint);
6865    
6866                            qPos.add(parentFolderId);
6867    
6868                            Long count = (Long)q.uniqueResult();
6869    
6870                            return count.intValue();
6871                    }
6872                    catch (Exception e) {
6873                            throw processException(e);
6874                    }
6875                    finally {
6876                            closeSession(session);
6877                    }
6878            }
6879    
6880            private static final String _FINDER_COLUMN_G_M_P_GROUPID_2 = "dlFolder.groupId = ? AND ";
6881            private static final String _FINDER_COLUMN_G_M_P_MOUNTPOINT_2 = "dlFolder.mountPoint = ? AND ";
6882            private static final String _FINDER_COLUMN_G_M_P_PARENTFOLDERID_2 = "dlFolder.parentFolderId = ?";
6883            public static final FinderPath FINDER_PATH_FETCH_BY_G_P_N = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
6884                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
6885                            FINDER_CLASS_NAME_ENTITY, "fetchByG_P_N",
6886                            new String[] {
6887                                    Long.class.getName(), Long.class.getName(),
6888                                    String.class.getName()
6889                            },
6890                            DLFolderModelImpl.GROUPID_COLUMN_BITMASK |
6891                            DLFolderModelImpl.PARENTFOLDERID_COLUMN_BITMASK |
6892                            DLFolderModelImpl.NAME_COLUMN_BITMASK);
6893            public static final FinderPath FINDER_PATH_COUNT_BY_G_P_N = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
6894                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
6895                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P_N",
6896                            new String[] {
6897                                    Long.class.getName(), Long.class.getName(),
6898                                    String.class.getName()
6899                            });
6900    
6901            /**
6902             * 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.
6903             *
6904             * @param groupId the group ID
6905             * @param parentFolderId the parent folder ID
6906             * @param name the name
6907             * @return the matching document library folder
6908             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
6909             */
6910            @Override
6911            public DLFolder findByG_P_N(long groupId, long parentFolderId, String name)
6912                    throws NoSuchFolderException {
6913                    DLFolder dlFolder = fetchByG_P_N(groupId, parentFolderId, name);
6914    
6915                    if (dlFolder == null) {
6916                            StringBundler msg = new StringBundler(8);
6917    
6918                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6919    
6920                            msg.append("groupId=");
6921                            msg.append(groupId);
6922    
6923                            msg.append(", parentFolderId=");
6924                            msg.append(parentFolderId);
6925    
6926                            msg.append(", name=");
6927                            msg.append(name);
6928    
6929                            msg.append(StringPool.CLOSE_CURLY_BRACE);
6930    
6931                            if (_log.isWarnEnabled()) {
6932                                    _log.warn(msg.toString());
6933                            }
6934    
6935                            throw new NoSuchFolderException(msg.toString());
6936                    }
6937    
6938                    return dlFolder;
6939            }
6940    
6941            /**
6942             * 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.
6943             *
6944             * @param groupId the group ID
6945             * @param parentFolderId the parent folder ID
6946             * @param name the name
6947             * @return the matching document library folder, or <code>null</code> if a matching document library folder could not be found
6948             */
6949            @Override
6950            public DLFolder fetchByG_P_N(long groupId, long parentFolderId, String name) {
6951                    return fetchByG_P_N(groupId, parentFolderId, name, true);
6952            }
6953    
6954            /**
6955             * 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.
6956             *
6957             * @param groupId the group ID
6958             * @param parentFolderId the parent folder ID
6959             * @param name the name
6960             * @param retrieveFromCache whether to use the finder cache
6961             * @return the matching document library folder, or <code>null</code> if a matching document library folder could not be found
6962             */
6963            @Override
6964            public DLFolder fetchByG_P_N(long groupId, long parentFolderId,
6965                    String name, boolean retrieveFromCache) {
6966                    Object[] finderArgs = new Object[] { groupId, parentFolderId, name };
6967    
6968                    Object result = null;
6969    
6970                    if (retrieveFromCache) {
6971                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_P_N,
6972                                            finderArgs, this);
6973                    }
6974    
6975                    if (result instanceof DLFolder) {
6976                            DLFolder dlFolder = (DLFolder)result;
6977    
6978                            if ((groupId != dlFolder.getGroupId()) ||
6979                                            (parentFolderId != dlFolder.getParentFolderId()) ||
6980                                            !Validator.equals(name, dlFolder.getName())) {
6981                                    result = null;
6982                            }
6983                    }
6984    
6985                    if (result == null) {
6986                            StringBundler query = new StringBundler(5);
6987    
6988                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
6989    
6990                            query.append(_FINDER_COLUMN_G_P_N_GROUPID_2);
6991    
6992                            query.append(_FINDER_COLUMN_G_P_N_PARENTFOLDERID_2);
6993    
6994                            boolean bindName = false;
6995    
6996                            if (name == null) {
6997                                    query.append(_FINDER_COLUMN_G_P_N_NAME_1);
6998                            }
6999                            else if (name.equals(StringPool.BLANK)) {
7000                                    query.append(_FINDER_COLUMN_G_P_N_NAME_3);
7001                            }
7002                            else {
7003                                    bindName = true;
7004    
7005                                    query.append(_FINDER_COLUMN_G_P_N_NAME_2);
7006                            }
7007    
7008                            String sql = query.toString();
7009    
7010                            Session session = null;
7011    
7012                            try {
7013                                    session = openSession();
7014    
7015                                    Query q = session.createQuery(sql);
7016    
7017                                    QueryPos qPos = QueryPos.getInstance(q);
7018    
7019                                    qPos.add(groupId);
7020    
7021                                    qPos.add(parentFolderId);
7022    
7023                                    if (bindName) {
7024                                            qPos.add(name);
7025                                    }
7026    
7027                                    List<DLFolder> list = q.list();
7028    
7029                                    if (list.isEmpty()) {
7030                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_N,
7031                                                    finderArgs, list);
7032                                    }
7033                                    else {
7034                                            DLFolder dlFolder = list.get(0);
7035    
7036                                            result = dlFolder;
7037    
7038                                            cacheResult(dlFolder);
7039    
7040                                            if ((dlFolder.getGroupId() != groupId) ||
7041                                                            (dlFolder.getParentFolderId() != parentFolderId) ||
7042                                                            (dlFolder.getName() == null) ||
7043                                                            !dlFolder.getName().equals(name)) {
7044                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_N,
7045                                                            finderArgs, dlFolder);
7046                                            }
7047                                    }
7048                            }
7049                            catch (Exception e) {
7050                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P_N,
7051                                            finderArgs);
7052    
7053                                    throw processException(e);
7054                            }
7055                            finally {
7056                                    closeSession(session);
7057                            }
7058                    }
7059    
7060                    if (result instanceof List<?>) {
7061                            return null;
7062                    }
7063                    else {
7064                            return (DLFolder)result;
7065                    }
7066            }
7067    
7068            /**
7069             * Removes the document library folder where groupId = &#63; and parentFolderId = &#63; and name = &#63; from the database.
7070             *
7071             * @param groupId the group ID
7072             * @param parentFolderId the parent folder ID
7073             * @param name the name
7074             * @return the document library folder that was removed
7075             */
7076            @Override
7077            public DLFolder removeByG_P_N(long groupId, long parentFolderId, String name)
7078                    throws NoSuchFolderException {
7079                    DLFolder dlFolder = findByG_P_N(groupId, parentFolderId, name);
7080    
7081                    return remove(dlFolder);
7082            }
7083    
7084            /**
7085             * Returns the number of document library folders where groupId = &#63; and parentFolderId = &#63; and name = &#63;.
7086             *
7087             * @param groupId the group ID
7088             * @param parentFolderId the parent folder ID
7089             * @param name the name
7090             * @return the number of matching document library folders
7091             */
7092            @Override
7093            public int countByG_P_N(long groupId, long parentFolderId, String name) {
7094                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_P_N;
7095    
7096                    Object[] finderArgs = new Object[] { groupId, parentFolderId, name };
7097    
7098                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
7099                                    this);
7100    
7101                    if (count == null) {
7102                            StringBundler query = new StringBundler(4);
7103    
7104                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
7105    
7106                            query.append(_FINDER_COLUMN_G_P_N_GROUPID_2);
7107    
7108                            query.append(_FINDER_COLUMN_G_P_N_PARENTFOLDERID_2);
7109    
7110                            boolean bindName = false;
7111    
7112                            if (name == null) {
7113                                    query.append(_FINDER_COLUMN_G_P_N_NAME_1);
7114                            }
7115                            else if (name.equals(StringPool.BLANK)) {
7116                                    query.append(_FINDER_COLUMN_G_P_N_NAME_3);
7117                            }
7118                            else {
7119                                    bindName = true;
7120    
7121                                    query.append(_FINDER_COLUMN_G_P_N_NAME_2);
7122                            }
7123    
7124                            String sql = query.toString();
7125    
7126                            Session session = null;
7127    
7128                            try {
7129                                    session = openSession();
7130    
7131                                    Query q = session.createQuery(sql);
7132    
7133                                    QueryPos qPos = QueryPos.getInstance(q);
7134    
7135                                    qPos.add(groupId);
7136    
7137                                    qPos.add(parentFolderId);
7138    
7139                                    if (bindName) {
7140                                            qPos.add(name);
7141                                    }
7142    
7143                                    count = (Long)q.uniqueResult();
7144    
7145                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
7146                            }
7147                            catch (Exception e) {
7148                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
7149    
7150                                    throw processException(e);
7151                            }
7152                            finally {
7153                                    closeSession(session);
7154                            }
7155                    }
7156    
7157                    return count.intValue();
7158            }
7159    
7160            private static final String _FINDER_COLUMN_G_P_N_GROUPID_2 = "dlFolder.groupId = ? AND ";
7161            private static final String _FINDER_COLUMN_G_P_N_PARENTFOLDERID_2 = "dlFolder.parentFolderId = ? AND ";
7162            private static final String _FINDER_COLUMN_G_P_N_NAME_1 = "dlFolder.name IS NULL";
7163            private static final String _FINDER_COLUMN_G_P_N_NAME_2 = "dlFolder.name = ?";
7164            private static final String _FINDER_COLUMN_G_P_N_NAME_3 = "(dlFolder.name IS NULL OR dlFolder.name = '')";
7165            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_F_C_P_NOTS =
7166                    new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
7167                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
7168                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByF_C_P_NotS",
7169                            new String[] {
7170                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
7171                                    Integer.class.getName(),
7172                                    
7173                            Integer.class.getName(), Integer.class.getName(),
7174                                    OrderByComparator.class.getName()
7175                            });
7176            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_F_C_P_NOTS =
7177                    new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
7178                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
7179                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByF_C_P_NotS",
7180                            new String[] {
7181                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
7182                                    Integer.class.getName()
7183                            });
7184    
7185            /**
7186             * Returns all the document library folders where folderId &gt; &#63; and companyId = &#63; and parentFolderId = &#63; and status &ne; &#63;.
7187             *
7188             * @param folderId the folder ID
7189             * @param companyId the company ID
7190             * @param parentFolderId the parent folder ID
7191             * @param status the status
7192             * @return the matching document library folders
7193             */
7194            @Override
7195            public List<DLFolder> findByF_C_P_NotS(long folderId, long companyId,
7196                    long parentFolderId, int status) {
7197                    return findByF_C_P_NotS(folderId, companyId, parentFolderId, status,
7198                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
7199            }
7200    
7201            /**
7202             * Returns a range of all the document library folders where folderId &gt; &#63; and companyId = &#63; and parentFolderId = &#63; and status &ne; &#63;.
7203             *
7204             * <p>
7205             * 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.
7206             * </p>
7207             *
7208             * @param folderId the folder ID
7209             * @param companyId the company ID
7210             * @param parentFolderId the parent folder ID
7211             * @param status the status
7212             * @param start the lower bound of the range of document library folders
7213             * @param end the upper bound of the range of document library folders (not inclusive)
7214             * @return the range of matching document library folders
7215             */
7216            @Override
7217            public List<DLFolder> findByF_C_P_NotS(long folderId, long companyId,
7218                    long parentFolderId, int status, int start, int end) {
7219                    return findByF_C_P_NotS(folderId, companyId, parentFolderId, status,
7220                            start, end, null);
7221            }
7222    
7223            /**
7224             * Returns an ordered range of all the document library folders where folderId &gt; &#63; and companyId = &#63; and parentFolderId = &#63; and status &ne; &#63;.
7225             *
7226             * <p>
7227             * 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.
7228             * </p>
7229             *
7230             * @param folderId the folder ID
7231             * @param companyId the company ID
7232             * @param parentFolderId the parent folder ID
7233             * @param status the status
7234             * @param start the lower bound of the range of document library folders
7235             * @param end the upper bound of the range of document library folders (not inclusive)
7236             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7237             * @return the ordered range of matching document library folders
7238             */
7239            @Override
7240            public List<DLFolder> findByF_C_P_NotS(long folderId, long companyId,
7241                    long parentFolderId, int status, int start, int end,
7242                    OrderByComparator<DLFolder> orderByComparator) {
7243                    boolean pagination = true;
7244                    FinderPath finderPath = null;
7245                    Object[] finderArgs = null;
7246    
7247                    finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_F_C_P_NOTS;
7248                    finderArgs = new Object[] {
7249                                    folderId, companyId, parentFolderId, status,
7250                                    
7251                                    start, end, orderByComparator
7252                            };
7253    
7254                    List<DLFolder> list = (List<DLFolder>)FinderCacheUtil.getResult(finderPath,
7255                                    finderArgs, this);
7256    
7257                    if ((list != null) && !list.isEmpty()) {
7258                            for (DLFolder dlFolder : list) {
7259                                    if ((folderId >= dlFolder.getFolderId()) ||
7260                                                    (companyId != dlFolder.getCompanyId()) ||
7261                                                    (parentFolderId != dlFolder.getParentFolderId()) ||
7262                                                    (status == dlFolder.getStatus())) {
7263                                            list = null;
7264    
7265                                            break;
7266                                    }
7267                            }
7268                    }
7269    
7270                    if (list == null) {
7271                            StringBundler query = null;
7272    
7273                            if (orderByComparator != null) {
7274                                    query = new StringBundler(6 +
7275                                                    (orderByComparator.getOrderByFields().length * 3));
7276                            }
7277                            else {
7278                                    query = new StringBundler(6);
7279                            }
7280    
7281                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
7282    
7283                            query.append(_FINDER_COLUMN_F_C_P_NOTS_FOLDERID_2);
7284    
7285                            query.append(_FINDER_COLUMN_F_C_P_NOTS_COMPANYID_2);
7286    
7287                            query.append(_FINDER_COLUMN_F_C_P_NOTS_PARENTFOLDERID_2);
7288    
7289                            query.append(_FINDER_COLUMN_F_C_P_NOTS_STATUS_2);
7290    
7291                            if (orderByComparator != null) {
7292                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7293                                            orderByComparator);
7294                            }
7295                            else
7296                             if (pagination) {
7297                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
7298                            }
7299    
7300                            String sql = query.toString();
7301    
7302                            Session session = null;
7303    
7304                            try {
7305                                    session = openSession();
7306    
7307                                    Query q = session.createQuery(sql);
7308    
7309                                    QueryPos qPos = QueryPos.getInstance(q);
7310    
7311                                    qPos.add(folderId);
7312    
7313                                    qPos.add(companyId);
7314    
7315                                    qPos.add(parentFolderId);
7316    
7317                                    qPos.add(status);
7318    
7319                                    if (!pagination) {
7320                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
7321                                                            start, end, false);
7322    
7323                                            Collections.sort(list);
7324    
7325                                            list = Collections.unmodifiableList(list);
7326                                    }
7327                                    else {
7328                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
7329                                                            start, end);
7330                                    }
7331    
7332                                    cacheResult(list);
7333    
7334                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
7335                            }
7336                            catch (Exception e) {
7337                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
7338    
7339                                    throw processException(e);
7340                            }
7341                            finally {
7342                                    closeSession(session);
7343                            }
7344                    }
7345    
7346                    return list;
7347            }
7348    
7349            /**
7350             * Returns the first document library folder in the ordered set where folderId &gt; &#63; and companyId = &#63; and parentFolderId = &#63; and status &ne; &#63;.
7351             *
7352             * @param folderId the folder ID
7353             * @param companyId the company ID
7354             * @param parentFolderId the parent folder ID
7355             * @param status the status
7356             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7357             * @return the first matching document library folder
7358             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
7359             */
7360            @Override
7361            public DLFolder findByF_C_P_NotS_First(long folderId, long companyId,
7362                    long parentFolderId, int status,
7363                    OrderByComparator<DLFolder> orderByComparator)
7364                    throws NoSuchFolderException {
7365                    DLFolder dlFolder = fetchByF_C_P_NotS_First(folderId, companyId,
7366                                    parentFolderId, status, orderByComparator);
7367    
7368                    if (dlFolder != null) {
7369                            return dlFolder;
7370                    }
7371    
7372                    StringBundler msg = new StringBundler(10);
7373    
7374                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7375    
7376                    msg.append("folderId=");
7377                    msg.append(folderId);
7378    
7379                    msg.append(", companyId=");
7380                    msg.append(companyId);
7381    
7382                    msg.append(", parentFolderId=");
7383                    msg.append(parentFolderId);
7384    
7385                    msg.append(", status=");
7386                    msg.append(status);
7387    
7388                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7389    
7390                    throw new NoSuchFolderException(msg.toString());
7391            }
7392    
7393            /**
7394             * Returns the first document library folder in the ordered set where folderId &gt; &#63; and companyId = &#63; and parentFolderId = &#63; and status &ne; &#63;.
7395             *
7396             * @param folderId the folder ID
7397             * @param companyId the company ID
7398             * @param parentFolderId the parent folder ID
7399             * @param status the status
7400             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7401             * @return the first matching document library folder, or <code>null</code> if a matching document library folder could not be found
7402             */
7403            @Override
7404            public DLFolder fetchByF_C_P_NotS_First(long folderId, long companyId,
7405                    long parentFolderId, int status,
7406                    OrderByComparator<DLFolder> orderByComparator) {
7407                    List<DLFolder> list = findByF_C_P_NotS(folderId, companyId,
7408                                    parentFolderId, status, 0, 1, orderByComparator);
7409    
7410                    if (!list.isEmpty()) {
7411                            return list.get(0);
7412                    }
7413    
7414                    return null;
7415            }
7416    
7417            /**
7418             * Returns the last document library folder in the ordered set where folderId &gt; &#63; and companyId = &#63; and parentFolderId = &#63; and status &ne; &#63;.
7419             *
7420             * @param folderId the folder ID
7421             * @param companyId the company ID
7422             * @param parentFolderId the parent folder ID
7423             * @param status the status
7424             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7425             * @return the last matching document library folder
7426             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
7427             */
7428            @Override
7429            public DLFolder findByF_C_P_NotS_Last(long folderId, long companyId,
7430                    long parentFolderId, int status,
7431                    OrderByComparator<DLFolder> orderByComparator)
7432                    throws NoSuchFolderException {
7433                    DLFolder dlFolder = fetchByF_C_P_NotS_Last(folderId, companyId,
7434                                    parentFolderId, status, orderByComparator);
7435    
7436                    if (dlFolder != null) {
7437                            return dlFolder;
7438                    }
7439    
7440                    StringBundler msg = new StringBundler(10);
7441    
7442                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7443    
7444                    msg.append("folderId=");
7445                    msg.append(folderId);
7446    
7447                    msg.append(", companyId=");
7448                    msg.append(companyId);
7449    
7450                    msg.append(", parentFolderId=");
7451                    msg.append(parentFolderId);
7452    
7453                    msg.append(", status=");
7454                    msg.append(status);
7455    
7456                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7457    
7458                    throw new NoSuchFolderException(msg.toString());
7459            }
7460    
7461            /**
7462             * Returns the last document library folder in the ordered set where folderId &gt; &#63; and companyId = &#63; and parentFolderId = &#63; and status &ne; &#63;.
7463             *
7464             * @param folderId the folder ID
7465             * @param companyId the company ID
7466             * @param parentFolderId the parent folder ID
7467             * @param status the status
7468             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7469             * @return the last matching document library folder, or <code>null</code> if a matching document library folder could not be found
7470             */
7471            @Override
7472            public DLFolder fetchByF_C_P_NotS_Last(long folderId, long companyId,
7473                    long parentFolderId, int status,
7474                    OrderByComparator<DLFolder> orderByComparator) {
7475                    int count = countByF_C_P_NotS(folderId, companyId, parentFolderId,
7476                                    status);
7477    
7478                    if (count == 0) {
7479                            return null;
7480                    }
7481    
7482                    List<DLFolder> list = findByF_C_P_NotS(folderId, companyId,
7483                                    parentFolderId, status, count - 1, count, orderByComparator);
7484    
7485                    if (!list.isEmpty()) {
7486                            return list.get(0);
7487                    }
7488    
7489                    return null;
7490            }
7491    
7492            /**
7493             * Removes all the document library folders where folderId &gt; &#63; and companyId = &#63; and parentFolderId = &#63; and status &ne; &#63; from the database.
7494             *
7495             * @param folderId the folder ID
7496             * @param companyId the company ID
7497             * @param parentFolderId the parent folder ID
7498             * @param status the status
7499             */
7500            @Override
7501            public void removeByF_C_P_NotS(long folderId, long companyId,
7502                    long parentFolderId, int status) {
7503                    for (DLFolder dlFolder : findByF_C_P_NotS(folderId, companyId,
7504                                    parentFolderId, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
7505                                    null)) {
7506                            remove(dlFolder);
7507                    }
7508            }
7509    
7510            /**
7511             * Returns the number of document library folders where folderId &gt; &#63; and companyId = &#63; and parentFolderId = &#63; and status &ne; &#63;.
7512             *
7513             * @param folderId the folder ID
7514             * @param companyId the company ID
7515             * @param parentFolderId the parent folder ID
7516             * @param status the status
7517             * @return the number of matching document library folders
7518             */
7519            @Override
7520            public int countByF_C_P_NotS(long folderId, long companyId,
7521                    long parentFolderId, int status) {
7522                    FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_F_C_P_NOTS;
7523    
7524                    Object[] finderArgs = new Object[] {
7525                                    folderId, companyId, parentFolderId, status
7526                            };
7527    
7528                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
7529                                    this);
7530    
7531                    if (count == null) {
7532                            StringBundler query = new StringBundler(5);
7533    
7534                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
7535    
7536                            query.append(_FINDER_COLUMN_F_C_P_NOTS_FOLDERID_2);
7537    
7538                            query.append(_FINDER_COLUMN_F_C_P_NOTS_COMPANYID_2);
7539    
7540                            query.append(_FINDER_COLUMN_F_C_P_NOTS_PARENTFOLDERID_2);
7541    
7542                            query.append(_FINDER_COLUMN_F_C_P_NOTS_STATUS_2);
7543    
7544                            String sql = query.toString();
7545    
7546                            Session session = null;
7547    
7548                            try {
7549                                    session = openSession();
7550    
7551                                    Query q = session.createQuery(sql);
7552    
7553                                    QueryPos qPos = QueryPos.getInstance(q);
7554    
7555                                    qPos.add(folderId);
7556    
7557                                    qPos.add(companyId);
7558    
7559                                    qPos.add(parentFolderId);
7560    
7561                                    qPos.add(status);
7562    
7563                                    count = (Long)q.uniqueResult();
7564    
7565                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
7566                            }
7567                            catch (Exception e) {
7568                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
7569    
7570                                    throw processException(e);
7571                            }
7572                            finally {
7573                                    closeSession(session);
7574                            }
7575                    }
7576    
7577                    return count.intValue();
7578            }
7579    
7580            private static final String _FINDER_COLUMN_F_C_P_NOTS_FOLDERID_2 = "dlFolder.folderId > ? AND ";
7581            private static final String _FINDER_COLUMN_F_C_P_NOTS_COMPANYID_2 = "dlFolder.companyId = ? AND ";
7582            private static final String _FINDER_COLUMN_F_C_P_NOTS_PARENTFOLDERID_2 = "dlFolder.parentFolderId = ? AND ";
7583            private static final String _FINDER_COLUMN_F_C_P_NOTS_STATUS_2 = "dlFolder.status != ?";
7584            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_M_P_H = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
7585                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
7586                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_M_P_H",
7587                            new String[] {
7588                                    Long.class.getName(), Boolean.class.getName(),
7589                                    Long.class.getName(), Boolean.class.getName(),
7590                                    
7591                            Integer.class.getName(), Integer.class.getName(),
7592                                    OrderByComparator.class.getName()
7593                            });
7594            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P_H =
7595                    new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
7596                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
7597                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_M_P_H",
7598                            new String[] {
7599                                    Long.class.getName(), Boolean.class.getName(),
7600                                    Long.class.getName(), Boolean.class.getName()
7601                            },
7602                            DLFolderModelImpl.GROUPID_COLUMN_BITMASK |
7603                            DLFolderModelImpl.MOUNTPOINT_COLUMN_BITMASK |
7604                            DLFolderModelImpl.PARENTFOLDERID_COLUMN_BITMASK |
7605                            DLFolderModelImpl.HIDDEN_COLUMN_BITMASK |
7606                            DLFolderModelImpl.NAME_COLUMN_BITMASK);
7607            public static final FinderPath FINDER_PATH_COUNT_BY_G_M_P_H = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
7608                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
7609                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_M_P_H",
7610                            new String[] {
7611                                    Long.class.getName(), Boolean.class.getName(),
7612                                    Long.class.getName(), Boolean.class.getName()
7613                            });
7614    
7615            /**
7616             * Returns all the document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63;.
7617             *
7618             * @param groupId the group ID
7619             * @param mountPoint the mount point
7620             * @param parentFolderId the parent folder ID
7621             * @param hidden the hidden
7622             * @return the matching document library folders
7623             */
7624            @Override
7625            public List<DLFolder> findByG_M_P_H(long groupId, boolean mountPoint,
7626                    long parentFolderId, boolean hidden) {
7627                    return findByG_M_P_H(groupId, mountPoint, parentFolderId, hidden,
7628                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
7629            }
7630    
7631            /**
7632             * Returns a range of all the document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63;.
7633             *
7634             * <p>
7635             * 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.
7636             * </p>
7637             *
7638             * @param groupId the group ID
7639             * @param mountPoint the mount point
7640             * @param parentFolderId the parent folder ID
7641             * @param hidden the hidden
7642             * @param start the lower bound of the range of document library folders
7643             * @param end the upper bound of the range of document library folders (not inclusive)
7644             * @return the range of matching document library folders
7645             */
7646            @Override
7647            public List<DLFolder> findByG_M_P_H(long groupId, boolean mountPoint,
7648                    long parentFolderId, boolean hidden, int start, int end) {
7649                    return findByG_M_P_H(groupId, mountPoint, parentFolderId, hidden,
7650                            start, end, null);
7651            }
7652    
7653            /**
7654             * Returns an ordered range of all the document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63;.
7655             *
7656             * <p>
7657             * 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.
7658             * </p>
7659             *
7660             * @param groupId the group ID
7661             * @param mountPoint the mount point
7662             * @param parentFolderId the parent folder ID
7663             * @param hidden the hidden
7664             * @param start the lower bound of the range of document library folders
7665             * @param end the upper bound of the range of document library folders (not inclusive)
7666             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7667             * @return the ordered range of matching document library folders
7668             */
7669            @Override
7670            public List<DLFolder> findByG_M_P_H(long groupId, boolean mountPoint,
7671                    long parentFolderId, boolean hidden, int start, int end,
7672                    OrderByComparator<DLFolder> orderByComparator) {
7673                    boolean pagination = true;
7674                    FinderPath finderPath = null;
7675                    Object[] finderArgs = null;
7676    
7677                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7678                                    (orderByComparator == null)) {
7679                            pagination = false;
7680                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P_H;
7681                            finderArgs = new Object[] {
7682                                            groupId, mountPoint, parentFolderId, hidden
7683                                    };
7684                    }
7685                    else {
7686                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_M_P_H;
7687                            finderArgs = new Object[] {
7688                                            groupId, mountPoint, parentFolderId, hidden,
7689                                            
7690                                            start, end, orderByComparator
7691                                    };
7692                    }
7693    
7694                    List<DLFolder> list = (List<DLFolder>)FinderCacheUtil.getResult(finderPath,
7695                                    finderArgs, this);
7696    
7697                    if ((list != null) && !list.isEmpty()) {
7698                            for (DLFolder dlFolder : list) {
7699                                    if ((groupId != dlFolder.getGroupId()) ||
7700                                                    (mountPoint != dlFolder.getMountPoint()) ||
7701                                                    (parentFolderId != dlFolder.getParentFolderId()) ||
7702                                                    (hidden != dlFolder.getHidden())) {
7703                                            list = null;
7704    
7705                                            break;
7706                                    }
7707                            }
7708                    }
7709    
7710                    if (list == null) {
7711                            StringBundler query = null;
7712    
7713                            if (orderByComparator != null) {
7714                                    query = new StringBundler(6 +
7715                                                    (orderByComparator.getOrderByFields().length * 3));
7716                            }
7717                            else {
7718                                    query = new StringBundler(6);
7719                            }
7720    
7721                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
7722    
7723                            query.append(_FINDER_COLUMN_G_M_P_H_GROUPID_2);
7724    
7725                            query.append(_FINDER_COLUMN_G_M_P_H_MOUNTPOINT_2);
7726    
7727                            query.append(_FINDER_COLUMN_G_M_P_H_PARENTFOLDERID_2);
7728    
7729                            query.append(_FINDER_COLUMN_G_M_P_H_HIDDEN_2);
7730    
7731                            if (orderByComparator != null) {
7732                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7733                                            orderByComparator);
7734                            }
7735                            else
7736                             if (pagination) {
7737                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
7738                            }
7739    
7740                            String sql = query.toString();
7741    
7742                            Session session = null;
7743    
7744                            try {
7745                                    session = openSession();
7746    
7747                                    Query q = session.createQuery(sql);
7748    
7749                                    QueryPos qPos = QueryPos.getInstance(q);
7750    
7751                                    qPos.add(groupId);
7752    
7753                                    qPos.add(mountPoint);
7754    
7755                                    qPos.add(parentFolderId);
7756    
7757                                    qPos.add(hidden);
7758    
7759                                    if (!pagination) {
7760                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
7761                                                            start, end, false);
7762    
7763                                            Collections.sort(list);
7764    
7765                                            list = Collections.unmodifiableList(list);
7766                                    }
7767                                    else {
7768                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
7769                                                            start, end);
7770                                    }
7771    
7772                                    cacheResult(list);
7773    
7774                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
7775                            }
7776                            catch (Exception e) {
7777                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
7778    
7779                                    throw processException(e);
7780                            }
7781                            finally {
7782                                    closeSession(session);
7783                            }
7784                    }
7785    
7786                    return list;
7787            }
7788    
7789            /**
7790             * Returns the first document library folder in the ordered set where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63;.
7791             *
7792             * @param groupId the group ID
7793             * @param mountPoint the mount point
7794             * @param parentFolderId the parent folder ID
7795             * @param hidden the hidden
7796             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7797             * @return the first matching document library folder
7798             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
7799             */
7800            @Override
7801            public DLFolder findByG_M_P_H_First(long groupId, boolean mountPoint,
7802                    long parentFolderId, boolean hidden,
7803                    OrderByComparator<DLFolder> orderByComparator)
7804                    throws NoSuchFolderException {
7805                    DLFolder dlFolder = fetchByG_M_P_H_First(groupId, mountPoint,
7806                                    parentFolderId, hidden, orderByComparator);
7807    
7808                    if (dlFolder != null) {
7809                            return dlFolder;
7810                    }
7811    
7812                    StringBundler msg = new StringBundler(10);
7813    
7814                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7815    
7816                    msg.append("groupId=");
7817                    msg.append(groupId);
7818    
7819                    msg.append(", mountPoint=");
7820                    msg.append(mountPoint);
7821    
7822                    msg.append(", parentFolderId=");
7823                    msg.append(parentFolderId);
7824    
7825                    msg.append(", hidden=");
7826                    msg.append(hidden);
7827    
7828                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7829    
7830                    throw new NoSuchFolderException(msg.toString());
7831            }
7832    
7833            /**
7834             * Returns the first document library folder in the ordered set where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63;.
7835             *
7836             * @param groupId the group ID
7837             * @param mountPoint the mount point
7838             * @param parentFolderId the parent folder ID
7839             * @param hidden the hidden
7840             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7841             * @return the first matching document library folder, or <code>null</code> if a matching document library folder could not be found
7842             */
7843            @Override
7844            public DLFolder fetchByG_M_P_H_First(long groupId, boolean mountPoint,
7845                    long parentFolderId, boolean hidden,
7846                    OrderByComparator<DLFolder> orderByComparator) {
7847                    List<DLFolder> list = findByG_M_P_H(groupId, mountPoint,
7848                                    parentFolderId, hidden, 0, 1, orderByComparator);
7849    
7850                    if (!list.isEmpty()) {
7851                            return list.get(0);
7852                    }
7853    
7854                    return null;
7855            }
7856    
7857            /**
7858             * Returns the last document library folder in the ordered set where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63;.
7859             *
7860             * @param groupId the group ID
7861             * @param mountPoint the mount point
7862             * @param parentFolderId the parent folder ID
7863             * @param hidden the hidden
7864             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7865             * @return the last matching document library folder
7866             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
7867             */
7868            @Override
7869            public DLFolder findByG_M_P_H_Last(long groupId, boolean mountPoint,
7870                    long parentFolderId, boolean hidden,
7871                    OrderByComparator<DLFolder> orderByComparator)
7872                    throws NoSuchFolderException {
7873                    DLFolder dlFolder = fetchByG_M_P_H_Last(groupId, mountPoint,
7874                                    parentFolderId, hidden, orderByComparator);
7875    
7876                    if (dlFolder != null) {
7877                            return dlFolder;
7878                    }
7879    
7880                    StringBundler msg = new StringBundler(10);
7881    
7882                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7883    
7884                    msg.append("groupId=");
7885                    msg.append(groupId);
7886    
7887                    msg.append(", mountPoint=");
7888                    msg.append(mountPoint);
7889    
7890                    msg.append(", parentFolderId=");
7891                    msg.append(parentFolderId);
7892    
7893                    msg.append(", hidden=");
7894                    msg.append(hidden);
7895    
7896                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7897    
7898                    throw new NoSuchFolderException(msg.toString());
7899            }
7900    
7901            /**
7902             * Returns the last document library folder in the ordered set where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63;.
7903             *
7904             * @param groupId the group ID
7905             * @param mountPoint the mount point
7906             * @param parentFolderId the parent folder ID
7907             * @param hidden the hidden
7908             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7909             * @return the last matching document library folder, or <code>null</code> if a matching document library folder could not be found
7910             */
7911            @Override
7912            public DLFolder fetchByG_M_P_H_Last(long groupId, boolean mountPoint,
7913                    long parentFolderId, boolean hidden,
7914                    OrderByComparator<DLFolder> orderByComparator) {
7915                    int count = countByG_M_P_H(groupId, mountPoint, parentFolderId, hidden);
7916    
7917                    if (count == 0) {
7918                            return null;
7919                    }
7920    
7921                    List<DLFolder> list = findByG_M_P_H(groupId, mountPoint,
7922                                    parentFolderId, hidden, count - 1, count, orderByComparator);
7923    
7924                    if (!list.isEmpty()) {
7925                            return list.get(0);
7926                    }
7927    
7928                    return null;
7929            }
7930    
7931            /**
7932             * 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;.
7933             *
7934             * @param folderId the primary key of the current document library folder
7935             * @param groupId the group ID
7936             * @param mountPoint the mount point
7937             * @param parentFolderId the parent folder ID
7938             * @param hidden the hidden
7939             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7940             * @return the previous, current, and next document library folder
7941             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
7942             */
7943            @Override
7944            public DLFolder[] findByG_M_P_H_PrevAndNext(long folderId, long groupId,
7945                    boolean mountPoint, long parentFolderId, boolean hidden,
7946                    OrderByComparator<DLFolder> orderByComparator)
7947                    throws NoSuchFolderException {
7948                    DLFolder dlFolder = findByPrimaryKey(folderId);
7949    
7950                    Session session = null;
7951    
7952                    try {
7953                            session = openSession();
7954    
7955                            DLFolder[] array = new DLFolderImpl[3];
7956    
7957                            array[0] = getByG_M_P_H_PrevAndNext(session, dlFolder, groupId,
7958                                            mountPoint, parentFolderId, hidden, orderByComparator, true);
7959    
7960                            array[1] = dlFolder;
7961    
7962                            array[2] = getByG_M_P_H_PrevAndNext(session, dlFolder, groupId,
7963                                            mountPoint, parentFolderId, hidden, orderByComparator, false);
7964    
7965                            return array;
7966                    }
7967                    catch (Exception e) {
7968                            throw processException(e);
7969                    }
7970                    finally {
7971                            closeSession(session);
7972                    }
7973            }
7974    
7975            protected DLFolder getByG_M_P_H_PrevAndNext(Session session,
7976                    DLFolder dlFolder, long groupId, boolean mountPoint,
7977                    long parentFolderId, boolean hidden,
7978                    OrderByComparator<DLFolder> orderByComparator, boolean previous) {
7979                    StringBundler query = null;
7980    
7981                    if (orderByComparator != null) {
7982                            query = new StringBundler(6 +
7983                                            (orderByComparator.getOrderByFields().length * 6));
7984                    }
7985                    else {
7986                            query = new StringBundler(3);
7987                    }
7988    
7989                    query.append(_SQL_SELECT_DLFOLDER_WHERE);
7990    
7991                    query.append(_FINDER_COLUMN_G_M_P_H_GROUPID_2);
7992    
7993                    query.append(_FINDER_COLUMN_G_M_P_H_MOUNTPOINT_2);
7994    
7995                    query.append(_FINDER_COLUMN_G_M_P_H_PARENTFOLDERID_2);
7996    
7997                    query.append(_FINDER_COLUMN_G_M_P_H_HIDDEN_2);
7998    
7999                    if (orderByComparator != null) {
8000                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
8001    
8002                            if (orderByConditionFields.length > 0) {
8003                                    query.append(WHERE_AND);
8004                            }
8005    
8006                            for (int i = 0; i < orderByConditionFields.length; i++) {
8007                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8008                                    query.append(orderByConditionFields[i]);
8009    
8010                                    if ((i + 1) < orderByConditionFields.length) {
8011                                            if (orderByComparator.isAscending() ^ previous) {
8012                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
8013                                            }
8014                                            else {
8015                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
8016                                            }
8017                                    }
8018                                    else {
8019                                            if (orderByComparator.isAscending() ^ previous) {
8020                                                    query.append(WHERE_GREATER_THAN);
8021                                            }
8022                                            else {
8023                                                    query.append(WHERE_LESSER_THAN);
8024                                            }
8025                                    }
8026                            }
8027    
8028                            query.append(ORDER_BY_CLAUSE);
8029    
8030                            String[] orderByFields = orderByComparator.getOrderByFields();
8031    
8032                            for (int i = 0; i < orderByFields.length; i++) {
8033                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8034                                    query.append(orderByFields[i]);
8035    
8036                                    if ((i + 1) < orderByFields.length) {
8037                                            if (orderByComparator.isAscending() ^ previous) {
8038                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
8039                                            }
8040                                            else {
8041                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
8042                                            }
8043                                    }
8044                                    else {
8045                                            if (orderByComparator.isAscending() ^ previous) {
8046                                                    query.append(ORDER_BY_ASC);
8047                                            }
8048                                            else {
8049                                                    query.append(ORDER_BY_DESC);
8050                                            }
8051                                    }
8052                            }
8053                    }
8054                    else {
8055                            query.append(DLFolderModelImpl.ORDER_BY_JPQL);
8056                    }
8057    
8058                    String sql = query.toString();
8059    
8060                    Query q = session.createQuery(sql);
8061    
8062                    q.setFirstResult(0);
8063                    q.setMaxResults(2);
8064    
8065                    QueryPos qPos = QueryPos.getInstance(q);
8066    
8067                    qPos.add(groupId);
8068    
8069                    qPos.add(mountPoint);
8070    
8071                    qPos.add(parentFolderId);
8072    
8073                    qPos.add(hidden);
8074    
8075                    if (orderByComparator != null) {
8076                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
8077    
8078                            for (Object value : values) {
8079                                    qPos.add(value);
8080                            }
8081                    }
8082    
8083                    List<DLFolder> list = q.list();
8084    
8085                    if (list.size() == 2) {
8086                            return list.get(1);
8087                    }
8088                    else {
8089                            return null;
8090                    }
8091            }
8092    
8093            /**
8094             * 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;.
8095             *
8096             * @param groupId the group ID
8097             * @param mountPoint the mount point
8098             * @param parentFolderId the parent folder ID
8099             * @param hidden the hidden
8100             * @return the matching document library folders that the user has permission to view
8101             */
8102            @Override
8103            public List<DLFolder> filterFindByG_M_P_H(long groupId, boolean mountPoint,
8104                    long parentFolderId, boolean hidden) {
8105                    return filterFindByG_M_P_H(groupId, mountPoint, parentFolderId, hidden,
8106                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
8107            }
8108    
8109            /**
8110             * 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;.
8111             *
8112             * <p>
8113             * 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.
8114             * </p>
8115             *
8116             * @param groupId the group ID
8117             * @param mountPoint the mount point
8118             * @param parentFolderId the parent folder ID
8119             * @param hidden the hidden
8120             * @param start the lower bound of the range of document library folders
8121             * @param end the upper bound of the range of document library folders (not inclusive)
8122             * @return the range of matching document library folders that the user has permission to view
8123             */
8124            @Override
8125            public List<DLFolder> filterFindByG_M_P_H(long groupId, boolean mountPoint,
8126                    long parentFolderId, boolean hidden, int start, int end) {
8127                    return filterFindByG_M_P_H(groupId, mountPoint, parentFolderId, hidden,
8128                            start, end, null);
8129            }
8130    
8131            /**
8132             * 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;.
8133             *
8134             * <p>
8135             * 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.
8136             * </p>
8137             *
8138             * @param groupId the group ID
8139             * @param mountPoint the mount point
8140             * @param parentFolderId the parent folder ID
8141             * @param hidden the hidden
8142             * @param start the lower bound of the range of document library folders
8143             * @param end the upper bound of the range of document library folders (not inclusive)
8144             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8145             * @return the ordered range of matching document library folders that the user has permission to view
8146             */
8147            @Override
8148            public List<DLFolder> filterFindByG_M_P_H(long groupId, boolean mountPoint,
8149                    long parentFolderId, boolean hidden, int start, int end,
8150                    OrderByComparator<DLFolder> orderByComparator) {
8151                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8152                            return findByG_M_P_H(groupId, mountPoint, parentFolderId, hidden,
8153                                    start, end, orderByComparator);
8154                    }
8155    
8156                    StringBundler query = null;
8157    
8158                    if (orderByComparator != null) {
8159                            query = new StringBundler(6 +
8160                                            (orderByComparator.getOrderByFields().length * 3));
8161                    }
8162                    else {
8163                            query = new StringBundler(6);
8164                    }
8165    
8166                    if (getDB().isSupportsInlineDistinct()) {
8167                            query.append(_FILTER_SQL_SELECT_DLFOLDER_WHERE);
8168                    }
8169                    else {
8170                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1);
8171                    }
8172    
8173                    query.append(_FINDER_COLUMN_G_M_P_H_GROUPID_2);
8174    
8175                    query.append(_FINDER_COLUMN_G_M_P_H_MOUNTPOINT_2);
8176    
8177                    query.append(_FINDER_COLUMN_G_M_P_H_PARENTFOLDERID_2);
8178    
8179                    query.append(_FINDER_COLUMN_G_M_P_H_HIDDEN_2_SQL);
8180    
8181                    if (!getDB().isSupportsInlineDistinct()) {
8182                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2);
8183                    }
8184    
8185                    if (orderByComparator != null) {
8186                            if (getDB().isSupportsInlineDistinct()) {
8187                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8188                                            orderByComparator, true);
8189                            }
8190                            else {
8191                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
8192                                            orderByComparator, true);
8193                            }
8194                    }
8195                    else {
8196                            if (getDB().isSupportsInlineDistinct()) {
8197                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
8198                            }
8199                            else {
8200                                    query.append(DLFolderModelImpl.ORDER_BY_SQL);
8201                            }
8202                    }
8203    
8204                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8205                                    DLFolder.class.getName(),
8206                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8207    
8208                    Session session = null;
8209    
8210                    try {
8211                            session = openSession();
8212    
8213                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
8214    
8215                            if (getDB().isSupportsInlineDistinct()) {
8216                                    q.addEntity(_FILTER_ENTITY_ALIAS, DLFolderImpl.class);
8217                            }
8218                            else {
8219                                    q.addEntity(_FILTER_ENTITY_TABLE, DLFolderImpl.class);
8220                            }
8221    
8222                            QueryPos qPos = QueryPos.getInstance(q);
8223    
8224                            qPos.add(groupId);
8225    
8226                            qPos.add(mountPoint);
8227    
8228                            qPos.add(parentFolderId);
8229    
8230                            qPos.add(hidden);
8231    
8232                            return (List<DLFolder>)QueryUtil.list(q, getDialect(), start, end);
8233                    }
8234                    catch (Exception e) {
8235                            throw processException(e);
8236                    }
8237                    finally {
8238                            closeSession(session);
8239                    }
8240            }
8241    
8242            /**
8243             * 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;.
8244             *
8245             * @param folderId the primary key of the current document library folder
8246             * @param groupId the group ID
8247             * @param mountPoint the mount point
8248             * @param parentFolderId the parent folder ID
8249             * @param hidden the hidden
8250             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8251             * @return the previous, current, and next document library folder
8252             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
8253             */
8254            @Override
8255            public DLFolder[] filterFindByG_M_P_H_PrevAndNext(long folderId,
8256                    long groupId, boolean mountPoint, long parentFolderId, boolean hidden,
8257                    OrderByComparator<DLFolder> orderByComparator)
8258                    throws NoSuchFolderException {
8259                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8260                            return findByG_M_P_H_PrevAndNext(folderId, groupId, mountPoint,
8261                                    parentFolderId, hidden, orderByComparator);
8262                    }
8263    
8264                    DLFolder dlFolder = findByPrimaryKey(folderId);
8265    
8266                    Session session = null;
8267    
8268                    try {
8269                            session = openSession();
8270    
8271                            DLFolder[] array = new DLFolderImpl[3];
8272    
8273                            array[0] = filterGetByG_M_P_H_PrevAndNext(session, dlFolder,
8274                                            groupId, mountPoint, parentFolderId, hidden,
8275                                            orderByComparator, true);
8276    
8277                            array[1] = dlFolder;
8278    
8279                            array[2] = filterGetByG_M_P_H_PrevAndNext(session, dlFolder,
8280                                            groupId, mountPoint, parentFolderId, hidden,
8281                                            orderByComparator, false);
8282    
8283                            return array;
8284                    }
8285                    catch (Exception e) {
8286                            throw processException(e);
8287                    }
8288                    finally {
8289                            closeSession(session);
8290                    }
8291            }
8292    
8293            protected DLFolder filterGetByG_M_P_H_PrevAndNext(Session session,
8294                    DLFolder dlFolder, long groupId, boolean mountPoint,
8295                    long parentFolderId, boolean hidden,
8296                    OrderByComparator<DLFolder> orderByComparator, boolean previous) {
8297                    StringBundler query = null;
8298    
8299                    if (orderByComparator != null) {
8300                            query = new StringBundler(6 +
8301                                            (orderByComparator.getOrderByFields().length * 6));
8302                    }
8303                    else {
8304                            query = new StringBundler(3);
8305                    }
8306    
8307                    if (getDB().isSupportsInlineDistinct()) {
8308                            query.append(_FILTER_SQL_SELECT_DLFOLDER_WHERE);
8309                    }
8310                    else {
8311                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1);
8312                    }
8313    
8314                    query.append(_FINDER_COLUMN_G_M_P_H_GROUPID_2);
8315    
8316                    query.append(_FINDER_COLUMN_G_M_P_H_MOUNTPOINT_2);
8317    
8318                    query.append(_FINDER_COLUMN_G_M_P_H_PARENTFOLDERID_2);
8319    
8320                    query.append(_FINDER_COLUMN_G_M_P_H_HIDDEN_2_SQL);
8321    
8322                    if (!getDB().isSupportsInlineDistinct()) {
8323                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2);
8324                    }
8325    
8326                    if (orderByComparator != null) {
8327                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
8328    
8329                            if (orderByConditionFields.length > 0) {
8330                                    query.append(WHERE_AND);
8331                            }
8332    
8333                            for (int i = 0; i < orderByConditionFields.length; i++) {
8334                                    if (getDB().isSupportsInlineDistinct()) {
8335                                            query.append(_ORDER_BY_ENTITY_ALIAS);
8336                                    }
8337                                    else {
8338                                            query.append(_ORDER_BY_ENTITY_TABLE);
8339                                    }
8340    
8341                                    query.append(orderByConditionFields[i]);
8342    
8343                                    if ((i + 1) < orderByConditionFields.length) {
8344                                            if (orderByComparator.isAscending() ^ previous) {
8345                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
8346                                            }
8347                                            else {
8348                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
8349                                            }
8350                                    }
8351                                    else {
8352                                            if (orderByComparator.isAscending() ^ previous) {
8353                                                    query.append(WHERE_GREATER_THAN);
8354                                            }
8355                                            else {
8356                                                    query.append(WHERE_LESSER_THAN);
8357                                            }
8358                                    }
8359                            }
8360    
8361                            query.append(ORDER_BY_CLAUSE);
8362    
8363                            String[] orderByFields = orderByComparator.getOrderByFields();
8364    
8365                            for (int i = 0; i < orderByFields.length; i++) {
8366                                    if (getDB().isSupportsInlineDistinct()) {
8367                                            query.append(_ORDER_BY_ENTITY_ALIAS);
8368                                    }
8369                                    else {
8370                                            query.append(_ORDER_BY_ENTITY_TABLE);
8371                                    }
8372    
8373                                    query.append(orderByFields[i]);
8374    
8375                                    if ((i + 1) < orderByFields.length) {
8376                                            if (orderByComparator.isAscending() ^ previous) {
8377                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
8378                                            }
8379                                            else {
8380                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
8381                                            }
8382                                    }
8383                                    else {
8384                                            if (orderByComparator.isAscending() ^ previous) {
8385                                                    query.append(ORDER_BY_ASC);
8386                                            }
8387                                            else {
8388                                                    query.append(ORDER_BY_DESC);
8389                                            }
8390                                    }
8391                            }
8392                    }
8393                    else {
8394                            if (getDB().isSupportsInlineDistinct()) {
8395                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
8396                            }
8397                            else {
8398                                    query.append(DLFolderModelImpl.ORDER_BY_SQL);
8399                            }
8400                    }
8401    
8402                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8403                                    DLFolder.class.getName(),
8404                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8405    
8406                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
8407    
8408                    q.setFirstResult(0);
8409                    q.setMaxResults(2);
8410    
8411                    if (getDB().isSupportsInlineDistinct()) {
8412                            q.addEntity(_FILTER_ENTITY_ALIAS, DLFolderImpl.class);
8413                    }
8414                    else {
8415                            q.addEntity(_FILTER_ENTITY_TABLE, DLFolderImpl.class);
8416                    }
8417    
8418                    QueryPos qPos = QueryPos.getInstance(q);
8419    
8420                    qPos.add(groupId);
8421    
8422                    qPos.add(mountPoint);
8423    
8424                    qPos.add(parentFolderId);
8425    
8426                    qPos.add(hidden);
8427    
8428                    if (orderByComparator != null) {
8429                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
8430    
8431                            for (Object value : values) {
8432                                    qPos.add(value);
8433                            }
8434                    }
8435    
8436                    List<DLFolder> list = q.list();
8437    
8438                    if (list.size() == 2) {
8439                            return list.get(1);
8440                    }
8441                    else {
8442                            return null;
8443                    }
8444            }
8445    
8446            /**
8447             * Removes all the document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63; from the database.
8448             *
8449             * @param groupId the group ID
8450             * @param mountPoint the mount point
8451             * @param parentFolderId the parent folder ID
8452             * @param hidden the hidden
8453             */
8454            @Override
8455            public void removeByG_M_P_H(long groupId, boolean mountPoint,
8456                    long parentFolderId, boolean hidden) {
8457                    for (DLFolder dlFolder : findByG_M_P_H(groupId, mountPoint,
8458                                    parentFolderId, hidden, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
8459                                    null)) {
8460                            remove(dlFolder);
8461                    }
8462            }
8463    
8464            /**
8465             * Returns the number of document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63;.
8466             *
8467             * @param groupId the group ID
8468             * @param mountPoint the mount point
8469             * @param parentFolderId the parent folder ID
8470             * @param hidden the hidden
8471             * @return the number of matching document library folders
8472             */
8473            @Override
8474            public int countByG_M_P_H(long groupId, boolean mountPoint,
8475                    long parentFolderId, boolean hidden) {
8476                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_M_P_H;
8477    
8478                    Object[] finderArgs = new Object[] {
8479                                    groupId, mountPoint, parentFolderId, hidden
8480                            };
8481    
8482                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
8483                                    this);
8484    
8485                    if (count == null) {
8486                            StringBundler query = new StringBundler(5);
8487    
8488                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
8489    
8490                            query.append(_FINDER_COLUMN_G_M_P_H_GROUPID_2);
8491    
8492                            query.append(_FINDER_COLUMN_G_M_P_H_MOUNTPOINT_2);
8493    
8494                            query.append(_FINDER_COLUMN_G_M_P_H_PARENTFOLDERID_2);
8495    
8496                            query.append(_FINDER_COLUMN_G_M_P_H_HIDDEN_2);
8497    
8498                            String sql = query.toString();
8499    
8500                            Session session = null;
8501    
8502                            try {
8503                                    session = openSession();
8504    
8505                                    Query q = session.createQuery(sql);
8506    
8507                                    QueryPos qPos = QueryPos.getInstance(q);
8508    
8509                                    qPos.add(groupId);
8510    
8511                                    qPos.add(mountPoint);
8512    
8513                                    qPos.add(parentFolderId);
8514    
8515                                    qPos.add(hidden);
8516    
8517                                    count = (Long)q.uniqueResult();
8518    
8519                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
8520                            }
8521                            catch (Exception e) {
8522                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
8523    
8524                                    throw processException(e);
8525                            }
8526                            finally {
8527                                    closeSession(session);
8528                            }
8529                    }
8530    
8531                    return count.intValue();
8532            }
8533    
8534            /**
8535             * 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;.
8536             *
8537             * @param groupId the group ID
8538             * @param mountPoint the mount point
8539             * @param parentFolderId the parent folder ID
8540             * @param hidden the hidden
8541             * @return the number of matching document library folders that the user has permission to view
8542             */
8543            @Override
8544            public int filterCountByG_M_P_H(long groupId, boolean mountPoint,
8545                    long parentFolderId, boolean hidden) {
8546                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8547                            return countByG_M_P_H(groupId, mountPoint, parentFolderId, hidden);
8548                    }
8549    
8550                    StringBundler query = new StringBundler(5);
8551    
8552                    query.append(_FILTER_SQL_COUNT_DLFOLDER_WHERE);
8553    
8554                    query.append(_FINDER_COLUMN_G_M_P_H_GROUPID_2);
8555    
8556                    query.append(_FINDER_COLUMN_G_M_P_H_MOUNTPOINT_2);
8557    
8558                    query.append(_FINDER_COLUMN_G_M_P_H_PARENTFOLDERID_2);
8559    
8560                    query.append(_FINDER_COLUMN_G_M_P_H_HIDDEN_2_SQL);
8561    
8562                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8563                                    DLFolder.class.getName(),
8564                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8565    
8566                    Session session = null;
8567    
8568                    try {
8569                            session = openSession();
8570    
8571                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
8572    
8573                            q.addScalar(COUNT_COLUMN_NAME,
8574                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
8575    
8576                            QueryPos qPos = QueryPos.getInstance(q);
8577    
8578                            qPos.add(groupId);
8579    
8580                            qPos.add(mountPoint);
8581    
8582                            qPos.add(parentFolderId);
8583    
8584                            qPos.add(hidden);
8585    
8586                            Long count = (Long)q.uniqueResult();
8587    
8588                            return count.intValue();
8589                    }
8590                    catch (Exception e) {
8591                            throw processException(e);
8592                    }
8593                    finally {
8594                            closeSession(session);
8595                    }
8596            }
8597    
8598            private static final String _FINDER_COLUMN_G_M_P_H_GROUPID_2 = "dlFolder.groupId = ? AND ";
8599            private static final String _FINDER_COLUMN_G_M_P_H_MOUNTPOINT_2 = "dlFolder.mountPoint = ? AND ";
8600            private static final String _FINDER_COLUMN_G_M_P_H_PARENTFOLDERID_2 = "dlFolder.parentFolderId = ? AND ";
8601            private static final String _FINDER_COLUMN_G_M_P_H_HIDDEN_2 = "dlFolder.hidden = ?";
8602            private static final String _FINDER_COLUMN_G_M_P_H_HIDDEN_2_SQL = "dlFolder.hidden_ = ?";
8603            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_H_S = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
8604                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
8605                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_P_H_S",
8606                            new String[] {
8607                                    Long.class.getName(), Long.class.getName(),
8608                                    Boolean.class.getName(), Integer.class.getName(),
8609                                    
8610                            Integer.class.getName(), Integer.class.getName(),
8611                                    OrderByComparator.class.getName()
8612                            });
8613            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_H_S =
8614                    new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
8615                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
8616                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_P_H_S",
8617                            new String[] {
8618                                    Long.class.getName(), Long.class.getName(),
8619                                    Boolean.class.getName(), Integer.class.getName()
8620                            },
8621                            DLFolderModelImpl.GROUPID_COLUMN_BITMASK |
8622                            DLFolderModelImpl.PARENTFOLDERID_COLUMN_BITMASK |
8623                            DLFolderModelImpl.HIDDEN_COLUMN_BITMASK |
8624                            DLFolderModelImpl.STATUS_COLUMN_BITMASK |
8625                            DLFolderModelImpl.NAME_COLUMN_BITMASK);
8626            public static final FinderPath FINDER_PATH_COUNT_BY_G_P_H_S = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
8627                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
8628                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P_H_S",
8629                            new String[] {
8630                                    Long.class.getName(), Long.class.getName(),
8631                                    Boolean.class.getName(), Integer.class.getName()
8632                            });
8633    
8634            /**
8635             * Returns all the document library folders where groupId = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
8636             *
8637             * @param groupId the group ID
8638             * @param parentFolderId the parent folder ID
8639             * @param hidden the hidden
8640             * @param status the status
8641             * @return the matching document library folders
8642             */
8643            @Override
8644            public List<DLFolder> findByG_P_H_S(long groupId, long parentFolderId,
8645                    boolean hidden, int status) {
8646                    return findByG_P_H_S(groupId, parentFolderId, hidden, status,
8647                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
8648            }
8649    
8650            /**
8651             * Returns a range of all the document library folders where groupId = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
8652             *
8653             * <p>
8654             * 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.
8655             * </p>
8656             *
8657             * @param groupId the group ID
8658             * @param parentFolderId the parent folder ID
8659             * @param hidden the hidden
8660             * @param status the status
8661             * @param start the lower bound of the range of document library folders
8662             * @param end the upper bound of the range of document library folders (not inclusive)
8663             * @return the range of matching document library folders
8664             */
8665            @Override
8666            public List<DLFolder> findByG_P_H_S(long groupId, long parentFolderId,
8667                    boolean hidden, int status, int start, int end) {
8668                    return findByG_P_H_S(groupId, parentFolderId, hidden, status, start,
8669                            end, null);
8670            }
8671    
8672            /**
8673             * Returns an ordered range of all the document library folders where groupId = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
8674             *
8675             * <p>
8676             * 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.
8677             * </p>
8678             *
8679             * @param groupId the group ID
8680             * @param parentFolderId the parent folder ID
8681             * @param hidden the hidden
8682             * @param status the status
8683             * @param start the lower bound of the range of document library folders
8684             * @param end the upper bound of the range of document library folders (not inclusive)
8685             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8686             * @return the ordered range of matching document library folders
8687             */
8688            @Override
8689            public List<DLFolder> findByG_P_H_S(long groupId, long parentFolderId,
8690                    boolean hidden, int status, int start, int end,
8691                    OrderByComparator<DLFolder> orderByComparator) {
8692                    boolean pagination = true;
8693                    FinderPath finderPath = null;
8694                    Object[] finderArgs = null;
8695    
8696                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8697                                    (orderByComparator == null)) {
8698                            pagination = false;
8699                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_H_S;
8700                            finderArgs = new Object[] { groupId, parentFolderId, hidden, status };
8701                    }
8702                    else {
8703                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_H_S;
8704                            finderArgs = new Object[] {
8705                                            groupId, parentFolderId, hidden, status,
8706                                            
8707                                            start, end, orderByComparator
8708                                    };
8709                    }
8710    
8711                    List<DLFolder> list = (List<DLFolder>)FinderCacheUtil.getResult(finderPath,
8712                                    finderArgs, this);
8713    
8714                    if ((list != null) && !list.isEmpty()) {
8715                            for (DLFolder dlFolder : list) {
8716                                    if ((groupId != dlFolder.getGroupId()) ||
8717                                                    (parentFolderId != dlFolder.getParentFolderId()) ||
8718                                                    (hidden != dlFolder.getHidden()) ||
8719                                                    (status != dlFolder.getStatus())) {
8720                                            list = null;
8721    
8722                                            break;
8723                                    }
8724                            }
8725                    }
8726    
8727                    if (list == null) {
8728                            StringBundler query = null;
8729    
8730                            if (orderByComparator != null) {
8731                                    query = new StringBundler(6 +
8732                                                    (orderByComparator.getOrderByFields().length * 3));
8733                            }
8734                            else {
8735                                    query = new StringBundler(6);
8736                            }
8737    
8738                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
8739    
8740                            query.append(_FINDER_COLUMN_G_P_H_S_GROUPID_2);
8741    
8742                            query.append(_FINDER_COLUMN_G_P_H_S_PARENTFOLDERID_2);
8743    
8744                            query.append(_FINDER_COLUMN_G_P_H_S_HIDDEN_2);
8745    
8746                            query.append(_FINDER_COLUMN_G_P_H_S_STATUS_2);
8747    
8748                            if (orderByComparator != null) {
8749                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8750                                            orderByComparator);
8751                            }
8752                            else
8753                             if (pagination) {
8754                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
8755                            }
8756    
8757                            String sql = query.toString();
8758    
8759                            Session session = null;
8760    
8761                            try {
8762                                    session = openSession();
8763    
8764                                    Query q = session.createQuery(sql);
8765    
8766                                    QueryPos qPos = QueryPos.getInstance(q);
8767    
8768                                    qPos.add(groupId);
8769    
8770                                    qPos.add(parentFolderId);
8771    
8772                                    qPos.add(hidden);
8773    
8774                                    qPos.add(status);
8775    
8776                                    if (!pagination) {
8777                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
8778                                                            start, end, false);
8779    
8780                                            Collections.sort(list);
8781    
8782                                            list = Collections.unmodifiableList(list);
8783                                    }
8784                                    else {
8785                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
8786                                                            start, end);
8787                                    }
8788    
8789                                    cacheResult(list);
8790    
8791                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
8792                            }
8793                            catch (Exception e) {
8794                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
8795    
8796                                    throw processException(e);
8797                            }
8798                            finally {
8799                                    closeSession(session);
8800                            }
8801                    }
8802    
8803                    return list;
8804            }
8805    
8806            /**
8807             * Returns the first document library folder in the ordered set where groupId = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
8808             *
8809             * @param groupId the group ID
8810             * @param parentFolderId the parent folder ID
8811             * @param hidden the hidden
8812             * @param status the status
8813             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8814             * @return the first matching document library folder
8815             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
8816             */
8817            @Override
8818            public DLFolder findByG_P_H_S_First(long groupId, long parentFolderId,
8819                    boolean hidden, int status,
8820                    OrderByComparator<DLFolder> orderByComparator)
8821                    throws NoSuchFolderException {
8822                    DLFolder dlFolder = fetchByG_P_H_S_First(groupId, parentFolderId,
8823                                    hidden, status, orderByComparator);
8824    
8825                    if (dlFolder != null) {
8826                            return dlFolder;
8827                    }
8828    
8829                    StringBundler msg = new StringBundler(10);
8830    
8831                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8832    
8833                    msg.append("groupId=");
8834                    msg.append(groupId);
8835    
8836                    msg.append(", parentFolderId=");
8837                    msg.append(parentFolderId);
8838    
8839                    msg.append(", hidden=");
8840                    msg.append(hidden);
8841    
8842                    msg.append(", status=");
8843                    msg.append(status);
8844    
8845                    msg.append(StringPool.CLOSE_CURLY_BRACE);
8846    
8847                    throw new NoSuchFolderException(msg.toString());
8848            }
8849    
8850            /**
8851             * Returns the first document library folder in the ordered set where groupId = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
8852             *
8853             * @param groupId the group ID
8854             * @param parentFolderId the parent folder ID
8855             * @param hidden the hidden
8856             * @param status the status
8857             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8858             * @return the first matching document library folder, or <code>null</code> if a matching document library folder could not be found
8859             */
8860            @Override
8861            public DLFolder fetchByG_P_H_S_First(long groupId, long parentFolderId,
8862                    boolean hidden, int status,
8863                    OrderByComparator<DLFolder> orderByComparator) {
8864                    List<DLFolder> list = findByG_P_H_S(groupId, parentFolderId, hidden,
8865                                    status, 0, 1, orderByComparator);
8866    
8867                    if (!list.isEmpty()) {
8868                            return list.get(0);
8869                    }
8870    
8871                    return null;
8872            }
8873    
8874            /**
8875             * Returns the last document library folder in the ordered set where groupId = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
8876             *
8877             * @param groupId the group ID
8878             * @param parentFolderId the parent folder ID
8879             * @param hidden the hidden
8880             * @param status the status
8881             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8882             * @return the last matching document library folder
8883             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
8884             */
8885            @Override
8886            public DLFolder findByG_P_H_S_Last(long groupId, long parentFolderId,
8887                    boolean hidden, int status,
8888                    OrderByComparator<DLFolder> orderByComparator)
8889                    throws NoSuchFolderException {
8890                    DLFolder dlFolder = fetchByG_P_H_S_Last(groupId, parentFolderId,
8891                                    hidden, status, orderByComparator);
8892    
8893                    if (dlFolder != null) {
8894                            return dlFolder;
8895                    }
8896    
8897                    StringBundler msg = new StringBundler(10);
8898    
8899                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8900    
8901                    msg.append("groupId=");
8902                    msg.append(groupId);
8903    
8904                    msg.append(", parentFolderId=");
8905                    msg.append(parentFolderId);
8906    
8907                    msg.append(", hidden=");
8908                    msg.append(hidden);
8909    
8910                    msg.append(", status=");
8911                    msg.append(status);
8912    
8913                    msg.append(StringPool.CLOSE_CURLY_BRACE);
8914    
8915                    throw new NoSuchFolderException(msg.toString());
8916            }
8917    
8918            /**
8919             * Returns the last document library folder in the ordered set where groupId = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
8920             *
8921             * @param groupId the group ID
8922             * @param parentFolderId the parent folder ID
8923             * @param hidden the hidden
8924             * @param status the status
8925             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8926             * @return the last matching document library folder, or <code>null</code> if a matching document library folder could not be found
8927             */
8928            @Override
8929            public DLFolder fetchByG_P_H_S_Last(long groupId, long parentFolderId,
8930                    boolean hidden, int status,
8931                    OrderByComparator<DLFolder> orderByComparator) {
8932                    int count = countByG_P_H_S(groupId, parentFolderId, hidden, status);
8933    
8934                    if (count == 0) {
8935                            return null;
8936                    }
8937    
8938                    List<DLFolder> list = findByG_P_H_S(groupId, parentFolderId, hidden,
8939                                    status, count - 1, count, orderByComparator);
8940    
8941                    if (!list.isEmpty()) {
8942                            return list.get(0);
8943                    }
8944    
8945                    return null;
8946            }
8947    
8948            /**
8949             * 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;.
8950             *
8951             * @param folderId the primary key of the current document library folder
8952             * @param groupId the group ID
8953             * @param parentFolderId the parent folder ID
8954             * @param hidden the hidden
8955             * @param status the status
8956             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8957             * @return the previous, current, and next document library folder
8958             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
8959             */
8960            @Override
8961            public DLFolder[] findByG_P_H_S_PrevAndNext(long folderId, long groupId,
8962                    long parentFolderId, boolean hidden, int status,
8963                    OrderByComparator<DLFolder> orderByComparator)
8964                    throws NoSuchFolderException {
8965                    DLFolder dlFolder = findByPrimaryKey(folderId);
8966    
8967                    Session session = null;
8968    
8969                    try {
8970                            session = openSession();
8971    
8972                            DLFolder[] array = new DLFolderImpl[3];
8973    
8974                            array[0] = getByG_P_H_S_PrevAndNext(session, dlFolder, groupId,
8975                                            parentFolderId, hidden, status, orderByComparator, true);
8976    
8977                            array[1] = dlFolder;
8978    
8979                            array[2] = getByG_P_H_S_PrevAndNext(session, dlFolder, groupId,
8980                                            parentFolderId, hidden, status, orderByComparator, false);
8981    
8982                            return array;
8983                    }
8984                    catch (Exception e) {
8985                            throw processException(e);
8986                    }
8987                    finally {
8988                            closeSession(session);
8989                    }
8990            }
8991    
8992            protected DLFolder getByG_P_H_S_PrevAndNext(Session session,
8993                    DLFolder dlFolder, long groupId, long parentFolderId, boolean hidden,
8994                    int status, OrderByComparator<DLFolder> orderByComparator,
8995                    boolean previous) {
8996                    StringBundler query = null;
8997    
8998                    if (orderByComparator != null) {
8999                            query = new StringBundler(6 +
9000                                            (orderByComparator.getOrderByFields().length * 6));
9001                    }
9002                    else {
9003                            query = new StringBundler(3);
9004                    }
9005    
9006                    query.append(_SQL_SELECT_DLFOLDER_WHERE);
9007    
9008                    query.append(_FINDER_COLUMN_G_P_H_S_GROUPID_2);
9009    
9010                    query.append(_FINDER_COLUMN_G_P_H_S_PARENTFOLDERID_2);
9011    
9012                    query.append(_FINDER_COLUMN_G_P_H_S_HIDDEN_2);
9013    
9014                    query.append(_FINDER_COLUMN_G_P_H_S_STATUS_2);
9015    
9016                    if (orderByComparator != null) {
9017                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
9018    
9019                            if (orderByConditionFields.length > 0) {
9020                                    query.append(WHERE_AND);
9021                            }
9022    
9023                            for (int i = 0; i < orderByConditionFields.length; i++) {
9024                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9025                                    query.append(orderByConditionFields[i]);
9026    
9027                                    if ((i + 1) < orderByConditionFields.length) {
9028                                            if (orderByComparator.isAscending() ^ previous) {
9029                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
9030                                            }
9031                                            else {
9032                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
9033                                            }
9034                                    }
9035                                    else {
9036                                            if (orderByComparator.isAscending() ^ previous) {
9037                                                    query.append(WHERE_GREATER_THAN);
9038                                            }
9039                                            else {
9040                                                    query.append(WHERE_LESSER_THAN);
9041                                            }
9042                                    }
9043                            }
9044    
9045                            query.append(ORDER_BY_CLAUSE);
9046    
9047                            String[] orderByFields = orderByComparator.getOrderByFields();
9048    
9049                            for (int i = 0; i < orderByFields.length; i++) {
9050                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9051                                    query.append(orderByFields[i]);
9052    
9053                                    if ((i + 1) < orderByFields.length) {
9054                                            if (orderByComparator.isAscending() ^ previous) {
9055                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
9056                                            }
9057                                            else {
9058                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
9059                                            }
9060                                    }
9061                                    else {
9062                                            if (orderByComparator.isAscending() ^ previous) {
9063                                                    query.append(ORDER_BY_ASC);
9064                                            }
9065                                            else {
9066                                                    query.append(ORDER_BY_DESC);
9067                                            }
9068                                    }
9069                            }
9070                    }
9071                    else {
9072                            query.append(DLFolderModelImpl.ORDER_BY_JPQL);
9073                    }
9074    
9075                    String sql = query.toString();
9076    
9077                    Query q = session.createQuery(sql);
9078    
9079                    q.setFirstResult(0);
9080                    q.setMaxResults(2);
9081    
9082                    QueryPos qPos = QueryPos.getInstance(q);
9083    
9084                    qPos.add(groupId);
9085    
9086                    qPos.add(parentFolderId);
9087    
9088                    qPos.add(hidden);
9089    
9090                    qPos.add(status);
9091    
9092                    if (orderByComparator != null) {
9093                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
9094    
9095                            for (Object value : values) {
9096                                    qPos.add(value);
9097                            }
9098                    }
9099    
9100                    List<DLFolder> list = q.list();
9101    
9102                    if (list.size() == 2) {
9103                            return list.get(1);
9104                    }
9105                    else {
9106                            return null;
9107                    }
9108            }
9109    
9110            /**
9111             * 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;.
9112             *
9113             * @param groupId the group ID
9114             * @param parentFolderId the parent folder ID
9115             * @param hidden the hidden
9116             * @param status the status
9117             * @return the matching document library folders that the user has permission to view
9118             */
9119            @Override
9120            public List<DLFolder> filterFindByG_P_H_S(long groupId,
9121                    long parentFolderId, boolean hidden, int status) {
9122                    return filterFindByG_P_H_S(groupId, parentFolderId, hidden, status,
9123                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
9124            }
9125    
9126            /**
9127             * 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;.
9128             *
9129             * <p>
9130             * 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.
9131             * </p>
9132             *
9133             * @param groupId the group ID
9134             * @param parentFolderId the parent folder ID
9135             * @param hidden the hidden
9136             * @param status the status
9137             * @param start the lower bound of the range of document library folders
9138             * @param end the upper bound of the range of document library folders (not inclusive)
9139             * @return the range of matching document library folders that the user has permission to view
9140             */
9141            @Override
9142            public List<DLFolder> filterFindByG_P_H_S(long groupId,
9143                    long parentFolderId, boolean hidden, int status, int start, int end) {
9144                    return filterFindByG_P_H_S(groupId, parentFolderId, hidden, status,
9145                            start, end, null);
9146            }
9147    
9148            /**
9149             * 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;.
9150             *
9151             * <p>
9152             * 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.
9153             * </p>
9154             *
9155             * @param groupId the group ID
9156             * @param parentFolderId the parent folder ID
9157             * @param hidden the hidden
9158             * @param status the status
9159             * @param start the lower bound of the range of document library folders
9160             * @param end the upper bound of the range of document library folders (not inclusive)
9161             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9162             * @return the ordered range of matching document library folders that the user has permission to view
9163             */
9164            @Override
9165            public List<DLFolder> filterFindByG_P_H_S(long groupId,
9166                    long parentFolderId, boolean hidden, int status, int start, int end,
9167                    OrderByComparator<DLFolder> orderByComparator) {
9168                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
9169                            return findByG_P_H_S(groupId, parentFolderId, hidden, status,
9170                                    start, end, orderByComparator);
9171                    }
9172    
9173                    StringBundler query = null;
9174    
9175                    if (orderByComparator != null) {
9176                            query = new StringBundler(6 +
9177                                            (orderByComparator.getOrderByFields().length * 3));
9178                    }
9179                    else {
9180                            query = new StringBundler(6);
9181                    }
9182    
9183                    if (getDB().isSupportsInlineDistinct()) {
9184                            query.append(_FILTER_SQL_SELECT_DLFOLDER_WHERE);
9185                    }
9186                    else {
9187                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1);
9188                    }
9189    
9190                    query.append(_FINDER_COLUMN_G_P_H_S_GROUPID_2);
9191    
9192                    query.append(_FINDER_COLUMN_G_P_H_S_PARENTFOLDERID_2);
9193    
9194                    query.append(_FINDER_COLUMN_G_P_H_S_HIDDEN_2_SQL);
9195    
9196                    query.append(_FINDER_COLUMN_G_P_H_S_STATUS_2);
9197    
9198                    if (!getDB().isSupportsInlineDistinct()) {
9199                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2);
9200                    }
9201    
9202                    if (orderByComparator != null) {
9203                            if (getDB().isSupportsInlineDistinct()) {
9204                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9205                                            orderByComparator, true);
9206                            }
9207                            else {
9208                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
9209                                            orderByComparator, true);
9210                            }
9211                    }
9212                    else {
9213                            if (getDB().isSupportsInlineDistinct()) {
9214                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
9215                            }
9216                            else {
9217                                    query.append(DLFolderModelImpl.ORDER_BY_SQL);
9218                            }
9219                    }
9220    
9221                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
9222                                    DLFolder.class.getName(),
9223                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
9224    
9225                    Session session = null;
9226    
9227                    try {
9228                            session = openSession();
9229    
9230                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
9231    
9232                            if (getDB().isSupportsInlineDistinct()) {
9233                                    q.addEntity(_FILTER_ENTITY_ALIAS, DLFolderImpl.class);
9234                            }
9235                            else {
9236                                    q.addEntity(_FILTER_ENTITY_TABLE, DLFolderImpl.class);
9237                            }
9238    
9239                            QueryPos qPos = QueryPos.getInstance(q);
9240    
9241                            qPos.add(groupId);
9242    
9243                            qPos.add(parentFolderId);
9244    
9245                            qPos.add(hidden);
9246    
9247                            qPos.add(status);
9248    
9249                            return (List<DLFolder>)QueryUtil.list(q, getDialect(), start, end);
9250                    }
9251                    catch (Exception e) {
9252                            throw processException(e);
9253                    }
9254                    finally {
9255                            closeSession(session);
9256                    }
9257            }
9258    
9259            /**
9260             * 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;.
9261             *
9262             * @param folderId the primary key of the current document library folder
9263             * @param groupId the group ID
9264             * @param parentFolderId the parent folder ID
9265             * @param hidden the hidden
9266             * @param status the status
9267             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9268             * @return the previous, current, and next document library folder
9269             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
9270             */
9271            @Override
9272            public DLFolder[] filterFindByG_P_H_S_PrevAndNext(long folderId,
9273                    long groupId, long parentFolderId, boolean hidden, int status,
9274                    OrderByComparator<DLFolder> orderByComparator)
9275                    throws NoSuchFolderException {
9276                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
9277                            return findByG_P_H_S_PrevAndNext(folderId, groupId, parentFolderId,
9278                                    hidden, status, orderByComparator);
9279                    }
9280    
9281                    DLFolder dlFolder = findByPrimaryKey(folderId);
9282    
9283                    Session session = null;
9284    
9285                    try {
9286                            session = openSession();
9287    
9288                            DLFolder[] array = new DLFolderImpl[3];
9289    
9290                            array[0] = filterGetByG_P_H_S_PrevAndNext(session, dlFolder,
9291                                            groupId, parentFolderId, hidden, status, orderByComparator,
9292                                            true);
9293    
9294                            array[1] = dlFolder;
9295    
9296                            array[2] = filterGetByG_P_H_S_PrevAndNext(session, dlFolder,
9297                                            groupId, parentFolderId, hidden, status, orderByComparator,
9298                                            false);
9299    
9300                            return array;
9301                    }
9302                    catch (Exception e) {
9303                            throw processException(e);
9304                    }
9305                    finally {
9306                            closeSession(session);
9307                    }
9308            }
9309    
9310            protected DLFolder filterGetByG_P_H_S_PrevAndNext(Session session,
9311                    DLFolder dlFolder, long groupId, long parentFolderId, boolean hidden,
9312                    int status, OrderByComparator<DLFolder> orderByComparator,
9313                    boolean previous) {
9314                    StringBundler query = null;
9315    
9316                    if (orderByComparator != null) {
9317                            query = new StringBundler(6 +
9318                                            (orderByComparator.getOrderByFields().length * 6));
9319                    }
9320                    else {
9321                            query = new StringBundler(3);
9322                    }
9323    
9324                    if (getDB().isSupportsInlineDistinct()) {
9325                            query.append(_FILTER_SQL_SELECT_DLFOLDER_WHERE);
9326                    }
9327                    else {
9328                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1);
9329                    }
9330    
9331                    query.append(_FINDER_COLUMN_G_P_H_S_GROUPID_2);
9332    
9333                    query.append(_FINDER_COLUMN_G_P_H_S_PARENTFOLDERID_2);
9334    
9335                    query.append(_FINDER_COLUMN_G_P_H_S_HIDDEN_2_SQL);
9336    
9337                    query.append(_FINDER_COLUMN_G_P_H_S_STATUS_2);
9338    
9339                    if (!getDB().isSupportsInlineDistinct()) {
9340                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2);
9341                    }
9342    
9343                    if (orderByComparator != null) {
9344                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
9345    
9346                            if (orderByConditionFields.length > 0) {
9347                                    query.append(WHERE_AND);
9348                            }
9349    
9350                            for (int i = 0; i < orderByConditionFields.length; i++) {
9351                                    if (getDB().isSupportsInlineDistinct()) {
9352                                            query.append(_ORDER_BY_ENTITY_ALIAS);
9353                                    }
9354                                    else {
9355                                            query.append(_ORDER_BY_ENTITY_TABLE);
9356                                    }
9357    
9358                                    query.append(orderByConditionFields[i]);
9359    
9360                                    if ((i + 1) < orderByConditionFields.length) {
9361                                            if (orderByComparator.isAscending() ^ previous) {
9362                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
9363                                            }
9364                                            else {
9365                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
9366                                            }
9367                                    }
9368                                    else {
9369                                            if (orderByComparator.isAscending() ^ previous) {
9370                                                    query.append(WHERE_GREATER_THAN);
9371                                            }
9372                                            else {
9373                                                    query.append(WHERE_LESSER_THAN);
9374                                            }
9375                                    }
9376                            }
9377    
9378                            query.append(ORDER_BY_CLAUSE);
9379    
9380                            String[] orderByFields = orderByComparator.getOrderByFields();
9381    
9382                            for (int i = 0; i < orderByFields.length; i++) {
9383                                    if (getDB().isSupportsInlineDistinct()) {
9384                                            query.append(_ORDER_BY_ENTITY_ALIAS);
9385                                    }
9386                                    else {
9387                                            query.append(_ORDER_BY_ENTITY_TABLE);
9388                                    }
9389    
9390                                    query.append(orderByFields[i]);
9391    
9392                                    if ((i + 1) < orderByFields.length) {
9393                                            if (orderByComparator.isAscending() ^ previous) {
9394                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
9395                                            }
9396                                            else {
9397                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
9398                                            }
9399                                    }
9400                                    else {
9401                                            if (orderByComparator.isAscending() ^ previous) {
9402                                                    query.append(ORDER_BY_ASC);
9403                                            }
9404                                            else {
9405                                                    query.append(ORDER_BY_DESC);
9406                                            }
9407                                    }
9408                            }
9409                    }
9410                    else {
9411                            if (getDB().isSupportsInlineDistinct()) {
9412                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
9413                            }
9414                            else {
9415                                    query.append(DLFolderModelImpl.ORDER_BY_SQL);
9416                            }
9417                    }
9418    
9419                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
9420                                    DLFolder.class.getName(),
9421                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
9422    
9423                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
9424    
9425                    q.setFirstResult(0);
9426                    q.setMaxResults(2);
9427    
9428                    if (getDB().isSupportsInlineDistinct()) {
9429                            q.addEntity(_FILTER_ENTITY_ALIAS, DLFolderImpl.class);
9430                    }
9431                    else {
9432                            q.addEntity(_FILTER_ENTITY_TABLE, DLFolderImpl.class);
9433                    }
9434    
9435                    QueryPos qPos = QueryPos.getInstance(q);
9436    
9437                    qPos.add(groupId);
9438    
9439                    qPos.add(parentFolderId);
9440    
9441                    qPos.add(hidden);
9442    
9443                    qPos.add(status);
9444    
9445                    if (orderByComparator != null) {
9446                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
9447    
9448                            for (Object value : values) {
9449                                    qPos.add(value);
9450                            }
9451                    }
9452    
9453                    List<DLFolder> list = q.list();
9454    
9455                    if (list.size() == 2) {
9456                            return list.get(1);
9457                    }
9458                    else {
9459                            return null;
9460                    }
9461            }
9462    
9463            /**
9464             * Removes all the document library folders where groupId = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63; from the database.
9465             *
9466             * @param groupId the group ID
9467             * @param parentFolderId the parent folder ID
9468             * @param hidden the hidden
9469             * @param status the status
9470             */
9471            @Override
9472            public void removeByG_P_H_S(long groupId, long parentFolderId,
9473                    boolean hidden, int status) {
9474                    for (DLFolder dlFolder : findByG_P_H_S(groupId, parentFolderId, hidden,
9475                                    status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
9476                            remove(dlFolder);
9477                    }
9478            }
9479    
9480            /**
9481             * Returns the number of document library folders where groupId = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
9482             *
9483             * @param groupId the group ID
9484             * @param parentFolderId the parent folder ID
9485             * @param hidden the hidden
9486             * @param status the status
9487             * @return the number of matching document library folders
9488             */
9489            @Override
9490            public int countByG_P_H_S(long groupId, long parentFolderId,
9491                    boolean hidden, int status) {
9492                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_P_H_S;
9493    
9494                    Object[] finderArgs = new Object[] {
9495                                    groupId, parentFolderId, hidden, status
9496                            };
9497    
9498                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
9499                                    this);
9500    
9501                    if (count == null) {
9502                            StringBundler query = new StringBundler(5);
9503    
9504                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
9505    
9506                            query.append(_FINDER_COLUMN_G_P_H_S_GROUPID_2);
9507    
9508                            query.append(_FINDER_COLUMN_G_P_H_S_PARENTFOLDERID_2);
9509    
9510                            query.append(_FINDER_COLUMN_G_P_H_S_HIDDEN_2);
9511    
9512                            query.append(_FINDER_COLUMN_G_P_H_S_STATUS_2);
9513    
9514                            String sql = query.toString();
9515    
9516                            Session session = null;
9517    
9518                            try {
9519                                    session = openSession();
9520    
9521                                    Query q = session.createQuery(sql);
9522    
9523                                    QueryPos qPos = QueryPos.getInstance(q);
9524    
9525                                    qPos.add(groupId);
9526    
9527                                    qPos.add(parentFolderId);
9528    
9529                                    qPos.add(hidden);
9530    
9531                                    qPos.add(status);
9532    
9533                                    count = (Long)q.uniqueResult();
9534    
9535                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
9536                            }
9537                            catch (Exception e) {
9538                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
9539    
9540                                    throw processException(e);
9541                            }
9542                            finally {
9543                                    closeSession(session);
9544                            }
9545                    }
9546    
9547                    return count.intValue();
9548            }
9549    
9550            /**
9551             * 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;.
9552             *
9553             * @param groupId the group ID
9554             * @param parentFolderId the parent folder ID
9555             * @param hidden the hidden
9556             * @param status the status
9557             * @return the number of matching document library folders that the user has permission to view
9558             */
9559            @Override
9560            public int filterCountByG_P_H_S(long groupId, long parentFolderId,
9561                    boolean hidden, int status) {
9562                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
9563                            return countByG_P_H_S(groupId, parentFolderId, hidden, status);
9564                    }
9565    
9566                    StringBundler query = new StringBundler(5);
9567    
9568                    query.append(_FILTER_SQL_COUNT_DLFOLDER_WHERE);
9569    
9570                    query.append(_FINDER_COLUMN_G_P_H_S_GROUPID_2);
9571    
9572                    query.append(_FINDER_COLUMN_G_P_H_S_PARENTFOLDERID_2);
9573    
9574                    query.append(_FINDER_COLUMN_G_P_H_S_HIDDEN_2_SQL);
9575    
9576                    query.append(_FINDER_COLUMN_G_P_H_S_STATUS_2);
9577    
9578                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
9579                                    DLFolder.class.getName(),
9580                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
9581    
9582                    Session session = null;
9583    
9584                    try {
9585                            session = openSession();
9586    
9587                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
9588    
9589                            q.addScalar(COUNT_COLUMN_NAME,
9590                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
9591    
9592                            QueryPos qPos = QueryPos.getInstance(q);
9593    
9594                            qPos.add(groupId);
9595    
9596                            qPos.add(parentFolderId);
9597    
9598                            qPos.add(hidden);
9599    
9600                            qPos.add(status);
9601    
9602                            Long count = (Long)q.uniqueResult();
9603    
9604                            return count.intValue();
9605                    }
9606                    catch (Exception e) {
9607                            throw processException(e);
9608                    }
9609                    finally {
9610                            closeSession(session);
9611                    }
9612            }
9613    
9614            private static final String _FINDER_COLUMN_G_P_H_S_GROUPID_2 = "dlFolder.groupId = ? AND ";
9615            private static final String _FINDER_COLUMN_G_P_H_S_PARENTFOLDERID_2 = "dlFolder.parentFolderId = ? AND ";
9616            private static final String _FINDER_COLUMN_G_P_H_S_HIDDEN_2 = "dlFolder.hidden = ? AND ";
9617            private static final String _FINDER_COLUMN_G_P_H_S_HIDDEN_2_SQL = "dlFolder.hidden_ = ? AND ";
9618            private static final String _FINDER_COLUMN_G_P_H_S_STATUS_2 = "dlFolder.status = ?";
9619            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_M_P_H_S =
9620                    new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
9621                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
9622                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_M_P_H_S",
9623                            new String[] {
9624                                    Long.class.getName(), Boolean.class.getName(),
9625                                    Long.class.getName(), Boolean.class.getName(),
9626                                    Integer.class.getName(),
9627                                    
9628                            Integer.class.getName(), Integer.class.getName(),
9629                                    OrderByComparator.class.getName()
9630                            });
9631            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P_H_S =
9632                    new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
9633                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
9634                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_M_P_H_S",
9635                            new String[] {
9636                                    Long.class.getName(), Boolean.class.getName(),
9637                                    Long.class.getName(), Boolean.class.getName(),
9638                                    Integer.class.getName()
9639                            },
9640                            DLFolderModelImpl.GROUPID_COLUMN_BITMASK |
9641                            DLFolderModelImpl.MOUNTPOINT_COLUMN_BITMASK |
9642                            DLFolderModelImpl.PARENTFOLDERID_COLUMN_BITMASK |
9643                            DLFolderModelImpl.HIDDEN_COLUMN_BITMASK |
9644                            DLFolderModelImpl.STATUS_COLUMN_BITMASK |
9645                            DLFolderModelImpl.NAME_COLUMN_BITMASK);
9646            public static final FinderPath FINDER_PATH_COUNT_BY_G_M_P_H_S = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
9647                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
9648                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_M_P_H_S",
9649                            new String[] {
9650                                    Long.class.getName(), Boolean.class.getName(),
9651                                    Long.class.getName(), Boolean.class.getName(),
9652                                    Integer.class.getName()
9653                            });
9654    
9655            /**
9656             * Returns all the document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
9657             *
9658             * @param groupId the group ID
9659             * @param mountPoint the mount point
9660             * @param parentFolderId the parent folder ID
9661             * @param hidden the hidden
9662             * @param status the status
9663             * @return the matching document library folders
9664             */
9665            @Override
9666            public List<DLFolder> findByG_M_P_H_S(long groupId, boolean mountPoint,
9667                    long parentFolderId, boolean hidden, int status) {
9668                    return findByG_M_P_H_S(groupId, mountPoint, parentFolderId, hidden,
9669                            status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
9670            }
9671    
9672            /**
9673             * Returns a range of all the document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
9674             *
9675             * <p>
9676             * 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.
9677             * </p>
9678             *
9679             * @param groupId the group ID
9680             * @param mountPoint the mount point
9681             * @param parentFolderId the parent folder ID
9682             * @param hidden the hidden
9683             * @param status the status
9684             * @param start the lower bound of the range of document library folders
9685             * @param end the upper bound of the range of document library folders (not inclusive)
9686             * @return the range of matching document library folders
9687             */
9688            @Override
9689            public List<DLFolder> findByG_M_P_H_S(long groupId, boolean mountPoint,
9690                    long parentFolderId, boolean hidden, int status, int start, int end) {
9691                    return findByG_M_P_H_S(groupId, mountPoint, parentFolderId, hidden,
9692                            status, start, end, null);
9693            }
9694    
9695            /**
9696             * 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;.
9697             *
9698             * <p>
9699             * 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.
9700             * </p>
9701             *
9702             * @param groupId the group ID
9703             * @param mountPoint the mount point
9704             * @param parentFolderId the parent folder ID
9705             * @param hidden the hidden
9706             * @param status the status
9707             * @param start the lower bound of the range of document library folders
9708             * @param end the upper bound of the range of document library folders (not inclusive)
9709             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9710             * @return the ordered range of matching document library folders
9711             */
9712            @Override
9713            public List<DLFolder> findByG_M_P_H_S(long groupId, boolean mountPoint,
9714                    long parentFolderId, boolean hidden, int status, int start, int end,
9715                    OrderByComparator<DLFolder> orderByComparator) {
9716                    boolean pagination = true;
9717                    FinderPath finderPath = null;
9718                    Object[] finderArgs = null;
9719    
9720                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
9721                                    (orderByComparator == null)) {
9722                            pagination = false;
9723                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P_H_S;
9724                            finderArgs = new Object[] {
9725                                            groupId, mountPoint, parentFolderId, hidden, status
9726                                    };
9727                    }
9728                    else {
9729                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_M_P_H_S;
9730                            finderArgs = new Object[] {
9731                                            groupId, mountPoint, parentFolderId, hidden, status,
9732                                            
9733                                            start, end, orderByComparator
9734                                    };
9735                    }
9736    
9737                    List<DLFolder> list = (List<DLFolder>)FinderCacheUtil.getResult(finderPath,
9738                                    finderArgs, this);
9739    
9740                    if ((list != null) && !list.isEmpty()) {
9741                            for (DLFolder dlFolder : list) {
9742                                    if ((groupId != dlFolder.getGroupId()) ||
9743                                                    (mountPoint != dlFolder.getMountPoint()) ||
9744                                                    (parentFolderId != dlFolder.getParentFolderId()) ||
9745                                                    (hidden != dlFolder.getHidden()) ||
9746                                                    (status != dlFolder.getStatus())) {
9747                                            list = null;
9748    
9749                                            break;
9750                                    }
9751                            }
9752                    }
9753    
9754                    if (list == null) {
9755                            StringBundler query = null;
9756    
9757                            if (orderByComparator != null) {
9758                                    query = new StringBundler(7 +
9759                                                    (orderByComparator.getOrderByFields().length * 3));
9760                            }
9761                            else {
9762                                    query = new StringBundler(7);
9763                            }
9764    
9765                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
9766    
9767                            query.append(_FINDER_COLUMN_G_M_P_H_S_GROUPID_2);
9768    
9769                            query.append(_FINDER_COLUMN_G_M_P_H_S_MOUNTPOINT_2);
9770    
9771                            query.append(_FINDER_COLUMN_G_M_P_H_S_PARENTFOLDERID_2);
9772    
9773                            query.append(_FINDER_COLUMN_G_M_P_H_S_HIDDEN_2);
9774    
9775                            query.append(_FINDER_COLUMN_G_M_P_H_S_STATUS_2);
9776    
9777                            if (orderByComparator != null) {
9778                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9779                                            orderByComparator);
9780                            }
9781                            else
9782                             if (pagination) {
9783                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
9784                            }
9785    
9786                            String sql = query.toString();
9787    
9788                            Session session = null;
9789    
9790                            try {
9791                                    session = openSession();
9792    
9793                                    Query q = session.createQuery(sql);
9794    
9795                                    QueryPos qPos = QueryPos.getInstance(q);
9796    
9797                                    qPos.add(groupId);
9798    
9799                                    qPos.add(mountPoint);
9800    
9801                                    qPos.add(parentFolderId);
9802    
9803                                    qPos.add(hidden);
9804    
9805                                    qPos.add(status);
9806    
9807                                    if (!pagination) {
9808                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
9809                                                            start, end, false);
9810    
9811                                            Collections.sort(list);
9812    
9813                                            list = Collections.unmodifiableList(list);
9814                                    }
9815                                    else {
9816                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
9817                                                            start, end);
9818                                    }
9819    
9820                                    cacheResult(list);
9821    
9822                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
9823                            }
9824                            catch (Exception e) {
9825                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
9826    
9827                                    throw processException(e);
9828                            }
9829                            finally {
9830                                    closeSession(session);
9831                            }
9832                    }
9833    
9834                    return list;
9835            }
9836    
9837            /**
9838             * 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;.
9839             *
9840             * @param groupId the group ID
9841             * @param mountPoint the mount point
9842             * @param parentFolderId the parent folder ID
9843             * @param hidden the hidden
9844             * @param status the status
9845             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9846             * @return the first matching document library folder
9847             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
9848             */
9849            @Override
9850            public DLFolder findByG_M_P_H_S_First(long groupId, boolean mountPoint,
9851                    long parentFolderId, boolean hidden, int status,
9852                    OrderByComparator<DLFolder> orderByComparator)
9853                    throws NoSuchFolderException {
9854                    DLFolder dlFolder = fetchByG_M_P_H_S_First(groupId, mountPoint,
9855                                    parentFolderId, hidden, status, orderByComparator);
9856    
9857                    if (dlFolder != null) {
9858                            return dlFolder;
9859                    }
9860    
9861                    StringBundler msg = new StringBundler(12);
9862    
9863                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9864    
9865                    msg.append("groupId=");
9866                    msg.append(groupId);
9867    
9868                    msg.append(", mountPoint=");
9869                    msg.append(mountPoint);
9870    
9871                    msg.append(", parentFolderId=");
9872                    msg.append(parentFolderId);
9873    
9874                    msg.append(", hidden=");
9875                    msg.append(hidden);
9876    
9877                    msg.append(", status=");
9878                    msg.append(status);
9879    
9880                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9881    
9882                    throw new NoSuchFolderException(msg.toString());
9883            }
9884    
9885            /**
9886             * 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;.
9887             *
9888             * @param groupId the group ID
9889             * @param mountPoint the mount point
9890             * @param parentFolderId the parent folder ID
9891             * @param hidden the hidden
9892             * @param status the status
9893             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9894             * @return the first matching document library folder, or <code>null</code> if a matching document library folder could not be found
9895             */
9896            @Override
9897            public DLFolder fetchByG_M_P_H_S_First(long groupId, boolean mountPoint,
9898                    long parentFolderId, boolean hidden, int status,
9899                    OrderByComparator<DLFolder> orderByComparator) {
9900                    List<DLFolder> list = findByG_M_P_H_S(groupId, mountPoint,
9901                                    parentFolderId, hidden, status, 0, 1, orderByComparator);
9902    
9903                    if (!list.isEmpty()) {
9904                            return list.get(0);
9905                    }
9906    
9907                    return null;
9908            }
9909    
9910            /**
9911             * 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;.
9912             *
9913             * @param groupId the group ID
9914             * @param mountPoint the mount point
9915             * @param parentFolderId the parent folder ID
9916             * @param hidden the hidden
9917             * @param status the status
9918             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9919             * @return the last matching document library folder
9920             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
9921             */
9922            @Override
9923            public DLFolder findByG_M_P_H_S_Last(long groupId, boolean mountPoint,
9924                    long parentFolderId, boolean hidden, int status,
9925                    OrderByComparator<DLFolder> orderByComparator)
9926                    throws NoSuchFolderException {
9927                    DLFolder dlFolder = fetchByG_M_P_H_S_Last(groupId, mountPoint,
9928                                    parentFolderId, hidden, status, orderByComparator);
9929    
9930                    if (dlFolder != null) {
9931                            return dlFolder;
9932                    }
9933    
9934                    StringBundler msg = new StringBundler(12);
9935    
9936                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9937    
9938                    msg.append("groupId=");
9939                    msg.append(groupId);
9940    
9941                    msg.append(", mountPoint=");
9942                    msg.append(mountPoint);
9943    
9944                    msg.append(", parentFolderId=");
9945                    msg.append(parentFolderId);
9946    
9947                    msg.append(", hidden=");
9948                    msg.append(hidden);
9949    
9950                    msg.append(", status=");
9951                    msg.append(status);
9952    
9953                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9954    
9955                    throw new NoSuchFolderException(msg.toString());
9956            }
9957    
9958            /**
9959             * 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;.
9960             *
9961             * @param groupId the group ID
9962             * @param mountPoint the mount point
9963             * @param parentFolderId the parent folder ID
9964             * @param hidden the hidden
9965             * @param status the status
9966             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9967             * @return the last matching document library folder, or <code>null</code> if a matching document library folder could not be found
9968             */
9969            @Override
9970            public DLFolder fetchByG_M_P_H_S_Last(long groupId, boolean mountPoint,
9971                    long parentFolderId, boolean hidden, int status,
9972                    OrderByComparator<DLFolder> orderByComparator) {
9973                    int count = countByG_M_P_H_S(groupId, mountPoint, parentFolderId,
9974                                    hidden, status);
9975    
9976                    if (count == 0) {
9977                            return null;
9978                    }
9979    
9980                    List<DLFolder> list = findByG_M_P_H_S(groupId, mountPoint,
9981                                    parentFolderId, hidden, status, count - 1, count,
9982                                    orderByComparator);
9983    
9984                    if (!list.isEmpty()) {
9985                            return list.get(0);
9986                    }
9987    
9988                    return null;
9989            }
9990    
9991            /**
9992             * 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;.
9993             *
9994             * @param folderId the primary key of the current document library folder
9995             * @param groupId the group ID
9996             * @param mountPoint the mount point
9997             * @param parentFolderId the parent folder ID
9998             * @param hidden the hidden
9999             * @param status the status
10000             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10001             * @return the previous, current, and next document library folder
10002             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
10003             */
10004            @Override
10005            public DLFolder[] findByG_M_P_H_S_PrevAndNext(long folderId, long groupId,
10006                    boolean mountPoint, long parentFolderId, boolean hidden, int status,
10007                    OrderByComparator<DLFolder> orderByComparator)
10008                    throws NoSuchFolderException {
10009                    DLFolder dlFolder = findByPrimaryKey(folderId);
10010    
10011                    Session session = null;
10012    
10013                    try {
10014                            session = openSession();
10015    
10016                            DLFolder[] array = new DLFolderImpl[3];
10017    
10018                            array[0] = getByG_M_P_H_S_PrevAndNext(session, dlFolder, groupId,
10019                                            mountPoint, parentFolderId, hidden, status,
10020                                            orderByComparator, true);
10021    
10022                            array[1] = dlFolder;
10023    
10024                            array[2] = getByG_M_P_H_S_PrevAndNext(session, dlFolder, groupId,
10025                                            mountPoint, parentFolderId, hidden, status,
10026                                            orderByComparator, false);
10027    
10028                            return array;
10029                    }
10030                    catch (Exception e) {
10031                            throw processException(e);
10032                    }
10033                    finally {
10034                            closeSession(session);
10035                    }
10036            }
10037    
10038            protected DLFolder getByG_M_P_H_S_PrevAndNext(Session session,
10039                    DLFolder dlFolder, long groupId, boolean mountPoint,
10040                    long parentFolderId, boolean hidden, int status,
10041                    OrderByComparator<DLFolder> orderByComparator, boolean previous) {
10042                    StringBundler query = null;
10043    
10044                    if (orderByComparator != null) {
10045                            query = new StringBundler(6 +
10046                                            (orderByComparator.getOrderByFields().length * 6));
10047                    }
10048                    else {
10049                            query = new StringBundler(3);
10050                    }
10051    
10052                    query.append(_SQL_SELECT_DLFOLDER_WHERE);
10053    
10054                    query.append(_FINDER_COLUMN_G_M_P_H_S_GROUPID_2);
10055    
10056                    query.append(_FINDER_COLUMN_G_M_P_H_S_MOUNTPOINT_2);
10057    
10058                    query.append(_FINDER_COLUMN_G_M_P_H_S_PARENTFOLDERID_2);
10059    
10060                    query.append(_FINDER_COLUMN_G_M_P_H_S_HIDDEN_2);
10061    
10062                    query.append(_FINDER_COLUMN_G_M_P_H_S_STATUS_2);
10063    
10064                    if (orderByComparator != null) {
10065                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
10066    
10067                            if (orderByConditionFields.length > 0) {
10068                                    query.append(WHERE_AND);
10069                            }
10070    
10071                            for (int i = 0; i < orderByConditionFields.length; i++) {
10072                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10073                                    query.append(orderByConditionFields[i]);
10074    
10075                                    if ((i + 1) < orderByConditionFields.length) {
10076                                            if (orderByComparator.isAscending() ^ previous) {
10077                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
10078                                            }
10079                                            else {
10080                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
10081                                            }
10082                                    }
10083                                    else {
10084                                            if (orderByComparator.isAscending() ^ previous) {
10085                                                    query.append(WHERE_GREATER_THAN);
10086                                            }
10087                                            else {
10088                                                    query.append(WHERE_LESSER_THAN);
10089                                            }
10090                                    }
10091                            }
10092    
10093                            query.append(ORDER_BY_CLAUSE);
10094    
10095                            String[] orderByFields = orderByComparator.getOrderByFields();
10096    
10097                            for (int i = 0; i < orderByFields.length; i++) {
10098                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10099                                    query.append(orderByFields[i]);
10100    
10101                                    if ((i + 1) < orderByFields.length) {
10102                                            if (orderByComparator.isAscending() ^ previous) {
10103                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
10104                                            }
10105                                            else {
10106                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
10107                                            }
10108                                    }
10109                                    else {
10110                                            if (orderByComparator.isAscending() ^ previous) {
10111                                                    query.append(ORDER_BY_ASC);
10112                                            }
10113                                            else {
10114                                                    query.append(ORDER_BY_DESC);
10115                                            }
10116                                    }
10117                            }
10118                    }
10119                    else {
10120                            query.append(DLFolderModelImpl.ORDER_BY_JPQL);
10121                    }
10122    
10123                    String sql = query.toString();
10124    
10125                    Query q = session.createQuery(sql);
10126    
10127                    q.setFirstResult(0);
10128                    q.setMaxResults(2);
10129    
10130                    QueryPos qPos = QueryPos.getInstance(q);
10131    
10132                    qPos.add(groupId);
10133    
10134                    qPos.add(mountPoint);
10135    
10136                    qPos.add(parentFolderId);
10137    
10138                    qPos.add(hidden);
10139    
10140                    qPos.add(status);
10141    
10142                    if (orderByComparator != null) {
10143                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
10144    
10145                            for (Object value : values) {
10146                                    qPos.add(value);
10147                            }
10148                    }
10149    
10150                    List<DLFolder> list = q.list();
10151    
10152                    if (list.size() == 2) {
10153                            return list.get(1);
10154                    }
10155                    else {
10156                            return null;
10157                    }
10158            }
10159    
10160            /**
10161             * 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;.
10162             *
10163             * @param groupId the group ID
10164             * @param mountPoint the mount point
10165             * @param parentFolderId the parent folder ID
10166             * @param hidden the hidden
10167             * @param status the status
10168             * @return the matching document library folders that the user has permission to view
10169             */
10170            @Override
10171            public List<DLFolder> filterFindByG_M_P_H_S(long groupId,
10172                    boolean mountPoint, long parentFolderId, boolean hidden, int status) {
10173                    return filterFindByG_M_P_H_S(groupId, mountPoint, parentFolderId,
10174                            hidden, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
10175            }
10176    
10177            /**
10178             * 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;.
10179             *
10180             * <p>
10181             * 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.
10182             * </p>
10183             *
10184             * @param groupId the group ID
10185             * @param mountPoint the mount point
10186             * @param parentFolderId the parent folder ID
10187             * @param hidden the hidden
10188             * @param status the status
10189             * @param start the lower bound of the range of document library folders
10190             * @param end the upper bound of the range of document library folders (not inclusive)
10191             * @return the range of matching document library folders that the user has permission to view
10192             */
10193            @Override
10194            public List<DLFolder> filterFindByG_M_P_H_S(long groupId,
10195                    boolean mountPoint, long parentFolderId, boolean hidden, int status,
10196                    int start, int end) {
10197                    return filterFindByG_M_P_H_S(groupId, mountPoint, parentFolderId,
10198                            hidden, status, start, end, null);
10199            }
10200    
10201            /**
10202             * 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;.
10203             *
10204             * <p>
10205             * 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.
10206             * </p>
10207             *
10208             * @param groupId the group ID
10209             * @param mountPoint the mount point
10210             * @param parentFolderId the parent folder ID
10211             * @param hidden the hidden
10212             * @param status the status
10213             * @param start the lower bound of the range of document library folders
10214             * @param end the upper bound of the range of document library folders (not inclusive)
10215             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10216             * @return the ordered range of matching document library folders that the user has permission to view
10217             */
10218            @Override
10219            public List<DLFolder> filterFindByG_M_P_H_S(long groupId,
10220                    boolean mountPoint, long parentFolderId, boolean hidden, int status,
10221                    int start, int end, OrderByComparator<DLFolder> orderByComparator) {
10222                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
10223                            return findByG_M_P_H_S(groupId, mountPoint, parentFolderId, hidden,
10224                                    status, start, end, orderByComparator);
10225                    }
10226    
10227                    StringBundler query = null;
10228    
10229                    if (orderByComparator != null) {
10230                            query = new StringBundler(7 +
10231                                            (orderByComparator.getOrderByFields().length * 3));
10232                    }
10233                    else {
10234                            query = new StringBundler(7);
10235                    }
10236    
10237                    if (getDB().isSupportsInlineDistinct()) {
10238                            query.append(_FILTER_SQL_SELECT_DLFOLDER_WHERE);
10239                    }
10240                    else {
10241                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1);
10242                    }
10243    
10244                    query.append(_FINDER_COLUMN_G_M_P_H_S_GROUPID_2);
10245    
10246                    query.append(_FINDER_COLUMN_G_M_P_H_S_MOUNTPOINT_2);
10247    
10248                    query.append(_FINDER_COLUMN_G_M_P_H_S_PARENTFOLDERID_2);
10249    
10250                    query.append(_FINDER_COLUMN_G_M_P_H_S_HIDDEN_2_SQL);
10251    
10252                    query.append(_FINDER_COLUMN_G_M_P_H_S_STATUS_2);
10253    
10254                    if (!getDB().isSupportsInlineDistinct()) {
10255                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2);
10256                    }
10257    
10258                    if (orderByComparator != null) {
10259                            if (getDB().isSupportsInlineDistinct()) {
10260                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10261                                            orderByComparator, true);
10262                            }
10263                            else {
10264                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
10265                                            orderByComparator, true);
10266                            }
10267                    }
10268                    else {
10269                            if (getDB().isSupportsInlineDistinct()) {
10270                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
10271                            }
10272                            else {
10273                                    query.append(DLFolderModelImpl.ORDER_BY_SQL);
10274                            }
10275                    }
10276    
10277                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
10278                                    DLFolder.class.getName(),
10279                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
10280    
10281                    Session session = null;
10282    
10283                    try {
10284                            session = openSession();
10285    
10286                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
10287    
10288                            if (getDB().isSupportsInlineDistinct()) {
10289                                    q.addEntity(_FILTER_ENTITY_ALIAS, DLFolderImpl.class);
10290                            }
10291                            else {
10292                                    q.addEntity(_FILTER_ENTITY_TABLE, DLFolderImpl.class);
10293                            }
10294    
10295                            QueryPos qPos = QueryPos.getInstance(q);
10296    
10297                            qPos.add(groupId);
10298    
10299                            qPos.add(mountPoint);
10300    
10301                            qPos.add(parentFolderId);
10302    
10303                            qPos.add(hidden);
10304    
10305                            qPos.add(status);
10306    
10307                            return (List<DLFolder>)QueryUtil.list(q, getDialect(), start, end);
10308                    }
10309                    catch (Exception e) {
10310                            throw processException(e);
10311                    }
10312                    finally {
10313                            closeSession(session);
10314                    }
10315            }
10316    
10317            /**
10318             * 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;.
10319             *
10320             * @param folderId the primary key of the current document library folder
10321             * @param groupId the group ID
10322             * @param mountPoint the mount point
10323             * @param parentFolderId the parent folder ID
10324             * @param hidden the hidden
10325             * @param status the status
10326             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10327             * @return the previous, current, and next document library folder
10328             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
10329             */
10330            @Override
10331            public DLFolder[] filterFindByG_M_P_H_S_PrevAndNext(long folderId,
10332                    long groupId, boolean mountPoint, long parentFolderId, boolean hidden,
10333                    int status, OrderByComparator<DLFolder> orderByComparator)
10334                    throws NoSuchFolderException {
10335                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
10336                            return findByG_M_P_H_S_PrevAndNext(folderId, groupId, mountPoint,
10337                                    parentFolderId, hidden, status, orderByComparator);
10338                    }
10339    
10340                    DLFolder dlFolder = findByPrimaryKey(folderId);
10341    
10342                    Session session = null;
10343    
10344                    try {
10345                            session = openSession();
10346    
10347                            DLFolder[] array = new DLFolderImpl[3];
10348    
10349                            array[0] = filterGetByG_M_P_H_S_PrevAndNext(session, dlFolder,
10350                                            groupId, mountPoint, parentFolderId, hidden, status,
10351                                            orderByComparator, true);
10352    
10353                            array[1] = dlFolder;
10354    
10355                            array[2] = filterGetByG_M_P_H_S_PrevAndNext(session, dlFolder,
10356                                            groupId, mountPoint, parentFolderId, hidden, status,
10357                                            orderByComparator, false);
10358    
10359                            return array;
10360                    }
10361                    catch (Exception e) {
10362                            throw processException(e);
10363                    }
10364                    finally {
10365                            closeSession(session);
10366                    }
10367            }
10368    
10369            protected DLFolder filterGetByG_M_P_H_S_PrevAndNext(Session session,
10370                    DLFolder dlFolder, long groupId, boolean mountPoint,
10371                    long parentFolderId, boolean hidden, int status,
10372                    OrderByComparator<DLFolder> orderByComparator, boolean previous) {
10373                    StringBundler query = null;
10374    
10375                    if (orderByComparator != null) {
10376                            query = new StringBundler(6 +
10377                                            (orderByComparator.getOrderByFields().length * 6));
10378                    }
10379                    else {
10380                            query = new StringBundler(3);
10381                    }
10382    
10383                    if (getDB().isSupportsInlineDistinct()) {
10384                            query.append(_FILTER_SQL_SELECT_DLFOLDER_WHERE);
10385                    }
10386                    else {
10387                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1);
10388                    }
10389    
10390                    query.append(_FINDER_COLUMN_G_M_P_H_S_GROUPID_2);
10391    
10392                    query.append(_FINDER_COLUMN_G_M_P_H_S_MOUNTPOINT_2);
10393    
10394                    query.append(_FINDER_COLUMN_G_M_P_H_S_PARENTFOLDERID_2);
10395    
10396                    query.append(_FINDER_COLUMN_G_M_P_H_S_HIDDEN_2_SQL);
10397    
10398                    query.append(_FINDER_COLUMN_G_M_P_H_S_STATUS_2);
10399    
10400                    if (!getDB().isSupportsInlineDistinct()) {
10401                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2);
10402                    }
10403    
10404                    if (orderByComparator != null) {
10405                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
10406    
10407                            if (orderByConditionFields.length > 0) {
10408                                    query.append(WHERE_AND);
10409                            }
10410    
10411                            for (int i = 0; i < orderByConditionFields.length; i++) {
10412                                    if (getDB().isSupportsInlineDistinct()) {
10413                                            query.append(_ORDER_BY_ENTITY_ALIAS);
10414                                    }
10415                                    else {
10416                                            query.append(_ORDER_BY_ENTITY_TABLE);
10417                                    }
10418    
10419                                    query.append(orderByConditionFields[i]);
10420    
10421                                    if ((i + 1) < orderByConditionFields.length) {
10422                                            if (orderByComparator.isAscending() ^ previous) {
10423                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
10424                                            }
10425                                            else {
10426                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
10427                                            }
10428                                    }
10429                                    else {
10430                                            if (orderByComparator.isAscending() ^ previous) {
10431                                                    query.append(WHERE_GREATER_THAN);
10432                                            }
10433                                            else {
10434                                                    query.append(WHERE_LESSER_THAN);
10435                                            }
10436                                    }
10437                            }
10438    
10439                            query.append(ORDER_BY_CLAUSE);
10440    
10441                            String[] orderByFields = orderByComparator.getOrderByFields();
10442    
10443                            for (int i = 0; i < orderByFields.length; i++) {
10444                                    if (getDB().isSupportsInlineDistinct()) {
10445                                            query.append(_ORDER_BY_ENTITY_ALIAS);
10446                                    }
10447                                    else {
10448                                            query.append(_ORDER_BY_ENTITY_TABLE);
10449                                    }
10450    
10451                                    query.append(orderByFields[i]);
10452    
10453                                    if ((i + 1) < orderByFields.length) {
10454                                            if (orderByComparator.isAscending() ^ previous) {
10455                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
10456                                            }
10457                                            else {
10458                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
10459                                            }
10460                                    }
10461                                    else {
10462                                            if (orderByComparator.isAscending() ^ previous) {
10463                                                    query.append(ORDER_BY_ASC);
10464                                            }
10465                                            else {
10466                                                    query.append(ORDER_BY_DESC);
10467                                            }
10468                                    }
10469                            }
10470                    }
10471                    else {
10472                            if (getDB().isSupportsInlineDistinct()) {
10473                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
10474                            }
10475                            else {
10476                                    query.append(DLFolderModelImpl.ORDER_BY_SQL);
10477                            }
10478                    }
10479    
10480                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
10481                                    DLFolder.class.getName(),
10482                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
10483    
10484                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
10485    
10486                    q.setFirstResult(0);
10487                    q.setMaxResults(2);
10488    
10489                    if (getDB().isSupportsInlineDistinct()) {
10490                            q.addEntity(_FILTER_ENTITY_ALIAS, DLFolderImpl.class);
10491                    }
10492                    else {
10493                            q.addEntity(_FILTER_ENTITY_TABLE, DLFolderImpl.class);
10494                    }
10495    
10496                    QueryPos qPos = QueryPos.getInstance(q);
10497    
10498                    qPos.add(groupId);
10499    
10500                    qPos.add(mountPoint);
10501    
10502                    qPos.add(parentFolderId);
10503    
10504                    qPos.add(hidden);
10505    
10506                    qPos.add(status);
10507    
10508                    if (orderByComparator != null) {
10509                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
10510    
10511                            for (Object value : values) {
10512                                    qPos.add(value);
10513                            }
10514                    }
10515    
10516                    List<DLFolder> list = q.list();
10517    
10518                    if (list.size() == 2) {
10519                            return list.get(1);
10520                    }
10521                    else {
10522                            return null;
10523                    }
10524            }
10525    
10526            /**
10527             * Removes all the document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63; from the database.
10528             *
10529             * @param groupId the group ID
10530             * @param mountPoint the mount point
10531             * @param parentFolderId the parent folder ID
10532             * @param hidden the hidden
10533             * @param status the status
10534             */
10535            @Override
10536            public void removeByG_M_P_H_S(long groupId, boolean mountPoint,
10537                    long parentFolderId, boolean hidden, int status) {
10538                    for (DLFolder dlFolder : findByG_M_P_H_S(groupId, mountPoint,
10539                                    parentFolderId, hidden, status, QueryUtil.ALL_POS,
10540                                    QueryUtil.ALL_POS, null)) {
10541                            remove(dlFolder);
10542                    }
10543            }
10544    
10545            /**
10546             * Returns the number of document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
10547             *
10548             * @param groupId the group ID
10549             * @param mountPoint the mount point
10550             * @param parentFolderId the parent folder ID
10551             * @param hidden the hidden
10552             * @param status the status
10553             * @return the number of matching document library folders
10554             */
10555            @Override
10556            public int countByG_M_P_H_S(long groupId, boolean mountPoint,
10557                    long parentFolderId, boolean hidden, int status) {
10558                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_M_P_H_S;
10559    
10560                    Object[] finderArgs = new Object[] {
10561                                    groupId, mountPoint, parentFolderId, hidden, status
10562                            };
10563    
10564                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
10565                                    this);
10566    
10567                    if (count == null) {
10568                            StringBundler query = new StringBundler(6);
10569    
10570                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
10571    
10572                            query.append(_FINDER_COLUMN_G_M_P_H_S_GROUPID_2);
10573    
10574                            query.append(_FINDER_COLUMN_G_M_P_H_S_MOUNTPOINT_2);
10575    
10576                            query.append(_FINDER_COLUMN_G_M_P_H_S_PARENTFOLDERID_2);
10577    
10578                            query.append(_FINDER_COLUMN_G_M_P_H_S_HIDDEN_2);
10579    
10580                            query.append(_FINDER_COLUMN_G_M_P_H_S_STATUS_2);
10581    
10582                            String sql = query.toString();
10583    
10584                            Session session = null;
10585    
10586                            try {
10587                                    session = openSession();
10588    
10589                                    Query q = session.createQuery(sql);
10590    
10591                                    QueryPos qPos = QueryPos.getInstance(q);
10592    
10593                                    qPos.add(groupId);
10594    
10595                                    qPos.add(mountPoint);
10596    
10597                                    qPos.add(parentFolderId);
10598    
10599                                    qPos.add(hidden);
10600    
10601                                    qPos.add(status);
10602    
10603                                    count = (Long)q.uniqueResult();
10604    
10605                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
10606                            }
10607                            catch (Exception e) {
10608                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
10609    
10610                                    throw processException(e);
10611                            }
10612                            finally {
10613                                    closeSession(session);
10614                            }
10615                    }
10616    
10617                    return count.intValue();
10618            }
10619    
10620            /**
10621             * 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;.
10622             *
10623             * @param groupId the group ID
10624             * @param mountPoint the mount point
10625             * @param parentFolderId the parent folder ID
10626             * @param hidden the hidden
10627             * @param status the status
10628             * @return the number of matching document library folders that the user has permission to view
10629             */
10630            @Override
10631            public int filterCountByG_M_P_H_S(long groupId, boolean mountPoint,
10632                    long parentFolderId, boolean hidden, int status) {
10633                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
10634                            return countByG_M_P_H_S(groupId, mountPoint, parentFolderId,
10635                                    hidden, status);
10636                    }
10637    
10638                    StringBundler query = new StringBundler(6);
10639    
10640                    query.append(_FILTER_SQL_COUNT_DLFOLDER_WHERE);
10641    
10642                    query.append(_FINDER_COLUMN_G_M_P_H_S_GROUPID_2);
10643    
10644                    query.append(_FINDER_COLUMN_G_M_P_H_S_MOUNTPOINT_2);
10645    
10646                    query.append(_FINDER_COLUMN_G_M_P_H_S_PARENTFOLDERID_2);
10647    
10648                    query.append(_FINDER_COLUMN_G_M_P_H_S_HIDDEN_2_SQL);
10649    
10650                    query.append(_FINDER_COLUMN_G_M_P_H_S_STATUS_2);
10651    
10652                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
10653                                    DLFolder.class.getName(),
10654                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
10655    
10656                    Session session = null;
10657    
10658                    try {
10659                            session = openSession();
10660    
10661                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
10662    
10663                            q.addScalar(COUNT_COLUMN_NAME,
10664                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
10665    
10666                            QueryPos qPos = QueryPos.getInstance(q);
10667    
10668                            qPos.add(groupId);
10669    
10670                            qPos.add(mountPoint);
10671    
10672                            qPos.add(parentFolderId);
10673    
10674                            qPos.add(hidden);
10675    
10676                            qPos.add(status);
10677    
10678                            Long count = (Long)q.uniqueResult();
10679    
10680                            return count.intValue();
10681                    }
10682                    catch (Exception e) {
10683                            throw processException(e);
10684                    }
10685                    finally {
10686                            closeSession(session);
10687                    }
10688            }
10689    
10690            private static final String _FINDER_COLUMN_G_M_P_H_S_GROUPID_2 = "dlFolder.groupId = ? AND ";
10691            private static final String _FINDER_COLUMN_G_M_P_H_S_MOUNTPOINT_2 = "dlFolder.mountPoint = ? AND ";
10692            private static final String _FINDER_COLUMN_G_M_P_H_S_PARENTFOLDERID_2 = "dlFolder.parentFolderId = ? AND ";
10693            private static final String _FINDER_COLUMN_G_M_P_H_S_HIDDEN_2 = "dlFolder.hidden = ? AND ";
10694            private static final String _FINDER_COLUMN_G_M_P_H_S_HIDDEN_2_SQL = "dlFolder.hidden_ = ? AND ";
10695            private static final String _FINDER_COLUMN_G_M_P_H_S_STATUS_2 = "dlFolder.status = ?";
10696    
10697            public DLFolderPersistenceImpl() {
10698                    setModelClass(DLFolder.class);
10699            }
10700    
10701            /**
10702             * Caches the document library folder in the entity cache if it is enabled.
10703             *
10704             * @param dlFolder the document library folder
10705             */
10706            @Override
10707            public void cacheResult(DLFolder dlFolder) {
10708                    EntityCacheUtil.putResult(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
10709                            DLFolderImpl.class, dlFolder.getPrimaryKey(), dlFolder);
10710    
10711                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
10712                            new Object[] { dlFolder.getUuid(), dlFolder.getGroupId() }, dlFolder);
10713    
10714                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_M,
10715                            new Object[] { dlFolder.getRepositoryId(), dlFolder.getMountPoint() },
10716                            dlFolder);
10717    
10718                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_N,
10719                            new Object[] {
10720                                    dlFolder.getGroupId(), dlFolder.getParentFolderId(),
10721                                    dlFolder.getName()
10722                            }, dlFolder);
10723    
10724                    dlFolder.resetOriginalValues();
10725            }
10726    
10727            /**
10728             * Caches the document library folders in the entity cache if it is enabled.
10729             *
10730             * @param dlFolders the document library folders
10731             */
10732            @Override
10733            public void cacheResult(List<DLFolder> dlFolders) {
10734                    for (DLFolder dlFolder : dlFolders) {
10735                            if (EntityCacheUtil.getResult(
10736                                                    DLFolderModelImpl.ENTITY_CACHE_ENABLED,
10737                                                    DLFolderImpl.class, dlFolder.getPrimaryKey()) == null) {
10738                                    cacheResult(dlFolder);
10739                            }
10740                            else {
10741                                    dlFolder.resetOriginalValues();
10742                            }
10743                    }
10744            }
10745    
10746            /**
10747             * Clears the cache for all document library folders.
10748             *
10749             * <p>
10750             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
10751             * </p>
10752             */
10753            @Override
10754            public void clearCache() {
10755                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
10756                            CacheRegistryUtil.clear(DLFolderImpl.class.getName());
10757                    }
10758    
10759                    EntityCacheUtil.clearCache(DLFolderImpl.class);
10760    
10761                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
10762                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
10763                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
10764            }
10765    
10766            /**
10767             * Clears the cache for the document library folder.
10768             *
10769             * <p>
10770             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
10771             * </p>
10772             */
10773            @Override
10774            public void clearCache(DLFolder dlFolder) {
10775                    EntityCacheUtil.removeResult(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
10776                            DLFolderImpl.class, dlFolder.getPrimaryKey());
10777    
10778                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
10779                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
10780    
10781                    clearUniqueFindersCache(dlFolder);
10782            }
10783    
10784            @Override
10785            public void clearCache(List<DLFolder> dlFolders) {
10786                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
10787                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
10788    
10789                    for (DLFolder dlFolder : dlFolders) {
10790                            EntityCacheUtil.removeResult(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
10791                                    DLFolderImpl.class, dlFolder.getPrimaryKey());
10792    
10793                            clearUniqueFindersCache(dlFolder);
10794                    }
10795            }
10796    
10797            protected void cacheUniqueFindersCache(DLFolder dlFolder) {
10798                    if (dlFolder.isNew()) {
10799                            Object[] args = new Object[] {
10800                                            dlFolder.getUuid(), dlFolder.getGroupId()
10801                                    };
10802    
10803                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
10804                                    Long.valueOf(1));
10805                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
10806                                    dlFolder);
10807    
10808                            args = new Object[] {
10809                                            dlFolder.getRepositoryId(), dlFolder.getMountPoint()
10810                                    };
10811    
10812                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_R_M, args,
10813                                    Long.valueOf(1));
10814                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_M, args, dlFolder);
10815    
10816                            args = new Object[] {
10817                                            dlFolder.getGroupId(), dlFolder.getParentFolderId(),
10818                                            dlFolder.getName()
10819                                    };
10820    
10821                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_P_N, args,
10822                                    Long.valueOf(1));
10823                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_N, args, dlFolder);
10824                    }
10825                    else {
10826                            DLFolderModelImpl dlFolderModelImpl = (DLFolderModelImpl)dlFolder;
10827    
10828                            if ((dlFolderModelImpl.getColumnBitmask() &
10829                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
10830                                    Object[] args = new Object[] {
10831                                                    dlFolder.getUuid(), dlFolder.getGroupId()
10832                                            };
10833    
10834                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
10835                                            Long.valueOf(1));
10836                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
10837                                            dlFolder);
10838                            }
10839    
10840                            if ((dlFolderModelImpl.getColumnBitmask() &
10841                                            FINDER_PATH_FETCH_BY_R_M.getColumnBitmask()) != 0) {
10842                                    Object[] args = new Object[] {
10843                                                    dlFolder.getRepositoryId(), dlFolder.getMountPoint()
10844                                            };
10845    
10846                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_R_M, args,
10847                                            Long.valueOf(1));
10848                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_M, args,
10849                                            dlFolder);
10850                            }
10851    
10852                            if ((dlFolderModelImpl.getColumnBitmask() &
10853                                            FINDER_PATH_FETCH_BY_G_P_N.getColumnBitmask()) != 0) {
10854                                    Object[] args = new Object[] {
10855                                                    dlFolder.getGroupId(), dlFolder.getParentFolderId(),
10856                                                    dlFolder.getName()
10857                                            };
10858    
10859                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_P_N, args,
10860                                            Long.valueOf(1));
10861                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_N, args,
10862                                            dlFolder);
10863                            }
10864                    }
10865            }
10866    
10867            protected void clearUniqueFindersCache(DLFolder dlFolder) {
10868                    DLFolderModelImpl dlFolderModelImpl = (DLFolderModelImpl)dlFolder;
10869    
10870                    Object[] args = new Object[] { dlFolder.getUuid(), dlFolder.getGroupId() };
10871    
10872                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
10873                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
10874    
10875                    if ((dlFolderModelImpl.getColumnBitmask() &
10876                                    FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
10877                            args = new Object[] {
10878                                            dlFolderModelImpl.getOriginalUuid(),
10879                                            dlFolderModelImpl.getOriginalGroupId()
10880                                    };
10881    
10882                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
10883                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
10884                    }
10885    
10886                    args = new Object[] { dlFolder.getRepositoryId(), dlFolder.getMountPoint() };
10887    
10888                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_M, args);
10889                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_R_M, args);
10890    
10891                    if ((dlFolderModelImpl.getColumnBitmask() &
10892                                    FINDER_PATH_FETCH_BY_R_M.getColumnBitmask()) != 0) {
10893                            args = new Object[] {
10894                                            dlFolderModelImpl.getOriginalRepositoryId(),
10895                                            dlFolderModelImpl.getOriginalMountPoint()
10896                                    };
10897    
10898                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_M, args);
10899                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_R_M, args);
10900                    }
10901    
10902                    args = new Object[] {
10903                                    dlFolder.getGroupId(), dlFolder.getParentFolderId(),
10904                                    dlFolder.getName()
10905                            };
10906    
10907                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_N, args);
10908                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P_N, args);
10909    
10910                    if ((dlFolderModelImpl.getColumnBitmask() &
10911                                    FINDER_PATH_FETCH_BY_G_P_N.getColumnBitmask()) != 0) {
10912                            args = new Object[] {
10913                                            dlFolderModelImpl.getOriginalGroupId(),
10914                                            dlFolderModelImpl.getOriginalParentFolderId(),
10915                                            dlFolderModelImpl.getOriginalName()
10916                                    };
10917    
10918                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_N, args);
10919                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P_N, args);
10920                    }
10921            }
10922    
10923            /**
10924             * Creates a new document library folder with the primary key. Does not add the document library folder to the database.
10925             *
10926             * @param folderId the primary key for the new document library folder
10927             * @return the new document library folder
10928             */
10929            @Override
10930            public DLFolder create(long folderId) {
10931                    DLFolder dlFolder = new DLFolderImpl();
10932    
10933                    dlFolder.setNew(true);
10934                    dlFolder.setPrimaryKey(folderId);
10935    
10936                    String uuid = PortalUUIDUtil.generate();
10937    
10938                    dlFolder.setUuid(uuid);
10939    
10940                    return dlFolder;
10941            }
10942    
10943            /**
10944             * Removes the document library folder with the primary key from the database. Also notifies the appropriate model listeners.
10945             *
10946             * @param folderId the primary key of the document library folder
10947             * @return the document library folder that was removed
10948             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
10949             */
10950            @Override
10951            public DLFolder remove(long folderId) throws NoSuchFolderException {
10952                    return remove((Serializable)folderId);
10953            }
10954    
10955            /**
10956             * Removes the document library folder with the primary key from the database. Also notifies the appropriate model listeners.
10957             *
10958             * @param primaryKey the primary key of the document library folder
10959             * @return the document library folder that was removed
10960             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
10961             */
10962            @Override
10963            public DLFolder remove(Serializable primaryKey)
10964                    throws NoSuchFolderException {
10965                    Session session = null;
10966    
10967                    try {
10968                            session = openSession();
10969    
10970                            DLFolder dlFolder = (DLFolder)session.get(DLFolderImpl.class,
10971                                            primaryKey);
10972    
10973                            if (dlFolder == null) {
10974                                    if (_log.isWarnEnabled()) {
10975                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
10976                                    }
10977    
10978                                    throw new NoSuchFolderException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
10979                                            primaryKey);
10980                            }
10981    
10982                            return remove(dlFolder);
10983                    }
10984                    catch (NoSuchFolderException nsee) {
10985                            throw nsee;
10986                    }
10987                    catch (Exception e) {
10988                            throw processException(e);
10989                    }
10990                    finally {
10991                            closeSession(session);
10992                    }
10993            }
10994    
10995            @Override
10996            protected DLFolder removeImpl(DLFolder dlFolder) {
10997                    dlFolder = toUnwrappedModel(dlFolder);
10998    
10999                    dlFolderToDLFileEntryTypeTableMapper.deleteLeftPrimaryKeyTableMappings(dlFolder.getPrimaryKey());
11000    
11001                    Session session = null;
11002    
11003                    try {
11004                            session = openSession();
11005    
11006                            if (!session.contains(dlFolder)) {
11007                                    dlFolder = (DLFolder)session.get(DLFolderImpl.class,
11008                                                    dlFolder.getPrimaryKeyObj());
11009                            }
11010    
11011                            if (dlFolder != null) {
11012                                    session.delete(dlFolder);
11013                            }
11014                    }
11015                    catch (Exception e) {
11016                            throw processException(e);
11017                    }
11018                    finally {
11019                            closeSession(session);
11020                    }
11021    
11022                    if (dlFolder != null) {
11023                            clearCache(dlFolder);
11024                    }
11025    
11026                    return dlFolder;
11027            }
11028    
11029            @Override
11030            public DLFolder updateImpl(
11031                    com.liferay.portlet.documentlibrary.model.DLFolder dlFolder) {
11032                    dlFolder = toUnwrappedModel(dlFolder);
11033    
11034                    boolean isNew = dlFolder.isNew();
11035    
11036                    DLFolderModelImpl dlFolderModelImpl = (DLFolderModelImpl)dlFolder;
11037    
11038                    if (Validator.isNull(dlFolder.getUuid())) {
11039                            String uuid = PortalUUIDUtil.generate();
11040    
11041                            dlFolder.setUuid(uuid);
11042                    }
11043    
11044                    Session session = null;
11045    
11046                    try {
11047                            session = openSession();
11048    
11049                            if (dlFolder.isNew()) {
11050                                    session.save(dlFolder);
11051    
11052                                    dlFolder.setNew(false);
11053                            }
11054                            else {
11055                                    session.merge(dlFolder);
11056                            }
11057                    }
11058                    catch (Exception e) {
11059                            throw processException(e);
11060                    }
11061                    finally {
11062                            closeSession(session);
11063                    }
11064    
11065                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
11066    
11067                    if (isNew || !DLFolderModelImpl.COLUMN_BITMASK_ENABLED) {
11068                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
11069                    }
11070    
11071                    else {
11072                            if ((dlFolderModelImpl.getColumnBitmask() &
11073                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
11074                                    Object[] args = new Object[] { dlFolderModelImpl.getOriginalUuid() };
11075    
11076                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
11077                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
11078                                            args);
11079    
11080                                    args = new Object[] { dlFolderModelImpl.getUuid() };
11081    
11082                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
11083                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
11084                                            args);
11085                            }
11086    
11087                            if ((dlFolderModelImpl.getColumnBitmask() &
11088                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
11089                                    Object[] args = new Object[] {
11090                                                    dlFolderModelImpl.getOriginalUuid(),
11091                                                    dlFolderModelImpl.getOriginalCompanyId()
11092                                            };
11093    
11094                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
11095                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
11096                                            args);
11097    
11098                                    args = new Object[] {
11099                                                    dlFolderModelImpl.getUuid(),
11100                                                    dlFolderModelImpl.getCompanyId()
11101                                            };
11102    
11103                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
11104                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
11105                                            args);
11106                            }
11107    
11108                            if ((dlFolderModelImpl.getColumnBitmask() &
11109                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
11110                                    Object[] args = new Object[] {
11111                                                    dlFolderModelImpl.getOriginalGroupId()
11112                                            };
11113    
11114                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
11115                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
11116                                            args);
11117    
11118                                    args = new Object[] { dlFolderModelImpl.getGroupId() };
11119    
11120                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
11121                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
11122                                            args);
11123                            }
11124    
11125                            if ((dlFolderModelImpl.getColumnBitmask() &
11126                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
11127                                    Object[] args = new Object[] {
11128                                                    dlFolderModelImpl.getOriginalCompanyId()
11129                                            };
11130    
11131                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
11132                                            args);
11133                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
11134                                            args);
11135    
11136                                    args = new Object[] { dlFolderModelImpl.getCompanyId() };
11137    
11138                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
11139                                            args);
11140                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
11141                                            args);
11142                            }
11143    
11144                            if ((dlFolderModelImpl.getColumnBitmask() &
11145                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_REPOSITORYID.getColumnBitmask()) != 0) {
11146                                    Object[] args = new Object[] {
11147                                                    dlFolderModelImpl.getOriginalRepositoryId()
11148                                            };
11149    
11150                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_REPOSITORYID,
11151                                            args);
11152                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_REPOSITORYID,
11153                                            args);
11154    
11155                                    args = new Object[] { dlFolderModelImpl.getRepositoryId() };
11156    
11157                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_REPOSITORYID,
11158                                            args);
11159                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_REPOSITORYID,
11160                                            args);
11161                            }
11162    
11163                            if ((dlFolderModelImpl.getColumnBitmask() &
11164                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P.getColumnBitmask()) != 0) {
11165                                    Object[] args = new Object[] {
11166                                                    dlFolderModelImpl.getOriginalGroupId(),
11167                                                    dlFolderModelImpl.getOriginalParentFolderId()
11168                                            };
11169    
11170                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P, args);
11171                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P,
11172                                            args);
11173    
11174                                    args = new Object[] {
11175                                                    dlFolderModelImpl.getGroupId(),
11176                                                    dlFolderModelImpl.getParentFolderId()
11177                                            };
11178    
11179                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P, args);
11180                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P,
11181                                            args);
11182                            }
11183    
11184                            if ((dlFolderModelImpl.getColumnBitmask() &
11185                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_P.getColumnBitmask()) != 0) {
11186                                    Object[] args = new Object[] {
11187                                                    dlFolderModelImpl.getOriginalRepositoryId(),
11188                                                    dlFolderModelImpl.getOriginalParentFolderId()
11189                                            };
11190    
11191                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_P, args);
11192                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_P,
11193                                            args);
11194    
11195                                    args = new Object[] {
11196                                                    dlFolderModelImpl.getRepositoryId(),
11197                                                    dlFolderModelImpl.getParentFolderId()
11198                                            };
11199    
11200                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_P, args);
11201                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_P,
11202                                            args);
11203                            }
11204    
11205                            if ((dlFolderModelImpl.getColumnBitmask() &
11206                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_N.getColumnBitmask()) != 0) {
11207                                    Object[] args = new Object[] {
11208                                                    dlFolderModelImpl.getOriginalParentFolderId(),
11209                                                    dlFolderModelImpl.getOriginalName()
11210                                            };
11211    
11212                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_P_N, args);
11213                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_N,
11214                                            args);
11215    
11216                                    args = new Object[] {
11217                                                    dlFolderModelImpl.getParentFolderId(),
11218                                                    dlFolderModelImpl.getName()
11219                                            };
11220    
11221                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_P_N, args);
11222                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_N,
11223                                            args);
11224                            }
11225    
11226                            if ((dlFolderModelImpl.getColumnBitmask() &
11227                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P.getColumnBitmask()) != 0) {
11228                                    Object[] args = new Object[] {
11229                                                    dlFolderModelImpl.getOriginalGroupId(),
11230                                                    dlFolderModelImpl.getOriginalMountPoint(),
11231                                                    dlFolderModelImpl.getOriginalParentFolderId()
11232                                            };
11233    
11234                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_M_P, args);
11235                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P,
11236                                            args);
11237    
11238                                    args = new Object[] {
11239                                                    dlFolderModelImpl.getGroupId(),
11240                                                    dlFolderModelImpl.getMountPoint(),
11241                                                    dlFolderModelImpl.getParentFolderId()
11242                                            };
11243    
11244                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_M_P, args);
11245                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P,
11246                                            args);
11247                            }
11248    
11249                            if ((dlFolderModelImpl.getColumnBitmask() &
11250                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P_H.getColumnBitmask()) != 0) {
11251                                    Object[] args = new Object[] {
11252                                                    dlFolderModelImpl.getOriginalGroupId(),
11253                                                    dlFolderModelImpl.getOriginalMountPoint(),
11254                                                    dlFolderModelImpl.getOriginalParentFolderId(),
11255                                                    dlFolderModelImpl.getOriginalHidden()
11256                                            };
11257    
11258                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_M_P_H, args);
11259                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P_H,
11260                                            args);
11261    
11262                                    args = new Object[] {
11263                                                    dlFolderModelImpl.getGroupId(),
11264                                                    dlFolderModelImpl.getMountPoint(),
11265                                                    dlFolderModelImpl.getParentFolderId(),
11266                                                    dlFolderModelImpl.getHidden()
11267                                            };
11268    
11269                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_M_P_H, args);
11270                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P_H,
11271                                            args);
11272                            }
11273    
11274                            if ((dlFolderModelImpl.getColumnBitmask() &
11275                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_H_S.getColumnBitmask()) != 0) {
11276                                    Object[] args = new Object[] {
11277                                                    dlFolderModelImpl.getOriginalGroupId(),
11278                                                    dlFolderModelImpl.getOriginalParentFolderId(),
11279                                                    dlFolderModelImpl.getOriginalHidden(),
11280                                                    dlFolderModelImpl.getOriginalStatus()
11281                                            };
11282    
11283                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_H_S, args);
11284                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_H_S,
11285                                            args);
11286    
11287                                    args = new Object[] {
11288                                                    dlFolderModelImpl.getGroupId(),
11289                                                    dlFolderModelImpl.getParentFolderId(),
11290                                                    dlFolderModelImpl.getHidden(),
11291                                                    dlFolderModelImpl.getStatus()
11292                                            };
11293    
11294                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_H_S, args);
11295                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_H_S,
11296                                            args);
11297                            }
11298    
11299                            if ((dlFolderModelImpl.getColumnBitmask() &
11300                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P_H_S.getColumnBitmask()) != 0) {
11301                                    Object[] args = new Object[] {
11302                                                    dlFolderModelImpl.getOriginalGroupId(),
11303                                                    dlFolderModelImpl.getOriginalMountPoint(),
11304                                                    dlFolderModelImpl.getOriginalParentFolderId(),
11305                                                    dlFolderModelImpl.getOriginalHidden(),
11306                                                    dlFolderModelImpl.getOriginalStatus()
11307                                            };
11308    
11309                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_M_P_H_S,
11310                                            args);
11311                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P_H_S,
11312                                            args);
11313    
11314                                    args = new Object[] {
11315                                                    dlFolderModelImpl.getGroupId(),
11316                                                    dlFolderModelImpl.getMountPoint(),
11317                                                    dlFolderModelImpl.getParentFolderId(),
11318                                                    dlFolderModelImpl.getHidden(),
11319                                                    dlFolderModelImpl.getStatus()
11320                                            };
11321    
11322                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_M_P_H_S,
11323                                            args);
11324                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P_H_S,
11325                                            args);
11326                            }
11327                    }
11328    
11329                    EntityCacheUtil.putResult(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
11330                            DLFolderImpl.class, dlFolder.getPrimaryKey(), dlFolder, false);
11331    
11332                    clearUniqueFindersCache(dlFolder);
11333                    cacheUniqueFindersCache(dlFolder);
11334    
11335                    dlFolder.resetOriginalValues();
11336    
11337                    return dlFolder;
11338            }
11339    
11340            protected DLFolder toUnwrappedModel(DLFolder dlFolder) {
11341                    if (dlFolder instanceof DLFolderImpl) {
11342                            return dlFolder;
11343                    }
11344    
11345                    DLFolderImpl dlFolderImpl = new DLFolderImpl();
11346    
11347                    dlFolderImpl.setNew(dlFolder.isNew());
11348                    dlFolderImpl.setPrimaryKey(dlFolder.getPrimaryKey());
11349    
11350                    dlFolderImpl.setUuid(dlFolder.getUuid());
11351                    dlFolderImpl.setFolderId(dlFolder.getFolderId());
11352                    dlFolderImpl.setGroupId(dlFolder.getGroupId());
11353                    dlFolderImpl.setCompanyId(dlFolder.getCompanyId());
11354                    dlFolderImpl.setUserId(dlFolder.getUserId());
11355                    dlFolderImpl.setUserName(dlFolder.getUserName());
11356                    dlFolderImpl.setCreateDate(dlFolder.getCreateDate());
11357                    dlFolderImpl.setModifiedDate(dlFolder.getModifiedDate());
11358                    dlFolderImpl.setRepositoryId(dlFolder.getRepositoryId());
11359                    dlFolderImpl.setMountPoint(dlFolder.isMountPoint());
11360                    dlFolderImpl.setParentFolderId(dlFolder.getParentFolderId());
11361                    dlFolderImpl.setTreePath(dlFolder.getTreePath());
11362                    dlFolderImpl.setName(dlFolder.getName());
11363                    dlFolderImpl.setDescription(dlFolder.getDescription());
11364                    dlFolderImpl.setLastPostDate(dlFolder.getLastPostDate());
11365                    dlFolderImpl.setDefaultFileEntryTypeId(dlFolder.getDefaultFileEntryTypeId());
11366                    dlFolderImpl.setHidden(dlFolder.isHidden());
11367                    dlFolderImpl.setRestrictionType(dlFolder.getRestrictionType());
11368                    dlFolderImpl.setStatus(dlFolder.getStatus());
11369                    dlFolderImpl.setStatusByUserId(dlFolder.getStatusByUserId());
11370                    dlFolderImpl.setStatusByUserName(dlFolder.getStatusByUserName());
11371                    dlFolderImpl.setStatusDate(dlFolder.getStatusDate());
11372    
11373                    return dlFolderImpl;
11374            }
11375    
11376            /**
11377             * Returns the document library folder with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
11378             *
11379             * @param primaryKey the primary key of the document library folder
11380             * @return the document library folder
11381             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
11382             */
11383            @Override
11384            public DLFolder findByPrimaryKey(Serializable primaryKey)
11385                    throws NoSuchFolderException {
11386                    DLFolder dlFolder = fetchByPrimaryKey(primaryKey);
11387    
11388                    if (dlFolder == null) {
11389                            if (_log.isWarnEnabled()) {
11390                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
11391                            }
11392    
11393                            throw new NoSuchFolderException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
11394                                    primaryKey);
11395                    }
11396    
11397                    return dlFolder;
11398            }
11399    
11400            /**
11401             * Returns the document library folder with the primary key or throws a {@link com.liferay.portlet.documentlibrary.NoSuchFolderException} if it could not be found.
11402             *
11403             * @param folderId the primary key of the document library folder
11404             * @return the document library folder
11405             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
11406             */
11407            @Override
11408            public DLFolder findByPrimaryKey(long folderId)
11409                    throws NoSuchFolderException {
11410                    return findByPrimaryKey((Serializable)folderId);
11411            }
11412    
11413            /**
11414             * Returns the document library folder with the primary key or returns <code>null</code> if it could not be found.
11415             *
11416             * @param primaryKey the primary key of the document library folder
11417             * @return the document library folder, or <code>null</code> if a document library folder with the primary key could not be found
11418             */
11419            @Override
11420            public DLFolder fetchByPrimaryKey(Serializable primaryKey) {
11421                    DLFolder dlFolder = (DLFolder)EntityCacheUtil.getResult(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
11422                                    DLFolderImpl.class, primaryKey);
11423    
11424                    if (dlFolder == _nullDLFolder) {
11425                            return null;
11426                    }
11427    
11428                    if (dlFolder == null) {
11429                            Session session = null;
11430    
11431                            try {
11432                                    session = openSession();
11433    
11434                                    dlFolder = (DLFolder)session.get(DLFolderImpl.class, primaryKey);
11435    
11436                                    if (dlFolder != null) {
11437                                            cacheResult(dlFolder);
11438                                    }
11439                                    else {
11440                                            EntityCacheUtil.putResult(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
11441                                                    DLFolderImpl.class, primaryKey, _nullDLFolder);
11442                                    }
11443                            }
11444                            catch (Exception e) {
11445                                    EntityCacheUtil.removeResult(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
11446                                            DLFolderImpl.class, primaryKey);
11447    
11448                                    throw processException(e);
11449                            }
11450                            finally {
11451                                    closeSession(session);
11452                            }
11453                    }
11454    
11455                    return dlFolder;
11456            }
11457    
11458            /**
11459             * Returns the document library folder with the primary key or returns <code>null</code> if it could not be found.
11460             *
11461             * @param folderId the primary key of the document library folder
11462             * @return the document library folder, or <code>null</code> if a document library folder with the primary key could not be found
11463             */
11464            @Override
11465            public DLFolder fetchByPrimaryKey(long folderId) {
11466                    return fetchByPrimaryKey((Serializable)folderId);
11467            }
11468    
11469            @Override
11470            public Map<Serializable, DLFolder> fetchByPrimaryKeys(
11471                    Set<Serializable> primaryKeys) {
11472                    if (primaryKeys.isEmpty()) {
11473                            return Collections.emptyMap();
11474                    }
11475    
11476                    Map<Serializable, DLFolder> map = new HashMap<Serializable, DLFolder>();
11477    
11478                    if (primaryKeys.size() == 1) {
11479                            Iterator<Serializable> iterator = primaryKeys.iterator();
11480    
11481                            Serializable primaryKey = iterator.next();
11482    
11483                            DLFolder dlFolder = fetchByPrimaryKey(primaryKey);
11484    
11485                            if (dlFolder != null) {
11486                                    map.put(primaryKey, dlFolder);
11487                            }
11488    
11489                            return map;
11490                    }
11491    
11492                    Set<Serializable> uncachedPrimaryKeys = null;
11493    
11494                    for (Serializable primaryKey : primaryKeys) {
11495                            DLFolder dlFolder = (DLFolder)EntityCacheUtil.getResult(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
11496                                            DLFolderImpl.class, primaryKey);
11497    
11498                            if (dlFolder == null) {
11499                                    if (uncachedPrimaryKeys == null) {
11500                                            uncachedPrimaryKeys = new HashSet<Serializable>();
11501                                    }
11502    
11503                                    uncachedPrimaryKeys.add(primaryKey);
11504                            }
11505                            else {
11506                                    map.put(primaryKey, dlFolder);
11507                            }
11508                    }
11509    
11510                    if (uncachedPrimaryKeys == null) {
11511                            return map;
11512                    }
11513    
11514                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
11515                                    1);
11516    
11517                    query.append(_SQL_SELECT_DLFOLDER_WHERE_PKS_IN);
11518    
11519                    for (Serializable primaryKey : uncachedPrimaryKeys) {
11520                            query.append(String.valueOf(primaryKey));
11521    
11522                            query.append(StringPool.COMMA);
11523                    }
11524    
11525                    query.setIndex(query.index() - 1);
11526    
11527                    query.append(StringPool.CLOSE_PARENTHESIS);
11528    
11529                    String sql = query.toString();
11530    
11531                    Session session = null;
11532    
11533                    try {
11534                            session = openSession();
11535    
11536                            Query q = session.createQuery(sql);
11537    
11538                            for (DLFolder dlFolder : (List<DLFolder>)q.list()) {
11539                                    map.put(dlFolder.getPrimaryKeyObj(), dlFolder);
11540    
11541                                    cacheResult(dlFolder);
11542    
11543                                    uncachedPrimaryKeys.remove(dlFolder.getPrimaryKeyObj());
11544                            }
11545    
11546                            for (Serializable primaryKey : uncachedPrimaryKeys) {
11547                                    EntityCacheUtil.putResult(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
11548                                            DLFolderImpl.class, primaryKey, _nullDLFolder);
11549                            }
11550                    }
11551                    catch (Exception e) {
11552                            throw processException(e);
11553                    }
11554                    finally {
11555                            closeSession(session);
11556                    }
11557    
11558                    return map;
11559            }
11560    
11561            /**
11562             * Returns all the document library folders.
11563             *
11564             * @return the document library folders
11565             */
11566            @Override
11567            public List<DLFolder> findAll() {
11568                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
11569            }
11570    
11571            /**
11572             * Returns a range of all the document library folders.
11573             *
11574             * <p>
11575             * 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.
11576             * </p>
11577             *
11578             * @param start the lower bound of the range of document library folders
11579             * @param end the upper bound of the range of document library folders (not inclusive)
11580             * @return the range of document library folders
11581             */
11582            @Override
11583            public List<DLFolder> findAll(int start, int end) {
11584                    return findAll(start, end, null);
11585            }
11586    
11587            /**
11588             * Returns an ordered range of all the document library folders.
11589             *
11590             * <p>
11591             * 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.
11592             * </p>
11593             *
11594             * @param start the lower bound of the range of document library folders
11595             * @param end the upper bound of the range of document library folders (not inclusive)
11596             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
11597             * @return the ordered range of document library folders
11598             */
11599            @Override
11600            public List<DLFolder> findAll(int start, int end,
11601                    OrderByComparator<DLFolder> orderByComparator) {
11602                    boolean pagination = true;
11603                    FinderPath finderPath = null;
11604                    Object[] finderArgs = null;
11605    
11606                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
11607                                    (orderByComparator == null)) {
11608                            pagination = false;
11609                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
11610                            finderArgs = FINDER_ARGS_EMPTY;
11611                    }
11612                    else {
11613                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
11614                            finderArgs = new Object[] { start, end, orderByComparator };
11615                    }
11616    
11617                    List<DLFolder> list = (List<DLFolder>)FinderCacheUtil.getResult(finderPath,
11618                                    finderArgs, this);
11619    
11620                    if (list == null) {
11621                            StringBundler query = null;
11622                            String sql = null;
11623    
11624                            if (orderByComparator != null) {
11625                                    query = new StringBundler(2 +
11626                                                    (orderByComparator.getOrderByFields().length * 3));
11627    
11628                                    query.append(_SQL_SELECT_DLFOLDER);
11629    
11630                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
11631                                            orderByComparator);
11632    
11633                                    sql = query.toString();
11634                            }
11635                            else {
11636                                    sql = _SQL_SELECT_DLFOLDER;
11637    
11638                                    if (pagination) {
11639                                            sql = sql.concat(DLFolderModelImpl.ORDER_BY_JPQL);
11640                                    }
11641                            }
11642    
11643                            Session session = null;
11644    
11645                            try {
11646                                    session = openSession();
11647    
11648                                    Query q = session.createQuery(sql);
11649    
11650                                    if (!pagination) {
11651                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
11652                                                            start, end, false);
11653    
11654                                            Collections.sort(list);
11655    
11656                                            list = Collections.unmodifiableList(list);
11657                                    }
11658                                    else {
11659                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
11660                                                            start, end);
11661                                    }
11662    
11663                                    cacheResult(list);
11664    
11665                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
11666                            }
11667                            catch (Exception e) {
11668                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
11669    
11670                                    throw processException(e);
11671                            }
11672                            finally {
11673                                    closeSession(session);
11674                            }
11675                    }
11676    
11677                    return list;
11678            }
11679    
11680            /**
11681             * Removes all the document library folders from the database.
11682             *
11683             */
11684            @Override
11685            public void removeAll() {
11686                    for (DLFolder dlFolder : findAll()) {
11687                            remove(dlFolder);
11688                    }
11689            }
11690    
11691            /**
11692             * Returns the number of document library folders.
11693             *
11694             * @return the number of document library folders
11695             */
11696            @Override
11697            public int countAll() {
11698                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
11699                                    FINDER_ARGS_EMPTY, this);
11700    
11701                    if (count == null) {
11702                            Session session = null;
11703    
11704                            try {
11705                                    session = openSession();
11706    
11707                                    Query q = session.createQuery(_SQL_COUNT_DLFOLDER);
11708    
11709                                    count = (Long)q.uniqueResult();
11710    
11711                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
11712                                            FINDER_ARGS_EMPTY, count);
11713                            }
11714                            catch (Exception e) {
11715                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
11716                                            FINDER_ARGS_EMPTY);
11717    
11718                                    throw processException(e);
11719                            }
11720                            finally {
11721                                    closeSession(session);
11722                            }
11723                    }
11724    
11725                    return count.intValue();
11726            }
11727    
11728            /**
11729             * Returns the primaryKeys of document library file entry types associated with the document library folder.
11730             *
11731             * @param pk the primary key of the document library folder
11732             * @return long[] of the primaryKeys of document library file entry types associated with the document library folder
11733             */
11734            @Override
11735            public long[] getDLFileEntryTypePrimaryKeys(long pk) {
11736                    long[] pks = dlFolderToDLFileEntryTypeTableMapper.getRightPrimaryKeys(pk);
11737    
11738                    return pks.clone();
11739            }
11740    
11741            /**
11742             * Returns all the document library file entry types associated with the document library folder.
11743             *
11744             * @param pk the primary key of the document library folder
11745             * @return the document library file entry types associated with the document library folder
11746             */
11747            @Override
11748            public List<com.liferay.portlet.documentlibrary.model.DLFileEntryType> getDLFileEntryTypes(
11749                    long pk) {
11750                    return getDLFileEntryTypes(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
11751            }
11752    
11753            /**
11754             * Returns a range of all the document library file entry types associated with the document library folder.
11755             *
11756             * <p>
11757             * 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.
11758             * </p>
11759             *
11760             * @param pk the primary key of the document library folder
11761             * @param start the lower bound of the range of document library folders
11762             * @param end the upper bound of the range of document library folders (not inclusive)
11763             * @return the range of document library file entry types associated with the document library folder
11764             */
11765            @Override
11766            public List<com.liferay.portlet.documentlibrary.model.DLFileEntryType> getDLFileEntryTypes(
11767                    long pk, int start, int end) {
11768                    return getDLFileEntryTypes(pk, start, end, null);
11769            }
11770    
11771            /**
11772             * Returns an ordered range of all the document library file entry types associated with the document library folder.
11773             *
11774             * <p>
11775             * 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.
11776             * </p>
11777             *
11778             * @param pk the primary key of the document library folder
11779             * @param start the lower bound of the range of document library folders
11780             * @param end the upper bound of the range of document library folders (not inclusive)
11781             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
11782             * @return the ordered range of document library file entry types associated with the document library folder
11783             */
11784            @Override
11785            public List<com.liferay.portlet.documentlibrary.model.DLFileEntryType> getDLFileEntryTypes(
11786                    long pk, int start, int end,
11787                    OrderByComparator<com.liferay.portlet.documentlibrary.model.DLFileEntryType> orderByComparator) {
11788                    return dlFolderToDLFileEntryTypeTableMapper.getRightBaseModels(pk,
11789                            start, end, orderByComparator);
11790            }
11791    
11792            /**
11793             * Returns the number of document library file entry types associated with the document library folder.
11794             *
11795             * @param pk the primary key of the document library folder
11796             * @return the number of document library file entry types associated with the document library folder
11797             */
11798            @Override
11799            public int getDLFileEntryTypesSize(long pk) {
11800                    long[] pks = dlFolderToDLFileEntryTypeTableMapper.getRightPrimaryKeys(pk);
11801    
11802                    return pks.length;
11803            }
11804    
11805            /**
11806             * Returns <code>true</code> if the document library file entry type is associated with the document library folder.
11807             *
11808             * @param pk the primary key of the document library folder
11809             * @param dlFileEntryTypePK the primary key of the document library file entry type
11810             * @return <code>true</code> if the document library file entry type is associated with the document library folder; <code>false</code> otherwise
11811             */
11812            @Override
11813            public boolean containsDLFileEntryType(long pk, long dlFileEntryTypePK) {
11814                    return dlFolderToDLFileEntryTypeTableMapper.containsTableMapping(pk,
11815                            dlFileEntryTypePK);
11816            }
11817    
11818            /**
11819             * Returns <code>true</code> if the document library folder has any document library file entry types associated with it.
11820             *
11821             * @param pk the primary key of the document library folder to check for associations with document library file entry types
11822             * @return <code>true</code> if the document library folder has any document library file entry types associated with it; <code>false</code> otherwise
11823             */
11824            @Override
11825            public boolean containsDLFileEntryTypes(long pk) {
11826                    if (getDLFileEntryTypesSize(pk) > 0) {
11827                            return true;
11828                    }
11829                    else {
11830                            return false;
11831                    }
11832            }
11833    
11834            /**
11835             * 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.
11836             *
11837             * @param pk the primary key of the document library folder
11838             * @param dlFileEntryTypePK the primary key of the document library file entry type
11839             */
11840            @Override
11841            public void addDLFileEntryType(long pk, long dlFileEntryTypePK) {
11842                    dlFolderToDLFileEntryTypeTableMapper.addTableMapping(pk,
11843                            dlFileEntryTypePK);
11844            }
11845    
11846            /**
11847             * 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.
11848             *
11849             * @param pk the primary key of the document library folder
11850             * @param dlFileEntryType the document library file entry type
11851             */
11852            @Override
11853            public void addDLFileEntryType(long pk,
11854                    com.liferay.portlet.documentlibrary.model.DLFileEntryType dlFileEntryType) {
11855                    dlFolderToDLFileEntryTypeTableMapper.addTableMapping(pk,
11856                            dlFileEntryType.getPrimaryKey());
11857            }
11858    
11859            /**
11860             * 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.
11861             *
11862             * @param pk the primary key of the document library folder
11863             * @param dlFileEntryTypePKs the primary keys of the document library file entry types
11864             */
11865            @Override
11866            public void addDLFileEntryTypes(long pk, long[] dlFileEntryTypePKs) {
11867                    for (long dlFileEntryTypePK : dlFileEntryTypePKs) {
11868                            dlFolderToDLFileEntryTypeTableMapper.addTableMapping(pk,
11869                                    dlFileEntryTypePK);
11870                    }
11871            }
11872    
11873            /**
11874             * 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.
11875             *
11876             * @param pk the primary key of the document library folder
11877             * @param dlFileEntryTypes the document library file entry types
11878             */
11879            @Override
11880            public void addDLFileEntryTypes(long pk,
11881                    List<com.liferay.portlet.documentlibrary.model.DLFileEntryType> dlFileEntryTypes) {
11882                    for (com.liferay.portlet.documentlibrary.model.DLFileEntryType dlFileEntryType : dlFileEntryTypes) {
11883                            dlFolderToDLFileEntryTypeTableMapper.addTableMapping(pk,
11884                                    dlFileEntryType.getPrimaryKey());
11885                    }
11886            }
11887    
11888            /**
11889             * 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.
11890             *
11891             * @param pk the primary key of the document library folder to clear the associated document library file entry types from
11892             */
11893            @Override
11894            public void clearDLFileEntryTypes(long pk) {
11895                    dlFolderToDLFileEntryTypeTableMapper.deleteLeftPrimaryKeyTableMappings(pk);
11896            }
11897    
11898            /**
11899             * 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.
11900             *
11901             * @param pk the primary key of the document library folder
11902             * @param dlFileEntryTypePK the primary key of the document library file entry type
11903             */
11904            @Override
11905            public void removeDLFileEntryType(long pk, long dlFileEntryTypePK) {
11906                    dlFolderToDLFileEntryTypeTableMapper.deleteTableMapping(pk,
11907                            dlFileEntryTypePK);
11908            }
11909    
11910            /**
11911             * 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.
11912             *
11913             * @param pk the primary key of the document library folder
11914             * @param dlFileEntryType the document library file entry type
11915             */
11916            @Override
11917            public void removeDLFileEntryType(long pk,
11918                    com.liferay.portlet.documentlibrary.model.DLFileEntryType dlFileEntryType) {
11919                    dlFolderToDLFileEntryTypeTableMapper.deleteTableMapping(pk,
11920                            dlFileEntryType.getPrimaryKey());
11921            }
11922    
11923            /**
11924             * 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.
11925             *
11926             * @param pk the primary key of the document library folder
11927             * @param dlFileEntryTypePKs the primary keys of the document library file entry types
11928             */
11929            @Override
11930            public void removeDLFileEntryTypes(long pk, long[] dlFileEntryTypePKs) {
11931                    for (long dlFileEntryTypePK : dlFileEntryTypePKs) {
11932                            dlFolderToDLFileEntryTypeTableMapper.deleteTableMapping(pk,
11933                                    dlFileEntryTypePK);
11934                    }
11935            }
11936    
11937            /**
11938             * 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.
11939             *
11940             * @param pk the primary key of the document library folder
11941             * @param dlFileEntryTypes the document library file entry types
11942             */
11943            @Override
11944            public void removeDLFileEntryTypes(long pk,
11945                    List<com.liferay.portlet.documentlibrary.model.DLFileEntryType> dlFileEntryTypes) {
11946                    for (com.liferay.portlet.documentlibrary.model.DLFileEntryType dlFileEntryType : dlFileEntryTypes) {
11947                            dlFolderToDLFileEntryTypeTableMapper.deleteTableMapping(pk,
11948                                    dlFileEntryType.getPrimaryKey());
11949                    }
11950            }
11951    
11952            /**
11953             * 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.
11954             *
11955             * @param pk the primary key of the document library folder
11956             * @param dlFileEntryTypePKs the primary keys of the document library file entry types to be associated with the document library folder
11957             */
11958            @Override
11959            public void setDLFileEntryTypes(long pk, long[] dlFileEntryTypePKs) {
11960                    Set<Long> newDLFileEntryTypePKsSet = SetUtil.fromArray(dlFileEntryTypePKs);
11961                    Set<Long> oldDLFileEntryTypePKsSet = SetUtil.fromArray(dlFolderToDLFileEntryTypeTableMapper.getRightPrimaryKeys(
11962                                            pk));
11963    
11964                    Set<Long> removeDLFileEntryTypePKsSet = new HashSet<Long>(oldDLFileEntryTypePKsSet);
11965    
11966                    removeDLFileEntryTypePKsSet.removeAll(newDLFileEntryTypePKsSet);
11967    
11968                    for (long removeDLFileEntryTypePK : removeDLFileEntryTypePKsSet) {
11969                            dlFolderToDLFileEntryTypeTableMapper.deleteTableMapping(pk,
11970                                    removeDLFileEntryTypePK);
11971                    }
11972    
11973                    newDLFileEntryTypePKsSet.removeAll(oldDLFileEntryTypePKsSet);
11974    
11975                    for (long newDLFileEntryTypePK : newDLFileEntryTypePKsSet) {
11976                            dlFolderToDLFileEntryTypeTableMapper.addTableMapping(pk,
11977                                    newDLFileEntryTypePK);
11978                    }
11979            }
11980    
11981            /**
11982             * 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.
11983             *
11984             * @param pk the primary key of the document library folder
11985             * @param dlFileEntryTypes the document library file entry types to be associated with the document library folder
11986             */
11987            @Override
11988            public void setDLFileEntryTypes(long pk,
11989                    List<com.liferay.portlet.documentlibrary.model.DLFileEntryType> dlFileEntryTypes) {
11990                    try {
11991                            long[] dlFileEntryTypePKs = new long[dlFileEntryTypes.size()];
11992    
11993                            for (int i = 0; i < dlFileEntryTypes.size(); i++) {
11994                                    com.liferay.portlet.documentlibrary.model.DLFileEntryType dlFileEntryType =
11995                                            dlFileEntryTypes.get(i);
11996    
11997                                    dlFileEntryTypePKs[i] = dlFileEntryType.getPrimaryKey();
11998                            }
11999    
12000                            setDLFileEntryTypes(pk, dlFileEntryTypePKs);
12001                    }
12002                    catch (Exception e) {
12003                            throw processException(e);
12004                    }
12005            }
12006    
12007            @Override
12008            protected Set<String> getBadColumnNames() {
12009                    return _badColumnNames;
12010            }
12011    
12012            /**
12013             * Initializes the document library folder persistence.
12014             */
12015            public void afterPropertiesSet() {
12016                    dlFolderToDLFileEntryTypeTableMapper = TableMapperFactory.getTableMapper("DLFileEntryTypes_DLFolders",
12017                                    "folderId", "fileEntryTypeId", this, dlFileEntryTypePersistence);
12018            }
12019    
12020            public void destroy() {
12021                    EntityCacheUtil.removeCache(DLFolderImpl.class.getName());
12022                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
12023                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
12024                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
12025    
12026                    TableMapperFactory.removeTableMapper("DLFileEntryTypes_DLFolders");
12027            }
12028    
12029            @BeanReference(type = DLFileEntryTypePersistence.class)
12030            protected DLFileEntryTypePersistence dlFileEntryTypePersistence;
12031            protected TableMapper<DLFolder, com.liferay.portlet.documentlibrary.model.DLFileEntryType> dlFolderToDLFileEntryTypeTableMapper;
12032            private static final String _SQL_SELECT_DLFOLDER = "SELECT dlFolder FROM DLFolder dlFolder";
12033            private static final String _SQL_SELECT_DLFOLDER_WHERE_PKS_IN = "SELECT dlFolder FROM DLFolder dlFolder WHERE folderId IN (";
12034            private static final String _SQL_SELECT_DLFOLDER_WHERE = "SELECT dlFolder FROM DLFolder dlFolder WHERE ";
12035            private static final String _SQL_COUNT_DLFOLDER = "SELECT COUNT(dlFolder) FROM DLFolder dlFolder";
12036            private static final String _SQL_COUNT_DLFOLDER_WHERE = "SELECT COUNT(dlFolder) FROM DLFolder dlFolder WHERE ";
12037            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "dlFolder.folderId";
12038            private static final String _FILTER_SQL_SELECT_DLFOLDER_WHERE = "SELECT DISTINCT {dlFolder.*} FROM DLFolder dlFolder WHERE ";
12039            private static final String _FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1 =
12040                    "SELECT {DLFolder.*} FROM (SELECT DISTINCT dlFolder.folderId FROM DLFolder dlFolder WHERE ";
12041            private static final String _FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2 =
12042                    ") TEMP_TABLE INNER JOIN DLFolder ON TEMP_TABLE.folderId = DLFolder.folderId";
12043            private static final String _FILTER_SQL_COUNT_DLFOLDER_WHERE = "SELECT COUNT(DISTINCT dlFolder.folderId) AS COUNT_VALUE FROM DLFolder dlFolder WHERE ";
12044            private static final String _FILTER_ENTITY_ALIAS = "dlFolder";
12045            private static final String _FILTER_ENTITY_TABLE = "DLFolder";
12046            private static final String _ORDER_BY_ENTITY_ALIAS = "dlFolder.";
12047            private static final String _ORDER_BY_ENTITY_TABLE = "DLFolder.";
12048            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No DLFolder exists with the primary key ";
12049            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No DLFolder exists with the key {";
12050            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
12051            private static final Log _log = LogFactoryUtil.getLog(DLFolderPersistenceImpl.class);
12052            private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
12053                                    "uuid", "hidden"
12054                            });
12055            private static final DLFolder _nullDLFolder = new DLFolderImpl() {
12056                            @Override
12057                            public Object clone() {
12058                                    return this;
12059                            }
12060    
12061                            @Override
12062                            public CacheModel<DLFolder> toCacheModel() {
12063                                    return _nullDLFolderCacheModel;
12064                            }
12065                    };
12066    
12067            private static final CacheModel<DLFolder> _nullDLFolderCacheModel = new CacheModel<DLFolder>() {
12068                            @Override
12069                            public DLFolder toEntityModel() {
12070                                    return _nullDLFolder;
12071                            }
12072                    };
12073    }