001    /**
002     * Copyright (c) 2000-2013 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;
016    
017    import com.liferay.portal.kernel.bean.BeanReference;
018    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
019    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
020    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderPath;
022    import com.liferay.portal.kernel.dao.orm.Query;
023    import com.liferay.portal.kernel.dao.orm.QueryPos;
024    import com.liferay.portal.kernel.dao.orm.QueryUtil;
025    import com.liferay.portal.kernel.dao.orm.SQLQuery;
026    import com.liferay.portal.kernel.dao.orm.Session;
027    import com.liferay.portal.kernel.exception.SystemException;
028    import com.liferay.portal.kernel.log.Log;
029    import com.liferay.portal.kernel.log.LogFactoryUtil;
030    import com.liferay.portal.kernel.util.GetterUtil;
031    import com.liferay.portal.kernel.util.InstanceFactory;
032    import com.liferay.portal.kernel.util.OrderByComparator;
033    import com.liferay.portal.kernel.util.SetUtil;
034    import com.liferay.portal.kernel.util.StringBundler;
035    import com.liferay.portal.kernel.util.StringPool;
036    import com.liferay.portal.kernel.util.StringUtil;
037    import com.liferay.portal.kernel.util.UnmodifiableList;
038    import com.liferay.portal.kernel.util.Validator;
039    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
040    import com.liferay.portal.model.CacheModel;
041    import com.liferay.portal.model.ModelListener;
042    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
043    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
044    import com.liferay.portal.service.persistence.impl.TableMapper;
045    import com.liferay.portal.service.persistence.impl.TableMapperFactory;
046    
047    import com.liferay.portlet.documentlibrary.NoSuchFolderException;
048    import com.liferay.portlet.documentlibrary.model.DLFolder;
049    import com.liferay.portlet.documentlibrary.model.impl.DLFolderImpl;
050    import com.liferay.portlet.documentlibrary.model.impl.DLFolderModelImpl;
051    
052    import java.io.Serializable;
053    
054    import java.util.ArrayList;
055    import java.util.Collections;
056    import java.util.List;
057    import java.util.Set;
058    
059    /**
060     * The persistence implementation for the document library folder service.
061     *
062     * <p>
063     * Caching information and settings can be found in <code>portal.properties</code>
064     * </p>
065     *
066     * @author Brian Wing Shun Chan
067     * @see DLFolderPersistence
068     * @see DLFolderUtil
069     * @generated
070     */
071    public class DLFolderPersistenceImpl extends BasePersistenceImpl<DLFolder>
072            implements DLFolderPersistence {
073            /*
074             * NOTE FOR DEVELOPERS:
075             *
076             * 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.
077             */
078            public static final String FINDER_CLASS_NAME_ENTITY = DLFolderImpl.class.getName();
079            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
080                    ".List1";
081            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
082                    ".List2";
083            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
084                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
085                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
086            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
087                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
088                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
089            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
090                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
091                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
092            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
093                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
094                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
095                            new String[] {
096                                    String.class.getName(),
097                                    
098                            Integer.class.getName(), Integer.class.getName(),
099                                    OrderByComparator.class.getName()
100                            });
101            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
102                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
103                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
104                            new String[] { String.class.getName() },
105                            DLFolderModelImpl.UUID_COLUMN_BITMASK |
106                            DLFolderModelImpl.PARENTFOLDERID_COLUMN_BITMASK |
107                            DLFolderModelImpl.NAME_COLUMN_BITMASK);
108            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
109                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
110                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
111                            new String[] { String.class.getName() });
112    
113            /**
114             * Returns all the document library folders where uuid = &#63;.
115             *
116             * @param uuid the uuid
117             * @return the matching document library folders
118             * @throws SystemException if a system exception occurred
119             */
120            @Override
121            public List<DLFolder> findByUuid(String uuid) throws SystemException {
122                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
123            }
124    
125            /**
126             * Returns a range of all the document library folders where uuid = &#63;.
127             *
128             * <p>
129             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
130             * </p>
131             *
132             * @param uuid the uuid
133             * @param start the lower bound of the range of document library folders
134             * @param end the upper bound of the range of document library folders (not inclusive)
135             * @return the range of matching document library folders
136             * @throws SystemException if a system exception occurred
137             */
138            @Override
139            public List<DLFolder> findByUuid(String uuid, int start, int end)
140                    throws SystemException {
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             * @throws SystemException if a system exception occurred
157             */
158            @Override
159            public List<DLFolder> findByUuid(String uuid, int start, int end,
160                    OrderByComparator orderByComparator) throws SystemException {
161                    boolean pagination = true;
162                    FinderPath finderPath = null;
163                    Object[] finderArgs = null;
164    
165                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
166                                    (orderByComparator == null)) {
167                            pagination = false;
168                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
169                            finderArgs = new Object[] { uuid };
170                    }
171                    else {
172                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
173                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
174                    }
175    
176                    List<DLFolder> list = (List<DLFolder>)FinderCacheUtil.getResult(finderPath,
177                                    finderArgs, this);
178    
179                    if ((list != null) && !list.isEmpty()) {
180                            for (DLFolder dlFolder : list) {
181                                    if (!Validator.equals(uuid, dlFolder.getUuid())) {
182                                            list = null;
183    
184                                            break;
185                                    }
186                            }
187                    }
188    
189                    if (list == null) {
190                            StringBundler query = null;
191    
192                            if (orderByComparator != null) {
193                                    query = new StringBundler(3 +
194                                                    (orderByComparator.getOrderByFields().length * 3));
195                            }
196                            else {
197                                    query = new StringBundler(3);
198                            }
199    
200                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
201    
202                            boolean bindUuid = false;
203    
204                            if (uuid == null) {
205                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
206                            }
207                            else if (uuid.equals(StringPool.BLANK)) {
208                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
209                            }
210                            else {
211                                    bindUuid = true;
212    
213                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
214                            }
215    
216                            if (orderByComparator != null) {
217                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
218                                            orderByComparator);
219                            }
220                            else
221                             if (pagination) {
222                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
223                            }
224    
225                            String sql = query.toString();
226    
227                            Session session = null;
228    
229                            try {
230                                    session = openSession();
231    
232                                    Query q = session.createQuery(sql);
233    
234                                    QueryPos qPos = QueryPos.getInstance(q);
235    
236                                    if (bindUuid) {
237                                            qPos.add(uuid);
238                                    }
239    
240                                    if (!pagination) {
241                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
242                                                            start, end, false);
243    
244                                            Collections.sort(list);
245    
246                                            list = new UnmodifiableList<DLFolder>(list);
247                                    }
248                                    else {
249                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
250                                                            start, end);
251                                    }
252    
253                                    cacheResult(list);
254    
255                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
256                            }
257                            catch (Exception e) {
258                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
259    
260                                    throw processException(e);
261                            }
262                            finally {
263                                    closeSession(session);
264                            }
265                    }
266    
267                    return list;
268            }
269    
270            /**
271             * Returns the first document library folder in the ordered set where uuid = &#63;.
272             *
273             * @param uuid the uuid
274             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
275             * @return the first matching document library folder
276             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
277             * @throws SystemException if a system exception occurred
278             */
279            @Override
280            public DLFolder findByUuid_First(String uuid,
281                    OrderByComparator orderByComparator)
282                    throws NoSuchFolderException, SystemException {
283                    DLFolder dlFolder = fetchByUuid_First(uuid, orderByComparator);
284    
285                    if (dlFolder != null) {
286                            return dlFolder;
287                    }
288    
289                    StringBundler msg = new StringBundler(4);
290    
291                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
292    
293                    msg.append("uuid=");
294                    msg.append(uuid);
295    
296                    msg.append(StringPool.CLOSE_CURLY_BRACE);
297    
298                    throw new NoSuchFolderException(msg.toString());
299            }
300    
301            /**
302             * Returns the first document library folder in the ordered set where uuid = &#63;.
303             *
304             * @param uuid the uuid
305             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
306             * @return the first matching document library folder, or <code>null</code> if a matching document library folder could not be found
307             * @throws SystemException if a system exception occurred
308             */
309            @Override
310            public DLFolder fetchByUuid_First(String uuid,
311                    OrderByComparator orderByComparator) throws SystemException {
312                    List<DLFolder> list = findByUuid(uuid, 0, 1, orderByComparator);
313    
314                    if (!list.isEmpty()) {
315                            return list.get(0);
316                    }
317    
318                    return null;
319            }
320    
321            /**
322             * Returns the last document library folder in the ordered set where uuid = &#63;.
323             *
324             * @param uuid the uuid
325             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
326             * @return the last matching document library folder
327             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
328             * @throws SystemException if a system exception occurred
329             */
330            @Override
331            public DLFolder findByUuid_Last(String uuid,
332                    OrderByComparator orderByComparator)
333                    throws NoSuchFolderException, SystemException {
334                    DLFolder dlFolder = fetchByUuid_Last(uuid, orderByComparator);
335    
336                    if (dlFolder != null) {
337                            return dlFolder;
338                    }
339    
340                    StringBundler msg = new StringBundler(4);
341    
342                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
343    
344                    msg.append("uuid=");
345                    msg.append(uuid);
346    
347                    msg.append(StringPool.CLOSE_CURLY_BRACE);
348    
349                    throw new NoSuchFolderException(msg.toString());
350            }
351    
352            /**
353             * Returns the last document library folder in the ordered set where uuid = &#63;.
354             *
355             * @param uuid the uuid
356             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
357             * @return the last matching document library folder, or <code>null</code> if a matching document library folder could not be found
358             * @throws SystemException if a system exception occurred
359             */
360            @Override
361            public DLFolder fetchByUuid_Last(String uuid,
362                    OrderByComparator orderByComparator) throws SystemException {
363                    int count = countByUuid(uuid);
364    
365                    if (count == 0) {
366                            return null;
367                    }
368    
369                    List<DLFolder> list = findByUuid(uuid, count - 1, count,
370                                    orderByComparator);
371    
372                    if (!list.isEmpty()) {
373                            return list.get(0);
374                    }
375    
376                    return null;
377            }
378    
379            /**
380             * Returns the document library folders before and after the current document library folder in the ordered set where uuid = &#63;.
381             *
382             * @param folderId the primary key of the current document library folder
383             * @param uuid the uuid
384             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
385             * @return the previous, current, and next document library folder
386             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
387             * @throws SystemException if a system exception occurred
388             */
389            @Override
390            public DLFolder[] findByUuid_PrevAndNext(long folderId, String uuid,
391                    OrderByComparator orderByComparator)
392                    throws NoSuchFolderException, SystemException {
393                    DLFolder dlFolder = findByPrimaryKey(folderId);
394    
395                    Session session = null;
396    
397                    try {
398                            session = openSession();
399    
400                            DLFolder[] array = new DLFolderImpl[3];
401    
402                            array[0] = getByUuid_PrevAndNext(session, dlFolder, uuid,
403                                            orderByComparator, true);
404    
405                            array[1] = dlFolder;
406    
407                            array[2] = getByUuid_PrevAndNext(session, dlFolder, uuid,
408                                            orderByComparator, false);
409    
410                            return array;
411                    }
412                    catch (Exception e) {
413                            throw processException(e);
414                    }
415                    finally {
416                            closeSession(session);
417                    }
418            }
419    
420            protected DLFolder getByUuid_PrevAndNext(Session session,
421                    DLFolder dlFolder, String uuid, OrderByComparator orderByComparator,
422                    boolean previous) {
423                    StringBundler query = null;
424    
425                    if (orderByComparator != null) {
426                            query = new StringBundler(6 +
427                                            (orderByComparator.getOrderByFields().length * 6));
428                    }
429                    else {
430                            query = new StringBundler(3);
431                    }
432    
433                    query.append(_SQL_SELECT_DLFOLDER_WHERE);
434    
435                    boolean bindUuid = false;
436    
437                    if (uuid == null) {
438                            query.append(_FINDER_COLUMN_UUID_UUID_1);
439                    }
440                    else if (uuid.equals(StringPool.BLANK)) {
441                            query.append(_FINDER_COLUMN_UUID_UUID_3);
442                    }
443                    else {
444                            bindUuid = true;
445    
446                            query.append(_FINDER_COLUMN_UUID_UUID_2);
447                    }
448    
449                    if (orderByComparator != null) {
450                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
451    
452                            if (orderByConditionFields.length > 0) {
453                                    query.append(WHERE_AND);
454                            }
455    
456                            for (int i = 0; i < orderByConditionFields.length; i++) {
457                                    query.append(_ORDER_BY_ENTITY_ALIAS);
458                                    query.append(orderByConditionFields[i]);
459    
460                                    if ((i + 1) < orderByConditionFields.length) {
461                                            if (orderByComparator.isAscending() ^ previous) {
462                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
463                                            }
464                                            else {
465                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
466                                            }
467                                    }
468                                    else {
469                                            if (orderByComparator.isAscending() ^ previous) {
470                                                    query.append(WHERE_GREATER_THAN);
471                                            }
472                                            else {
473                                                    query.append(WHERE_LESSER_THAN);
474                                            }
475                                    }
476                            }
477    
478                            query.append(ORDER_BY_CLAUSE);
479    
480                            String[] orderByFields = orderByComparator.getOrderByFields();
481    
482                            for (int i = 0; i < orderByFields.length; i++) {
483                                    query.append(_ORDER_BY_ENTITY_ALIAS);
484                                    query.append(orderByFields[i]);
485    
486                                    if ((i + 1) < orderByFields.length) {
487                                            if (orderByComparator.isAscending() ^ previous) {
488                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
489                                            }
490                                            else {
491                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
492                                            }
493                                    }
494                                    else {
495                                            if (orderByComparator.isAscending() ^ previous) {
496                                                    query.append(ORDER_BY_ASC);
497                                            }
498                                            else {
499                                                    query.append(ORDER_BY_DESC);
500                                            }
501                                    }
502                            }
503                    }
504                    else {
505                            query.append(DLFolderModelImpl.ORDER_BY_JPQL);
506                    }
507    
508                    String sql = query.toString();
509    
510                    Query q = session.createQuery(sql);
511    
512                    q.setFirstResult(0);
513                    q.setMaxResults(2);
514    
515                    QueryPos qPos = QueryPos.getInstance(q);
516    
517                    if (bindUuid) {
518                            qPos.add(uuid);
519                    }
520    
521                    if (orderByComparator != null) {
522                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
523    
524                            for (Object value : values) {
525                                    qPos.add(value);
526                            }
527                    }
528    
529                    List<DLFolder> list = q.list();
530    
531                    if (list.size() == 2) {
532                            return list.get(1);
533                    }
534                    else {
535                            return null;
536                    }
537            }
538    
539            /**
540             * Removes all the document library folders where uuid = &#63; from the database.
541             *
542             * @param uuid the uuid
543             * @throws SystemException if a system exception occurred
544             */
545            @Override
546            public void removeByUuid(String uuid) throws SystemException {
547                    for (DLFolder dlFolder : findByUuid(uuid, QueryUtil.ALL_POS,
548                                    QueryUtil.ALL_POS, null)) {
549                            remove(dlFolder);
550                    }
551            }
552    
553            /**
554             * Returns the number of document library folders where uuid = &#63;.
555             *
556             * @param uuid the uuid
557             * @return the number of matching document library folders
558             * @throws SystemException if a system exception occurred
559             */
560            @Override
561            public int countByUuid(String uuid) throws SystemException {
562                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
563    
564                    Object[] finderArgs = new Object[] { uuid };
565    
566                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
567                                    this);
568    
569                    if (count == null) {
570                            StringBundler query = new StringBundler(2);
571    
572                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
573    
574                            boolean bindUuid = false;
575    
576                            if (uuid == null) {
577                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
578                            }
579                            else if (uuid.equals(StringPool.BLANK)) {
580                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
581                            }
582                            else {
583                                    bindUuid = true;
584    
585                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
586                            }
587    
588                            String sql = query.toString();
589    
590                            Session session = null;
591    
592                            try {
593                                    session = openSession();
594    
595                                    Query q = session.createQuery(sql);
596    
597                                    QueryPos qPos = QueryPos.getInstance(q);
598    
599                                    if (bindUuid) {
600                                            qPos.add(uuid);
601                                    }
602    
603                                    count = (Long)q.uniqueResult();
604    
605                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
606                            }
607                            catch (Exception e) {
608                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
609    
610                                    throw processException(e);
611                            }
612                            finally {
613                                    closeSession(session);
614                            }
615                    }
616    
617                    return count.intValue();
618            }
619    
620            private static final String _FINDER_COLUMN_UUID_UUID_1 = "dlFolder.uuid IS NULL";
621            private static final String _FINDER_COLUMN_UUID_UUID_2 = "dlFolder.uuid = ?";
622            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(dlFolder.uuid IS NULL OR dlFolder.uuid = '')";
623            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
624                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
625                            FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
626                            new String[] { String.class.getName(), Long.class.getName() },
627                            DLFolderModelImpl.UUID_COLUMN_BITMASK |
628                            DLFolderModelImpl.GROUPID_COLUMN_BITMASK);
629            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
630                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
631                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
632                            new String[] { String.class.getName(), Long.class.getName() });
633    
634            /**
635             * 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.
636             *
637             * @param uuid the uuid
638             * @param groupId the group ID
639             * @return the matching document library folder
640             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
641             * @throws SystemException if a system exception occurred
642             */
643            @Override
644            public DLFolder findByUUID_G(String uuid, long groupId)
645                    throws NoSuchFolderException, SystemException {
646                    DLFolder dlFolder = fetchByUUID_G(uuid, groupId);
647    
648                    if (dlFolder == null) {
649                            StringBundler msg = new StringBundler(6);
650    
651                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
652    
653                            msg.append("uuid=");
654                            msg.append(uuid);
655    
656                            msg.append(", groupId=");
657                            msg.append(groupId);
658    
659                            msg.append(StringPool.CLOSE_CURLY_BRACE);
660    
661                            if (_log.isWarnEnabled()) {
662                                    _log.warn(msg.toString());
663                            }
664    
665                            throw new NoSuchFolderException(msg.toString());
666                    }
667    
668                    return dlFolder;
669            }
670    
671            /**
672             * 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.
673             *
674             * @param uuid the uuid
675             * @param groupId the group ID
676             * @return the matching document library folder, or <code>null</code> if a matching document library folder could not be found
677             * @throws SystemException if a system exception occurred
678             */
679            @Override
680            public DLFolder fetchByUUID_G(String uuid, long groupId)
681                    throws SystemException {
682                    return fetchByUUID_G(uuid, groupId, true);
683            }
684    
685            /**
686             * 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.
687             *
688             * @param uuid the uuid
689             * @param groupId the group ID
690             * @param retrieveFromCache whether to use the finder cache
691             * @return the matching document library folder, or <code>null</code> if a matching document library folder could not be found
692             * @throws SystemException if a system exception occurred
693             */
694            @Override
695            public DLFolder fetchByUUID_G(String uuid, long groupId,
696                    boolean retrieveFromCache) throws SystemException {
697                    Object[] finderArgs = new Object[] { uuid, groupId };
698    
699                    Object result = null;
700    
701                    if (retrieveFromCache) {
702                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
703                                            finderArgs, this);
704                    }
705    
706                    if (result instanceof DLFolder) {
707                            DLFolder dlFolder = (DLFolder)result;
708    
709                            if (!Validator.equals(uuid, dlFolder.getUuid()) ||
710                                            (groupId != dlFolder.getGroupId())) {
711                                    result = null;
712                            }
713                    }
714    
715                    if (result == null) {
716                            StringBundler query = new StringBundler(4);
717    
718                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
719    
720                            boolean bindUuid = false;
721    
722                            if (uuid == null) {
723                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
724                            }
725                            else if (uuid.equals(StringPool.BLANK)) {
726                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
727                            }
728                            else {
729                                    bindUuid = true;
730    
731                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
732                            }
733    
734                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
735    
736                            String sql = query.toString();
737    
738                            Session session = null;
739    
740                            try {
741                                    session = openSession();
742    
743                                    Query q = session.createQuery(sql);
744    
745                                    QueryPos qPos = QueryPos.getInstance(q);
746    
747                                    if (bindUuid) {
748                                            qPos.add(uuid);
749                                    }
750    
751                                    qPos.add(groupId);
752    
753                                    List<DLFolder> list = q.list();
754    
755                                    if (list.isEmpty()) {
756                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
757                                                    finderArgs, list);
758                                    }
759                                    else {
760                                            DLFolder dlFolder = list.get(0);
761    
762                                            result = dlFolder;
763    
764                                            cacheResult(dlFolder);
765    
766                                            if ((dlFolder.getUuid() == null) ||
767                                                            !dlFolder.getUuid().equals(uuid) ||
768                                                            (dlFolder.getGroupId() != groupId)) {
769                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
770                                                            finderArgs, dlFolder);
771                                            }
772                                    }
773                            }
774                            catch (Exception e) {
775                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
776                                            finderArgs);
777    
778                                    throw processException(e);
779                            }
780                            finally {
781                                    closeSession(session);
782                            }
783                    }
784    
785                    if (result instanceof List<?>) {
786                            return null;
787                    }
788                    else {
789                            return (DLFolder)result;
790                    }
791            }
792    
793            /**
794             * Removes the document library folder where uuid = &#63; and groupId = &#63; from the database.
795             *
796             * @param uuid the uuid
797             * @param groupId the group ID
798             * @return the document library folder that was removed
799             * @throws SystemException if a system exception occurred
800             */
801            @Override
802            public DLFolder removeByUUID_G(String uuid, long groupId)
803                    throws NoSuchFolderException, SystemException {
804                    DLFolder dlFolder = findByUUID_G(uuid, groupId);
805    
806                    return remove(dlFolder);
807            }
808    
809            /**
810             * Returns the number of document library folders where uuid = &#63; and groupId = &#63;.
811             *
812             * @param uuid the uuid
813             * @param groupId the group ID
814             * @return the number of matching document library folders
815             * @throws SystemException if a system exception occurred
816             */
817            @Override
818            public int countByUUID_G(String uuid, long groupId)
819                    throws SystemException {
820                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G;
821    
822                    Object[] finderArgs = new Object[] { uuid, groupId };
823    
824                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
825                                    this);
826    
827                    if (count == null) {
828                            StringBundler query = new StringBundler(3);
829    
830                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
831    
832                            boolean bindUuid = false;
833    
834                            if (uuid == null) {
835                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
836                            }
837                            else if (uuid.equals(StringPool.BLANK)) {
838                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
839                            }
840                            else {
841                                    bindUuid = true;
842    
843                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
844                            }
845    
846                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
847    
848                            String sql = query.toString();
849    
850                            Session session = null;
851    
852                            try {
853                                    session = openSession();
854    
855                                    Query q = session.createQuery(sql);
856    
857                                    QueryPos qPos = QueryPos.getInstance(q);
858    
859                                    if (bindUuid) {
860                                            qPos.add(uuid);
861                                    }
862    
863                                    qPos.add(groupId);
864    
865                                    count = (Long)q.uniqueResult();
866    
867                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
868                            }
869                            catch (Exception e) {
870                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
871    
872                                    throw processException(e);
873                            }
874                            finally {
875                                    closeSession(session);
876                            }
877                    }
878    
879                    return count.intValue();
880            }
881    
882            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "dlFolder.uuid IS NULL AND ";
883            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "dlFolder.uuid = ? AND ";
884            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(dlFolder.uuid IS NULL OR dlFolder.uuid = '') AND ";
885            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "dlFolder.groupId = ?";
886            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
887                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
888                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
889                            new String[] {
890                                    String.class.getName(), Long.class.getName(),
891                                    
892                            Integer.class.getName(), Integer.class.getName(),
893                                    OrderByComparator.class.getName()
894                            });
895            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
896                    new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
897                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
898                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
899                            new String[] { String.class.getName(), Long.class.getName() },
900                            DLFolderModelImpl.UUID_COLUMN_BITMASK |
901                            DLFolderModelImpl.COMPANYID_COLUMN_BITMASK |
902                            DLFolderModelImpl.PARENTFOLDERID_COLUMN_BITMASK |
903                            DLFolderModelImpl.NAME_COLUMN_BITMASK);
904            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
905                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
906                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
907                            new String[] { String.class.getName(), Long.class.getName() });
908    
909            /**
910             * Returns all the document library folders where uuid = &#63; and companyId = &#63;.
911             *
912             * @param uuid the uuid
913             * @param companyId the company ID
914             * @return the matching document library folders
915             * @throws SystemException if a system exception occurred
916             */
917            @Override
918            public List<DLFolder> findByUuid_C(String uuid, long companyId)
919                    throws SystemException {
920                    return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
921                            QueryUtil.ALL_POS, null);
922            }
923    
924            /**
925             * Returns a range of all the document library folders where uuid = &#63; and companyId = &#63;.
926             *
927             * <p>
928             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
929             * </p>
930             *
931             * @param uuid the uuid
932             * @param companyId the company ID
933             * @param start the lower bound of the range of document library folders
934             * @param end the upper bound of the range of document library folders (not inclusive)
935             * @return the range of matching document library folders
936             * @throws SystemException if a system exception occurred
937             */
938            @Override
939            public List<DLFolder> findByUuid_C(String uuid, long companyId, int start,
940                    int end) throws SystemException {
941                    return findByUuid_C(uuid, companyId, start, end, null);
942            }
943    
944            /**
945             * Returns an ordered range of all the document library folders where uuid = &#63; and companyId = &#63;.
946             *
947             * <p>
948             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
949             * </p>
950             *
951             * @param uuid the uuid
952             * @param companyId the company ID
953             * @param start the lower bound of the range of document library folders
954             * @param end the upper bound of the range of document library folders (not inclusive)
955             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
956             * @return the ordered range of matching document library folders
957             * @throws SystemException if a system exception occurred
958             */
959            @Override
960            public List<DLFolder> findByUuid_C(String uuid, long companyId, int start,
961                    int end, OrderByComparator orderByComparator) throws SystemException {
962                    boolean pagination = true;
963                    FinderPath finderPath = null;
964                    Object[] finderArgs = null;
965    
966                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
967                                    (orderByComparator == null)) {
968                            pagination = false;
969                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
970                            finderArgs = new Object[] { uuid, companyId };
971                    }
972                    else {
973                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
974                            finderArgs = new Object[] {
975                                            uuid, companyId,
976                                            
977                                            start, end, orderByComparator
978                                    };
979                    }
980    
981                    List<DLFolder> list = (List<DLFolder>)FinderCacheUtil.getResult(finderPath,
982                                    finderArgs, this);
983    
984                    if ((list != null) && !list.isEmpty()) {
985                            for (DLFolder dlFolder : list) {
986                                    if (!Validator.equals(uuid, dlFolder.getUuid()) ||
987                                                    (companyId != dlFolder.getCompanyId())) {
988                                            list = null;
989    
990                                            break;
991                                    }
992                            }
993                    }
994    
995                    if (list == null) {
996                            StringBundler query = null;
997    
998                            if (orderByComparator != null) {
999                                    query = new StringBundler(4 +
1000                                                    (orderByComparator.getOrderByFields().length * 3));
1001                            }
1002                            else {
1003                                    query = new StringBundler(4);
1004                            }
1005    
1006                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
1007    
1008                            boolean bindUuid = false;
1009    
1010                            if (uuid == null) {
1011                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1012                            }
1013                            else if (uuid.equals(StringPool.BLANK)) {
1014                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1015                            }
1016                            else {
1017                                    bindUuid = true;
1018    
1019                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1020                            }
1021    
1022                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1023    
1024                            if (orderByComparator != null) {
1025                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1026                                            orderByComparator);
1027                            }
1028                            else
1029                             if (pagination) {
1030                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
1031                            }
1032    
1033                            String sql = query.toString();
1034    
1035                            Session session = null;
1036    
1037                            try {
1038                                    session = openSession();
1039    
1040                                    Query q = session.createQuery(sql);
1041    
1042                                    QueryPos qPos = QueryPos.getInstance(q);
1043    
1044                                    if (bindUuid) {
1045                                            qPos.add(uuid);
1046                                    }
1047    
1048                                    qPos.add(companyId);
1049    
1050                                    if (!pagination) {
1051                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
1052                                                            start, end, false);
1053    
1054                                            Collections.sort(list);
1055    
1056                                            list = new UnmodifiableList<DLFolder>(list);
1057                                    }
1058                                    else {
1059                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
1060                                                            start, end);
1061                                    }
1062    
1063                                    cacheResult(list);
1064    
1065                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1066                            }
1067                            catch (Exception e) {
1068                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1069    
1070                                    throw processException(e);
1071                            }
1072                            finally {
1073                                    closeSession(session);
1074                            }
1075                    }
1076    
1077                    return list;
1078            }
1079    
1080            /**
1081             * Returns the first document library folder in the ordered set where uuid = &#63; and companyId = &#63;.
1082             *
1083             * @param uuid the uuid
1084             * @param companyId the company ID
1085             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1086             * @return the first matching document library folder
1087             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
1088             * @throws SystemException if a system exception occurred
1089             */
1090            @Override
1091            public DLFolder findByUuid_C_First(String uuid, long companyId,
1092                    OrderByComparator orderByComparator)
1093                    throws NoSuchFolderException, SystemException {
1094                    DLFolder dlFolder = fetchByUuid_C_First(uuid, companyId,
1095                                    orderByComparator);
1096    
1097                    if (dlFolder != null) {
1098                            return dlFolder;
1099                    }
1100    
1101                    StringBundler msg = new StringBundler(6);
1102    
1103                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1104    
1105                    msg.append("uuid=");
1106                    msg.append(uuid);
1107    
1108                    msg.append(", companyId=");
1109                    msg.append(companyId);
1110    
1111                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1112    
1113                    throw new NoSuchFolderException(msg.toString());
1114            }
1115    
1116            /**
1117             * Returns the first document library folder in the ordered set where uuid = &#63; and companyId = &#63;.
1118             *
1119             * @param uuid the uuid
1120             * @param companyId the company ID
1121             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1122             * @return the first matching document library folder, or <code>null</code> if a matching document library folder could not be found
1123             * @throws SystemException if a system exception occurred
1124             */
1125            @Override
1126            public DLFolder fetchByUuid_C_First(String uuid, long companyId,
1127                    OrderByComparator orderByComparator) throws SystemException {
1128                    List<DLFolder> list = findByUuid_C(uuid, companyId, 0, 1,
1129                                    orderByComparator);
1130    
1131                    if (!list.isEmpty()) {
1132                            return list.get(0);
1133                    }
1134    
1135                    return null;
1136            }
1137    
1138            /**
1139             * Returns the last document library folder in the ordered set where uuid = &#63; and companyId = &#63;.
1140             *
1141             * @param uuid the uuid
1142             * @param companyId the company ID
1143             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1144             * @return the last matching document library folder
1145             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
1146             * @throws SystemException if a system exception occurred
1147             */
1148            @Override
1149            public DLFolder findByUuid_C_Last(String uuid, long companyId,
1150                    OrderByComparator orderByComparator)
1151                    throws NoSuchFolderException, SystemException {
1152                    DLFolder dlFolder = fetchByUuid_C_Last(uuid, companyId,
1153                                    orderByComparator);
1154    
1155                    if (dlFolder != null) {
1156                            return dlFolder;
1157                    }
1158    
1159                    StringBundler msg = new StringBundler(6);
1160    
1161                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1162    
1163                    msg.append("uuid=");
1164                    msg.append(uuid);
1165    
1166                    msg.append(", companyId=");
1167                    msg.append(companyId);
1168    
1169                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1170    
1171                    throw new NoSuchFolderException(msg.toString());
1172            }
1173    
1174            /**
1175             * Returns the last document library folder in the ordered set where uuid = &#63; and companyId = &#63;.
1176             *
1177             * @param uuid the uuid
1178             * @param companyId the company ID
1179             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1180             * @return the last matching document library folder, or <code>null</code> if a matching document library folder could not be found
1181             * @throws SystemException if a system exception occurred
1182             */
1183            @Override
1184            public DLFolder fetchByUuid_C_Last(String uuid, long companyId,
1185                    OrderByComparator orderByComparator) throws SystemException {
1186                    int count = countByUuid_C(uuid, companyId);
1187    
1188                    if (count == 0) {
1189                            return null;
1190                    }
1191    
1192                    List<DLFolder> list = findByUuid_C(uuid, companyId, count - 1, count,
1193                                    orderByComparator);
1194    
1195                    if (!list.isEmpty()) {
1196                            return list.get(0);
1197                    }
1198    
1199                    return null;
1200            }
1201    
1202            /**
1203             * Returns the document library folders before and after the current document library folder in the ordered set where uuid = &#63; and companyId = &#63;.
1204             *
1205             * @param folderId the primary key of the current document library folder
1206             * @param uuid the uuid
1207             * @param companyId the company ID
1208             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1209             * @return the previous, current, and next document library folder
1210             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
1211             * @throws SystemException if a system exception occurred
1212             */
1213            @Override
1214            public DLFolder[] findByUuid_C_PrevAndNext(long folderId, String uuid,
1215                    long companyId, OrderByComparator orderByComparator)
1216                    throws NoSuchFolderException, SystemException {
1217                    DLFolder dlFolder = findByPrimaryKey(folderId);
1218    
1219                    Session session = null;
1220    
1221                    try {
1222                            session = openSession();
1223    
1224                            DLFolder[] array = new DLFolderImpl[3];
1225    
1226                            array[0] = getByUuid_C_PrevAndNext(session, dlFolder, uuid,
1227                                            companyId, orderByComparator, true);
1228    
1229                            array[1] = dlFolder;
1230    
1231                            array[2] = getByUuid_C_PrevAndNext(session, dlFolder, uuid,
1232                                            companyId, orderByComparator, false);
1233    
1234                            return array;
1235                    }
1236                    catch (Exception e) {
1237                            throw processException(e);
1238                    }
1239                    finally {
1240                            closeSession(session);
1241                    }
1242            }
1243    
1244            protected DLFolder getByUuid_C_PrevAndNext(Session session,
1245                    DLFolder dlFolder, String uuid, long companyId,
1246                    OrderByComparator orderByComparator, boolean previous) {
1247                    StringBundler query = null;
1248    
1249                    if (orderByComparator != null) {
1250                            query = new StringBundler(6 +
1251                                            (orderByComparator.getOrderByFields().length * 6));
1252                    }
1253                    else {
1254                            query = new StringBundler(3);
1255                    }
1256    
1257                    query.append(_SQL_SELECT_DLFOLDER_WHERE);
1258    
1259                    boolean bindUuid = false;
1260    
1261                    if (uuid == null) {
1262                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1263                    }
1264                    else if (uuid.equals(StringPool.BLANK)) {
1265                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1266                    }
1267                    else {
1268                            bindUuid = true;
1269    
1270                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1271                    }
1272    
1273                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1274    
1275                    if (orderByComparator != null) {
1276                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1277    
1278                            if (orderByConditionFields.length > 0) {
1279                                    query.append(WHERE_AND);
1280                            }
1281    
1282                            for (int i = 0; i < orderByConditionFields.length; i++) {
1283                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1284                                    query.append(orderByConditionFields[i]);
1285    
1286                                    if ((i + 1) < orderByConditionFields.length) {
1287                                            if (orderByComparator.isAscending() ^ previous) {
1288                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1289                                            }
1290                                            else {
1291                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1292                                            }
1293                                    }
1294                                    else {
1295                                            if (orderByComparator.isAscending() ^ previous) {
1296                                                    query.append(WHERE_GREATER_THAN);
1297                                            }
1298                                            else {
1299                                                    query.append(WHERE_LESSER_THAN);
1300                                            }
1301                                    }
1302                            }
1303    
1304                            query.append(ORDER_BY_CLAUSE);
1305    
1306                            String[] orderByFields = orderByComparator.getOrderByFields();
1307    
1308                            for (int i = 0; i < orderByFields.length; i++) {
1309                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1310                                    query.append(orderByFields[i]);
1311    
1312                                    if ((i + 1) < orderByFields.length) {
1313                                            if (orderByComparator.isAscending() ^ previous) {
1314                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1315                                            }
1316                                            else {
1317                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1318                                            }
1319                                    }
1320                                    else {
1321                                            if (orderByComparator.isAscending() ^ previous) {
1322                                                    query.append(ORDER_BY_ASC);
1323                                            }
1324                                            else {
1325                                                    query.append(ORDER_BY_DESC);
1326                                            }
1327                                    }
1328                            }
1329                    }
1330                    else {
1331                            query.append(DLFolderModelImpl.ORDER_BY_JPQL);
1332                    }
1333    
1334                    String sql = query.toString();
1335    
1336                    Query q = session.createQuery(sql);
1337    
1338                    q.setFirstResult(0);
1339                    q.setMaxResults(2);
1340    
1341                    QueryPos qPos = QueryPos.getInstance(q);
1342    
1343                    if (bindUuid) {
1344                            qPos.add(uuid);
1345                    }
1346    
1347                    qPos.add(companyId);
1348    
1349                    if (orderByComparator != null) {
1350                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
1351    
1352                            for (Object value : values) {
1353                                    qPos.add(value);
1354                            }
1355                    }
1356    
1357                    List<DLFolder> list = q.list();
1358    
1359                    if (list.size() == 2) {
1360                            return list.get(1);
1361                    }
1362                    else {
1363                            return null;
1364                    }
1365            }
1366    
1367            /**
1368             * Removes all the document library folders where uuid = &#63; and companyId = &#63; from the database.
1369             *
1370             * @param uuid the uuid
1371             * @param companyId the company ID
1372             * @throws SystemException if a system exception occurred
1373             */
1374            @Override
1375            public void removeByUuid_C(String uuid, long companyId)
1376                    throws SystemException {
1377                    for (DLFolder dlFolder : findByUuid_C(uuid, companyId,
1378                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1379                            remove(dlFolder);
1380                    }
1381            }
1382    
1383            /**
1384             * Returns the number of document library folders where uuid = &#63; and companyId = &#63;.
1385             *
1386             * @param uuid the uuid
1387             * @param companyId the company ID
1388             * @return the number of matching document library folders
1389             * @throws SystemException if a system exception occurred
1390             */
1391            @Override
1392            public int countByUuid_C(String uuid, long companyId)
1393                    throws SystemException {
1394                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1395    
1396                    Object[] finderArgs = new Object[] { uuid, companyId };
1397    
1398                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1399                                    this);
1400    
1401                    if (count == null) {
1402                            StringBundler query = new StringBundler(3);
1403    
1404                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
1405    
1406                            boolean bindUuid = false;
1407    
1408                            if (uuid == null) {
1409                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1410                            }
1411                            else if (uuid.equals(StringPool.BLANK)) {
1412                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1413                            }
1414                            else {
1415                                    bindUuid = true;
1416    
1417                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1418                            }
1419    
1420                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1421    
1422                            String sql = query.toString();
1423    
1424                            Session session = null;
1425    
1426                            try {
1427                                    session = openSession();
1428    
1429                                    Query q = session.createQuery(sql);
1430    
1431                                    QueryPos qPos = QueryPos.getInstance(q);
1432    
1433                                    if (bindUuid) {
1434                                            qPos.add(uuid);
1435                                    }
1436    
1437                                    qPos.add(companyId);
1438    
1439                                    count = (Long)q.uniqueResult();
1440    
1441                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1442                            }
1443                            catch (Exception e) {
1444                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1445    
1446                                    throw processException(e);
1447                            }
1448                            finally {
1449                                    closeSession(session);
1450                            }
1451                    }
1452    
1453                    return count.intValue();
1454            }
1455    
1456            private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "dlFolder.uuid IS NULL AND ";
1457            private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "dlFolder.uuid = ? AND ";
1458            private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(dlFolder.uuid IS NULL OR dlFolder.uuid = '') AND ";
1459            private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "dlFolder.companyId = ?";
1460            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
1461                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
1462                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
1463                            new String[] {
1464                                    Long.class.getName(),
1465                                    
1466                            Integer.class.getName(), Integer.class.getName(),
1467                                    OrderByComparator.class.getName()
1468                            });
1469            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
1470                    new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
1471                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
1472                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
1473                            new String[] { Long.class.getName() },
1474                            DLFolderModelImpl.GROUPID_COLUMN_BITMASK |
1475                            DLFolderModelImpl.PARENTFOLDERID_COLUMN_BITMASK |
1476                            DLFolderModelImpl.NAME_COLUMN_BITMASK);
1477            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
1478                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
1479                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
1480                            new String[] { Long.class.getName() });
1481    
1482            /**
1483             * Returns all the document library folders where groupId = &#63;.
1484             *
1485             * @param groupId the group ID
1486             * @return the matching document library folders
1487             * @throws SystemException if a system exception occurred
1488             */
1489            @Override
1490            public List<DLFolder> findByGroupId(long groupId) throws SystemException {
1491                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1492            }
1493    
1494            /**
1495             * Returns a range of all the document library folders where groupId = &#63;.
1496             *
1497             * <p>
1498             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
1499             * </p>
1500             *
1501             * @param groupId the group ID
1502             * @param start the lower bound of the range of document library folders
1503             * @param end the upper bound of the range of document library folders (not inclusive)
1504             * @return the range of matching document library folders
1505             * @throws SystemException if a system exception occurred
1506             */
1507            @Override
1508            public List<DLFolder> findByGroupId(long groupId, int start, int end)
1509                    throws SystemException {
1510                    return findByGroupId(groupId, start, end, null);
1511            }
1512    
1513            /**
1514             * Returns an ordered range of all the document library folders where groupId = &#63;.
1515             *
1516             * <p>
1517             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
1518             * </p>
1519             *
1520             * @param groupId the group ID
1521             * @param start the lower bound of the range of document library folders
1522             * @param end the upper bound of the range of document library folders (not inclusive)
1523             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1524             * @return the ordered range of matching document library folders
1525             * @throws SystemException if a system exception occurred
1526             */
1527            @Override
1528            public List<DLFolder> findByGroupId(long groupId, int start, int end,
1529                    OrderByComparator orderByComparator) throws SystemException {
1530                    boolean pagination = true;
1531                    FinderPath finderPath = null;
1532                    Object[] finderArgs = null;
1533    
1534                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1535                                    (orderByComparator == null)) {
1536                            pagination = false;
1537                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1538                            finderArgs = new Object[] { groupId };
1539                    }
1540                    else {
1541                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1542                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
1543                    }
1544    
1545                    List<DLFolder> list = (List<DLFolder>)FinderCacheUtil.getResult(finderPath,
1546                                    finderArgs, this);
1547    
1548                    if ((list != null) && !list.isEmpty()) {
1549                            for (DLFolder dlFolder : list) {
1550                                    if ((groupId != dlFolder.getGroupId())) {
1551                                            list = null;
1552    
1553                                            break;
1554                                    }
1555                            }
1556                    }
1557    
1558                    if (list == null) {
1559                            StringBundler query = null;
1560    
1561                            if (orderByComparator != null) {
1562                                    query = new StringBundler(3 +
1563                                                    (orderByComparator.getOrderByFields().length * 3));
1564                            }
1565                            else {
1566                                    query = new StringBundler(3);
1567                            }
1568    
1569                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
1570    
1571                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1572    
1573                            if (orderByComparator != null) {
1574                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1575                                            orderByComparator);
1576                            }
1577                            else
1578                             if (pagination) {
1579                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
1580                            }
1581    
1582                            String sql = query.toString();
1583    
1584                            Session session = null;
1585    
1586                            try {
1587                                    session = openSession();
1588    
1589                                    Query q = session.createQuery(sql);
1590    
1591                                    QueryPos qPos = QueryPos.getInstance(q);
1592    
1593                                    qPos.add(groupId);
1594    
1595                                    if (!pagination) {
1596                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
1597                                                            start, end, false);
1598    
1599                                            Collections.sort(list);
1600    
1601                                            list = new UnmodifiableList<DLFolder>(list);
1602                                    }
1603                                    else {
1604                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
1605                                                            start, end);
1606                                    }
1607    
1608                                    cacheResult(list);
1609    
1610                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1611                            }
1612                            catch (Exception e) {
1613                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1614    
1615                                    throw processException(e);
1616                            }
1617                            finally {
1618                                    closeSession(session);
1619                            }
1620                    }
1621    
1622                    return list;
1623            }
1624    
1625            /**
1626             * Returns the first document library folder in the ordered set where groupId = &#63;.
1627             *
1628             * @param groupId the group ID
1629             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1630             * @return the first matching document library folder
1631             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
1632             * @throws SystemException if a system exception occurred
1633             */
1634            @Override
1635            public DLFolder findByGroupId_First(long groupId,
1636                    OrderByComparator orderByComparator)
1637                    throws NoSuchFolderException, SystemException {
1638                    DLFolder dlFolder = fetchByGroupId_First(groupId, orderByComparator);
1639    
1640                    if (dlFolder != null) {
1641                            return dlFolder;
1642                    }
1643    
1644                    StringBundler msg = new StringBundler(4);
1645    
1646                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1647    
1648                    msg.append("groupId=");
1649                    msg.append(groupId);
1650    
1651                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1652    
1653                    throw new NoSuchFolderException(msg.toString());
1654            }
1655    
1656            /**
1657             * Returns the first document library folder in the ordered set where groupId = &#63;.
1658             *
1659             * @param groupId the group ID
1660             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1661             * @return the first matching document library folder, or <code>null</code> if a matching document library folder could not be found
1662             * @throws SystemException if a system exception occurred
1663             */
1664            @Override
1665            public DLFolder fetchByGroupId_First(long groupId,
1666                    OrderByComparator orderByComparator) throws SystemException {
1667                    List<DLFolder> list = findByGroupId(groupId, 0, 1, orderByComparator);
1668    
1669                    if (!list.isEmpty()) {
1670                            return list.get(0);
1671                    }
1672    
1673                    return null;
1674            }
1675    
1676            /**
1677             * Returns the last document library folder in the ordered set where groupId = &#63;.
1678             *
1679             * @param groupId the group ID
1680             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1681             * @return the last matching document library folder
1682             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
1683             * @throws SystemException if a system exception occurred
1684             */
1685            @Override
1686            public DLFolder findByGroupId_Last(long groupId,
1687                    OrderByComparator orderByComparator)
1688                    throws NoSuchFolderException, SystemException {
1689                    DLFolder dlFolder = fetchByGroupId_Last(groupId, orderByComparator);
1690    
1691                    if (dlFolder != null) {
1692                            return dlFolder;
1693                    }
1694    
1695                    StringBundler msg = new StringBundler(4);
1696    
1697                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1698    
1699                    msg.append("groupId=");
1700                    msg.append(groupId);
1701    
1702                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1703    
1704                    throw new NoSuchFolderException(msg.toString());
1705            }
1706    
1707            /**
1708             * Returns the last document library folder in the ordered set where groupId = &#63;.
1709             *
1710             * @param groupId the group ID
1711             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1712             * @return the last matching document library folder, or <code>null</code> if a matching document library folder could not be found
1713             * @throws SystemException if a system exception occurred
1714             */
1715            @Override
1716            public DLFolder fetchByGroupId_Last(long groupId,
1717                    OrderByComparator orderByComparator) throws SystemException {
1718                    int count = countByGroupId(groupId);
1719    
1720                    if (count == 0) {
1721                            return null;
1722                    }
1723    
1724                    List<DLFolder> list = findByGroupId(groupId, count - 1, count,
1725                                    orderByComparator);
1726    
1727                    if (!list.isEmpty()) {
1728                            return list.get(0);
1729                    }
1730    
1731                    return null;
1732            }
1733    
1734            /**
1735             * Returns the document library folders before and after the current document library folder in the ordered set where groupId = &#63;.
1736             *
1737             * @param folderId the primary key of the current document library folder
1738             * @param groupId the group ID
1739             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1740             * @return the previous, current, and next document library folder
1741             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
1742             * @throws SystemException if a system exception occurred
1743             */
1744            @Override
1745            public DLFolder[] findByGroupId_PrevAndNext(long folderId, long groupId,
1746                    OrderByComparator orderByComparator)
1747                    throws NoSuchFolderException, SystemException {
1748                    DLFolder dlFolder = findByPrimaryKey(folderId);
1749    
1750                    Session session = null;
1751    
1752                    try {
1753                            session = openSession();
1754    
1755                            DLFolder[] array = new DLFolderImpl[3];
1756    
1757                            array[0] = getByGroupId_PrevAndNext(session, dlFolder, groupId,
1758                                            orderByComparator, true);
1759    
1760                            array[1] = dlFolder;
1761    
1762                            array[2] = getByGroupId_PrevAndNext(session, dlFolder, groupId,
1763                                            orderByComparator, false);
1764    
1765                            return array;
1766                    }
1767                    catch (Exception e) {
1768                            throw processException(e);
1769                    }
1770                    finally {
1771                            closeSession(session);
1772                    }
1773            }
1774    
1775            protected DLFolder getByGroupId_PrevAndNext(Session session,
1776                    DLFolder dlFolder, long groupId, OrderByComparator orderByComparator,
1777                    boolean previous) {
1778                    StringBundler query = null;
1779    
1780                    if (orderByComparator != null) {
1781                            query = new StringBundler(6 +
1782                                            (orderByComparator.getOrderByFields().length * 6));
1783                    }
1784                    else {
1785                            query = new StringBundler(3);
1786                    }
1787    
1788                    query.append(_SQL_SELECT_DLFOLDER_WHERE);
1789    
1790                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1791    
1792                    if (orderByComparator != null) {
1793                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1794    
1795                            if (orderByConditionFields.length > 0) {
1796                                    query.append(WHERE_AND);
1797                            }
1798    
1799                            for (int i = 0; i < orderByConditionFields.length; i++) {
1800                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1801                                    query.append(orderByConditionFields[i]);
1802    
1803                                    if ((i + 1) < orderByConditionFields.length) {
1804                                            if (orderByComparator.isAscending() ^ previous) {
1805                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1806                                            }
1807                                            else {
1808                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1809                                            }
1810                                    }
1811                                    else {
1812                                            if (orderByComparator.isAscending() ^ previous) {
1813                                                    query.append(WHERE_GREATER_THAN);
1814                                            }
1815                                            else {
1816                                                    query.append(WHERE_LESSER_THAN);
1817                                            }
1818                                    }
1819                            }
1820    
1821                            query.append(ORDER_BY_CLAUSE);
1822    
1823                            String[] orderByFields = orderByComparator.getOrderByFields();
1824    
1825                            for (int i = 0; i < orderByFields.length; i++) {
1826                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1827                                    query.append(orderByFields[i]);
1828    
1829                                    if ((i + 1) < orderByFields.length) {
1830                                            if (orderByComparator.isAscending() ^ previous) {
1831                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1832                                            }
1833                                            else {
1834                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1835                                            }
1836                                    }
1837                                    else {
1838                                            if (orderByComparator.isAscending() ^ previous) {
1839                                                    query.append(ORDER_BY_ASC);
1840                                            }
1841                                            else {
1842                                                    query.append(ORDER_BY_DESC);
1843                                            }
1844                                    }
1845                            }
1846                    }
1847                    else {
1848                            query.append(DLFolderModelImpl.ORDER_BY_JPQL);
1849                    }
1850    
1851                    String sql = query.toString();
1852    
1853                    Query q = session.createQuery(sql);
1854    
1855                    q.setFirstResult(0);
1856                    q.setMaxResults(2);
1857    
1858                    QueryPos qPos = QueryPos.getInstance(q);
1859    
1860                    qPos.add(groupId);
1861    
1862                    if (orderByComparator != null) {
1863                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
1864    
1865                            for (Object value : values) {
1866                                    qPos.add(value);
1867                            }
1868                    }
1869    
1870                    List<DLFolder> list = q.list();
1871    
1872                    if (list.size() == 2) {
1873                            return list.get(1);
1874                    }
1875                    else {
1876                            return null;
1877                    }
1878            }
1879    
1880            /**
1881             * Returns all the document library folders that the user has permission to view where groupId = &#63;.
1882             *
1883             * @param groupId the group ID
1884             * @return the matching document library folders that the user has permission to view
1885             * @throws SystemException if a system exception occurred
1886             */
1887            @Override
1888            public List<DLFolder> filterFindByGroupId(long groupId)
1889                    throws SystemException {
1890                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1891                            QueryUtil.ALL_POS, null);
1892            }
1893    
1894            /**
1895             * Returns a range of all the document library folders that the user has permission to view where groupId = &#63;.
1896             *
1897             * <p>
1898             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
1899             * </p>
1900             *
1901             * @param groupId the group ID
1902             * @param start the lower bound of the range of document library folders
1903             * @param end the upper bound of the range of document library folders (not inclusive)
1904             * @return the range of matching document library folders that the user has permission to view
1905             * @throws SystemException if a system exception occurred
1906             */
1907            @Override
1908            public List<DLFolder> filterFindByGroupId(long groupId, int start, int end)
1909                    throws SystemException {
1910                    return filterFindByGroupId(groupId, start, end, null);
1911            }
1912    
1913            /**
1914             * Returns an ordered range of all the document library folders that the user has permissions to view where groupId = &#63;.
1915             *
1916             * <p>
1917             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
1918             * </p>
1919             *
1920             * @param groupId the group ID
1921             * @param start the lower bound of the range of document library folders
1922             * @param end the upper bound of the range of document library folders (not inclusive)
1923             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1924             * @return the ordered range of matching document library folders that the user has permission to view
1925             * @throws SystemException if a system exception occurred
1926             */
1927            @Override
1928            public List<DLFolder> filterFindByGroupId(long groupId, int start, int end,
1929                    OrderByComparator orderByComparator) throws SystemException {
1930                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1931                            return findByGroupId(groupId, start, end, orderByComparator);
1932                    }
1933    
1934                    StringBundler query = null;
1935    
1936                    if (orderByComparator != null) {
1937                            query = new StringBundler(3 +
1938                                            (orderByComparator.getOrderByFields().length * 3));
1939                    }
1940                    else {
1941                            query = new StringBundler(3);
1942                    }
1943    
1944                    if (getDB().isSupportsInlineDistinct()) {
1945                            query.append(_FILTER_SQL_SELECT_DLFOLDER_WHERE);
1946                    }
1947                    else {
1948                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1);
1949                    }
1950    
1951                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1952    
1953                    if (!getDB().isSupportsInlineDistinct()) {
1954                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2);
1955                    }
1956    
1957                    if (orderByComparator != null) {
1958                            if (getDB().isSupportsInlineDistinct()) {
1959                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1960                                            orderByComparator, true);
1961                            }
1962                            else {
1963                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1964                                            orderByComparator, true);
1965                            }
1966                    }
1967                    else {
1968                            if (getDB().isSupportsInlineDistinct()) {
1969                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
1970                            }
1971                            else {
1972                                    query.append(DLFolderModelImpl.ORDER_BY_SQL);
1973                            }
1974                    }
1975    
1976                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1977                                    DLFolder.class.getName(),
1978                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1979    
1980                    Session session = null;
1981    
1982                    try {
1983                            session = openSession();
1984    
1985                            SQLQuery q = session.createSQLQuery(sql);
1986    
1987                            if (getDB().isSupportsInlineDistinct()) {
1988                                    q.addEntity(_FILTER_ENTITY_ALIAS, DLFolderImpl.class);
1989                            }
1990                            else {
1991                                    q.addEntity(_FILTER_ENTITY_TABLE, DLFolderImpl.class);
1992                            }
1993    
1994                            QueryPos qPos = QueryPos.getInstance(q);
1995    
1996                            qPos.add(groupId);
1997    
1998                            return (List<DLFolder>)QueryUtil.list(q, getDialect(), start, end);
1999                    }
2000                    catch (Exception e) {
2001                            throw processException(e);
2002                    }
2003                    finally {
2004                            closeSession(session);
2005                    }
2006            }
2007    
2008            /**
2009             * 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;.
2010             *
2011             * @param folderId the primary key of the current document library folder
2012             * @param groupId the group ID
2013             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2014             * @return the previous, current, and next document library folder
2015             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
2016             * @throws SystemException if a system exception occurred
2017             */
2018            @Override
2019            public DLFolder[] filterFindByGroupId_PrevAndNext(long folderId,
2020                    long groupId, OrderByComparator orderByComparator)
2021                    throws NoSuchFolderException, SystemException {
2022                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2023                            return findByGroupId_PrevAndNext(folderId, groupId,
2024                                    orderByComparator);
2025                    }
2026    
2027                    DLFolder dlFolder = findByPrimaryKey(folderId);
2028    
2029                    Session session = null;
2030    
2031                    try {
2032                            session = openSession();
2033    
2034                            DLFolder[] array = new DLFolderImpl[3];
2035    
2036                            array[0] = filterGetByGroupId_PrevAndNext(session, dlFolder,
2037                                            groupId, orderByComparator, true);
2038    
2039                            array[1] = dlFolder;
2040    
2041                            array[2] = filterGetByGroupId_PrevAndNext(session, dlFolder,
2042                                            groupId, orderByComparator, false);
2043    
2044                            return array;
2045                    }
2046                    catch (Exception e) {
2047                            throw processException(e);
2048                    }
2049                    finally {
2050                            closeSession(session);
2051                    }
2052            }
2053    
2054            protected DLFolder filterGetByGroupId_PrevAndNext(Session session,
2055                    DLFolder dlFolder, long groupId, OrderByComparator orderByComparator,
2056                    boolean previous) {
2057                    StringBundler query = null;
2058    
2059                    if (orderByComparator != null) {
2060                            query = new StringBundler(6 +
2061                                            (orderByComparator.getOrderByFields().length * 6));
2062                    }
2063                    else {
2064                            query = new StringBundler(3);
2065                    }
2066    
2067                    if (getDB().isSupportsInlineDistinct()) {
2068                            query.append(_FILTER_SQL_SELECT_DLFOLDER_WHERE);
2069                    }
2070                    else {
2071                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1);
2072                    }
2073    
2074                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2075    
2076                    if (!getDB().isSupportsInlineDistinct()) {
2077                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2);
2078                    }
2079    
2080                    if (orderByComparator != null) {
2081                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2082    
2083                            if (orderByConditionFields.length > 0) {
2084                                    query.append(WHERE_AND);
2085                            }
2086    
2087                            for (int i = 0; i < orderByConditionFields.length; i++) {
2088                                    if (getDB().isSupportsInlineDistinct()) {
2089                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2090                                    }
2091                                    else {
2092                                            query.append(_ORDER_BY_ENTITY_TABLE);
2093                                    }
2094    
2095                                    query.append(orderByConditionFields[i]);
2096    
2097                                    if ((i + 1) < orderByConditionFields.length) {
2098                                            if (orderByComparator.isAscending() ^ previous) {
2099                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2100                                            }
2101                                            else {
2102                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2103                                            }
2104                                    }
2105                                    else {
2106                                            if (orderByComparator.isAscending() ^ previous) {
2107                                                    query.append(WHERE_GREATER_THAN);
2108                                            }
2109                                            else {
2110                                                    query.append(WHERE_LESSER_THAN);
2111                                            }
2112                                    }
2113                            }
2114    
2115                            query.append(ORDER_BY_CLAUSE);
2116    
2117                            String[] orderByFields = orderByComparator.getOrderByFields();
2118    
2119                            for (int i = 0; i < orderByFields.length; i++) {
2120                                    if (getDB().isSupportsInlineDistinct()) {
2121                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2122                                    }
2123                                    else {
2124                                            query.append(_ORDER_BY_ENTITY_TABLE);
2125                                    }
2126    
2127                                    query.append(orderByFields[i]);
2128    
2129                                    if ((i + 1) < orderByFields.length) {
2130                                            if (orderByComparator.isAscending() ^ previous) {
2131                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2132                                            }
2133                                            else {
2134                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2135                                            }
2136                                    }
2137                                    else {
2138                                            if (orderByComparator.isAscending() ^ previous) {
2139                                                    query.append(ORDER_BY_ASC);
2140                                            }
2141                                            else {
2142                                                    query.append(ORDER_BY_DESC);
2143                                            }
2144                                    }
2145                            }
2146                    }
2147                    else {
2148                            if (getDB().isSupportsInlineDistinct()) {
2149                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
2150                            }
2151                            else {
2152                                    query.append(DLFolderModelImpl.ORDER_BY_SQL);
2153                            }
2154                    }
2155    
2156                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2157                                    DLFolder.class.getName(),
2158                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2159    
2160                    SQLQuery q = session.createSQLQuery(sql);
2161    
2162                    q.setFirstResult(0);
2163                    q.setMaxResults(2);
2164    
2165                    if (getDB().isSupportsInlineDistinct()) {
2166                            q.addEntity(_FILTER_ENTITY_ALIAS, DLFolderImpl.class);
2167                    }
2168                    else {
2169                            q.addEntity(_FILTER_ENTITY_TABLE, DLFolderImpl.class);
2170                    }
2171    
2172                    QueryPos qPos = QueryPos.getInstance(q);
2173    
2174                    qPos.add(groupId);
2175    
2176                    if (orderByComparator != null) {
2177                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
2178    
2179                            for (Object value : values) {
2180                                    qPos.add(value);
2181                            }
2182                    }
2183    
2184                    List<DLFolder> list = q.list();
2185    
2186                    if (list.size() == 2) {
2187                            return list.get(1);
2188                    }
2189                    else {
2190                            return null;
2191                    }
2192            }
2193    
2194            /**
2195             * Removes all the document library folders where groupId = &#63; from the database.
2196             *
2197             * @param groupId the group ID
2198             * @throws SystemException if a system exception occurred
2199             */
2200            @Override
2201            public void removeByGroupId(long groupId) throws SystemException {
2202                    for (DLFolder dlFolder : findByGroupId(groupId, QueryUtil.ALL_POS,
2203                                    QueryUtil.ALL_POS, null)) {
2204                            remove(dlFolder);
2205                    }
2206            }
2207    
2208            /**
2209             * Returns the number of document library folders where groupId = &#63;.
2210             *
2211             * @param groupId the group ID
2212             * @return the number of matching document library folders
2213             * @throws SystemException if a system exception occurred
2214             */
2215            @Override
2216            public int countByGroupId(long groupId) throws SystemException {
2217                    FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
2218    
2219                    Object[] finderArgs = new Object[] { groupId };
2220    
2221                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2222                                    this);
2223    
2224                    if (count == null) {
2225                            StringBundler query = new StringBundler(2);
2226    
2227                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
2228    
2229                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2230    
2231                            String sql = query.toString();
2232    
2233                            Session session = null;
2234    
2235                            try {
2236                                    session = openSession();
2237    
2238                                    Query q = session.createQuery(sql);
2239    
2240                                    QueryPos qPos = QueryPos.getInstance(q);
2241    
2242                                    qPos.add(groupId);
2243    
2244                                    count = (Long)q.uniqueResult();
2245    
2246                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2247                            }
2248                            catch (Exception e) {
2249                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2250    
2251                                    throw processException(e);
2252                            }
2253                            finally {
2254                                    closeSession(session);
2255                            }
2256                    }
2257    
2258                    return count.intValue();
2259            }
2260    
2261            /**
2262             * Returns the number of document library folders that the user has permission to view where groupId = &#63;.
2263             *
2264             * @param groupId the group ID
2265             * @return the number of matching document library folders that the user has permission to view
2266             * @throws SystemException if a system exception occurred
2267             */
2268            @Override
2269            public int filterCountByGroupId(long groupId) throws SystemException {
2270                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2271                            return countByGroupId(groupId);
2272                    }
2273    
2274                    StringBundler query = new StringBundler(2);
2275    
2276                    query.append(_FILTER_SQL_COUNT_DLFOLDER_WHERE);
2277    
2278                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2279    
2280                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2281                                    DLFolder.class.getName(),
2282                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2283    
2284                    Session session = null;
2285    
2286                    try {
2287                            session = openSession();
2288    
2289                            SQLQuery q = session.createSQLQuery(sql);
2290    
2291                            q.addScalar(COUNT_COLUMN_NAME,
2292                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
2293    
2294                            QueryPos qPos = QueryPos.getInstance(q);
2295    
2296                            qPos.add(groupId);
2297    
2298                            Long count = (Long)q.uniqueResult();
2299    
2300                            return count.intValue();
2301                    }
2302                    catch (Exception e) {
2303                            throw processException(e);
2304                    }
2305                    finally {
2306                            closeSession(session);
2307                    }
2308            }
2309    
2310            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "dlFolder.groupId = ?";
2311            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
2312                    new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
2313                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
2314                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
2315                            new String[] {
2316                                    Long.class.getName(),
2317                                    
2318                            Integer.class.getName(), Integer.class.getName(),
2319                                    OrderByComparator.class.getName()
2320                            });
2321            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
2322                    new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
2323                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
2324                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
2325                            new String[] { Long.class.getName() },
2326                            DLFolderModelImpl.COMPANYID_COLUMN_BITMASK |
2327                            DLFolderModelImpl.PARENTFOLDERID_COLUMN_BITMASK |
2328                            DLFolderModelImpl.NAME_COLUMN_BITMASK);
2329            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
2330                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
2331                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
2332                            new String[] { Long.class.getName() });
2333    
2334            /**
2335             * Returns all the document library folders where companyId = &#63;.
2336             *
2337             * @param companyId the company ID
2338             * @return the matching document library folders
2339             * @throws SystemException if a system exception occurred
2340             */
2341            @Override
2342            public List<DLFolder> findByCompanyId(long companyId)
2343                    throws SystemException {
2344                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2345                            null);
2346            }
2347    
2348            /**
2349             * Returns a range of all the document library folders where companyId = &#63;.
2350             *
2351             * <p>
2352             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
2353             * </p>
2354             *
2355             * @param companyId the company ID
2356             * @param start the lower bound of the range of document library folders
2357             * @param end the upper bound of the range of document library folders (not inclusive)
2358             * @return the range of matching document library folders
2359             * @throws SystemException if a system exception occurred
2360             */
2361            @Override
2362            public List<DLFolder> findByCompanyId(long companyId, int start, int end)
2363                    throws SystemException {
2364                    return findByCompanyId(companyId, start, end, null);
2365            }
2366    
2367            /**
2368             * Returns an ordered range of all the document library folders where companyId = &#63;.
2369             *
2370             * <p>
2371             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
2372             * </p>
2373             *
2374             * @param companyId the company ID
2375             * @param start the lower bound of the range of document library folders
2376             * @param end the upper bound of the range of document library folders (not inclusive)
2377             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2378             * @return the ordered range of matching document library folders
2379             * @throws SystemException if a system exception occurred
2380             */
2381            @Override
2382            public List<DLFolder> findByCompanyId(long companyId, int start, int end,
2383                    OrderByComparator orderByComparator) throws SystemException {
2384                    boolean pagination = true;
2385                    FinderPath finderPath = null;
2386                    Object[] finderArgs = null;
2387    
2388                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2389                                    (orderByComparator == null)) {
2390                            pagination = false;
2391                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
2392                            finderArgs = new Object[] { companyId };
2393                    }
2394                    else {
2395                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
2396                            finderArgs = new Object[] { companyId, start, end, orderByComparator };
2397                    }
2398    
2399                    List<DLFolder> list = (List<DLFolder>)FinderCacheUtil.getResult(finderPath,
2400                                    finderArgs, this);
2401    
2402                    if ((list != null) && !list.isEmpty()) {
2403                            for (DLFolder dlFolder : list) {
2404                                    if ((companyId != dlFolder.getCompanyId())) {
2405                                            list = null;
2406    
2407                                            break;
2408                                    }
2409                            }
2410                    }
2411    
2412                    if (list == null) {
2413                            StringBundler query = null;
2414    
2415                            if (orderByComparator != null) {
2416                                    query = new StringBundler(3 +
2417                                                    (orderByComparator.getOrderByFields().length * 3));
2418                            }
2419                            else {
2420                                    query = new StringBundler(3);
2421                            }
2422    
2423                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
2424    
2425                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2426    
2427                            if (orderByComparator != null) {
2428                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2429                                            orderByComparator);
2430                            }
2431                            else
2432                             if (pagination) {
2433                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
2434                            }
2435    
2436                            String sql = query.toString();
2437    
2438                            Session session = null;
2439    
2440                            try {
2441                                    session = openSession();
2442    
2443                                    Query q = session.createQuery(sql);
2444    
2445                                    QueryPos qPos = QueryPos.getInstance(q);
2446    
2447                                    qPos.add(companyId);
2448    
2449                                    if (!pagination) {
2450                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
2451                                                            start, end, false);
2452    
2453                                            Collections.sort(list);
2454    
2455                                            list = new UnmodifiableList<DLFolder>(list);
2456                                    }
2457                                    else {
2458                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
2459                                                            start, end);
2460                                    }
2461    
2462                                    cacheResult(list);
2463    
2464                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2465                            }
2466                            catch (Exception e) {
2467                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2468    
2469                                    throw processException(e);
2470                            }
2471                            finally {
2472                                    closeSession(session);
2473                            }
2474                    }
2475    
2476                    return list;
2477            }
2478    
2479            /**
2480             * Returns the first document library folder in the ordered set where companyId = &#63;.
2481             *
2482             * @param companyId the company ID
2483             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2484             * @return the first matching document library folder
2485             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
2486             * @throws SystemException if a system exception occurred
2487             */
2488            @Override
2489            public DLFolder findByCompanyId_First(long companyId,
2490                    OrderByComparator orderByComparator)
2491                    throws NoSuchFolderException, SystemException {
2492                    DLFolder dlFolder = fetchByCompanyId_First(companyId, orderByComparator);
2493    
2494                    if (dlFolder != null) {
2495                            return dlFolder;
2496                    }
2497    
2498                    StringBundler msg = new StringBundler(4);
2499    
2500                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2501    
2502                    msg.append("companyId=");
2503                    msg.append(companyId);
2504    
2505                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2506    
2507                    throw new NoSuchFolderException(msg.toString());
2508            }
2509    
2510            /**
2511             * Returns the first document library folder in the ordered set where companyId = &#63;.
2512             *
2513             * @param companyId the company ID
2514             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2515             * @return the first matching document library folder, or <code>null</code> if a matching document library folder could not be found
2516             * @throws SystemException if a system exception occurred
2517             */
2518            @Override
2519            public DLFolder fetchByCompanyId_First(long companyId,
2520                    OrderByComparator orderByComparator) throws SystemException {
2521                    List<DLFolder> list = findByCompanyId(companyId, 0, 1, orderByComparator);
2522    
2523                    if (!list.isEmpty()) {
2524                            return list.get(0);
2525                    }
2526    
2527                    return null;
2528            }
2529    
2530            /**
2531             * Returns the last document library folder in the ordered set where companyId = &#63;.
2532             *
2533             * @param companyId the company ID
2534             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2535             * @return the last matching document library folder
2536             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
2537             * @throws SystemException if a system exception occurred
2538             */
2539            @Override
2540            public DLFolder findByCompanyId_Last(long companyId,
2541                    OrderByComparator orderByComparator)
2542                    throws NoSuchFolderException, SystemException {
2543                    DLFolder dlFolder = fetchByCompanyId_Last(companyId, orderByComparator);
2544    
2545                    if (dlFolder != null) {
2546                            return dlFolder;
2547                    }
2548    
2549                    StringBundler msg = new StringBundler(4);
2550    
2551                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2552    
2553                    msg.append("companyId=");
2554                    msg.append(companyId);
2555    
2556                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2557    
2558                    throw new NoSuchFolderException(msg.toString());
2559            }
2560    
2561            /**
2562             * Returns the last document library folder in the ordered set where companyId = &#63;.
2563             *
2564             * @param companyId the company ID
2565             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2566             * @return the last matching document library folder, or <code>null</code> if a matching document library folder could not be found
2567             * @throws SystemException if a system exception occurred
2568             */
2569            @Override
2570            public DLFolder fetchByCompanyId_Last(long companyId,
2571                    OrderByComparator orderByComparator) throws SystemException {
2572                    int count = countByCompanyId(companyId);
2573    
2574                    if (count == 0) {
2575                            return null;
2576                    }
2577    
2578                    List<DLFolder> list = findByCompanyId(companyId, count - 1, count,
2579                                    orderByComparator);
2580    
2581                    if (!list.isEmpty()) {
2582                            return list.get(0);
2583                    }
2584    
2585                    return null;
2586            }
2587    
2588            /**
2589             * Returns the document library folders before and after the current document library folder in the ordered set where companyId = &#63;.
2590             *
2591             * @param folderId the primary key of the current document library folder
2592             * @param companyId the company ID
2593             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2594             * @return the previous, current, and next document library folder
2595             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
2596             * @throws SystemException if a system exception occurred
2597             */
2598            @Override
2599            public DLFolder[] findByCompanyId_PrevAndNext(long folderId,
2600                    long companyId, OrderByComparator orderByComparator)
2601                    throws NoSuchFolderException, SystemException {
2602                    DLFolder dlFolder = findByPrimaryKey(folderId);
2603    
2604                    Session session = null;
2605    
2606                    try {
2607                            session = openSession();
2608    
2609                            DLFolder[] array = new DLFolderImpl[3];
2610    
2611                            array[0] = getByCompanyId_PrevAndNext(session, dlFolder, companyId,
2612                                            orderByComparator, true);
2613    
2614                            array[1] = dlFolder;
2615    
2616                            array[2] = getByCompanyId_PrevAndNext(session, dlFolder, companyId,
2617                                            orderByComparator, false);
2618    
2619                            return array;
2620                    }
2621                    catch (Exception e) {
2622                            throw processException(e);
2623                    }
2624                    finally {
2625                            closeSession(session);
2626                    }
2627            }
2628    
2629            protected DLFolder getByCompanyId_PrevAndNext(Session session,
2630                    DLFolder dlFolder, long companyId, OrderByComparator orderByComparator,
2631                    boolean previous) {
2632                    StringBundler query = null;
2633    
2634                    if (orderByComparator != null) {
2635                            query = new StringBundler(6 +
2636                                            (orderByComparator.getOrderByFields().length * 6));
2637                    }
2638                    else {
2639                            query = new StringBundler(3);
2640                    }
2641    
2642                    query.append(_SQL_SELECT_DLFOLDER_WHERE);
2643    
2644                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2645    
2646                    if (orderByComparator != null) {
2647                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2648    
2649                            if (orderByConditionFields.length > 0) {
2650                                    query.append(WHERE_AND);
2651                            }
2652    
2653                            for (int i = 0; i < orderByConditionFields.length; i++) {
2654                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2655                                    query.append(orderByConditionFields[i]);
2656    
2657                                    if ((i + 1) < orderByConditionFields.length) {
2658                                            if (orderByComparator.isAscending() ^ previous) {
2659                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2660                                            }
2661                                            else {
2662                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2663                                            }
2664                                    }
2665                                    else {
2666                                            if (orderByComparator.isAscending() ^ previous) {
2667                                                    query.append(WHERE_GREATER_THAN);
2668                                            }
2669                                            else {
2670                                                    query.append(WHERE_LESSER_THAN);
2671                                            }
2672                                    }
2673                            }
2674    
2675                            query.append(ORDER_BY_CLAUSE);
2676    
2677                            String[] orderByFields = orderByComparator.getOrderByFields();
2678    
2679                            for (int i = 0; i < orderByFields.length; i++) {
2680                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2681                                    query.append(orderByFields[i]);
2682    
2683                                    if ((i + 1) < orderByFields.length) {
2684                                            if (orderByComparator.isAscending() ^ previous) {
2685                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2686                                            }
2687                                            else {
2688                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2689                                            }
2690                                    }
2691                                    else {
2692                                            if (orderByComparator.isAscending() ^ previous) {
2693                                                    query.append(ORDER_BY_ASC);
2694                                            }
2695                                            else {
2696                                                    query.append(ORDER_BY_DESC);
2697                                            }
2698                                    }
2699                            }
2700                    }
2701                    else {
2702                            query.append(DLFolderModelImpl.ORDER_BY_JPQL);
2703                    }
2704    
2705                    String sql = query.toString();
2706    
2707                    Query q = session.createQuery(sql);
2708    
2709                    q.setFirstResult(0);
2710                    q.setMaxResults(2);
2711    
2712                    QueryPos qPos = QueryPos.getInstance(q);
2713    
2714                    qPos.add(companyId);
2715    
2716                    if (orderByComparator != null) {
2717                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
2718    
2719                            for (Object value : values) {
2720                                    qPos.add(value);
2721                            }
2722                    }
2723    
2724                    List<DLFolder> list = q.list();
2725    
2726                    if (list.size() == 2) {
2727                            return list.get(1);
2728                    }
2729                    else {
2730                            return null;
2731                    }
2732            }
2733    
2734            /**
2735             * Removes all the document library folders where companyId = &#63; from the database.
2736             *
2737             * @param companyId the company ID
2738             * @throws SystemException if a system exception occurred
2739             */
2740            @Override
2741            public void removeByCompanyId(long companyId) throws SystemException {
2742                    for (DLFolder dlFolder : findByCompanyId(companyId, QueryUtil.ALL_POS,
2743                                    QueryUtil.ALL_POS, null)) {
2744                            remove(dlFolder);
2745                    }
2746            }
2747    
2748            /**
2749             * Returns the number of document library folders where companyId = &#63;.
2750             *
2751             * @param companyId the company ID
2752             * @return the number of matching document library folders
2753             * @throws SystemException if a system exception occurred
2754             */
2755            @Override
2756            public int countByCompanyId(long companyId) throws SystemException {
2757                    FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
2758    
2759                    Object[] finderArgs = new Object[] { companyId };
2760    
2761                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2762                                    this);
2763    
2764                    if (count == null) {
2765                            StringBundler query = new StringBundler(2);
2766    
2767                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
2768    
2769                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2770    
2771                            String sql = query.toString();
2772    
2773                            Session session = null;
2774    
2775                            try {
2776                                    session = openSession();
2777    
2778                                    Query q = session.createQuery(sql);
2779    
2780                                    QueryPos qPos = QueryPos.getInstance(q);
2781    
2782                                    qPos.add(companyId);
2783    
2784                                    count = (Long)q.uniqueResult();
2785    
2786                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2787                            }
2788                            catch (Exception e) {
2789                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2790    
2791                                    throw processException(e);
2792                            }
2793                            finally {
2794                                    closeSession(session);
2795                            }
2796                    }
2797    
2798                    return count.intValue();
2799            }
2800    
2801            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "dlFolder.companyId = ?";
2802            public static final FinderPath FINDER_PATH_FETCH_BY_REPOSITORYID = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
2803                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
2804                            FINDER_CLASS_NAME_ENTITY, "fetchByRepositoryId",
2805                            new String[] { Long.class.getName() },
2806                            DLFolderModelImpl.REPOSITORYID_COLUMN_BITMASK);
2807            public static final FinderPath FINDER_PATH_COUNT_BY_REPOSITORYID = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
2808                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
2809                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByRepositoryId",
2810                            new String[] { Long.class.getName() });
2811    
2812            /**
2813             * Returns the document library folder where repositoryId = &#63; or throws a {@link com.liferay.portlet.documentlibrary.NoSuchFolderException} if it could not be found.
2814             *
2815             * @param repositoryId the repository ID
2816             * @return the matching document library folder
2817             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
2818             * @throws SystemException if a system exception occurred
2819             */
2820            @Override
2821            public DLFolder findByRepositoryId(long repositoryId)
2822                    throws NoSuchFolderException, SystemException {
2823                    DLFolder dlFolder = fetchByRepositoryId(repositoryId);
2824    
2825                    if (dlFolder == null) {
2826                            StringBundler msg = new StringBundler(4);
2827    
2828                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2829    
2830                            msg.append("repositoryId=");
2831                            msg.append(repositoryId);
2832    
2833                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2834    
2835                            if (_log.isWarnEnabled()) {
2836                                    _log.warn(msg.toString());
2837                            }
2838    
2839                            throw new NoSuchFolderException(msg.toString());
2840                    }
2841    
2842                    return dlFolder;
2843            }
2844    
2845            /**
2846             * Returns the document library folder where repositoryId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
2847             *
2848             * @param repositoryId the repository ID
2849             * @return the matching document library folder, or <code>null</code> if a matching document library folder could not be found
2850             * @throws SystemException if a system exception occurred
2851             */
2852            @Override
2853            public DLFolder fetchByRepositoryId(long repositoryId)
2854                    throws SystemException {
2855                    return fetchByRepositoryId(repositoryId, true);
2856            }
2857    
2858            /**
2859             * Returns the document library folder where repositoryId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
2860             *
2861             * @param repositoryId the repository ID
2862             * @param retrieveFromCache whether to use the finder cache
2863             * @return the matching document library folder, or <code>null</code> if a matching document library folder could not be found
2864             * @throws SystemException if a system exception occurred
2865             */
2866            @Override
2867            public DLFolder fetchByRepositoryId(long repositoryId,
2868                    boolean retrieveFromCache) throws SystemException {
2869                    Object[] finderArgs = new Object[] { repositoryId };
2870    
2871                    Object result = null;
2872    
2873                    if (retrieveFromCache) {
2874                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_REPOSITORYID,
2875                                            finderArgs, this);
2876                    }
2877    
2878                    if (result instanceof DLFolder) {
2879                            DLFolder dlFolder = (DLFolder)result;
2880    
2881                            if ((repositoryId != dlFolder.getRepositoryId())) {
2882                                    result = null;
2883                            }
2884                    }
2885    
2886                    if (result == null) {
2887                            StringBundler query = new StringBundler(3);
2888    
2889                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
2890    
2891                            query.append(_FINDER_COLUMN_REPOSITORYID_REPOSITORYID_2);
2892    
2893                            String sql = query.toString();
2894    
2895                            Session session = null;
2896    
2897                            try {
2898                                    session = openSession();
2899    
2900                                    Query q = session.createQuery(sql);
2901    
2902                                    QueryPos qPos = QueryPos.getInstance(q);
2903    
2904                                    qPos.add(repositoryId);
2905    
2906                                    List<DLFolder> list = q.list();
2907    
2908                                    if (list.isEmpty()) {
2909                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_REPOSITORYID,
2910                                                    finderArgs, list);
2911                                    }
2912                                    else {
2913                                            if ((list.size() > 1) && _log.isWarnEnabled()) {
2914                                                    _log.warn(
2915                                                            "DLFolderPersistenceImpl.fetchByRepositoryId(long, boolean) with parameters (" +
2916                                                            StringUtil.merge(finderArgs) +
2917                                                            ") 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.");
2918                                            }
2919    
2920                                            DLFolder dlFolder = list.get(0);
2921    
2922                                            result = dlFolder;
2923    
2924                                            cacheResult(dlFolder);
2925    
2926                                            if ((dlFolder.getRepositoryId() != repositoryId)) {
2927                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_REPOSITORYID,
2928                                                            finderArgs, dlFolder);
2929                                            }
2930                                    }
2931                            }
2932                            catch (Exception e) {
2933                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_REPOSITORYID,
2934                                            finderArgs);
2935    
2936                                    throw processException(e);
2937                            }
2938                            finally {
2939                                    closeSession(session);
2940                            }
2941                    }
2942    
2943                    if (result instanceof List<?>) {
2944                            return null;
2945                    }
2946                    else {
2947                            return (DLFolder)result;
2948                    }
2949            }
2950    
2951            /**
2952             * Removes the document library folder where repositoryId = &#63; from the database.
2953             *
2954             * @param repositoryId the repository ID
2955             * @return the document library folder that was removed
2956             * @throws SystemException if a system exception occurred
2957             */
2958            @Override
2959            public DLFolder removeByRepositoryId(long repositoryId)
2960                    throws NoSuchFolderException, SystemException {
2961                    DLFolder dlFolder = findByRepositoryId(repositoryId);
2962    
2963                    return remove(dlFolder);
2964            }
2965    
2966            /**
2967             * Returns the number of document library folders where repositoryId = &#63;.
2968             *
2969             * @param repositoryId the repository ID
2970             * @return the number of matching document library folders
2971             * @throws SystemException if a system exception occurred
2972             */
2973            @Override
2974            public int countByRepositoryId(long repositoryId) throws SystemException {
2975                    FinderPath finderPath = FINDER_PATH_COUNT_BY_REPOSITORYID;
2976    
2977                    Object[] finderArgs = new Object[] { repositoryId };
2978    
2979                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2980                                    this);
2981    
2982                    if (count == null) {
2983                            StringBundler query = new StringBundler(2);
2984    
2985                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
2986    
2987                            query.append(_FINDER_COLUMN_REPOSITORYID_REPOSITORYID_2);
2988    
2989                            String sql = query.toString();
2990    
2991                            Session session = null;
2992    
2993                            try {
2994                                    session = openSession();
2995    
2996                                    Query q = session.createQuery(sql);
2997    
2998                                    QueryPos qPos = QueryPos.getInstance(q);
2999    
3000                                    qPos.add(repositoryId);
3001    
3002                                    count = (Long)q.uniqueResult();
3003    
3004                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
3005                            }
3006                            catch (Exception e) {
3007                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3008    
3009                                    throw processException(e);
3010                            }
3011                            finally {
3012                                    closeSession(session);
3013                            }
3014                    }
3015    
3016                    return count.intValue();
3017            }
3018    
3019            private static final String _FINDER_COLUMN_REPOSITORYID_REPOSITORYID_2 = "dlFolder.repositoryId = ?";
3020            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
3021                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
3022                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_P",
3023                            new String[] {
3024                                    Long.class.getName(), Long.class.getName(),
3025                                    
3026                            Integer.class.getName(), Integer.class.getName(),
3027                                    OrderByComparator.class.getName()
3028                            });
3029            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
3030                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
3031                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_P",
3032                            new String[] { Long.class.getName(), Long.class.getName() },
3033                            DLFolderModelImpl.GROUPID_COLUMN_BITMASK |
3034                            DLFolderModelImpl.PARENTFOLDERID_COLUMN_BITMASK |
3035                            DLFolderModelImpl.NAME_COLUMN_BITMASK);
3036            public static final FinderPath FINDER_PATH_COUNT_BY_G_P = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
3037                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
3038                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P",
3039                            new String[] { Long.class.getName(), Long.class.getName() });
3040    
3041            /**
3042             * Returns all the document library folders where groupId = &#63; and parentFolderId = &#63;.
3043             *
3044             * @param groupId the group ID
3045             * @param parentFolderId the parent folder ID
3046             * @return the matching document library folders
3047             * @throws SystemException if a system exception occurred
3048             */
3049            @Override
3050            public List<DLFolder> findByG_P(long groupId, long parentFolderId)
3051                    throws SystemException {
3052                    return findByG_P(groupId, parentFolderId, QueryUtil.ALL_POS,
3053                            QueryUtil.ALL_POS, null);
3054            }
3055    
3056            /**
3057             * Returns a range of all the document library folders where groupId = &#63; and parentFolderId = &#63;.
3058             *
3059             * <p>
3060             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
3061             * </p>
3062             *
3063             * @param groupId the group ID
3064             * @param parentFolderId the parent folder ID
3065             * @param start the lower bound of the range of document library folders
3066             * @param end the upper bound of the range of document library folders (not inclusive)
3067             * @return the range of matching document library folders
3068             * @throws SystemException if a system exception occurred
3069             */
3070            @Override
3071            public List<DLFolder> findByG_P(long groupId, long parentFolderId,
3072                    int start, int end) throws SystemException {
3073                    return findByG_P(groupId, parentFolderId, start, end, null);
3074            }
3075    
3076            /**
3077             * Returns an ordered range of all the document library folders where groupId = &#63; and parentFolderId = &#63;.
3078             *
3079             * <p>
3080             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
3081             * </p>
3082             *
3083             * @param groupId the group ID
3084             * @param parentFolderId the parent folder ID
3085             * @param start the lower bound of the range of document library folders
3086             * @param end the upper bound of the range of document library folders (not inclusive)
3087             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3088             * @return the ordered range of matching document library folders
3089             * @throws SystemException if a system exception occurred
3090             */
3091            @Override
3092            public List<DLFolder> findByG_P(long groupId, long parentFolderId,
3093                    int start, int end, OrderByComparator orderByComparator)
3094                    throws SystemException {
3095                    boolean pagination = true;
3096                    FinderPath finderPath = null;
3097                    Object[] finderArgs = null;
3098    
3099                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3100                                    (orderByComparator == null)) {
3101                            pagination = false;
3102                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P;
3103                            finderArgs = new Object[] { groupId, parentFolderId };
3104                    }
3105                    else {
3106                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P;
3107                            finderArgs = new Object[] {
3108                                            groupId, parentFolderId,
3109                                            
3110                                            start, end, orderByComparator
3111                                    };
3112                    }
3113    
3114                    List<DLFolder> list = (List<DLFolder>)FinderCacheUtil.getResult(finderPath,
3115                                    finderArgs, this);
3116    
3117                    if ((list != null) && !list.isEmpty()) {
3118                            for (DLFolder dlFolder : list) {
3119                                    if ((groupId != dlFolder.getGroupId()) ||
3120                                                    (parentFolderId != dlFolder.getParentFolderId())) {
3121                                            list = null;
3122    
3123                                            break;
3124                                    }
3125                            }
3126                    }
3127    
3128                    if (list == null) {
3129                            StringBundler query = null;
3130    
3131                            if (orderByComparator != null) {
3132                                    query = new StringBundler(4 +
3133                                                    (orderByComparator.getOrderByFields().length * 3));
3134                            }
3135                            else {
3136                                    query = new StringBundler(4);
3137                            }
3138    
3139                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
3140    
3141                            query.append(_FINDER_COLUMN_G_P_GROUPID_2);
3142    
3143                            query.append(_FINDER_COLUMN_G_P_PARENTFOLDERID_2);
3144    
3145                            if (orderByComparator != null) {
3146                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3147                                            orderByComparator);
3148                            }
3149                            else
3150                             if (pagination) {
3151                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
3152                            }
3153    
3154                            String sql = query.toString();
3155    
3156                            Session session = null;
3157    
3158                            try {
3159                                    session = openSession();
3160    
3161                                    Query q = session.createQuery(sql);
3162    
3163                                    QueryPos qPos = QueryPos.getInstance(q);
3164    
3165                                    qPos.add(groupId);
3166    
3167                                    qPos.add(parentFolderId);
3168    
3169                                    if (!pagination) {
3170                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
3171                                                            start, end, false);
3172    
3173                                            Collections.sort(list);
3174    
3175                                            list = new UnmodifiableList<DLFolder>(list);
3176                                    }
3177                                    else {
3178                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
3179                                                            start, end);
3180                                    }
3181    
3182                                    cacheResult(list);
3183    
3184                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
3185                            }
3186                            catch (Exception e) {
3187                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3188    
3189                                    throw processException(e);
3190                            }
3191                            finally {
3192                                    closeSession(session);
3193                            }
3194                    }
3195    
3196                    return list;
3197            }
3198    
3199            /**
3200             * Returns the first document library folder in the ordered set where groupId = &#63; and parentFolderId = &#63;.
3201             *
3202             * @param groupId the group ID
3203             * @param parentFolderId the parent folder ID
3204             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3205             * @return the first matching document library folder
3206             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
3207             * @throws SystemException if a system exception occurred
3208             */
3209            @Override
3210            public DLFolder findByG_P_First(long groupId, long parentFolderId,
3211                    OrderByComparator orderByComparator)
3212                    throws NoSuchFolderException, SystemException {
3213                    DLFolder dlFolder = fetchByG_P_First(groupId, parentFolderId,
3214                                    orderByComparator);
3215    
3216                    if (dlFolder != null) {
3217                            return dlFolder;
3218                    }
3219    
3220                    StringBundler msg = new StringBundler(6);
3221    
3222                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3223    
3224                    msg.append("groupId=");
3225                    msg.append(groupId);
3226    
3227                    msg.append(", parentFolderId=");
3228                    msg.append(parentFolderId);
3229    
3230                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3231    
3232                    throw new NoSuchFolderException(msg.toString());
3233            }
3234    
3235            /**
3236             * Returns the first document library folder in the ordered set where groupId = &#63; and parentFolderId = &#63;.
3237             *
3238             * @param groupId the group ID
3239             * @param parentFolderId the parent folder ID
3240             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3241             * @return the first matching document library folder, or <code>null</code> if a matching document library folder could not be found
3242             * @throws SystemException if a system exception occurred
3243             */
3244            @Override
3245            public DLFolder fetchByG_P_First(long groupId, long parentFolderId,
3246                    OrderByComparator orderByComparator) throws SystemException {
3247                    List<DLFolder> list = findByG_P(groupId, parentFolderId, 0, 1,
3248                                    orderByComparator);
3249    
3250                    if (!list.isEmpty()) {
3251                            return list.get(0);
3252                    }
3253    
3254                    return null;
3255            }
3256    
3257            /**
3258             * Returns the last document library folder in the ordered set where groupId = &#63; and parentFolderId = &#63;.
3259             *
3260             * @param groupId the group ID
3261             * @param parentFolderId the parent folder ID
3262             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3263             * @return the last matching document library folder
3264             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
3265             * @throws SystemException if a system exception occurred
3266             */
3267            @Override
3268            public DLFolder findByG_P_Last(long groupId, long parentFolderId,
3269                    OrderByComparator orderByComparator)
3270                    throws NoSuchFolderException, SystemException {
3271                    DLFolder dlFolder = fetchByG_P_Last(groupId, parentFolderId,
3272                                    orderByComparator);
3273    
3274                    if (dlFolder != null) {
3275                            return dlFolder;
3276                    }
3277    
3278                    StringBundler msg = new StringBundler(6);
3279    
3280                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3281    
3282                    msg.append("groupId=");
3283                    msg.append(groupId);
3284    
3285                    msg.append(", parentFolderId=");
3286                    msg.append(parentFolderId);
3287    
3288                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3289    
3290                    throw new NoSuchFolderException(msg.toString());
3291            }
3292    
3293            /**
3294             * Returns the last document library folder in the ordered set where groupId = &#63; and parentFolderId = &#63;.
3295             *
3296             * @param groupId the group ID
3297             * @param parentFolderId the parent folder ID
3298             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3299             * @return the last matching document library folder, or <code>null</code> if a matching document library folder could not be found
3300             * @throws SystemException if a system exception occurred
3301             */
3302            @Override
3303            public DLFolder fetchByG_P_Last(long groupId, long parentFolderId,
3304                    OrderByComparator orderByComparator) throws SystemException {
3305                    int count = countByG_P(groupId, parentFolderId);
3306    
3307                    if (count == 0) {
3308                            return null;
3309                    }
3310    
3311                    List<DLFolder> list = findByG_P(groupId, parentFolderId, count - 1,
3312                                    count, orderByComparator);
3313    
3314                    if (!list.isEmpty()) {
3315                            return list.get(0);
3316                    }
3317    
3318                    return null;
3319            }
3320    
3321            /**
3322             * Returns the document library folders before and after the current document library folder in the ordered set where groupId = &#63; and parentFolderId = &#63;.
3323             *
3324             * @param folderId the primary key of the current document library folder
3325             * @param groupId the group ID
3326             * @param parentFolderId the parent folder ID
3327             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3328             * @return the previous, current, and next document library folder
3329             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
3330             * @throws SystemException if a system exception occurred
3331             */
3332            @Override
3333            public DLFolder[] findByG_P_PrevAndNext(long folderId, long groupId,
3334                    long parentFolderId, OrderByComparator orderByComparator)
3335                    throws NoSuchFolderException, SystemException {
3336                    DLFolder dlFolder = findByPrimaryKey(folderId);
3337    
3338                    Session session = null;
3339    
3340                    try {
3341                            session = openSession();
3342    
3343                            DLFolder[] array = new DLFolderImpl[3];
3344    
3345                            array[0] = getByG_P_PrevAndNext(session, dlFolder, groupId,
3346                                            parentFolderId, orderByComparator, true);
3347    
3348                            array[1] = dlFolder;
3349    
3350                            array[2] = getByG_P_PrevAndNext(session, dlFolder, groupId,
3351                                            parentFolderId, orderByComparator, false);
3352    
3353                            return array;
3354                    }
3355                    catch (Exception e) {
3356                            throw processException(e);
3357                    }
3358                    finally {
3359                            closeSession(session);
3360                    }
3361            }
3362    
3363            protected DLFolder getByG_P_PrevAndNext(Session session, DLFolder dlFolder,
3364                    long groupId, long parentFolderId, OrderByComparator orderByComparator,
3365                    boolean previous) {
3366                    StringBundler query = null;
3367    
3368                    if (orderByComparator != null) {
3369                            query = new StringBundler(6 +
3370                                            (orderByComparator.getOrderByFields().length * 6));
3371                    }
3372                    else {
3373                            query = new StringBundler(3);
3374                    }
3375    
3376                    query.append(_SQL_SELECT_DLFOLDER_WHERE);
3377    
3378                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
3379    
3380                    query.append(_FINDER_COLUMN_G_P_PARENTFOLDERID_2);
3381    
3382                    if (orderByComparator != null) {
3383                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3384    
3385                            if (orderByConditionFields.length > 0) {
3386                                    query.append(WHERE_AND);
3387                            }
3388    
3389                            for (int i = 0; i < orderByConditionFields.length; i++) {
3390                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3391                                    query.append(orderByConditionFields[i]);
3392    
3393                                    if ((i + 1) < orderByConditionFields.length) {
3394                                            if (orderByComparator.isAscending() ^ previous) {
3395                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3396                                            }
3397                                            else {
3398                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3399                                            }
3400                                    }
3401                                    else {
3402                                            if (orderByComparator.isAscending() ^ previous) {
3403                                                    query.append(WHERE_GREATER_THAN);
3404                                            }
3405                                            else {
3406                                                    query.append(WHERE_LESSER_THAN);
3407                                            }
3408                                    }
3409                            }
3410    
3411                            query.append(ORDER_BY_CLAUSE);
3412    
3413                            String[] orderByFields = orderByComparator.getOrderByFields();
3414    
3415                            for (int i = 0; i < orderByFields.length; i++) {
3416                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3417                                    query.append(orderByFields[i]);
3418    
3419                                    if ((i + 1) < orderByFields.length) {
3420                                            if (orderByComparator.isAscending() ^ previous) {
3421                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3422                                            }
3423                                            else {
3424                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3425                                            }
3426                                    }
3427                                    else {
3428                                            if (orderByComparator.isAscending() ^ previous) {
3429                                                    query.append(ORDER_BY_ASC);
3430                                            }
3431                                            else {
3432                                                    query.append(ORDER_BY_DESC);
3433                                            }
3434                                    }
3435                            }
3436                    }
3437                    else {
3438                            query.append(DLFolderModelImpl.ORDER_BY_JPQL);
3439                    }
3440    
3441                    String sql = query.toString();
3442    
3443                    Query q = session.createQuery(sql);
3444    
3445                    q.setFirstResult(0);
3446                    q.setMaxResults(2);
3447    
3448                    QueryPos qPos = QueryPos.getInstance(q);
3449    
3450                    qPos.add(groupId);
3451    
3452                    qPos.add(parentFolderId);
3453    
3454                    if (orderByComparator != null) {
3455                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
3456    
3457                            for (Object value : values) {
3458                                    qPos.add(value);
3459                            }
3460                    }
3461    
3462                    List<DLFolder> list = q.list();
3463    
3464                    if (list.size() == 2) {
3465                            return list.get(1);
3466                    }
3467                    else {
3468                            return null;
3469                    }
3470            }
3471    
3472            /**
3473             * Returns all the document library folders that the user has permission to view where groupId = &#63; and parentFolderId = &#63;.
3474             *
3475             * @param groupId the group ID
3476             * @param parentFolderId the parent folder ID
3477             * @return the matching document library folders that the user has permission to view
3478             * @throws SystemException if a system exception occurred
3479             */
3480            @Override
3481            public List<DLFolder> filterFindByG_P(long groupId, long parentFolderId)
3482                    throws SystemException {
3483                    return filterFindByG_P(groupId, parentFolderId, QueryUtil.ALL_POS,
3484                            QueryUtil.ALL_POS, null);
3485            }
3486    
3487            /**
3488             * Returns a range of all the document library folders that the user has permission to view where groupId = &#63; and parentFolderId = &#63;.
3489             *
3490             * <p>
3491             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
3492             * </p>
3493             *
3494             * @param groupId the group ID
3495             * @param parentFolderId the parent folder ID
3496             * @param start the lower bound of the range of document library folders
3497             * @param end the upper bound of the range of document library folders (not inclusive)
3498             * @return the range of matching document library folders that the user has permission to view
3499             * @throws SystemException if a system exception occurred
3500             */
3501            @Override
3502            public List<DLFolder> filterFindByG_P(long groupId, long parentFolderId,
3503                    int start, int end) throws SystemException {
3504                    return filterFindByG_P(groupId, parentFolderId, start, end, null);
3505            }
3506    
3507            /**
3508             * Returns an ordered range of all the document library folders that the user has permissions to view where groupId = &#63; and parentFolderId = &#63;.
3509             *
3510             * <p>
3511             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
3512             * </p>
3513             *
3514             * @param groupId the group ID
3515             * @param parentFolderId the parent folder ID
3516             * @param start the lower bound of the range of document library folders
3517             * @param end the upper bound of the range of document library folders (not inclusive)
3518             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3519             * @return the ordered range of matching document library folders that the user has permission to view
3520             * @throws SystemException if a system exception occurred
3521             */
3522            @Override
3523            public List<DLFolder> filterFindByG_P(long groupId, long parentFolderId,
3524                    int start, int end, OrderByComparator orderByComparator)
3525                    throws SystemException {
3526                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3527                            return findByG_P(groupId, parentFolderId, start, end,
3528                                    orderByComparator);
3529                    }
3530    
3531                    StringBundler query = null;
3532    
3533                    if (orderByComparator != null) {
3534                            query = new StringBundler(4 +
3535                                            (orderByComparator.getOrderByFields().length * 3));
3536                    }
3537                    else {
3538                            query = new StringBundler(4);
3539                    }
3540    
3541                    if (getDB().isSupportsInlineDistinct()) {
3542                            query.append(_FILTER_SQL_SELECT_DLFOLDER_WHERE);
3543                    }
3544                    else {
3545                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1);
3546                    }
3547    
3548                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
3549    
3550                    query.append(_FINDER_COLUMN_G_P_PARENTFOLDERID_2);
3551    
3552                    if (!getDB().isSupportsInlineDistinct()) {
3553                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2);
3554                    }
3555    
3556                    if (orderByComparator != null) {
3557                            if (getDB().isSupportsInlineDistinct()) {
3558                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3559                                            orderByComparator, true);
3560                            }
3561                            else {
3562                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3563                                            orderByComparator, true);
3564                            }
3565                    }
3566                    else {
3567                            if (getDB().isSupportsInlineDistinct()) {
3568                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
3569                            }
3570                            else {
3571                                    query.append(DLFolderModelImpl.ORDER_BY_SQL);
3572                            }
3573                    }
3574    
3575                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3576                                    DLFolder.class.getName(),
3577                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3578    
3579                    Session session = null;
3580    
3581                    try {
3582                            session = openSession();
3583    
3584                            SQLQuery q = session.createSQLQuery(sql);
3585    
3586                            if (getDB().isSupportsInlineDistinct()) {
3587                                    q.addEntity(_FILTER_ENTITY_ALIAS, DLFolderImpl.class);
3588                            }
3589                            else {
3590                                    q.addEntity(_FILTER_ENTITY_TABLE, DLFolderImpl.class);
3591                            }
3592    
3593                            QueryPos qPos = QueryPos.getInstance(q);
3594    
3595                            qPos.add(groupId);
3596    
3597                            qPos.add(parentFolderId);
3598    
3599                            return (List<DLFolder>)QueryUtil.list(q, getDialect(), start, end);
3600                    }
3601                    catch (Exception e) {
3602                            throw processException(e);
3603                    }
3604                    finally {
3605                            closeSession(session);
3606                    }
3607            }
3608    
3609            /**
3610             * 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;.
3611             *
3612             * @param folderId the primary key of the current document library folder
3613             * @param groupId the group ID
3614             * @param parentFolderId the parent folder ID
3615             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3616             * @return the previous, current, and next document library folder
3617             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
3618             * @throws SystemException if a system exception occurred
3619             */
3620            @Override
3621            public DLFolder[] filterFindByG_P_PrevAndNext(long folderId, long groupId,
3622                    long parentFolderId, OrderByComparator orderByComparator)
3623                    throws NoSuchFolderException, SystemException {
3624                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3625                            return findByG_P_PrevAndNext(folderId, groupId, parentFolderId,
3626                                    orderByComparator);
3627                    }
3628    
3629                    DLFolder dlFolder = findByPrimaryKey(folderId);
3630    
3631                    Session session = null;
3632    
3633                    try {
3634                            session = openSession();
3635    
3636                            DLFolder[] array = new DLFolderImpl[3];
3637    
3638                            array[0] = filterGetByG_P_PrevAndNext(session, dlFolder, groupId,
3639                                            parentFolderId, orderByComparator, true);
3640    
3641                            array[1] = dlFolder;
3642    
3643                            array[2] = filterGetByG_P_PrevAndNext(session, dlFolder, groupId,
3644                                            parentFolderId, orderByComparator, false);
3645    
3646                            return array;
3647                    }
3648                    catch (Exception e) {
3649                            throw processException(e);
3650                    }
3651                    finally {
3652                            closeSession(session);
3653                    }
3654            }
3655    
3656            protected DLFolder filterGetByG_P_PrevAndNext(Session session,
3657                    DLFolder dlFolder, long groupId, long parentFolderId,
3658                    OrderByComparator orderByComparator, boolean previous) {
3659                    StringBundler query = null;
3660    
3661                    if (orderByComparator != null) {
3662                            query = new StringBundler(6 +
3663                                            (orderByComparator.getOrderByFields().length * 6));
3664                    }
3665                    else {
3666                            query = new StringBundler(3);
3667                    }
3668    
3669                    if (getDB().isSupportsInlineDistinct()) {
3670                            query.append(_FILTER_SQL_SELECT_DLFOLDER_WHERE);
3671                    }
3672                    else {
3673                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1);
3674                    }
3675    
3676                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
3677    
3678                    query.append(_FINDER_COLUMN_G_P_PARENTFOLDERID_2);
3679    
3680                    if (!getDB().isSupportsInlineDistinct()) {
3681                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2);
3682                    }
3683    
3684                    if (orderByComparator != null) {
3685                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3686    
3687                            if (orderByConditionFields.length > 0) {
3688                                    query.append(WHERE_AND);
3689                            }
3690    
3691                            for (int i = 0; i < orderByConditionFields.length; i++) {
3692                                    if (getDB().isSupportsInlineDistinct()) {
3693                                            query.append(_ORDER_BY_ENTITY_ALIAS);
3694                                    }
3695                                    else {
3696                                            query.append(_ORDER_BY_ENTITY_TABLE);
3697                                    }
3698    
3699                                    query.append(orderByConditionFields[i]);
3700    
3701                                    if ((i + 1) < orderByConditionFields.length) {
3702                                            if (orderByComparator.isAscending() ^ previous) {
3703                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3704                                            }
3705                                            else {
3706                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3707                                            }
3708                                    }
3709                                    else {
3710                                            if (orderByComparator.isAscending() ^ previous) {
3711                                                    query.append(WHERE_GREATER_THAN);
3712                                            }
3713                                            else {
3714                                                    query.append(WHERE_LESSER_THAN);
3715                                            }
3716                                    }
3717                            }
3718    
3719                            query.append(ORDER_BY_CLAUSE);
3720    
3721                            String[] orderByFields = orderByComparator.getOrderByFields();
3722    
3723                            for (int i = 0; i < orderByFields.length; i++) {
3724                                    if (getDB().isSupportsInlineDistinct()) {
3725                                            query.append(_ORDER_BY_ENTITY_ALIAS);
3726                                    }
3727                                    else {
3728                                            query.append(_ORDER_BY_ENTITY_TABLE);
3729                                    }
3730    
3731                                    query.append(orderByFields[i]);
3732    
3733                                    if ((i + 1) < orderByFields.length) {
3734                                            if (orderByComparator.isAscending() ^ previous) {
3735                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3736                                            }
3737                                            else {
3738                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3739                                            }
3740                                    }
3741                                    else {
3742                                            if (orderByComparator.isAscending() ^ previous) {
3743                                                    query.append(ORDER_BY_ASC);
3744                                            }
3745                                            else {
3746                                                    query.append(ORDER_BY_DESC);
3747                                            }
3748                                    }
3749                            }
3750                    }
3751                    else {
3752                            if (getDB().isSupportsInlineDistinct()) {
3753                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
3754                            }
3755                            else {
3756                                    query.append(DLFolderModelImpl.ORDER_BY_SQL);
3757                            }
3758                    }
3759    
3760                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3761                                    DLFolder.class.getName(),
3762                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3763    
3764                    SQLQuery q = session.createSQLQuery(sql);
3765    
3766                    q.setFirstResult(0);
3767                    q.setMaxResults(2);
3768    
3769                    if (getDB().isSupportsInlineDistinct()) {
3770                            q.addEntity(_FILTER_ENTITY_ALIAS, DLFolderImpl.class);
3771                    }
3772                    else {
3773                            q.addEntity(_FILTER_ENTITY_TABLE, DLFolderImpl.class);
3774                    }
3775    
3776                    QueryPos qPos = QueryPos.getInstance(q);
3777    
3778                    qPos.add(groupId);
3779    
3780                    qPos.add(parentFolderId);
3781    
3782                    if (orderByComparator != null) {
3783                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
3784    
3785                            for (Object value : values) {
3786                                    qPos.add(value);
3787                            }
3788                    }
3789    
3790                    List<DLFolder> list = q.list();
3791    
3792                    if (list.size() == 2) {
3793                            return list.get(1);
3794                    }
3795                    else {
3796                            return null;
3797                    }
3798            }
3799    
3800            /**
3801             * Removes all the document library folders where groupId = &#63; and parentFolderId = &#63; from the database.
3802             *
3803             * @param groupId the group ID
3804             * @param parentFolderId the parent folder ID
3805             * @throws SystemException if a system exception occurred
3806             */
3807            @Override
3808            public void removeByG_P(long groupId, long parentFolderId)
3809                    throws SystemException {
3810                    for (DLFolder dlFolder : findByG_P(groupId, parentFolderId,
3811                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3812                            remove(dlFolder);
3813                    }
3814            }
3815    
3816            /**
3817             * Returns the number of document library folders where groupId = &#63; and parentFolderId = &#63;.
3818             *
3819             * @param groupId the group ID
3820             * @param parentFolderId the parent folder ID
3821             * @return the number of matching document library folders
3822             * @throws SystemException if a system exception occurred
3823             */
3824            @Override
3825            public int countByG_P(long groupId, long parentFolderId)
3826                    throws SystemException {
3827                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_P;
3828    
3829                    Object[] finderArgs = new Object[] { groupId, parentFolderId };
3830    
3831                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3832                                    this);
3833    
3834                    if (count == null) {
3835                            StringBundler query = new StringBundler(3);
3836    
3837                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
3838    
3839                            query.append(_FINDER_COLUMN_G_P_GROUPID_2);
3840    
3841                            query.append(_FINDER_COLUMN_G_P_PARENTFOLDERID_2);
3842    
3843                            String sql = query.toString();
3844    
3845                            Session session = null;
3846    
3847                            try {
3848                                    session = openSession();
3849    
3850                                    Query q = session.createQuery(sql);
3851    
3852                                    QueryPos qPos = QueryPos.getInstance(q);
3853    
3854                                    qPos.add(groupId);
3855    
3856                                    qPos.add(parentFolderId);
3857    
3858                                    count = (Long)q.uniqueResult();
3859    
3860                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
3861                            }
3862                            catch (Exception e) {
3863                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3864    
3865                                    throw processException(e);
3866                            }
3867                            finally {
3868                                    closeSession(session);
3869                            }
3870                    }
3871    
3872                    return count.intValue();
3873            }
3874    
3875            /**
3876             * Returns the number of document library folders that the user has permission to view where groupId = &#63; and parentFolderId = &#63;.
3877             *
3878             * @param groupId the group ID
3879             * @param parentFolderId the parent folder ID
3880             * @return the number of matching document library folders that the user has permission to view
3881             * @throws SystemException if a system exception occurred
3882             */
3883            @Override
3884            public int filterCountByG_P(long groupId, long parentFolderId)
3885                    throws SystemException {
3886                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3887                            return countByG_P(groupId, parentFolderId);
3888                    }
3889    
3890                    StringBundler query = new StringBundler(3);
3891    
3892                    query.append(_FILTER_SQL_COUNT_DLFOLDER_WHERE);
3893    
3894                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
3895    
3896                    query.append(_FINDER_COLUMN_G_P_PARENTFOLDERID_2);
3897    
3898                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3899                                    DLFolder.class.getName(),
3900                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3901    
3902                    Session session = null;
3903    
3904                    try {
3905                            session = openSession();
3906    
3907                            SQLQuery q = session.createSQLQuery(sql);
3908    
3909                            q.addScalar(COUNT_COLUMN_NAME,
3910                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
3911    
3912                            QueryPos qPos = QueryPos.getInstance(q);
3913    
3914                            qPos.add(groupId);
3915    
3916                            qPos.add(parentFolderId);
3917    
3918                            Long count = (Long)q.uniqueResult();
3919    
3920                            return count.intValue();
3921                    }
3922                    catch (Exception e) {
3923                            throw processException(e);
3924                    }
3925                    finally {
3926                            closeSession(session);
3927                    }
3928            }
3929    
3930            private static final String _FINDER_COLUMN_G_P_GROUPID_2 = "dlFolder.groupId = ? AND ";
3931            private static final String _FINDER_COLUMN_G_P_PARENTFOLDERID_2 = "dlFolder.parentFolderId = ?";
3932            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_P_N = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
3933                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
3934                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByP_N",
3935                            new String[] {
3936                                    Long.class.getName(), String.class.getName(),
3937                                    
3938                            Integer.class.getName(), Integer.class.getName(),
3939                                    OrderByComparator.class.getName()
3940                            });
3941            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_N = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
3942                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
3943                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByP_N",
3944                            new String[] { Long.class.getName(), String.class.getName() },
3945                            DLFolderModelImpl.PARENTFOLDERID_COLUMN_BITMASK |
3946                            DLFolderModelImpl.NAME_COLUMN_BITMASK);
3947            public static final FinderPath FINDER_PATH_COUNT_BY_P_N = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
3948                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
3949                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByP_N",
3950                            new String[] { Long.class.getName(), String.class.getName() });
3951    
3952            /**
3953             * Returns all the document library folders where parentFolderId = &#63; and name = &#63;.
3954             *
3955             * @param parentFolderId the parent folder ID
3956             * @param name the name
3957             * @return the matching document library folders
3958             * @throws SystemException if a system exception occurred
3959             */
3960            @Override
3961            public List<DLFolder> findByP_N(long parentFolderId, String name)
3962                    throws SystemException {
3963                    return findByP_N(parentFolderId, name, QueryUtil.ALL_POS,
3964                            QueryUtil.ALL_POS, null);
3965            }
3966    
3967            /**
3968             * Returns a range of all the document library folders where parentFolderId = &#63; and name = &#63;.
3969             *
3970             * <p>
3971             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
3972             * </p>
3973             *
3974             * @param parentFolderId the parent folder ID
3975             * @param name the name
3976             * @param start the lower bound of the range of document library folders
3977             * @param end the upper bound of the range of document library folders (not inclusive)
3978             * @return the range of matching document library folders
3979             * @throws SystemException if a system exception occurred
3980             */
3981            @Override
3982            public List<DLFolder> findByP_N(long parentFolderId, String name,
3983                    int start, int end) throws SystemException {
3984                    return findByP_N(parentFolderId, name, start, end, null);
3985            }
3986    
3987            /**
3988             * Returns an ordered range of all the document library folders where parentFolderId = &#63; and name = &#63;.
3989             *
3990             * <p>
3991             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
3992             * </p>
3993             *
3994             * @param parentFolderId the parent folder ID
3995             * @param name the name
3996             * @param start the lower bound of the range of document library folders
3997             * @param end the upper bound of the range of document library folders (not inclusive)
3998             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3999             * @return the ordered range of matching document library folders
4000             * @throws SystemException if a system exception occurred
4001             */
4002            @Override
4003            public List<DLFolder> findByP_N(long parentFolderId, String name,
4004                    int start, int end, OrderByComparator orderByComparator)
4005                    throws SystemException {
4006                    boolean pagination = true;
4007                    FinderPath finderPath = null;
4008                    Object[] finderArgs = null;
4009    
4010                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4011                                    (orderByComparator == null)) {
4012                            pagination = false;
4013                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_N;
4014                            finderArgs = new Object[] { parentFolderId, name };
4015                    }
4016                    else {
4017                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_P_N;
4018                            finderArgs = new Object[] {
4019                                            parentFolderId, name,
4020                                            
4021                                            start, end, orderByComparator
4022                                    };
4023                    }
4024    
4025                    List<DLFolder> list = (List<DLFolder>)FinderCacheUtil.getResult(finderPath,
4026                                    finderArgs, this);
4027    
4028                    if ((list != null) && !list.isEmpty()) {
4029                            for (DLFolder dlFolder : list) {
4030                                    if ((parentFolderId != dlFolder.getParentFolderId()) ||
4031                                                    !Validator.equals(name, dlFolder.getName())) {
4032                                            list = null;
4033    
4034                                            break;
4035                                    }
4036                            }
4037                    }
4038    
4039                    if (list == null) {
4040                            StringBundler query = null;
4041    
4042                            if (orderByComparator != null) {
4043                                    query = new StringBundler(4 +
4044                                                    (orderByComparator.getOrderByFields().length * 3));
4045                            }
4046                            else {
4047                                    query = new StringBundler(4);
4048                            }
4049    
4050                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
4051    
4052                            query.append(_FINDER_COLUMN_P_N_PARENTFOLDERID_2);
4053    
4054                            boolean bindName = false;
4055    
4056                            if (name == null) {
4057                                    query.append(_FINDER_COLUMN_P_N_NAME_1);
4058                            }
4059                            else if (name.equals(StringPool.BLANK)) {
4060                                    query.append(_FINDER_COLUMN_P_N_NAME_3);
4061                            }
4062                            else {
4063                                    bindName = true;
4064    
4065                                    query.append(_FINDER_COLUMN_P_N_NAME_2);
4066                            }
4067    
4068                            if (orderByComparator != null) {
4069                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4070                                            orderByComparator);
4071                            }
4072                            else
4073                             if (pagination) {
4074                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
4075                            }
4076    
4077                            String sql = query.toString();
4078    
4079                            Session session = null;
4080    
4081                            try {
4082                                    session = openSession();
4083    
4084                                    Query q = session.createQuery(sql);
4085    
4086                                    QueryPos qPos = QueryPos.getInstance(q);
4087    
4088                                    qPos.add(parentFolderId);
4089    
4090                                    if (bindName) {
4091                                            qPos.add(name);
4092                                    }
4093    
4094                                    if (!pagination) {
4095                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
4096                                                            start, end, false);
4097    
4098                                            Collections.sort(list);
4099    
4100                                            list = new UnmodifiableList<DLFolder>(list);
4101                                    }
4102                                    else {
4103                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
4104                                                            start, end);
4105                                    }
4106    
4107                                    cacheResult(list);
4108    
4109                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
4110                            }
4111                            catch (Exception e) {
4112                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4113    
4114                                    throw processException(e);
4115                            }
4116                            finally {
4117                                    closeSession(session);
4118                            }
4119                    }
4120    
4121                    return list;
4122            }
4123    
4124            /**
4125             * Returns the first document library folder in the ordered set where parentFolderId = &#63; and name = &#63;.
4126             *
4127             * @param parentFolderId the parent folder ID
4128             * @param name the name
4129             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4130             * @return the first matching document library folder
4131             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
4132             * @throws SystemException if a system exception occurred
4133             */
4134            @Override
4135            public DLFolder findByP_N_First(long parentFolderId, String name,
4136                    OrderByComparator orderByComparator)
4137                    throws NoSuchFolderException, SystemException {
4138                    DLFolder dlFolder = fetchByP_N_First(parentFolderId, name,
4139                                    orderByComparator);
4140    
4141                    if (dlFolder != null) {
4142                            return dlFolder;
4143                    }
4144    
4145                    StringBundler msg = new StringBundler(6);
4146    
4147                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4148    
4149                    msg.append("parentFolderId=");
4150                    msg.append(parentFolderId);
4151    
4152                    msg.append(", name=");
4153                    msg.append(name);
4154    
4155                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4156    
4157                    throw new NoSuchFolderException(msg.toString());
4158            }
4159    
4160            /**
4161             * Returns the first document library folder in the ordered set where parentFolderId = &#63; and name = &#63;.
4162             *
4163             * @param parentFolderId the parent folder ID
4164             * @param name the name
4165             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4166             * @return the first matching document library folder, or <code>null</code> if a matching document library folder could not be found
4167             * @throws SystemException if a system exception occurred
4168             */
4169            @Override
4170            public DLFolder fetchByP_N_First(long parentFolderId, String name,
4171                    OrderByComparator orderByComparator) throws SystemException {
4172                    List<DLFolder> list = findByP_N(parentFolderId, name, 0, 1,
4173                                    orderByComparator);
4174    
4175                    if (!list.isEmpty()) {
4176                            return list.get(0);
4177                    }
4178    
4179                    return null;
4180            }
4181    
4182            /**
4183             * Returns the last document library folder in the ordered set where parentFolderId = &#63; and name = &#63;.
4184             *
4185             * @param parentFolderId the parent folder ID
4186             * @param name the name
4187             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4188             * @return the last matching document library folder
4189             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
4190             * @throws SystemException if a system exception occurred
4191             */
4192            @Override
4193            public DLFolder findByP_N_Last(long parentFolderId, String name,
4194                    OrderByComparator orderByComparator)
4195                    throws NoSuchFolderException, SystemException {
4196                    DLFolder dlFolder = fetchByP_N_Last(parentFolderId, name,
4197                                    orderByComparator);
4198    
4199                    if (dlFolder != null) {
4200                            return dlFolder;
4201                    }
4202    
4203                    StringBundler msg = new StringBundler(6);
4204    
4205                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4206    
4207                    msg.append("parentFolderId=");
4208                    msg.append(parentFolderId);
4209    
4210                    msg.append(", name=");
4211                    msg.append(name);
4212    
4213                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4214    
4215                    throw new NoSuchFolderException(msg.toString());
4216            }
4217    
4218            /**
4219             * Returns the last document library folder in the ordered set where parentFolderId = &#63; and name = &#63;.
4220             *
4221             * @param parentFolderId the parent folder ID
4222             * @param name the name
4223             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4224             * @return the last matching document library folder, or <code>null</code> if a matching document library folder could not be found
4225             * @throws SystemException if a system exception occurred
4226             */
4227            @Override
4228            public DLFolder fetchByP_N_Last(long parentFolderId, String name,
4229                    OrderByComparator orderByComparator) throws SystemException {
4230                    int count = countByP_N(parentFolderId, name);
4231    
4232                    if (count == 0) {
4233                            return null;
4234                    }
4235    
4236                    List<DLFolder> list = findByP_N(parentFolderId, name, count - 1, count,
4237                                    orderByComparator);
4238    
4239                    if (!list.isEmpty()) {
4240                            return list.get(0);
4241                    }
4242    
4243                    return null;
4244            }
4245    
4246            /**
4247             * Returns the document library folders before and after the current document library folder in the ordered set where parentFolderId = &#63; and name = &#63;.
4248             *
4249             * @param folderId the primary key of the current document library folder
4250             * @param parentFolderId the parent folder ID
4251             * @param name the name
4252             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4253             * @return the previous, current, and next document library folder
4254             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
4255             * @throws SystemException if a system exception occurred
4256             */
4257            @Override
4258            public DLFolder[] findByP_N_PrevAndNext(long folderId, long parentFolderId,
4259                    String name, OrderByComparator orderByComparator)
4260                    throws NoSuchFolderException, SystemException {
4261                    DLFolder dlFolder = findByPrimaryKey(folderId);
4262    
4263                    Session session = null;
4264    
4265                    try {
4266                            session = openSession();
4267    
4268                            DLFolder[] array = new DLFolderImpl[3];
4269    
4270                            array[0] = getByP_N_PrevAndNext(session, dlFolder, parentFolderId,
4271                                            name, orderByComparator, true);
4272    
4273                            array[1] = dlFolder;
4274    
4275                            array[2] = getByP_N_PrevAndNext(session, dlFolder, parentFolderId,
4276                                            name, orderByComparator, false);
4277    
4278                            return array;
4279                    }
4280                    catch (Exception e) {
4281                            throw processException(e);
4282                    }
4283                    finally {
4284                            closeSession(session);
4285                    }
4286            }
4287    
4288            protected DLFolder getByP_N_PrevAndNext(Session session, DLFolder dlFolder,
4289                    long parentFolderId, String name, OrderByComparator orderByComparator,
4290                    boolean previous) {
4291                    StringBundler query = null;
4292    
4293                    if (orderByComparator != null) {
4294                            query = new StringBundler(6 +
4295                                            (orderByComparator.getOrderByFields().length * 6));
4296                    }
4297                    else {
4298                            query = new StringBundler(3);
4299                    }
4300    
4301                    query.append(_SQL_SELECT_DLFOLDER_WHERE);
4302    
4303                    query.append(_FINDER_COLUMN_P_N_PARENTFOLDERID_2);
4304    
4305                    boolean bindName = false;
4306    
4307                    if (name == null) {
4308                            query.append(_FINDER_COLUMN_P_N_NAME_1);
4309                    }
4310                    else if (name.equals(StringPool.BLANK)) {
4311                            query.append(_FINDER_COLUMN_P_N_NAME_3);
4312                    }
4313                    else {
4314                            bindName = true;
4315    
4316                            query.append(_FINDER_COLUMN_P_N_NAME_2);
4317                    }
4318    
4319                    if (orderByComparator != null) {
4320                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4321    
4322                            if (orderByConditionFields.length > 0) {
4323                                    query.append(WHERE_AND);
4324                            }
4325    
4326                            for (int i = 0; i < orderByConditionFields.length; i++) {
4327                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4328                                    query.append(orderByConditionFields[i]);
4329    
4330                                    if ((i + 1) < orderByConditionFields.length) {
4331                                            if (orderByComparator.isAscending() ^ previous) {
4332                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4333                                            }
4334                                            else {
4335                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4336                                            }
4337                                    }
4338                                    else {
4339                                            if (orderByComparator.isAscending() ^ previous) {
4340                                                    query.append(WHERE_GREATER_THAN);
4341                                            }
4342                                            else {
4343                                                    query.append(WHERE_LESSER_THAN);
4344                                            }
4345                                    }
4346                            }
4347    
4348                            query.append(ORDER_BY_CLAUSE);
4349    
4350                            String[] orderByFields = orderByComparator.getOrderByFields();
4351    
4352                            for (int i = 0; i < orderByFields.length; i++) {
4353                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4354                                    query.append(orderByFields[i]);
4355    
4356                                    if ((i + 1) < orderByFields.length) {
4357                                            if (orderByComparator.isAscending() ^ previous) {
4358                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4359                                            }
4360                                            else {
4361                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4362                                            }
4363                                    }
4364                                    else {
4365                                            if (orderByComparator.isAscending() ^ previous) {
4366                                                    query.append(ORDER_BY_ASC);
4367                                            }
4368                                            else {
4369                                                    query.append(ORDER_BY_DESC);
4370                                            }
4371                                    }
4372                            }
4373                    }
4374                    else {
4375                            query.append(DLFolderModelImpl.ORDER_BY_JPQL);
4376                    }
4377    
4378                    String sql = query.toString();
4379    
4380                    Query q = session.createQuery(sql);
4381    
4382                    q.setFirstResult(0);
4383                    q.setMaxResults(2);
4384    
4385                    QueryPos qPos = QueryPos.getInstance(q);
4386    
4387                    qPos.add(parentFolderId);
4388    
4389                    if (bindName) {
4390                            qPos.add(name);
4391                    }
4392    
4393                    if (orderByComparator != null) {
4394                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
4395    
4396                            for (Object value : values) {
4397                                    qPos.add(value);
4398                            }
4399                    }
4400    
4401                    List<DLFolder> list = q.list();
4402    
4403                    if (list.size() == 2) {
4404                            return list.get(1);
4405                    }
4406                    else {
4407                            return null;
4408                    }
4409            }
4410    
4411            /**
4412             * Removes all the document library folders where parentFolderId = &#63; and name = &#63; from the database.
4413             *
4414             * @param parentFolderId the parent folder ID
4415             * @param name the name
4416             * @throws SystemException if a system exception occurred
4417             */
4418            @Override
4419            public void removeByP_N(long parentFolderId, String name)
4420                    throws SystemException {
4421                    for (DLFolder dlFolder : findByP_N(parentFolderId, name,
4422                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4423                            remove(dlFolder);
4424                    }
4425            }
4426    
4427            /**
4428             * Returns the number of document library folders where parentFolderId = &#63; and name = &#63;.
4429             *
4430             * @param parentFolderId the parent folder ID
4431             * @param name the name
4432             * @return the number of matching document library folders
4433             * @throws SystemException if a system exception occurred
4434             */
4435            @Override
4436            public int countByP_N(long parentFolderId, String name)
4437                    throws SystemException {
4438                    FinderPath finderPath = FINDER_PATH_COUNT_BY_P_N;
4439    
4440                    Object[] finderArgs = new Object[] { parentFolderId, name };
4441    
4442                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4443                                    this);
4444    
4445                    if (count == null) {
4446                            StringBundler query = new StringBundler(3);
4447    
4448                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
4449    
4450                            query.append(_FINDER_COLUMN_P_N_PARENTFOLDERID_2);
4451    
4452                            boolean bindName = false;
4453    
4454                            if (name == null) {
4455                                    query.append(_FINDER_COLUMN_P_N_NAME_1);
4456                            }
4457                            else if (name.equals(StringPool.BLANK)) {
4458                                    query.append(_FINDER_COLUMN_P_N_NAME_3);
4459                            }
4460                            else {
4461                                    bindName = true;
4462    
4463                                    query.append(_FINDER_COLUMN_P_N_NAME_2);
4464                            }
4465    
4466                            String sql = query.toString();
4467    
4468                            Session session = null;
4469    
4470                            try {
4471                                    session = openSession();
4472    
4473                                    Query q = session.createQuery(sql);
4474    
4475                                    QueryPos qPos = QueryPos.getInstance(q);
4476    
4477                                    qPos.add(parentFolderId);
4478    
4479                                    if (bindName) {
4480                                            qPos.add(name);
4481                                    }
4482    
4483                                    count = (Long)q.uniqueResult();
4484    
4485                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
4486                            }
4487                            catch (Exception e) {
4488                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4489    
4490                                    throw processException(e);
4491                            }
4492                            finally {
4493                                    closeSession(session);
4494                            }
4495                    }
4496    
4497                    return count.intValue();
4498            }
4499    
4500            private static final String _FINDER_COLUMN_P_N_PARENTFOLDERID_2 = "dlFolder.parentFolderId = ? AND ";
4501            private static final String _FINDER_COLUMN_P_N_NAME_1 = "dlFolder.name IS NULL";
4502            private static final String _FINDER_COLUMN_P_N_NAME_2 = "dlFolder.name = ?";
4503            private static final String _FINDER_COLUMN_P_N_NAME_3 = "(dlFolder.name IS NULL OR dlFolder.name = '')";
4504            public static final FinderPath FINDER_PATH_FETCH_BY_G_P_N = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
4505                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
4506                            FINDER_CLASS_NAME_ENTITY, "fetchByG_P_N",
4507                            new String[] {
4508                                    Long.class.getName(), Long.class.getName(),
4509                                    String.class.getName()
4510                            },
4511                            DLFolderModelImpl.GROUPID_COLUMN_BITMASK |
4512                            DLFolderModelImpl.PARENTFOLDERID_COLUMN_BITMASK |
4513                            DLFolderModelImpl.NAME_COLUMN_BITMASK);
4514            public static final FinderPath FINDER_PATH_COUNT_BY_G_P_N = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
4515                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
4516                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P_N",
4517                            new String[] {
4518                                    Long.class.getName(), Long.class.getName(),
4519                                    String.class.getName()
4520                            });
4521    
4522            /**
4523             * 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.
4524             *
4525             * @param groupId the group ID
4526             * @param parentFolderId the parent folder ID
4527             * @param name the name
4528             * @return the matching document library folder
4529             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
4530             * @throws SystemException if a system exception occurred
4531             */
4532            @Override
4533            public DLFolder findByG_P_N(long groupId, long parentFolderId, String name)
4534                    throws NoSuchFolderException, SystemException {
4535                    DLFolder dlFolder = fetchByG_P_N(groupId, parentFolderId, name);
4536    
4537                    if (dlFolder == null) {
4538                            StringBundler msg = new StringBundler(8);
4539    
4540                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4541    
4542                            msg.append("groupId=");
4543                            msg.append(groupId);
4544    
4545                            msg.append(", parentFolderId=");
4546                            msg.append(parentFolderId);
4547    
4548                            msg.append(", name=");
4549                            msg.append(name);
4550    
4551                            msg.append(StringPool.CLOSE_CURLY_BRACE);
4552    
4553                            if (_log.isWarnEnabled()) {
4554                                    _log.warn(msg.toString());
4555                            }
4556    
4557                            throw new NoSuchFolderException(msg.toString());
4558                    }
4559    
4560                    return dlFolder;
4561            }
4562    
4563            /**
4564             * 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.
4565             *
4566             * @param groupId the group ID
4567             * @param parentFolderId the parent folder ID
4568             * @param name the name
4569             * @return the matching document library folder, or <code>null</code> if a matching document library folder could not be found
4570             * @throws SystemException if a system exception occurred
4571             */
4572            @Override
4573            public DLFolder fetchByG_P_N(long groupId, long parentFolderId, String name)
4574                    throws SystemException {
4575                    return fetchByG_P_N(groupId, parentFolderId, name, true);
4576            }
4577    
4578            /**
4579             * 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.
4580             *
4581             * @param groupId the group ID
4582             * @param parentFolderId the parent folder ID
4583             * @param name the name
4584             * @param retrieveFromCache whether to use the finder cache
4585             * @return the matching document library folder, or <code>null</code> if a matching document library folder could not be found
4586             * @throws SystemException if a system exception occurred
4587             */
4588            @Override
4589            public DLFolder fetchByG_P_N(long groupId, long parentFolderId,
4590                    String name, boolean retrieveFromCache) throws SystemException {
4591                    Object[] finderArgs = new Object[] { groupId, parentFolderId, name };
4592    
4593                    Object result = null;
4594    
4595                    if (retrieveFromCache) {
4596                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_P_N,
4597                                            finderArgs, this);
4598                    }
4599    
4600                    if (result instanceof DLFolder) {
4601                            DLFolder dlFolder = (DLFolder)result;
4602    
4603                            if ((groupId != dlFolder.getGroupId()) ||
4604                                            (parentFolderId != dlFolder.getParentFolderId()) ||
4605                                            !Validator.equals(name, dlFolder.getName())) {
4606                                    result = null;
4607                            }
4608                    }
4609    
4610                    if (result == null) {
4611                            StringBundler query = new StringBundler(5);
4612    
4613                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
4614    
4615                            query.append(_FINDER_COLUMN_G_P_N_GROUPID_2);
4616    
4617                            query.append(_FINDER_COLUMN_G_P_N_PARENTFOLDERID_2);
4618    
4619                            boolean bindName = false;
4620    
4621                            if (name == null) {
4622                                    query.append(_FINDER_COLUMN_G_P_N_NAME_1);
4623                            }
4624                            else if (name.equals(StringPool.BLANK)) {
4625                                    query.append(_FINDER_COLUMN_G_P_N_NAME_3);
4626                            }
4627                            else {
4628                                    bindName = true;
4629    
4630                                    query.append(_FINDER_COLUMN_G_P_N_NAME_2);
4631                            }
4632    
4633                            String sql = query.toString();
4634    
4635                            Session session = null;
4636    
4637                            try {
4638                                    session = openSession();
4639    
4640                                    Query q = session.createQuery(sql);
4641    
4642                                    QueryPos qPos = QueryPos.getInstance(q);
4643    
4644                                    qPos.add(groupId);
4645    
4646                                    qPos.add(parentFolderId);
4647    
4648                                    if (bindName) {
4649                                            qPos.add(name);
4650                                    }
4651    
4652                                    List<DLFolder> list = q.list();
4653    
4654                                    if (list.isEmpty()) {
4655                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_N,
4656                                                    finderArgs, list);
4657                                    }
4658                                    else {
4659                                            DLFolder dlFolder = list.get(0);
4660    
4661                                            result = dlFolder;
4662    
4663                                            cacheResult(dlFolder);
4664    
4665                                            if ((dlFolder.getGroupId() != groupId) ||
4666                                                            (dlFolder.getParentFolderId() != parentFolderId) ||
4667                                                            (dlFolder.getName() == null) ||
4668                                                            !dlFolder.getName().equals(name)) {
4669                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_N,
4670                                                            finderArgs, dlFolder);
4671                                            }
4672                                    }
4673                            }
4674                            catch (Exception e) {
4675                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P_N,
4676                                            finderArgs);
4677    
4678                                    throw processException(e);
4679                            }
4680                            finally {
4681                                    closeSession(session);
4682                            }
4683                    }
4684    
4685                    if (result instanceof List<?>) {
4686                            return null;
4687                    }
4688                    else {
4689                            return (DLFolder)result;
4690                    }
4691            }
4692    
4693            /**
4694             * Removes the document library folder where groupId = &#63; and parentFolderId = &#63; and name = &#63; from the database.
4695             *
4696             * @param groupId the group ID
4697             * @param parentFolderId the parent folder ID
4698             * @param name the name
4699             * @return the document library folder that was removed
4700             * @throws SystemException if a system exception occurred
4701             */
4702            @Override
4703            public DLFolder removeByG_P_N(long groupId, long parentFolderId, String name)
4704                    throws NoSuchFolderException, SystemException {
4705                    DLFolder dlFolder = findByG_P_N(groupId, parentFolderId, name);
4706    
4707                    return remove(dlFolder);
4708            }
4709    
4710            /**
4711             * Returns the number of document library folders where groupId = &#63; and parentFolderId = &#63; and name = &#63;.
4712             *
4713             * @param groupId the group ID
4714             * @param parentFolderId the parent folder ID
4715             * @param name the name
4716             * @return the number of matching document library folders
4717             * @throws SystemException if a system exception occurred
4718             */
4719            @Override
4720            public int countByG_P_N(long groupId, long parentFolderId, String name)
4721                    throws SystemException {
4722                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_P_N;
4723    
4724                    Object[] finderArgs = new Object[] { groupId, parentFolderId, name };
4725    
4726                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4727                                    this);
4728    
4729                    if (count == null) {
4730                            StringBundler query = new StringBundler(4);
4731    
4732                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
4733    
4734                            query.append(_FINDER_COLUMN_G_P_N_GROUPID_2);
4735    
4736                            query.append(_FINDER_COLUMN_G_P_N_PARENTFOLDERID_2);
4737    
4738                            boolean bindName = false;
4739    
4740                            if (name == null) {
4741                                    query.append(_FINDER_COLUMN_G_P_N_NAME_1);
4742                            }
4743                            else if (name.equals(StringPool.BLANK)) {
4744                                    query.append(_FINDER_COLUMN_G_P_N_NAME_3);
4745                            }
4746                            else {
4747                                    bindName = true;
4748    
4749                                    query.append(_FINDER_COLUMN_G_P_N_NAME_2);
4750                            }
4751    
4752                            String sql = query.toString();
4753    
4754                            Session session = null;
4755    
4756                            try {
4757                                    session = openSession();
4758    
4759                                    Query q = session.createQuery(sql);
4760    
4761                                    QueryPos qPos = QueryPos.getInstance(q);
4762    
4763                                    qPos.add(groupId);
4764    
4765                                    qPos.add(parentFolderId);
4766    
4767                                    if (bindName) {
4768                                            qPos.add(name);
4769                                    }
4770    
4771                                    count = (Long)q.uniqueResult();
4772    
4773                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
4774                            }
4775                            catch (Exception e) {
4776                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4777    
4778                                    throw processException(e);
4779                            }
4780                            finally {
4781                                    closeSession(session);
4782                            }
4783                    }
4784    
4785                    return count.intValue();
4786            }
4787    
4788            private static final String _FINDER_COLUMN_G_P_N_GROUPID_2 = "dlFolder.groupId = ? AND ";
4789            private static final String _FINDER_COLUMN_G_P_N_PARENTFOLDERID_2 = "dlFolder.parentFolderId = ? AND ";
4790            private static final String _FINDER_COLUMN_G_P_N_NAME_1 = "dlFolder.name IS NULL";
4791            private static final String _FINDER_COLUMN_G_P_N_NAME_2 = "dlFolder.name = ?";
4792            private static final String _FINDER_COLUMN_G_P_N_NAME_3 = "(dlFolder.name IS NULL OR dlFolder.name = '')";
4793            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_M_P_H = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
4794                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
4795                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_M_P_H",
4796                            new String[] {
4797                                    Long.class.getName(), Boolean.class.getName(),
4798                                    Long.class.getName(), Boolean.class.getName(),
4799                                    
4800                            Integer.class.getName(), Integer.class.getName(),
4801                                    OrderByComparator.class.getName()
4802                            });
4803            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P_H =
4804                    new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
4805                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
4806                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_M_P_H",
4807                            new String[] {
4808                                    Long.class.getName(), Boolean.class.getName(),
4809                                    Long.class.getName(), Boolean.class.getName()
4810                            },
4811                            DLFolderModelImpl.GROUPID_COLUMN_BITMASK |
4812                            DLFolderModelImpl.MOUNTPOINT_COLUMN_BITMASK |
4813                            DLFolderModelImpl.PARENTFOLDERID_COLUMN_BITMASK |
4814                            DLFolderModelImpl.HIDDEN_COLUMN_BITMASK |
4815                            DLFolderModelImpl.NAME_COLUMN_BITMASK);
4816            public static final FinderPath FINDER_PATH_COUNT_BY_G_M_P_H = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
4817                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
4818                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_M_P_H",
4819                            new String[] {
4820                                    Long.class.getName(), Boolean.class.getName(),
4821                                    Long.class.getName(), Boolean.class.getName()
4822                            });
4823    
4824            /**
4825             * Returns all the document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63;.
4826             *
4827             * @param groupId the group ID
4828             * @param mountPoint the mount point
4829             * @param parentFolderId the parent folder ID
4830             * @param hidden the hidden
4831             * @return the matching document library folders
4832             * @throws SystemException if a system exception occurred
4833             */
4834            @Override
4835            public List<DLFolder> findByG_M_P_H(long groupId, boolean mountPoint,
4836                    long parentFolderId, boolean hidden) throws SystemException {
4837                    return findByG_M_P_H(groupId, mountPoint, parentFolderId, hidden,
4838                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
4839            }
4840    
4841            /**
4842             * Returns a range of all the document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63;.
4843             *
4844             * <p>
4845             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
4846             * </p>
4847             *
4848             * @param groupId the group ID
4849             * @param mountPoint the mount point
4850             * @param parentFolderId the parent folder ID
4851             * @param hidden the hidden
4852             * @param start the lower bound of the range of document library folders
4853             * @param end the upper bound of the range of document library folders (not inclusive)
4854             * @return the range of matching document library folders
4855             * @throws SystemException if a system exception occurred
4856             */
4857            @Override
4858            public List<DLFolder> findByG_M_P_H(long groupId, boolean mountPoint,
4859                    long parentFolderId, boolean hidden, int start, int end)
4860                    throws SystemException {
4861                    return findByG_M_P_H(groupId, mountPoint, parentFolderId, hidden,
4862                            start, end, null);
4863            }
4864    
4865            /**
4866             * Returns an ordered range of all the document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63;.
4867             *
4868             * <p>
4869             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
4870             * </p>
4871             *
4872             * @param groupId the group ID
4873             * @param mountPoint the mount point
4874             * @param parentFolderId the parent folder ID
4875             * @param hidden the hidden
4876             * @param start the lower bound of the range of document library folders
4877             * @param end the upper bound of the range of document library folders (not inclusive)
4878             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4879             * @return the ordered range of matching document library folders
4880             * @throws SystemException if a system exception occurred
4881             */
4882            @Override
4883            public List<DLFolder> findByG_M_P_H(long groupId, boolean mountPoint,
4884                    long parentFolderId, boolean hidden, int start, int end,
4885                    OrderByComparator orderByComparator) throws SystemException {
4886                    boolean pagination = true;
4887                    FinderPath finderPath = null;
4888                    Object[] finderArgs = null;
4889    
4890                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4891                                    (orderByComparator == null)) {
4892                            pagination = false;
4893                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P_H;
4894                            finderArgs = new Object[] {
4895                                            groupId, mountPoint, parentFolderId, hidden
4896                                    };
4897                    }
4898                    else {
4899                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_M_P_H;
4900                            finderArgs = new Object[] {
4901                                            groupId, mountPoint, parentFolderId, hidden,
4902                                            
4903                                            start, end, orderByComparator
4904                                    };
4905                    }
4906    
4907                    List<DLFolder> list = (List<DLFolder>)FinderCacheUtil.getResult(finderPath,
4908                                    finderArgs, this);
4909    
4910                    if ((list != null) && !list.isEmpty()) {
4911                            for (DLFolder dlFolder : list) {
4912                                    if ((groupId != dlFolder.getGroupId()) ||
4913                                                    (mountPoint != dlFolder.getMountPoint()) ||
4914                                                    (parentFolderId != dlFolder.getParentFolderId()) ||
4915                                                    (hidden != dlFolder.getHidden())) {
4916                                            list = null;
4917    
4918                                            break;
4919                                    }
4920                            }
4921                    }
4922    
4923                    if (list == null) {
4924                            StringBundler query = null;
4925    
4926                            if (orderByComparator != null) {
4927                                    query = new StringBundler(6 +
4928                                                    (orderByComparator.getOrderByFields().length * 3));
4929                            }
4930                            else {
4931                                    query = new StringBundler(6);
4932                            }
4933    
4934                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
4935    
4936                            query.append(_FINDER_COLUMN_G_M_P_H_GROUPID_2);
4937    
4938                            query.append(_FINDER_COLUMN_G_M_P_H_MOUNTPOINT_2);
4939    
4940                            query.append(_FINDER_COLUMN_G_M_P_H_PARENTFOLDERID_2);
4941    
4942                            query.append(_FINDER_COLUMN_G_M_P_H_HIDDEN_2);
4943    
4944                            if (orderByComparator != null) {
4945                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4946                                            orderByComparator);
4947                            }
4948                            else
4949                             if (pagination) {
4950                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
4951                            }
4952    
4953                            String sql = query.toString();
4954    
4955                            Session session = null;
4956    
4957                            try {
4958                                    session = openSession();
4959    
4960                                    Query q = session.createQuery(sql);
4961    
4962                                    QueryPos qPos = QueryPos.getInstance(q);
4963    
4964                                    qPos.add(groupId);
4965    
4966                                    qPos.add(mountPoint);
4967    
4968                                    qPos.add(parentFolderId);
4969    
4970                                    qPos.add(hidden);
4971    
4972                                    if (!pagination) {
4973                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
4974                                                            start, end, false);
4975    
4976                                            Collections.sort(list);
4977    
4978                                            list = new UnmodifiableList<DLFolder>(list);
4979                                    }
4980                                    else {
4981                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
4982                                                            start, end);
4983                                    }
4984    
4985                                    cacheResult(list);
4986    
4987                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
4988                            }
4989                            catch (Exception e) {
4990                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4991    
4992                                    throw processException(e);
4993                            }
4994                            finally {
4995                                    closeSession(session);
4996                            }
4997                    }
4998    
4999                    return list;
5000            }
5001    
5002            /**
5003             * Returns the first document library folder in the ordered set where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63;.
5004             *
5005             * @param groupId the group ID
5006             * @param mountPoint the mount point
5007             * @param parentFolderId the parent folder ID
5008             * @param hidden the hidden
5009             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5010             * @return the first matching document library folder
5011             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
5012             * @throws SystemException if a system exception occurred
5013             */
5014            @Override
5015            public DLFolder findByG_M_P_H_First(long groupId, boolean mountPoint,
5016                    long parentFolderId, boolean hidden, OrderByComparator orderByComparator)
5017                    throws NoSuchFolderException, SystemException {
5018                    DLFolder dlFolder = fetchByG_M_P_H_First(groupId, mountPoint,
5019                                    parentFolderId, hidden, orderByComparator);
5020    
5021                    if (dlFolder != null) {
5022                            return dlFolder;
5023                    }
5024    
5025                    StringBundler msg = new StringBundler(10);
5026    
5027                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5028    
5029                    msg.append("groupId=");
5030                    msg.append(groupId);
5031    
5032                    msg.append(", mountPoint=");
5033                    msg.append(mountPoint);
5034    
5035                    msg.append(", parentFolderId=");
5036                    msg.append(parentFolderId);
5037    
5038                    msg.append(", hidden=");
5039                    msg.append(hidden);
5040    
5041                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5042    
5043                    throw new NoSuchFolderException(msg.toString());
5044            }
5045    
5046            /**
5047             * Returns the first document library folder in the ordered set where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63;.
5048             *
5049             * @param groupId the group ID
5050             * @param mountPoint the mount point
5051             * @param parentFolderId the parent folder ID
5052             * @param hidden the hidden
5053             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5054             * @return the first matching document library folder, or <code>null</code> if a matching document library folder could not be found
5055             * @throws SystemException if a system exception occurred
5056             */
5057            @Override
5058            public DLFolder fetchByG_M_P_H_First(long groupId, boolean mountPoint,
5059                    long parentFolderId, boolean hidden, OrderByComparator orderByComparator)
5060                    throws SystemException {
5061                    List<DLFolder> list = findByG_M_P_H(groupId, mountPoint,
5062                                    parentFolderId, hidden, 0, 1, orderByComparator);
5063    
5064                    if (!list.isEmpty()) {
5065                            return list.get(0);
5066                    }
5067    
5068                    return null;
5069            }
5070    
5071            /**
5072             * Returns the last document library folder in the ordered set where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63;.
5073             *
5074             * @param groupId the group ID
5075             * @param mountPoint the mount point
5076             * @param parentFolderId the parent folder ID
5077             * @param hidden the hidden
5078             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5079             * @return the last matching document library folder
5080             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
5081             * @throws SystemException if a system exception occurred
5082             */
5083            @Override
5084            public DLFolder findByG_M_P_H_Last(long groupId, boolean mountPoint,
5085                    long parentFolderId, boolean hidden, OrderByComparator orderByComparator)
5086                    throws NoSuchFolderException, SystemException {
5087                    DLFolder dlFolder = fetchByG_M_P_H_Last(groupId, mountPoint,
5088                                    parentFolderId, hidden, orderByComparator);
5089    
5090                    if (dlFolder != null) {
5091                            return dlFolder;
5092                    }
5093    
5094                    StringBundler msg = new StringBundler(10);
5095    
5096                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5097    
5098                    msg.append("groupId=");
5099                    msg.append(groupId);
5100    
5101                    msg.append(", mountPoint=");
5102                    msg.append(mountPoint);
5103    
5104                    msg.append(", parentFolderId=");
5105                    msg.append(parentFolderId);
5106    
5107                    msg.append(", hidden=");
5108                    msg.append(hidden);
5109    
5110                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5111    
5112                    throw new NoSuchFolderException(msg.toString());
5113            }
5114    
5115            /**
5116             * Returns the last document library folder in the ordered set where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63;.
5117             *
5118             * @param groupId the group ID
5119             * @param mountPoint the mount point
5120             * @param parentFolderId the parent folder ID
5121             * @param hidden the hidden
5122             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5123             * @return the last matching document library folder, or <code>null</code> if a matching document library folder could not be found
5124             * @throws SystemException if a system exception occurred
5125             */
5126            @Override
5127            public DLFolder fetchByG_M_P_H_Last(long groupId, boolean mountPoint,
5128                    long parentFolderId, boolean hidden, OrderByComparator orderByComparator)
5129                    throws SystemException {
5130                    int count = countByG_M_P_H(groupId, mountPoint, parentFolderId, hidden);
5131    
5132                    if (count == 0) {
5133                            return null;
5134                    }
5135    
5136                    List<DLFolder> list = findByG_M_P_H(groupId, mountPoint,
5137                                    parentFolderId, hidden, count - 1, count, orderByComparator);
5138    
5139                    if (!list.isEmpty()) {
5140                            return list.get(0);
5141                    }
5142    
5143                    return null;
5144            }
5145    
5146            /**
5147             * 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;.
5148             *
5149             * @param folderId the primary key of the current document library folder
5150             * @param groupId the group ID
5151             * @param mountPoint the mount point
5152             * @param parentFolderId the parent folder ID
5153             * @param hidden the hidden
5154             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5155             * @return the previous, current, and next document library folder
5156             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
5157             * @throws SystemException if a system exception occurred
5158             */
5159            @Override
5160            public DLFolder[] findByG_M_P_H_PrevAndNext(long folderId, long groupId,
5161                    boolean mountPoint, long parentFolderId, boolean hidden,
5162                    OrderByComparator orderByComparator)
5163                    throws NoSuchFolderException, SystemException {
5164                    DLFolder dlFolder = findByPrimaryKey(folderId);
5165    
5166                    Session session = null;
5167    
5168                    try {
5169                            session = openSession();
5170    
5171                            DLFolder[] array = new DLFolderImpl[3];
5172    
5173                            array[0] = getByG_M_P_H_PrevAndNext(session, dlFolder, groupId,
5174                                            mountPoint, parentFolderId, hidden, orderByComparator, true);
5175    
5176                            array[1] = dlFolder;
5177    
5178                            array[2] = getByG_M_P_H_PrevAndNext(session, dlFolder, groupId,
5179                                            mountPoint, parentFolderId, hidden, orderByComparator, false);
5180    
5181                            return array;
5182                    }
5183                    catch (Exception e) {
5184                            throw processException(e);
5185                    }
5186                    finally {
5187                            closeSession(session);
5188                    }
5189            }
5190    
5191            protected DLFolder getByG_M_P_H_PrevAndNext(Session session,
5192                    DLFolder dlFolder, long groupId, boolean mountPoint,
5193                    long parentFolderId, boolean hidden,
5194                    OrderByComparator orderByComparator, boolean previous) {
5195                    StringBundler query = null;
5196    
5197                    if (orderByComparator != null) {
5198                            query = new StringBundler(6 +
5199                                            (orderByComparator.getOrderByFields().length * 6));
5200                    }
5201                    else {
5202                            query = new StringBundler(3);
5203                    }
5204    
5205                    query.append(_SQL_SELECT_DLFOLDER_WHERE);
5206    
5207                    query.append(_FINDER_COLUMN_G_M_P_H_GROUPID_2);
5208    
5209                    query.append(_FINDER_COLUMN_G_M_P_H_MOUNTPOINT_2);
5210    
5211                    query.append(_FINDER_COLUMN_G_M_P_H_PARENTFOLDERID_2);
5212    
5213                    query.append(_FINDER_COLUMN_G_M_P_H_HIDDEN_2);
5214    
5215                    if (orderByComparator != null) {
5216                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5217    
5218                            if (orderByConditionFields.length > 0) {
5219                                    query.append(WHERE_AND);
5220                            }
5221    
5222                            for (int i = 0; i < orderByConditionFields.length; i++) {
5223                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5224                                    query.append(orderByConditionFields[i]);
5225    
5226                                    if ((i + 1) < orderByConditionFields.length) {
5227                                            if (orderByComparator.isAscending() ^ previous) {
5228                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5229                                            }
5230                                            else {
5231                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5232                                            }
5233                                    }
5234                                    else {
5235                                            if (orderByComparator.isAscending() ^ previous) {
5236                                                    query.append(WHERE_GREATER_THAN);
5237                                            }
5238                                            else {
5239                                                    query.append(WHERE_LESSER_THAN);
5240                                            }
5241                                    }
5242                            }
5243    
5244                            query.append(ORDER_BY_CLAUSE);
5245    
5246                            String[] orderByFields = orderByComparator.getOrderByFields();
5247    
5248                            for (int i = 0; i < orderByFields.length; i++) {
5249                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5250                                    query.append(orderByFields[i]);
5251    
5252                                    if ((i + 1) < orderByFields.length) {
5253                                            if (orderByComparator.isAscending() ^ previous) {
5254                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5255                                            }
5256                                            else {
5257                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5258                                            }
5259                                    }
5260                                    else {
5261                                            if (orderByComparator.isAscending() ^ previous) {
5262                                                    query.append(ORDER_BY_ASC);
5263                                            }
5264                                            else {
5265                                                    query.append(ORDER_BY_DESC);
5266                                            }
5267                                    }
5268                            }
5269                    }
5270                    else {
5271                            query.append(DLFolderModelImpl.ORDER_BY_JPQL);
5272                    }
5273    
5274                    String sql = query.toString();
5275    
5276                    Query q = session.createQuery(sql);
5277    
5278                    q.setFirstResult(0);
5279                    q.setMaxResults(2);
5280    
5281                    QueryPos qPos = QueryPos.getInstance(q);
5282    
5283                    qPos.add(groupId);
5284    
5285                    qPos.add(mountPoint);
5286    
5287                    qPos.add(parentFolderId);
5288    
5289                    qPos.add(hidden);
5290    
5291                    if (orderByComparator != null) {
5292                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
5293    
5294                            for (Object value : values) {
5295                                    qPos.add(value);
5296                            }
5297                    }
5298    
5299                    List<DLFolder> list = q.list();
5300    
5301                    if (list.size() == 2) {
5302                            return list.get(1);
5303                    }
5304                    else {
5305                            return null;
5306                    }
5307            }
5308    
5309            /**
5310             * 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;.
5311             *
5312             * @param groupId the group ID
5313             * @param mountPoint the mount point
5314             * @param parentFolderId the parent folder ID
5315             * @param hidden the hidden
5316             * @return the matching document library folders that the user has permission to view
5317             * @throws SystemException if a system exception occurred
5318             */
5319            @Override
5320            public List<DLFolder> filterFindByG_M_P_H(long groupId, boolean mountPoint,
5321                    long parentFolderId, boolean hidden) throws SystemException {
5322                    return filterFindByG_M_P_H(groupId, mountPoint, parentFolderId, hidden,
5323                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
5324            }
5325    
5326            /**
5327             * 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;.
5328             *
5329             * <p>
5330             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
5331             * </p>
5332             *
5333             * @param groupId the group ID
5334             * @param mountPoint the mount point
5335             * @param parentFolderId the parent folder ID
5336             * @param hidden the hidden
5337             * @param start the lower bound of the range of document library folders
5338             * @param end the upper bound of the range of document library folders (not inclusive)
5339             * @return the range of matching document library folders that the user has permission to view
5340             * @throws SystemException if a system exception occurred
5341             */
5342            @Override
5343            public List<DLFolder> filterFindByG_M_P_H(long groupId, boolean mountPoint,
5344                    long parentFolderId, boolean hidden, int start, int end)
5345                    throws SystemException {
5346                    return filterFindByG_M_P_H(groupId, mountPoint, parentFolderId, hidden,
5347                            start, end, null);
5348            }
5349    
5350            /**
5351             * 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;.
5352             *
5353             * <p>
5354             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
5355             * </p>
5356             *
5357             * @param groupId the group ID
5358             * @param mountPoint the mount point
5359             * @param parentFolderId the parent folder ID
5360             * @param hidden the hidden
5361             * @param start the lower bound of the range of document library folders
5362             * @param end the upper bound of the range of document library folders (not inclusive)
5363             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5364             * @return the ordered range of matching document library folders that the user has permission to view
5365             * @throws SystemException if a system exception occurred
5366             */
5367            @Override
5368            public List<DLFolder> filterFindByG_M_P_H(long groupId, boolean mountPoint,
5369                    long parentFolderId, boolean hidden, int start, int end,
5370                    OrderByComparator orderByComparator) throws SystemException {
5371                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5372                            return findByG_M_P_H(groupId, mountPoint, parentFolderId, hidden,
5373                                    start, end, orderByComparator);
5374                    }
5375    
5376                    StringBundler query = null;
5377    
5378                    if (orderByComparator != null) {
5379                            query = new StringBundler(6 +
5380                                            (orderByComparator.getOrderByFields().length * 3));
5381                    }
5382                    else {
5383                            query = new StringBundler(6);
5384                    }
5385    
5386                    if (getDB().isSupportsInlineDistinct()) {
5387                            query.append(_FILTER_SQL_SELECT_DLFOLDER_WHERE);
5388                    }
5389                    else {
5390                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1);
5391                    }
5392    
5393                    query.append(_FINDER_COLUMN_G_M_P_H_GROUPID_2);
5394    
5395                    query.append(_FINDER_COLUMN_G_M_P_H_MOUNTPOINT_2);
5396    
5397                    query.append(_FINDER_COLUMN_G_M_P_H_PARENTFOLDERID_2);
5398    
5399                    query.append(_FINDER_COLUMN_G_M_P_H_HIDDEN_2_SQL);
5400    
5401                    if (!getDB().isSupportsInlineDistinct()) {
5402                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2);
5403                    }
5404    
5405                    if (orderByComparator != null) {
5406                            if (getDB().isSupportsInlineDistinct()) {
5407                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5408                                            orderByComparator, true);
5409                            }
5410                            else {
5411                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
5412                                            orderByComparator, true);
5413                            }
5414                    }
5415                    else {
5416                            if (getDB().isSupportsInlineDistinct()) {
5417                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
5418                            }
5419                            else {
5420                                    query.append(DLFolderModelImpl.ORDER_BY_SQL);
5421                            }
5422                    }
5423    
5424                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5425                                    DLFolder.class.getName(),
5426                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5427    
5428                    Session session = null;
5429    
5430                    try {
5431                            session = openSession();
5432    
5433                            SQLQuery q = session.createSQLQuery(sql);
5434    
5435                            if (getDB().isSupportsInlineDistinct()) {
5436                                    q.addEntity(_FILTER_ENTITY_ALIAS, DLFolderImpl.class);
5437                            }
5438                            else {
5439                                    q.addEntity(_FILTER_ENTITY_TABLE, DLFolderImpl.class);
5440                            }
5441    
5442                            QueryPos qPos = QueryPos.getInstance(q);
5443    
5444                            qPos.add(groupId);
5445    
5446                            qPos.add(mountPoint);
5447    
5448                            qPos.add(parentFolderId);
5449    
5450                            qPos.add(hidden);
5451    
5452                            return (List<DLFolder>)QueryUtil.list(q, getDialect(), start, end);
5453                    }
5454                    catch (Exception e) {
5455                            throw processException(e);
5456                    }
5457                    finally {
5458                            closeSession(session);
5459                    }
5460            }
5461    
5462            /**
5463             * 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;.
5464             *
5465             * @param folderId the primary key of the current document library folder
5466             * @param groupId the group ID
5467             * @param mountPoint the mount point
5468             * @param parentFolderId the parent folder ID
5469             * @param hidden the hidden
5470             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5471             * @return the previous, current, and next document library folder
5472             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
5473             * @throws SystemException if a system exception occurred
5474             */
5475            @Override
5476            public DLFolder[] filterFindByG_M_P_H_PrevAndNext(long folderId,
5477                    long groupId, boolean mountPoint, long parentFolderId, boolean hidden,
5478                    OrderByComparator orderByComparator)
5479                    throws NoSuchFolderException, SystemException {
5480                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5481                            return findByG_M_P_H_PrevAndNext(folderId, groupId, mountPoint,
5482                                    parentFolderId, hidden, orderByComparator);
5483                    }
5484    
5485                    DLFolder dlFolder = findByPrimaryKey(folderId);
5486    
5487                    Session session = null;
5488    
5489                    try {
5490                            session = openSession();
5491    
5492                            DLFolder[] array = new DLFolderImpl[3];
5493    
5494                            array[0] = filterGetByG_M_P_H_PrevAndNext(session, dlFolder,
5495                                            groupId, mountPoint, parentFolderId, hidden,
5496                                            orderByComparator, true);
5497    
5498                            array[1] = dlFolder;
5499    
5500                            array[2] = filterGetByG_M_P_H_PrevAndNext(session, dlFolder,
5501                                            groupId, mountPoint, parentFolderId, hidden,
5502                                            orderByComparator, false);
5503    
5504                            return array;
5505                    }
5506                    catch (Exception e) {
5507                            throw processException(e);
5508                    }
5509                    finally {
5510                            closeSession(session);
5511                    }
5512            }
5513    
5514            protected DLFolder filterGetByG_M_P_H_PrevAndNext(Session session,
5515                    DLFolder dlFolder, long groupId, boolean mountPoint,
5516                    long parentFolderId, boolean hidden,
5517                    OrderByComparator orderByComparator, boolean previous) {
5518                    StringBundler query = null;
5519    
5520                    if (orderByComparator != null) {
5521                            query = new StringBundler(6 +
5522                                            (orderByComparator.getOrderByFields().length * 6));
5523                    }
5524                    else {
5525                            query = new StringBundler(3);
5526                    }
5527    
5528                    if (getDB().isSupportsInlineDistinct()) {
5529                            query.append(_FILTER_SQL_SELECT_DLFOLDER_WHERE);
5530                    }
5531                    else {
5532                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1);
5533                    }
5534    
5535                    query.append(_FINDER_COLUMN_G_M_P_H_GROUPID_2);
5536    
5537                    query.append(_FINDER_COLUMN_G_M_P_H_MOUNTPOINT_2);
5538    
5539                    query.append(_FINDER_COLUMN_G_M_P_H_PARENTFOLDERID_2);
5540    
5541                    query.append(_FINDER_COLUMN_G_M_P_H_HIDDEN_2_SQL);
5542    
5543                    if (!getDB().isSupportsInlineDistinct()) {
5544                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2);
5545                    }
5546    
5547                    if (orderByComparator != null) {
5548                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5549    
5550                            if (orderByConditionFields.length > 0) {
5551                                    query.append(WHERE_AND);
5552                            }
5553    
5554                            for (int i = 0; i < orderByConditionFields.length; i++) {
5555                                    if (getDB().isSupportsInlineDistinct()) {
5556                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5557                                    }
5558                                    else {
5559                                            query.append(_ORDER_BY_ENTITY_TABLE);
5560                                    }
5561    
5562                                    query.append(orderByConditionFields[i]);
5563    
5564                                    if ((i + 1) < orderByConditionFields.length) {
5565                                            if (orderByComparator.isAscending() ^ previous) {
5566                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5567                                            }
5568                                            else {
5569                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5570                                            }
5571                                    }
5572                                    else {
5573                                            if (orderByComparator.isAscending() ^ previous) {
5574                                                    query.append(WHERE_GREATER_THAN);
5575                                            }
5576                                            else {
5577                                                    query.append(WHERE_LESSER_THAN);
5578                                            }
5579                                    }
5580                            }
5581    
5582                            query.append(ORDER_BY_CLAUSE);
5583    
5584                            String[] orderByFields = orderByComparator.getOrderByFields();
5585    
5586                            for (int i = 0; i < orderByFields.length; i++) {
5587                                    if (getDB().isSupportsInlineDistinct()) {
5588                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5589                                    }
5590                                    else {
5591                                            query.append(_ORDER_BY_ENTITY_TABLE);
5592                                    }
5593    
5594                                    query.append(orderByFields[i]);
5595    
5596                                    if ((i + 1) < orderByFields.length) {
5597                                            if (orderByComparator.isAscending() ^ previous) {
5598                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5599                                            }
5600                                            else {
5601                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5602                                            }
5603                                    }
5604                                    else {
5605                                            if (orderByComparator.isAscending() ^ previous) {
5606                                                    query.append(ORDER_BY_ASC);
5607                                            }
5608                                            else {
5609                                                    query.append(ORDER_BY_DESC);
5610                                            }
5611                                    }
5612                            }
5613                    }
5614                    else {
5615                            if (getDB().isSupportsInlineDistinct()) {
5616                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
5617                            }
5618                            else {
5619                                    query.append(DLFolderModelImpl.ORDER_BY_SQL);
5620                            }
5621                    }
5622    
5623                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5624                                    DLFolder.class.getName(),
5625                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5626    
5627                    SQLQuery q = session.createSQLQuery(sql);
5628    
5629                    q.setFirstResult(0);
5630                    q.setMaxResults(2);
5631    
5632                    if (getDB().isSupportsInlineDistinct()) {
5633                            q.addEntity(_FILTER_ENTITY_ALIAS, DLFolderImpl.class);
5634                    }
5635                    else {
5636                            q.addEntity(_FILTER_ENTITY_TABLE, DLFolderImpl.class);
5637                    }
5638    
5639                    QueryPos qPos = QueryPos.getInstance(q);
5640    
5641                    qPos.add(groupId);
5642    
5643                    qPos.add(mountPoint);
5644    
5645                    qPos.add(parentFolderId);
5646    
5647                    qPos.add(hidden);
5648    
5649                    if (orderByComparator != null) {
5650                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
5651    
5652                            for (Object value : values) {
5653                                    qPos.add(value);
5654                            }
5655                    }
5656    
5657                    List<DLFolder> list = q.list();
5658    
5659                    if (list.size() == 2) {
5660                            return list.get(1);
5661                    }
5662                    else {
5663                            return null;
5664                    }
5665            }
5666    
5667            /**
5668             * Removes all the document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63; from the database.
5669             *
5670             * @param groupId the group ID
5671             * @param mountPoint the mount point
5672             * @param parentFolderId the parent folder ID
5673             * @param hidden the hidden
5674             * @throws SystemException if a system exception occurred
5675             */
5676            @Override
5677            public void removeByG_M_P_H(long groupId, boolean mountPoint,
5678                    long parentFolderId, boolean hidden) throws SystemException {
5679                    for (DLFolder dlFolder : findByG_M_P_H(groupId, mountPoint,
5680                                    parentFolderId, hidden, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
5681                                    null)) {
5682                            remove(dlFolder);
5683                    }
5684            }
5685    
5686            /**
5687             * Returns the number of document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63;.
5688             *
5689             * @param groupId the group ID
5690             * @param mountPoint the mount point
5691             * @param parentFolderId the parent folder ID
5692             * @param hidden the hidden
5693             * @return the number of matching document library folders
5694             * @throws SystemException if a system exception occurred
5695             */
5696            @Override
5697            public int countByG_M_P_H(long groupId, boolean mountPoint,
5698                    long parentFolderId, boolean hidden) throws SystemException {
5699                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_M_P_H;
5700    
5701                    Object[] finderArgs = new Object[] {
5702                                    groupId, mountPoint, parentFolderId, hidden
5703                            };
5704    
5705                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5706                                    this);
5707    
5708                    if (count == null) {
5709                            StringBundler query = new StringBundler(5);
5710    
5711                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
5712    
5713                            query.append(_FINDER_COLUMN_G_M_P_H_GROUPID_2);
5714    
5715                            query.append(_FINDER_COLUMN_G_M_P_H_MOUNTPOINT_2);
5716    
5717                            query.append(_FINDER_COLUMN_G_M_P_H_PARENTFOLDERID_2);
5718    
5719                            query.append(_FINDER_COLUMN_G_M_P_H_HIDDEN_2);
5720    
5721                            String sql = query.toString();
5722    
5723                            Session session = null;
5724    
5725                            try {
5726                                    session = openSession();
5727    
5728                                    Query q = session.createQuery(sql);
5729    
5730                                    QueryPos qPos = QueryPos.getInstance(q);
5731    
5732                                    qPos.add(groupId);
5733    
5734                                    qPos.add(mountPoint);
5735    
5736                                    qPos.add(parentFolderId);
5737    
5738                                    qPos.add(hidden);
5739    
5740                                    count = (Long)q.uniqueResult();
5741    
5742                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
5743                            }
5744                            catch (Exception e) {
5745                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5746    
5747                                    throw processException(e);
5748                            }
5749                            finally {
5750                                    closeSession(session);
5751                            }
5752                    }
5753    
5754                    return count.intValue();
5755            }
5756    
5757            /**
5758             * 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;.
5759             *
5760             * @param groupId the group ID
5761             * @param mountPoint the mount point
5762             * @param parentFolderId the parent folder ID
5763             * @param hidden the hidden
5764             * @return the number of matching document library folders that the user has permission to view
5765             * @throws SystemException if a system exception occurred
5766             */
5767            @Override
5768            public int filterCountByG_M_P_H(long groupId, boolean mountPoint,
5769                    long parentFolderId, boolean hidden) throws SystemException {
5770                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5771                            return countByG_M_P_H(groupId, mountPoint, parentFolderId, hidden);
5772                    }
5773    
5774                    StringBundler query = new StringBundler(5);
5775    
5776                    query.append(_FILTER_SQL_COUNT_DLFOLDER_WHERE);
5777    
5778                    query.append(_FINDER_COLUMN_G_M_P_H_GROUPID_2);
5779    
5780                    query.append(_FINDER_COLUMN_G_M_P_H_MOUNTPOINT_2);
5781    
5782                    query.append(_FINDER_COLUMN_G_M_P_H_PARENTFOLDERID_2);
5783    
5784                    query.append(_FINDER_COLUMN_G_M_P_H_HIDDEN_2_SQL);
5785    
5786                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5787                                    DLFolder.class.getName(),
5788                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5789    
5790                    Session session = null;
5791    
5792                    try {
5793                            session = openSession();
5794    
5795                            SQLQuery q = session.createSQLQuery(sql);
5796    
5797                            q.addScalar(COUNT_COLUMN_NAME,
5798                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
5799    
5800                            QueryPos qPos = QueryPos.getInstance(q);
5801    
5802                            qPos.add(groupId);
5803    
5804                            qPos.add(mountPoint);
5805    
5806                            qPos.add(parentFolderId);
5807    
5808                            qPos.add(hidden);
5809    
5810                            Long count = (Long)q.uniqueResult();
5811    
5812                            return count.intValue();
5813                    }
5814                    catch (Exception e) {
5815                            throw processException(e);
5816                    }
5817                    finally {
5818                            closeSession(session);
5819                    }
5820            }
5821    
5822            private static final String _FINDER_COLUMN_G_M_P_H_GROUPID_2 = "dlFolder.groupId = ? AND ";
5823            private static final String _FINDER_COLUMN_G_M_P_H_MOUNTPOINT_2 = "dlFolder.mountPoint = ? AND ";
5824            private static final String _FINDER_COLUMN_G_M_P_H_PARENTFOLDERID_2 = "dlFolder.parentFolderId = ? AND ";
5825            private static final String _FINDER_COLUMN_G_M_P_H_HIDDEN_2 = "dlFolder.hidden = ?";
5826            private static final String _FINDER_COLUMN_G_M_P_H_HIDDEN_2_SQL = "dlFolder.hidden_ = ?";
5827            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_H_S = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
5828                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
5829                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_P_H_S",
5830                            new String[] {
5831                                    Long.class.getName(), Long.class.getName(),
5832                                    Boolean.class.getName(), Integer.class.getName(),
5833                                    
5834                            Integer.class.getName(), Integer.class.getName(),
5835                                    OrderByComparator.class.getName()
5836                            });
5837            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_H_S =
5838                    new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
5839                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
5840                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_P_H_S",
5841                            new String[] {
5842                                    Long.class.getName(), Long.class.getName(),
5843                                    Boolean.class.getName(), Integer.class.getName()
5844                            },
5845                            DLFolderModelImpl.GROUPID_COLUMN_BITMASK |
5846                            DLFolderModelImpl.PARENTFOLDERID_COLUMN_BITMASK |
5847                            DLFolderModelImpl.HIDDEN_COLUMN_BITMASK |
5848                            DLFolderModelImpl.STATUS_COLUMN_BITMASK |
5849                            DLFolderModelImpl.NAME_COLUMN_BITMASK);
5850            public static final FinderPath FINDER_PATH_COUNT_BY_G_P_H_S = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
5851                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
5852                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P_H_S",
5853                            new String[] {
5854                                    Long.class.getName(), Long.class.getName(),
5855                                    Boolean.class.getName(), Integer.class.getName()
5856                            });
5857    
5858            /**
5859             * Returns all the document library folders where groupId = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
5860             *
5861             * @param groupId the group ID
5862             * @param parentFolderId the parent folder ID
5863             * @param hidden the hidden
5864             * @param status the status
5865             * @return the matching document library folders
5866             * @throws SystemException if a system exception occurred
5867             */
5868            @Override
5869            public List<DLFolder> findByG_P_H_S(long groupId, long parentFolderId,
5870                    boolean hidden, int status) throws SystemException {
5871                    return findByG_P_H_S(groupId, parentFolderId, hidden, status,
5872                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
5873            }
5874    
5875            /**
5876             * Returns a range of all the document library folders where groupId = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
5877             *
5878             * <p>
5879             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
5880             * </p>
5881             *
5882             * @param groupId the group ID
5883             * @param parentFolderId the parent folder ID
5884             * @param hidden the hidden
5885             * @param status the status
5886             * @param start the lower bound of the range of document library folders
5887             * @param end the upper bound of the range of document library folders (not inclusive)
5888             * @return the range of matching document library folders
5889             * @throws SystemException if a system exception occurred
5890             */
5891            @Override
5892            public List<DLFolder> findByG_P_H_S(long groupId, long parentFolderId,
5893                    boolean hidden, int status, int start, int end)
5894                    throws SystemException {
5895                    return findByG_P_H_S(groupId, parentFolderId, hidden, status, start,
5896                            end, null);
5897            }
5898    
5899            /**
5900             * Returns an ordered range of all the document library folders where groupId = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
5901             *
5902             * <p>
5903             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
5904             * </p>
5905             *
5906             * @param groupId the group ID
5907             * @param parentFolderId the parent folder ID
5908             * @param hidden the hidden
5909             * @param status the status
5910             * @param start the lower bound of the range of document library folders
5911             * @param end the upper bound of the range of document library folders (not inclusive)
5912             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5913             * @return the ordered range of matching document library folders
5914             * @throws SystemException if a system exception occurred
5915             */
5916            @Override
5917            public List<DLFolder> findByG_P_H_S(long groupId, long parentFolderId,
5918                    boolean hidden, int status, int start, int end,
5919                    OrderByComparator orderByComparator) throws SystemException {
5920                    boolean pagination = true;
5921                    FinderPath finderPath = null;
5922                    Object[] finderArgs = null;
5923    
5924                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5925                                    (orderByComparator == null)) {
5926                            pagination = false;
5927                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_H_S;
5928                            finderArgs = new Object[] { groupId, parentFolderId, hidden, status };
5929                    }
5930                    else {
5931                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_H_S;
5932                            finderArgs = new Object[] {
5933                                            groupId, parentFolderId, hidden, status,
5934                                            
5935                                            start, end, orderByComparator
5936                                    };
5937                    }
5938    
5939                    List<DLFolder> list = (List<DLFolder>)FinderCacheUtil.getResult(finderPath,
5940                                    finderArgs, this);
5941    
5942                    if ((list != null) && !list.isEmpty()) {
5943                            for (DLFolder dlFolder : list) {
5944                                    if ((groupId != dlFolder.getGroupId()) ||
5945                                                    (parentFolderId != dlFolder.getParentFolderId()) ||
5946                                                    (hidden != dlFolder.getHidden()) ||
5947                                                    (status != dlFolder.getStatus())) {
5948                                            list = null;
5949    
5950                                            break;
5951                                    }
5952                            }
5953                    }
5954    
5955                    if (list == null) {
5956                            StringBundler query = null;
5957    
5958                            if (orderByComparator != null) {
5959                                    query = new StringBundler(6 +
5960                                                    (orderByComparator.getOrderByFields().length * 3));
5961                            }
5962                            else {
5963                                    query = new StringBundler(6);
5964                            }
5965    
5966                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
5967    
5968                            query.append(_FINDER_COLUMN_G_P_H_S_GROUPID_2);
5969    
5970                            query.append(_FINDER_COLUMN_G_P_H_S_PARENTFOLDERID_2);
5971    
5972                            query.append(_FINDER_COLUMN_G_P_H_S_HIDDEN_2);
5973    
5974                            query.append(_FINDER_COLUMN_G_P_H_S_STATUS_2);
5975    
5976                            if (orderByComparator != null) {
5977                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5978                                            orderByComparator);
5979                            }
5980                            else
5981                             if (pagination) {
5982                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
5983                            }
5984    
5985                            String sql = query.toString();
5986    
5987                            Session session = null;
5988    
5989                            try {
5990                                    session = openSession();
5991    
5992                                    Query q = session.createQuery(sql);
5993    
5994                                    QueryPos qPos = QueryPos.getInstance(q);
5995    
5996                                    qPos.add(groupId);
5997    
5998                                    qPos.add(parentFolderId);
5999    
6000                                    qPos.add(hidden);
6001    
6002                                    qPos.add(status);
6003    
6004                                    if (!pagination) {
6005                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
6006                                                            start, end, false);
6007    
6008                                            Collections.sort(list);
6009    
6010                                            list = new UnmodifiableList<DLFolder>(list);
6011                                    }
6012                                    else {
6013                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
6014                                                            start, end);
6015                                    }
6016    
6017                                    cacheResult(list);
6018    
6019                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
6020                            }
6021                            catch (Exception e) {
6022                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6023    
6024                                    throw processException(e);
6025                            }
6026                            finally {
6027                                    closeSession(session);
6028                            }
6029                    }
6030    
6031                    return list;
6032            }
6033    
6034            /**
6035             * Returns the first document library folder in the ordered set where groupId = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
6036             *
6037             * @param groupId the group ID
6038             * @param parentFolderId the parent folder ID
6039             * @param hidden the hidden
6040             * @param status the status
6041             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6042             * @return the first matching document library folder
6043             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
6044             * @throws SystemException if a system exception occurred
6045             */
6046            @Override
6047            public DLFolder findByG_P_H_S_First(long groupId, long parentFolderId,
6048                    boolean hidden, int status, OrderByComparator orderByComparator)
6049                    throws NoSuchFolderException, SystemException {
6050                    DLFolder dlFolder = fetchByG_P_H_S_First(groupId, parentFolderId,
6051                                    hidden, status, orderByComparator);
6052    
6053                    if (dlFolder != null) {
6054                            return dlFolder;
6055                    }
6056    
6057                    StringBundler msg = new StringBundler(10);
6058    
6059                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6060    
6061                    msg.append("groupId=");
6062                    msg.append(groupId);
6063    
6064                    msg.append(", parentFolderId=");
6065                    msg.append(parentFolderId);
6066    
6067                    msg.append(", hidden=");
6068                    msg.append(hidden);
6069    
6070                    msg.append(", status=");
6071                    msg.append(status);
6072    
6073                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6074    
6075                    throw new NoSuchFolderException(msg.toString());
6076            }
6077    
6078            /**
6079             * Returns the first document library folder in the ordered set where groupId = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
6080             *
6081             * @param groupId the group ID
6082             * @param parentFolderId the parent folder ID
6083             * @param hidden the hidden
6084             * @param status the status
6085             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6086             * @return the first matching document library folder, or <code>null</code> if a matching document library folder could not be found
6087             * @throws SystemException if a system exception occurred
6088             */
6089            @Override
6090            public DLFolder fetchByG_P_H_S_First(long groupId, long parentFolderId,
6091                    boolean hidden, int status, OrderByComparator orderByComparator)
6092                    throws SystemException {
6093                    List<DLFolder> list = findByG_P_H_S(groupId, parentFolderId, hidden,
6094                                    status, 0, 1, orderByComparator);
6095    
6096                    if (!list.isEmpty()) {
6097                            return list.get(0);
6098                    }
6099    
6100                    return null;
6101            }
6102    
6103            /**
6104             * Returns the last document library folder in the ordered set where groupId = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
6105             *
6106             * @param groupId the group ID
6107             * @param parentFolderId the parent folder ID
6108             * @param hidden the hidden
6109             * @param status the status
6110             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6111             * @return the last matching document library folder
6112             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
6113             * @throws SystemException if a system exception occurred
6114             */
6115            @Override
6116            public DLFolder findByG_P_H_S_Last(long groupId, long parentFolderId,
6117                    boolean hidden, int status, OrderByComparator orderByComparator)
6118                    throws NoSuchFolderException, SystemException {
6119                    DLFolder dlFolder = fetchByG_P_H_S_Last(groupId, parentFolderId,
6120                                    hidden, status, orderByComparator);
6121    
6122                    if (dlFolder != null) {
6123                            return dlFolder;
6124                    }
6125    
6126                    StringBundler msg = new StringBundler(10);
6127    
6128                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6129    
6130                    msg.append("groupId=");
6131                    msg.append(groupId);
6132    
6133                    msg.append(", parentFolderId=");
6134                    msg.append(parentFolderId);
6135    
6136                    msg.append(", hidden=");
6137                    msg.append(hidden);
6138    
6139                    msg.append(", status=");
6140                    msg.append(status);
6141    
6142                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6143    
6144                    throw new NoSuchFolderException(msg.toString());
6145            }
6146    
6147            /**
6148             * Returns the last document library folder in the ordered set where groupId = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
6149             *
6150             * @param groupId the group ID
6151             * @param parentFolderId the parent folder ID
6152             * @param hidden the hidden
6153             * @param status the status
6154             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6155             * @return the last matching document library folder, or <code>null</code> if a matching document library folder could not be found
6156             * @throws SystemException if a system exception occurred
6157             */
6158            @Override
6159            public DLFolder fetchByG_P_H_S_Last(long groupId, long parentFolderId,
6160                    boolean hidden, int status, OrderByComparator orderByComparator)
6161                    throws SystemException {
6162                    int count = countByG_P_H_S(groupId, parentFolderId, hidden, status);
6163    
6164                    if (count == 0) {
6165                            return null;
6166                    }
6167    
6168                    List<DLFolder> list = findByG_P_H_S(groupId, parentFolderId, hidden,
6169                                    status, count - 1, count, orderByComparator);
6170    
6171                    if (!list.isEmpty()) {
6172                            return list.get(0);
6173                    }
6174    
6175                    return null;
6176            }
6177    
6178            /**
6179             * 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;.
6180             *
6181             * @param folderId the primary key of the current document library folder
6182             * @param groupId the group ID
6183             * @param parentFolderId the parent folder ID
6184             * @param hidden the hidden
6185             * @param status the status
6186             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6187             * @return the previous, current, and next document library folder
6188             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
6189             * @throws SystemException if a system exception occurred
6190             */
6191            @Override
6192            public DLFolder[] findByG_P_H_S_PrevAndNext(long folderId, long groupId,
6193                    long parentFolderId, boolean hidden, int status,
6194                    OrderByComparator orderByComparator)
6195                    throws NoSuchFolderException, SystemException {
6196                    DLFolder dlFolder = findByPrimaryKey(folderId);
6197    
6198                    Session session = null;
6199    
6200                    try {
6201                            session = openSession();
6202    
6203                            DLFolder[] array = new DLFolderImpl[3];
6204    
6205                            array[0] = getByG_P_H_S_PrevAndNext(session, dlFolder, groupId,
6206                                            parentFolderId, hidden, status, orderByComparator, true);
6207    
6208                            array[1] = dlFolder;
6209    
6210                            array[2] = getByG_P_H_S_PrevAndNext(session, dlFolder, groupId,
6211                                            parentFolderId, hidden, status, orderByComparator, false);
6212    
6213                            return array;
6214                    }
6215                    catch (Exception e) {
6216                            throw processException(e);
6217                    }
6218                    finally {
6219                            closeSession(session);
6220                    }
6221            }
6222    
6223            protected DLFolder getByG_P_H_S_PrevAndNext(Session session,
6224                    DLFolder dlFolder, long groupId, long parentFolderId, boolean hidden,
6225                    int status, OrderByComparator orderByComparator, boolean previous) {
6226                    StringBundler query = null;
6227    
6228                    if (orderByComparator != null) {
6229                            query = new StringBundler(6 +
6230                                            (orderByComparator.getOrderByFields().length * 6));
6231                    }
6232                    else {
6233                            query = new StringBundler(3);
6234                    }
6235    
6236                    query.append(_SQL_SELECT_DLFOLDER_WHERE);
6237    
6238                    query.append(_FINDER_COLUMN_G_P_H_S_GROUPID_2);
6239    
6240                    query.append(_FINDER_COLUMN_G_P_H_S_PARENTFOLDERID_2);
6241    
6242                    query.append(_FINDER_COLUMN_G_P_H_S_HIDDEN_2);
6243    
6244                    query.append(_FINDER_COLUMN_G_P_H_S_STATUS_2);
6245    
6246                    if (orderByComparator != null) {
6247                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6248    
6249                            if (orderByConditionFields.length > 0) {
6250                                    query.append(WHERE_AND);
6251                            }
6252    
6253                            for (int i = 0; i < orderByConditionFields.length; i++) {
6254                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6255                                    query.append(orderByConditionFields[i]);
6256    
6257                                    if ((i + 1) < orderByConditionFields.length) {
6258                                            if (orderByComparator.isAscending() ^ previous) {
6259                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6260                                            }
6261                                            else {
6262                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6263                                            }
6264                                    }
6265                                    else {
6266                                            if (orderByComparator.isAscending() ^ previous) {
6267                                                    query.append(WHERE_GREATER_THAN);
6268                                            }
6269                                            else {
6270                                                    query.append(WHERE_LESSER_THAN);
6271                                            }
6272                                    }
6273                            }
6274    
6275                            query.append(ORDER_BY_CLAUSE);
6276    
6277                            String[] orderByFields = orderByComparator.getOrderByFields();
6278    
6279                            for (int i = 0; i < orderByFields.length; i++) {
6280                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6281                                    query.append(orderByFields[i]);
6282    
6283                                    if ((i + 1) < orderByFields.length) {
6284                                            if (orderByComparator.isAscending() ^ previous) {
6285                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6286                                            }
6287                                            else {
6288                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6289                                            }
6290                                    }
6291                                    else {
6292                                            if (orderByComparator.isAscending() ^ previous) {
6293                                                    query.append(ORDER_BY_ASC);
6294                                            }
6295                                            else {
6296                                                    query.append(ORDER_BY_DESC);
6297                                            }
6298                                    }
6299                            }
6300                    }
6301                    else {
6302                            query.append(DLFolderModelImpl.ORDER_BY_JPQL);
6303                    }
6304    
6305                    String sql = query.toString();
6306    
6307                    Query q = session.createQuery(sql);
6308    
6309                    q.setFirstResult(0);
6310                    q.setMaxResults(2);
6311    
6312                    QueryPos qPos = QueryPos.getInstance(q);
6313    
6314                    qPos.add(groupId);
6315    
6316                    qPos.add(parentFolderId);
6317    
6318                    qPos.add(hidden);
6319    
6320                    qPos.add(status);
6321    
6322                    if (orderByComparator != null) {
6323                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
6324    
6325                            for (Object value : values) {
6326                                    qPos.add(value);
6327                            }
6328                    }
6329    
6330                    List<DLFolder> list = q.list();
6331    
6332                    if (list.size() == 2) {
6333                            return list.get(1);
6334                    }
6335                    else {
6336                            return null;
6337                    }
6338            }
6339    
6340            /**
6341             * 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;.
6342             *
6343             * @param groupId the group ID
6344             * @param parentFolderId the parent folder ID
6345             * @param hidden the hidden
6346             * @param status the status
6347             * @return the matching document library folders that the user has permission to view
6348             * @throws SystemException if a system exception occurred
6349             */
6350            @Override
6351            public List<DLFolder> filterFindByG_P_H_S(long groupId,
6352                    long parentFolderId, boolean hidden, int status)
6353                    throws SystemException {
6354                    return filterFindByG_P_H_S(groupId, parentFolderId, hidden, status,
6355                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
6356            }
6357    
6358            /**
6359             * 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;.
6360             *
6361             * <p>
6362             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
6363             * </p>
6364             *
6365             * @param groupId the group ID
6366             * @param parentFolderId the parent folder ID
6367             * @param hidden the hidden
6368             * @param status the status
6369             * @param start the lower bound of the range of document library folders
6370             * @param end the upper bound of the range of document library folders (not inclusive)
6371             * @return the range of matching document library folders that the user has permission to view
6372             * @throws SystemException if a system exception occurred
6373             */
6374            @Override
6375            public List<DLFolder> filterFindByG_P_H_S(long groupId,
6376                    long parentFolderId, boolean hidden, int status, int start, int end)
6377                    throws SystemException {
6378                    return filterFindByG_P_H_S(groupId, parentFolderId, hidden, status,
6379                            start, end, null);
6380            }
6381    
6382            /**
6383             * 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;.
6384             *
6385             * <p>
6386             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
6387             * </p>
6388             *
6389             * @param groupId the group ID
6390             * @param parentFolderId the parent folder ID
6391             * @param hidden the hidden
6392             * @param status the status
6393             * @param start the lower bound of the range of document library folders
6394             * @param end the upper bound of the range of document library folders (not inclusive)
6395             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6396             * @return the ordered range of matching document library folders that the user has permission to view
6397             * @throws SystemException if a system exception occurred
6398             */
6399            @Override
6400            public List<DLFolder> filterFindByG_P_H_S(long groupId,
6401                    long parentFolderId, boolean hidden, int status, int start, int end,
6402                    OrderByComparator orderByComparator) throws SystemException {
6403                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6404                            return findByG_P_H_S(groupId, parentFolderId, hidden, status,
6405                                    start, end, orderByComparator);
6406                    }
6407    
6408                    StringBundler query = null;
6409    
6410                    if (orderByComparator != null) {
6411                            query = new StringBundler(6 +
6412                                            (orderByComparator.getOrderByFields().length * 3));
6413                    }
6414                    else {
6415                            query = new StringBundler(6);
6416                    }
6417    
6418                    if (getDB().isSupportsInlineDistinct()) {
6419                            query.append(_FILTER_SQL_SELECT_DLFOLDER_WHERE);
6420                    }
6421                    else {
6422                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1);
6423                    }
6424    
6425                    query.append(_FINDER_COLUMN_G_P_H_S_GROUPID_2);
6426    
6427                    query.append(_FINDER_COLUMN_G_P_H_S_PARENTFOLDERID_2);
6428    
6429                    query.append(_FINDER_COLUMN_G_P_H_S_HIDDEN_2_SQL);
6430    
6431                    query.append(_FINDER_COLUMN_G_P_H_S_STATUS_2);
6432    
6433                    if (!getDB().isSupportsInlineDistinct()) {
6434                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2);
6435                    }
6436    
6437                    if (orderByComparator != null) {
6438                            if (getDB().isSupportsInlineDistinct()) {
6439                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6440                                            orderByComparator, true);
6441                            }
6442                            else {
6443                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
6444                                            orderByComparator, true);
6445                            }
6446                    }
6447                    else {
6448                            if (getDB().isSupportsInlineDistinct()) {
6449                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
6450                            }
6451                            else {
6452                                    query.append(DLFolderModelImpl.ORDER_BY_SQL);
6453                            }
6454                    }
6455    
6456                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6457                                    DLFolder.class.getName(),
6458                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6459    
6460                    Session session = null;
6461    
6462                    try {
6463                            session = openSession();
6464    
6465                            SQLQuery q = session.createSQLQuery(sql);
6466    
6467                            if (getDB().isSupportsInlineDistinct()) {
6468                                    q.addEntity(_FILTER_ENTITY_ALIAS, DLFolderImpl.class);
6469                            }
6470                            else {
6471                                    q.addEntity(_FILTER_ENTITY_TABLE, DLFolderImpl.class);
6472                            }
6473    
6474                            QueryPos qPos = QueryPos.getInstance(q);
6475    
6476                            qPos.add(groupId);
6477    
6478                            qPos.add(parentFolderId);
6479    
6480                            qPos.add(hidden);
6481    
6482                            qPos.add(status);
6483    
6484                            return (List<DLFolder>)QueryUtil.list(q, getDialect(), start, end);
6485                    }
6486                    catch (Exception e) {
6487                            throw processException(e);
6488                    }
6489                    finally {
6490                            closeSession(session);
6491                    }
6492            }
6493    
6494            /**
6495             * 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;.
6496             *
6497             * @param folderId the primary key of the current document library folder
6498             * @param groupId the group ID
6499             * @param parentFolderId the parent folder ID
6500             * @param hidden the hidden
6501             * @param status the status
6502             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6503             * @return the previous, current, and next document library folder
6504             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
6505             * @throws SystemException if a system exception occurred
6506             */
6507            @Override
6508            public DLFolder[] filterFindByG_P_H_S_PrevAndNext(long folderId,
6509                    long groupId, long parentFolderId, boolean hidden, int status,
6510                    OrderByComparator orderByComparator)
6511                    throws NoSuchFolderException, SystemException {
6512                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6513                            return findByG_P_H_S_PrevAndNext(folderId, groupId, parentFolderId,
6514                                    hidden, status, orderByComparator);
6515                    }
6516    
6517                    DLFolder dlFolder = findByPrimaryKey(folderId);
6518    
6519                    Session session = null;
6520    
6521                    try {
6522                            session = openSession();
6523    
6524                            DLFolder[] array = new DLFolderImpl[3];
6525    
6526                            array[0] = filterGetByG_P_H_S_PrevAndNext(session, dlFolder,
6527                                            groupId, parentFolderId, hidden, status, orderByComparator,
6528                                            true);
6529    
6530                            array[1] = dlFolder;
6531    
6532                            array[2] = filterGetByG_P_H_S_PrevAndNext(session, dlFolder,
6533                                            groupId, parentFolderId, hidden, status, orderByComparator,
6534                                            false);
6535    
6536                            return array;
6537                    }
6538                    catch (Exception e) {
6539                            throw processException(e);
6540                    }
6541                    finally {
6542                            closeSession(session);
6543                    }
6544            }
6545    
6546            protected DLFolder filterGetByG_P_H_S_PrevAndNext(Session session,
6547                    DLFolder dlFolder, long groupId, long parentFolderId, boolean hidden,
6548                    int status, OrderByComparator orderByComparator, boolean previous) {
6549                    StringBundler query = null;
6550    
6551                    if (orderByComparator != null) {
6552                            query = new StringBundler(6 +
6553                                            (orderByComparator.getOrderByFields().length * 6));
6554                    }
6555                    else {
6556                            query = new StringBundler(3);
6557                    }
6558    
6559                    if (getDB().isSupportsInlineDistinct()) {
6560                            query.append(_FILTER_SQL_SELECT_DLFOLDER_WHERE);
6561                    }
6562                    else {
6563                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1);
6564                    }
6565    
6566                    query.append(_FINDER_COLUMN_G_P_H_S_GROUPID_2);
6567    
6568                    query.append(_FINDER_COLUMN_G_P_H_S_PARENTFOLDERID_2);
6569    
6570                    query.append(_FINDER_COLUMN_G_P_H_S_HIDDEN_2_SQL);
6571    
6572                    query.append(_FINDER_COLUMN_G_P_H_S_STATUS_2);
6573    
6574                    if (!getDB().isSupportsInlineDistinct()) {
6575                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2);
6576                    }
6577    
6578                    if (orderByComparator != null) {
6579                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6580    
6581                            if (orderByConditionFields.length > 0) {
6582                                    query.append(WHERE_AND);
6583                            }
6584    
6585                            for (int i = 0; i < orderByConditionFields.length; i++) {
6586                                    if (getDB().isSupportsInlineDistinct()) {
6587                                            query.append(_ORDER_BY_ENTITY_ALIAS);
6588                                    }
6589                                    else {
6590                                            query.append(_ORDER_BY_ENTITY_TABLE);
6591                                    }
6592    
6593                                    query.append(orderByConditionFields[i]);
6594    
6595                                    if ((i + 1) < orderByConditionFields.length) {
6596                                            if (orderByComparator.isAscending() ^ previous) {
6597                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6598                                            }
6599                                            else {
6600                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6601                                            }
6602                                    }
6603                                    else {
6604                                            if (orderByComparator.isAscending() ^ previous) {
6605                                                    query.append(WHERE_GREATER_THAN);
6606                                            }
6607                                            else {
6608                                                    query.append(WHERE_LESSER_THAN);
6609                                            }
6610                                    }
6611                            }
6612    
6613                            query.append(ORDER_BY_CLAUSE);
6614    
6615                            String[] orderByFields = orderByComparator.getOrderByFields();
6616    
6617                            for (int i = 0; i < orderByFields.length; i++) {
6618                                    if (getDB().isSupportsInlineDistinct()) {
6619                                            query.append(_ORDER_BY_ENTITY_ALIAS);
6620                                    }
6621                                    else {
6622                                            query.append(_ORDER_BY_ENTITY_TABLE);
6623                                    }
6624    
6625                                    query.append(orderByFields[i]);
6626    
6627                                    if ((i + 1) < orderByFields.length) {
6628                                            if (orderByComparator.isAscending() ^ previous) {
6629                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6630                                            }
6631                                            else {
6632                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6633                                            }
6634                                    }
6635                                    else {
6636                                            if (orderByComparator.isAscending() ^ previous) {
6637                                                    query.append(ORDER_BY_ASC);
6638                                            }
6639                                            else {
6640                                                    query.append(ORDER_BY_DESC);
6641                                            }
6642                                    }
6643                            }
6644                    }
6645                    else {
6646                            if (getDB().isSupportsInlineDistinct()) {
6647                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
6648                            }
6649                            else {
6650                                    query.append(DLFolderModelImpl.ORDER_BY_SQL);
6651                            }
6652                    }
6653    
6654                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6655                                    DLFolder.class.getName(),
6656                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6657    
6658                    SQLQuery q = session.createSQLQuery(sql);
6659    
6660                    q.setFirstResult(0);
6661                    q.setMaxResults(2);
6662    
6663                    if (getDB().isSupportsInlineDistinct()) {
6664                            q.addEntity(_FILTER_ENTITY_ALIAS, DLFolderImpl.class);
6665                    }
6666                    else {
6667                            q.addEntity(_FILTER_ENTITY_TABLE, DLFolderImpl.class);
6668                    }
6669    
6670                    QueryPos qPos = QueryPos.getInstance(q);
6671    
6672                    qPos.add(groupId);
6673    
6674                    qPos.add(parentFolderId);
6675    
6676                    qPos.add(hidden);
6677    
6678                    qPos.add(status);
6679    
6680                    if (orderByComparator != null) {
6681                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
6682    
6683                            for (Object value : values) {
6684                                    qPos.add(value);
6685                            }
6686                    }
6687    
6688                    List<DLFolder> list = q.list();
6689    
6690                    if (list.size() == 2) {
6691                            return list.get(1);
6692                    }
6693                    else {
6694                            return null;
6695                    }
6696            }
6697    
6698            /**
6699             * Removes all the document library folders where groupId = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63; from the database.
6700             *
6701             * @param groupId the group ID
6702             * @param parentFolderId the parent folder ID
6703             * @param hidden the hidden
6704             * @param status the status
6705             * @throws SystemException if a system exception occurred
6706             */
6707            @Override
6708            public void removeByG_P_H_S(long groupId, long parentFolderId,
6709                    boolean hidden, int status) throws SystemException {
6710                    for (DLFolder dlFolder : findByG_P_H_S(groupId, parentFolderId, hidden,
6711                                    status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
6712                            remove(dlFolder);
6713                    }
6714            }
6715    
6716            /**
6717             * Returns the number of document library folders where groupId = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
6718             *
6719             * @param groupId the group ID
6720             * @param parentFolderId the parent folder ID
6721             * @param hidden the hidden
6722             * @param status the status
6723             * @return the number of matching document library folders
6724             * @throws SystemException if a system exception occurred
6725             */
6726            @Override
6727            public int countByG_P_H_S(long groupId, long parentFolderId,
6728                    boolean hidden, int status) throws SystemException {
6729                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_P_H_S;
6730    
6731                    Object[] finderArgs = new Object[] {
6732                                    groupId, parentFolderId, hidden, status
6733                            };
6734    
6735                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
6736                                    this);
6737    
6738                    if (count == null) {
6739                            StringBundler query = new StringBundler(5);
6740    
6741                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
6742    
6743                            query.append(_FINDER_COLUMN_G_P_H_S_GROUPID_2);
6744    
6745                            query.append(_FINDER_COLUMN_G_P_H_S_PARENTFOLDERID_2);
6746    
6747                            query.append(_FINDER_COLUMN_G_P_H_S_HIDDEN_2);
6748    
6749                            query.append(_FINDER_COLUMN_G_P_H_S_STATUS_2);
6750    
6751                            String sql = query.toString();
6752    
6753                            Session session = null;
6754    
6755                            try {
6756                                    session = openSession();
6757    
6758                                    Query q = session.createQuery(sql);
6759    
6760                                    QueryPos qPos = QueryPos.getInstance(q);
6761    
6762                                    qPos.add(groupId);
6763    
6764                                    qPos.add(parentFolderId);
6765    
6766                                    qPos.add(hidden);
6767    
6768                                    qPos.add(status);
6769    
6770                                    count = (Long)q.uniqueResult();
6771    
6772                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
6773                            }
6774                            catch (Exception e) {
6775                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6776    
6777                                    throw processException(e);
6778                            }
6779                            finally {
6780                                    closeSession(session);
6781                            }
6782                    }
6783    
6784                    return count.intValue();
6785            }
6786    
6787            /**
6788             * 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;.
6789             *
6790             * @param groupId the group ID
6791             * @param parentFolderId the parent folder ID
6792             * @param hidden the hidden
6793             * @param status the status
6794             * @return the number of matching document library folders that the user has permission to view
6795             * @throws SystemException if a system exception occurred
6796             */
6797            @Override
6798            public int filterCountByG_P_H_S(long groupId, long parentFolderId,
6799                    boolean hidden, int status) throws SystemException {
6800                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6801                            return countByG_P_H_S(groupId, parentFolderId, hidden, status);
6802                    }
6803    
6804                    StringBundler query = new StringBundler(5);
6805    
6806                    query.append(_FILTER_SQL_COUNT_DLFOLDER_WHERE);
6807    
6808                    query.append(_FINDER_COLUMN_G_P_H_S_GROUPID_2);
6809    
6810                    query.append(_FINDER_COLUMN_G_P_H_S_PARENTFOLDERID_2);
6811    
6812                    query.append(_FINDER_COLUMN_G_P_H_S_HIDDEN_2_SQL);
6813    
6814                    query.append(_FINDER_COLUMN_G_P_H_S_STATUS_2);
6815    
6816                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6817                                    DLFolder.class.getName(),
6818                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6819    
6820                    Session session = null;
6821    
6822                    try {
6823                            session = openSession();
6824    
6825                            SQLQuery q = session.createSQLQuery(sql);
6826    
6827                            q.addScalar(COUNT_COLUMN_NAME,
6828                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
6829    
6830                            QueryPos qPos = QueryPos.getInstance(q);
6831    
6832                            qPos.add(groupId);
6833    
6834                            qPos.add(parentFolderId);
6835    
6836                            qPos.add(hidden);
6837    
6838                            qPos.add(status);
6839    
6840                            Long count = (Long)q.uniqueResult();
6841    
6842                            return count.intValue();
6843                    }
6844                    catch (Exception e) {
6845                            throw processException(e);
6846                    }
6847                    finally {
6848                            closeSession(session);
6849                    }
6850            }
6851    
6852            private static final String _FINDER_COLUMN_G_P_H_S_GROUPID_2 = "dlFolder.groupId = ? AND ";
6853            private static final String _FINDER_COLUMN_G_P_H_S_PARENTFOLDERID_2 = "dlFolder.parentFolderId = ? AND ";
6854            private static final String _FINDER_COLUMN_G_P_H_S_HIDDEN_2 = "dlFolder.hidden = ? AND ";
6855            private static final String _FINDER_COLUMN_G_P_H_S_HIDDEN_2_SQL = "dlFolder.hidden_ = ? AND ";
6856            private static final String _FINDER_COLUMN_G_P_H_S_STATUS_2 = "dlFolder.status = ?";
6857            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_M_P_H_S =
6858                    new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
6859                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
6860                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_M_P_H_S",
6861                            new String[] {
6862                                    Long.class.getName(), Boolean.class.getName(),
6863                                    Long.class.getName(), Boolean.class.getName(),
6864                                    Integer.class.getName(),
6865                                    
6866                            Integer.class.getName(), Integer.class.getName(),
6867                                    OrderByComparator.class.getName()
6868                            });
6869            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P_H_S =
6870                    new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
6871                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
6872                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_M_P_H_S",
6873                            new String[] {
6874                                    Long.class.getName(), Boolean.class.getName(),
6875                                    Long.class.getName(), Boolean.class.getName(),
6876                                    Integer.class.getName()
6877                            },
6878                            DLFolderModelImpl.GROUPID_COLUMN_BITMASK |
6879                            DLFolderModelImpl.MOUNTPOINT_COLUMN_BITMASK |
6880                            DLFolderModelImpl.PARENTFOLDERID_COLUMN_BITMASK |
6881                            DLFolderModelImpl.HIDDEN_COLUMN_BITMASK |
6882                            DLFolderModelImpl.STATUS_COLUMN_BITMASK |
6883                            DLFolderModelImpl.NAME_COLUMN_BITMASK);
6884            public static final FinderPath FINDER_PATH_COUNT_BY_G_M_P_H_S = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
6885                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
6886                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_M_P_H_S",
6887                            new String[] {
6888                                    Long.class.getName(), Boolean.class.getName(),
6889                                    Long.class.getName(), Boolean.class.getName(),
6890                                    Integer.class.getName()
6891                            });
6892    
6893            /**
6894             * Returns all the document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
6895             *
6896             * @param groupId the group ID
6897             * @param mountPoint the mount point
6898             * @param parentFolderId the parent folder ID
6899             * @param hidden the hidden
6900             * @param status the status
6901             * @return the matching document library folders
6902             * @throws SystemException if a system exception occurred
6903             */
6904            @Override
6905            public List<DLFolder> findByG_M_P_H_S(long groupId, boolean mountPoint,
6906                    long parentFolderId, boolean hidden, int status)
6907                    throws SystemException {
6908                    return findByG_M_P_H_S(groupId, mountPoint, parentFolderId, hidden,
6909                            status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
6910            }
6911    
6912            /**
6913             * Returns a range of all the document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
6914             *
6915             * <p>
6916             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
6917             * </p>
6918             *
6919             * @param groupId the group ID
6920             * @param mountPoint the mount point
6921             * @param parentFolderId the parent folder ID
6922             * @param hidden the hidden
6923             * @param status the status
6924             * @param start the lower bound of the range of document library folders
6925             * @param end the upper bound of the range of document library folders (not inclusive)
6926             * @return the range of matching document library folders
6927             * @throws SystemException if a system exception occurred
6928             */
6929            @Override
6930            public List<DLFolder> findByG_M_P_H_S(long groupId, boolean mountPoint,
6931                    long parentFolderId, boolean hidden, int status, int start, int end)
6932                    throws SystemException {
6933                    return findByG_M_P_H_S(groupId, mountPoint, parentFolderId, hidden,
6934                            status, start, end, null);
6935            }
6936    
6937            /**
6938             * 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;.
6939             *
6940             * <p>
6941             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
6942             * </p>
6943             *
6944             * @param groupId the group ID
6945             * @param mountPoint the mount point
6946             * @param parentFolderId the parent folder ID
6947             * @param hidden the hidden
6948             * @param status the status
6949             * @param start the lower bound of the range of document library folders
6950             * @param end the upper bound of the range of document library folders (not inclusive)
6951             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6952             * @return the ordered range of matching document library folders
6953             * @throws SystemException if a system exception occurred
6954             */
6955            @Override
6956            public List<DLFolder> findByG_M_P_H_S(long groupId, boolean mountPoint,
6957                    long parentFolderId, boolean hidden, int status, int start, int end,
6958                    OrderByComparator orderByComparator) throws SystemException {
6959                    boolean pagination = true;
6960                    FinderPath finderPath = null;
6961                    Object[] finderArgs = null;
6962    
6963                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6964                                    (orderByComparator == null)) {
6965                            pagination = false;
6966                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P_H_S;
6967                            finderArgs = new Object[] {
6968                                            groupId, mountPoint, parentFolderId, hidden, status
6969                                    };
6970                    }
6971                    else {
6972                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_M_P_H_S;
6973                            finderArgs = new Object[] {
6974                                            groupId, mountPoint, parentFolderId, hidden, status,
6975                                            
6976                                            start, end, orderByComparator
6977                                    };
6978                    }
6979    
6980                    List<DLFolder> list = (List<DLFolder>)FinderCacheUtil.getResult(finderPath,
6981                                    finderArgs, this);
6982    
6983                    if ((list != null) && !list.isEmpty()) {
6984                            for (DLFolder dlFolder : list) {
6985                                    if ((groupId != dlFolder.getGroupId()) ||
6986                                                    (mountPoint != dlFolder.getMountPoint()) ||
6987                                                    (parentFolderId != dlFolder.getParentFolderId()) ||
6988                                                    (hidden != dlFolder.getHidden()) ||
6989                                                    (status != dlFolder.getStatus())) {
6990                                            list = null;
6991    
6992                                            break;
6993                                    }
6994                            }
6995                    }
6996    
6997                    if (list == null) {
6998                            StringBundler query = null;
6999    
7000                            if (orderByComparator != null) {
7001                                    query = new StringBundler(7 +
7002                                                    (orderByComparator.getOrderByFields().length * 3));
7003                            }
7004                            else {
7005                                    query = new StringBundler(7);
7006                            }
7007    
7008                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
7009    
7010                            query.append(_FINDER_COLUMN_G_M_P_H_S_GROUPID_2);
7011    
7012                            query.append(_FINDER_COLUMN_G_M_P_H_S_MOUNTPOINT_2);
7013    
7014                            query.append(_FINDER_COLUMN_G_M_P_H_S_PARENTFOLDERID_2);
7015    
7016                            query.append(_FINDER_COLUMN_G_M_P_H_S_HIDDEN_2);
7017    
7018                            query.append(_FINDER_COLUMN_G_M_P_H_S_STATUS_2);
7019    
7020                            if (orderByComparator != null) {
7021                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7022                                            orderByComparator);
7023                            }
7024                            else
7025                             if (pagination) {
7026                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
7027                            }
7028    
7029                            String sql = query.toString();
7030    
7031                            Session session = null;
7032    
7033                            try {
7034                                    session = openSession();
7035    
7036                                    Query q = session.createQuery(sql);
7037    
7038                                    QueryPos qPos = QueryPos.getInstance(q);
7039    
7040                                    qPos.add(groupId);
7041    
7042                                    qPos.add(mountPoint);
7043    
7044                                    qPos.add(parentFolderId);
7045    
7046                                    qPos.add(hidden);
7047    
7048                                    qPos.add(status);
7049    
7050                                    if (!pagination) {
7051                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
7052                                                            start, end, false);
7053    
7054                                            Collections.sort(list);
7055    
7056                                            list = new UnmodifiableList<DLFolder>(list);
7057                                    }
7058                                    else {
7059                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
7060                                                            start, end);
7061                                    }
7062    
7063                                    cacheResult(list);
7064    
7065                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
7066                            }
7067                            catch (Exception e) {
7068                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
7069    
7070                                    throw processException(e);
7071                            }
7072                            finally {
7073                                    closeSession(session);
7074                            }
7075                    }
7076    
7077                    return list;
7078            }
7079    
7080            /**
7081             * 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;.
7082             *
7083             * @param groupId the group ID
7084             * @param mountPoint the mount point
7085             * @param parentFolderId the parent folder ID
7086             * @param hidden the hidden
7087             * @param status the status
7088             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7089             * @return the first matching document library folder
7090             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
7091             * @throws SystemException if a system exception occurred
7092             */
7093            @Override
7094            public DLFolder findByG_M_P_H_S_First(long groupId, boolean mountPoint,
7095                    long parentFolderId, boolean hidden, int status,
7096                    OrderByComparator orderByComparator)
7097                    throws NoSuchFolderException, SystemException {
7098                    DLFolder dlFolder = fetchByG_M_P_H_S_First(groupId, mountPoint,
7099                                    parentFolderId, hidden, status, orderByComparator);
7100    
7101                    if (dlFolder != null) {
7102                            return dlFolder;
7103                    }
7104    
7105                    StringBundler msg = new StringBundler(12);
7106    
7107                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7108    
7109                    msg.append("groupId=");
7110                    msg.append(groupId);
7111    
7112                    msg.append(", mountPoint=");
7113                    msg.append(mountPoint);
7114    
7115                    msg.append(", parentFolderId=");
7116                    msg.append(parentFolderId);
7117    
7118                    msg.append(", hidden=");
7119                    msg.append(hidden);
7120    
7121                    msg.append(", status=");
7122                    msg.append(status);
7123    
7124                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7125    
7126                    throw new NoSuchFolderException(msg.toString());
7127            }
7128    
7129            /**
7130             * 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;.
7131             *
7132             * @param groupId the group ID
7133             * @param mountPoint the mount point
7134             * @param parentFolderId the parent folder ID
7135             * @param hidden the hidden
7136             * @param status the status
7137             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7138             * @return the first matching document library folder, or <code>null</code> if a matching document library folder could not be found
7139             * @throws SystemException if a system exception occurred
7140             */
7141            @Override
7142            public DLFolder fetchByG_M_P_H_S_First(long groupId, boolean mountPoint,
7143                    long parentFolderId, boolean hidden, int status,
7144                    OrderByComparator orderByComparator) throws SystemException {
7145                    List<DLFolder> list = findByG_M_P_H_S(groupId, mountPoint,
7146                                    parentFolderId, hidden, status, 0, 1, orderByComparator);
7147    
7148                    if (!list.isEmpty()) {
7149                            return list.get(0);
7150                    }
7151    
7152                    return null;
7153            }
7154    
7155            /**
7156             * 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;.
7157             *
7158             * @param groupId the group ID
7159             * @param mountPoint the mount point
7160             * @param parentFolderId the parent folder ID
7161             * @param hidden the hidden
7162             * @param status the status
7163             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7164             * @return the last matching document library folder
7165             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
7166             * @throws SystemException if a system exception occurred
7167             */
7168            @Override
7169            public DLFolder findByG_M_P_H_S_Last(long groupId, boolean mountPoint,
7170                    long parentFolderId, boolean hidden, int status,
7171                    OrderByComparator orderByComparator)
7172                    throws NoSuchFolderException, SystemException {
7173                    DLFolder dlFolder = fetchByG_M_P_H_S_Last(groupId, mountPoint,
7174                                    parentFolderId, hidden, status, orderByComparator);
7175    
7176                    if (dlFolder != null) {
7177                            return dlFolder;
7178                    }
7179    
7180                    StringBundler msg = new StringBundler(12);
7181    
7182                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7183    
7184                    msg.append("groupId=");
7185                    msg.append(groupId);
7186    
7187                    msg.append(", mountPoint=");
7188                    msg.append(mountPoint);
7189    
7190                    msg.append(", parentFolderId=");
7191                    msg.append(parentFolderId);
7192    
7193                    msg.append(", hidden=");
7194                    msg.append(hidden);
7195    
7196                    msg.append(", status=");
7197                    msg.append(status);
7198    
7199                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7200    
7201                    throw new NoSuchFolderException(msg.toString());
7202            }
7203    
7204            /**
7205             * 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;.
7206             *
7207             * @param groupId the group ID
7208             * @param mountPoint the mount point
7209             * @param parentFolderId the parent folder ID
7210             * @param hidden the hidden
7211             * @param status the status
7212             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7213             * @return the last matching document library folder, or <code>null</code> if a matching document library folder could not be found
7214             * @throws SystemException if a system exception occurred
7215             */
7216            @Override
7217            public DLFolder fetchByG_M_P_H_S_Last(long groupId, boolean mountPoint,
7218                    long parentFolderId, boolean hidden, int status,
7219                    OrderByComparator orderByComparator) throws SystemException {
7220                    int count = countByG_M_P_H_S(groupId, mountPoint, parentFolderId,
7221                                    hidden, status);
7222    
7223                    if (count == 0) {
7224                            return null;
7225                    }
7226    
7227                    List<DLFolder> list = findByG_M_P_H_S(groupId, mountPoint,
7228                                    parentFolderId, hidden, status, count - 1, count,
7229                                    orderByComparator);
7230    
7231                    if (!list.isEmpty()) {
7232                            return list.get(0);
7233                    }
7234    
7235                    return null;
7236            }
7237    
7238            /**
7239             * 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;.
7240             *
7241             * @param folderId the primary key of the current document library folder
7242             * @param groupId the group ID
7243             * @param mountPoint the mount point
7244             * @param parentFolderId the parent folder ID
7245             * @param hidden the hidden
7246             * @param status the status
7247             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7248             * @return the previous, current, and next document library folder
7249             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
7250             * @throws SystemException if a system exception occurred
7251             */
7252            @Override
7253            public DLFolder[] findByG_M_P_H_S_PrevAndNext(long folderId, long groupId,
7254                    boolean mountPoint, long parentFolderId, boolean hidden, int status,
7255                    OrderByComparator orderByComparator)
7256                    throws NoSuchFolderException, SystemException {
7257                    DLFolder dlFolder = findByPrimaryKey(folderId);
7258    
7259                    Session session = null;
7260    
7261                    try {
7262                            session = openSession();
7263    
7264                            DLFolder[] array = new DLFolderImpl[3];
7265    
7266                            array[0] = getByG_M_P_H_S_PrevAndNext(session, dlFolder, groupId,
7267                                            mountPoint, parentFolderId, hidden, status,
7268                                            orderByComparator, true);
7269    
7270                            array[1] = dlFolder;
7271    
7272                            array[2] = getByG_M_P_H_S_PrevAndNext(session, dlFolder, groupId,
7273                                            mountPoint, parentFolderId, hidden, status,
7274                                            orderByComparator, false);
7275    
7276                            return array;
7277                    }
7278                    catch (Exception e) {
7279                            throw processException(e);
7280                    }
7281                    finally {
7282                            closeSession(session);
7283                    }
7284            }
7285    
7286            protected DLFolder getByG_M_P_H_S_PrevAndNext(Session session,
7287                    DLFolder dlFolder, long groupId, boolean mountPoint,
7288                    long parentFolderId, boolean hidden, int status,
7289                    OrderByComparator orderByComparator, boolean previous) {
7290                    StringBundler query = null;
7291    
7292                    if (orderByComparator != null) {
7293                            query = new StringBundler(6 +
7294                                            (orderByComparator.getOrderByFields().length * 6));
7295                    }
7296                    else {
7297                            query = new StringBundler(3);
7298                    }
7299    
7300                    query.append(_SQL_SELECT_DLFOLDER_WHERE);
7301    
7302                    query.append(_FINDER_COLUMN_G_M_P_H_S_GROUPID_2);
7303    
7304                    query.append(_FINDER_COLUMN_G_M_P_H_S_MOUNTPOINT_2);
7305    
7306                    query.append(_FINDER_COLUMN_G_M_P_H_S_PARENTFOLDERID_2);
7307    
7308                    query.append(_FINDER_COLUMN_G_M_P_H_S_HIDDEN_2);
7309    
7310                    query.append(_FINDER_COLUMN_G_M_P_H_S_STATUS_2);
7311    
7312                    if (orderByComparator != null) {
7313                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7314    
7315                            if (orderByConditionFields.length > 0) {
7316                                    query.append(WHERE_AND);
7317                            }
7318    
7319                            for (int i = 0; i < orderByConditionFields.length; i++) {
7320                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7321                                    query.append(orderByConditionFields[i]);
7322    
7323                                    if ((i + 1) < orderByConditionFields.length) {
7324                                            if (orderByComparator.isAscending() ^ previous) {
7325                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
7326                                            }
7327                                            else {
7328                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
7329                                            }
7330                                    }
7331                                    else {
7332                                            if (orderByComparator.isAscending() ^ previous) {
7333                                                    query.append(WHERE_GREATER_THAN);
7334                                            }
7335                                            else {
7336                                                    query.append(WHERE_LESSER_THAN);
7337                                            }
7338                                    }
7339                            }
7340    
7341                            query.append(ORDER_BY_CLAUSE);
7342    
7343                            String[] orderByFields = orderByComparator.getOrderByFields();
7344    
7345                            for (int i = 0; i < orderByFields.length; i++) {
7346                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7347                                    query.append(orderByFields[i]);
7348    
7349                                    if ((i + 1) < orderByFields.length) {
7350                                            if (orderByComparator.isAscending() ^ previous) {
7351                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
7352                                            }
7353                                            else {
7354                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
7355                                            }
7356                                    }
7357                                    else {
7358                                            if (orderByComparator.isAscending() ^ previous) {
7359                                                    query.append(ORDER_BY_ASC);
7360                                            }
7361                                            else {
7362                                                    query.append(ORDER_BY_DESC);
7363                                            }
7364                                    }
7365                            }
7366                    }
7367                    else {
7368                            query.append(DLFolderModelImpl.ORDER_BY_JPQL);
7369                    }
7370    
7371                    String sql = query.toString();
7372    
7373                    Query q = session.createQuery(sql);
7374    
7375                    q.setFirstResult(0);
7376                    q.setMaxResults(2);
7377    
7378                    QueryPos qPos = QueryPos.getInstance(q);
7379    
7380                    qPos.add(groupId);
7381    
7382                    qPos.add(mountPoint);
7383    
7384                    qPos.add(parentFolderId);
7385    
7386                    qPos.add(hidden);
7387    
7388                    qPos.add(status);
7389    
7390                    if (orderByComparator != null) {
7391                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
7392    
7393                            for (Object value : values) {
7394                                    qPos.add(value);
7395                            }
7396                    }
7397    
7398                    List<DLFolder> list = q.list();
7399    
7400                    if (list.size() == 2) {
7401                            return list.get(1);
7402                    }
7403                    else {
7404                            return null;
7405                    }
7406            }
7407    
7408            /**
7409             * 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;.
7410             *
7411             * @param groupId the group ID
7412             * @param mountPoint the mount point
7413             * @param parentFolderId the parent folder ID
7414             * @param hidden the hidden
7415             * @param status the status
7416             * @return the matching document library folders that the user has permission to view
7417             * @throws SystemException if a system exception occurred
7418             */
7419            @Override
7420            public List<DLFolder> filterFindByG_M_P_H_S(long groupId,
7421                    boolean mountPoint, long parentFolderId, boolean hidden, int status)
7422                    throws SystemException {
7423                    return filterFindByG_M_P_H_S(groupId, mountPoint, parentFolderId,
7424                            hidden, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
7425            }
7426    
7427            /**
7428             * 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;.
7429             *
7430             * <p>
7431             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
7432             * </p>
7433             *
7434             * @param groupId the group ID
7435             * @param mountPoint the mount point
7436             * @param parentFolderId the parent folder ID
7437             * @param hidden the hidden
7438             * @param status the status
7439             * @param start the lower bound of the range of document library folders
7440             * @param end the upper bound of the range of document library folders (not inclusive)
7441             * @return the range of matching document library folders that the user has permission to view
7442             * @throws SystemException if a system exception occurred
7443             */
7444            @Override
7445            public List<DLFolder> filterFindByG_M_P_H_S(long groupId,
7446                    boolean mountPoint, long parentFolderId, boolean hidden, int status,
7447                    int start, int end) throws SystemException {
7448                    return filterFindByG_M_P_H_S(groupId, mountPoint, parentFolderId,
7449                            hidden, status, start, end, null);
7450            }
7451    
7452            /**
7453             * 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;.
7454             *
7455             * <p>
7456             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link 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.
7457             * </p>
7458             *
7459             * @param groupId the group ID
7460             * @param mountPoint the mount point
7461             * @param parentFolderId the parent folder ID
7462             * @param hidden the hidden
7463             * @param status the status
7464             * @param start the lower bound of the range of document library folders
7465             * @param end the upper bound of the range of document library folders (not inclusive)
7466             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7467             * @return the ordered range of matching document library folders that the user has permission to view
7468             * @throws SystemException if a system exception occurred
7469             */
7470            @Override
7471            public List<DLFolder> filterFindByG_M_P_H_S(long groupId,
7472                    boolean mountPoint, long parentFolderId, boolean hidden, int status,
7473                    int start, int end, OrderByComparator orderByComparator)
7474                    throws SystemException {
7475                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7476                            return findByG_M_P_H_S(groupId, mountPoint, parentFolderId, hidden,
7477                                    status, start, end, orderByComparator);
7478                    }
7479    
7480                    StringBundler query = null;
7481    
7482                    if (orderByComparator != null) {
7483                            query = new StringBundler(7 +
7484                                            (orderByComparator.getOrderByFields().length * 3));
7485                    }
7486                    else {
7487                            query = new StringBundler(7);
7488                    }
7489    
7490                    if (getDB().isSupportsInlineDistinct()) {
7491                            query.append(_FILTER_SQL_SELECT_DLFOLDER_WHERE);
7492                    }
7493                    else {
7494                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1);
7495                    }
7496    
7497                    query.append(_FINDER_COLUMN_G_M_P_H_S_GROUPID_2);
7498    
7499                    query.append(_FINDER_COLUMN_G_M_P_H_S_MOUNTPOINT_2);
7500    
7501                    query.append(_FINDER_COLUMN_G_M_P_H_S_PARENTFOLDERID_2);
7502    
7503                    query.append(_FINDER_COLUMN_G_M_P_H_S_HIDDEN_2_SQL);
7504    
7505                    query.append(_FINDER_COLUMN_G_M_P_H_S_STATUS_2);
7506    
7507                    if (!getDB().isSupportsInlineDistinct()) {
7508                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2);
7509                    }
7510    
7511                    if (orderByComparator != null) {
7512                            if (getDB().isSupportsInlineDistinct()) {
7513                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7514                                            orderByComparator, true);
7515                            }
7516                            else {
7517                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
7518                                            orderByComparator, true);
7519                            }
7520                    }
7521                    else {
7522                            if (getDB().isSupportsInlineDistinct()) {
7523                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
7524                            }
7525                            else {
7526                                    query.append(DLFolderModelImpl.ORDER_BY_SQL);
7527                            }
7528                    }
7529    
7530                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7531                                    DLFolder.class.getName(),
7532                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7533    
7534                    Session session = null;
7535    
7536                    try {
7537                            session = openSession();
7538    
7539                            SQLQuery q = session.createSQLQuery(sql);
7540    
7541                            if (getDB().isSupportsInlineDistinct()) {
7542                                    q.addEntity(_FILTER_ENTITY_ALIAS, DLFolderImpl.class);
7543                            }
7544                            else {
7545                                    q.addEntity(_FILTER_ENTITY_TABLE, DLFolderImpl.class);
7546                            }
7547    
7548                            QueryPos qPos = QueryPos.getInstance(q);
7549    
7550                            qPos.add(groupId);
7551    
7552                            qPos.add(mountPoint);
7553    
7554                            qPos.add(parentFolderId);
7555    
7556                            qPos.add(hidden);
7557    
7558                            qPos.add(status);
7559    
7560                            return (List<DLFolder>)QueryUtil.list(q, getDialect(), start, end);
7561                    }
7562                    catch (Exception e) {
7563                            throw processException(e);
7564                    }
7565                    finally {
7566                            closeSession(session);
7567                    }
7568            }
7569    
7570            /**
7571             * 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;.
7572             *
7573             * @param folderId the primary key of the current document library folder
7574             * @param groupId the group ID
7575             * @param mountPoint the mount point
7576             * @param parentFolderId the parent folder ID
7577             * @param hidden the hidden
7578             * @param status the status
7579             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7580             * @return the previous, current, and next document library folder
7581             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
7582             * @throws SystemException if a system exception occurred
7583             */
7584            @Override
7585            public DLFolder[] filterFindByG_M_P_H_S_PrevAndNext(long folderId,
7586                    long groupId, boolean mountPoint, long parentFolderId, boolean hidden,
7587                    int status, OrderByComparator orderByComparator)
7588                    throws NoSuchFolderException, SystemException {
7589                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7590                            return findByG_M_P_H_S_PrevAndNext(folderId, groupId, mountPoint,
7591                                    parentFolderId, hidden, status, orderByComparator);
7592                    }
7593    
7594                    DLFolder dlFolder = findByPrimaryKey(folderId);
7595    
7596                    Session session = null;
7597    
7598                    try {
7599                            session = openSession();
7600    
7601                            DLFolder[] array = new DLFolderImpl[3];
7602    
7603                            array[0] = filterGetByG_M_P_H_S_PrevAndNext(session, dlFolder,
7604                                            groupId, mountPoint, parentFolderId, hidden, status,
7605                                            orderByComparator, true);
7606    
7607                            array[1] = dlFolder;
7608    
7609                            array[2] = filterGetByG_M_P_H_S_PrevAndNext(session, dlFolder,
7610                                            groupId, mountPoint, parentFolderId, hidden, status,
7611                                            orderByComparator, false);
7612    
7613                            return array;
7614                    }
7615                    catch (Exception e) {
7616                            throw processException(e);
7617                    }
7618                    finally {
7619                            closeSession(session);
7620                    }
7621            }
7622    
7623            protected DLFolder filterGetByG_M_P_H_S_PrevAndNext(Session session,
7624                    DLFolder dlFolder, long groupId, boolean mountPoint,
7625                    long parentFolderId, boolean hidden, int status,
7626                    OrderByComparator orderByComparator, boolean previous) {
7627                    StringBundler query = null;
7628    
7629                    if (orderByComparator != null) {
7630                            query = new StringBundler(6 +
7631                                            (orderByComparator.getOrderByFields().length * 6));
7632                    }
7633                    else {
7634                            query = new StringBundler(3);
7635                    }
7636    
7637                    if (getDB().isSupportsInlineDistinct()) {
7638                            query.append(_FILTER_SQL_SELECT_DLFOLDER_WHERE);
7639                    }
7640                    else {
7641                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1);
7642                    }
7643    
7644                    query.append(_FINDER_COLUMN_G_M_P_H_S_GROUPID_2);
7645    
7646                    query.append(_FINDER_COLUMN_G_M_P_H_S_MOUNTPOINT_2);
7647    
7648                    query.append(_FINDER_COLUMN_G_M_P_H_S_PARENTFOLDERID_2);
7649    
7650                    query.append(_FINDER_COLUMN_G_M_P_H_S_HIDDEN_2_SQL);
7651    
7652                    query.append(_FINDER_COLUMN_G_M_P_H_S_STATUS_2);
7653    
7654                    if (!getDB().isSupportsInlineDistinct()) {
7655                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2);
7656                    }
7657    
7658                    if (orderByComparator != null) {
7659                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7660    
7661                            if (orderByConditionFields.length > 0) {
7662                                    query.append(WHERE_AND);
7663                            }
7664    
7665                            for (int i = 0; i < orderByConditionFields.length; i++) {
7666                                    if (getDB().isSupportsInlineDistinct()) {
7667                                            query.append(_ORDER_BY_ENTITY_ALIAS);
7668                                    }
7669                                    else {
7670                                            query.append(_ORDER_BY_ENTITY_TABLE);
7671                                    }
7672    
7673                                    query.append(orderByConditionFields[i]);
7674    
7675                                    if ((i + 1) < orderByConditionFields.length) {
7676                                            if (orderByComparator.isAscending() ^ previous) {
7677                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
7678                                            }
7679                                            else {
7680                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
7681                                            }
7682                                    }
7683                                    else {
7684                                            if (orderByComparator.isAscending() ^ previous) {
7685                                                    query.append(WHERE_GREATER_THAN);
7686                                            }
7687                                            else {
7688                                                    query.append(WHERE_LESSER_THAN);
7689                                            }
7690                                    }
7691                            }
7692    
7693                            query.append(ORDER_BY_CLAUSE);
7694    
7695                            String[] orderByFields = orderByComparator.getOrderByFields();
7696    
7697                            for (int i = 0; i < orderByFields.length; i++) {
7698                                    if (getDB().isSupportsInlineDistinct()) {
7699                                            query.append(_ORDER_BY_ENTITY_ALIAS);
7700                                    }
7701                                    else {
7702                                            query.append(_ORDER_BY_ENTITY_TABLE);
7703                                    }
7704    
7705                                    query.append(orderByFields[i]);
7706    
7707                                    if ((i + 1) < orderByFields.length) {
7708                                            if (orderByComparator.isAscending() ^ previous) {
7709                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
7710                                            }
7711                                            else {
7712                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
7713                                            }
7714                                    }
7715                                    else {
7716                                            if (orderByComparator.isAscending() ^ previous) {
7717                                                    query.append(ORDER_BY_ASC);
7718                                            }
7719                                            else {
7720                                                    query.append(ORDER_BY_DESC);
7721                                            }
7722                                    }
7723                            }
7724                    }
7725                    else {
7726                            if (getDB().isSupportsInlineDistinct()) {
7727                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
7728                            }
7729                            else {
7730                                    query.append(DLFolderModelImpl.ORDER_BY_SQL);
7731                            }
7732                    }
7733    
7734                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7735                                    DLFolder.class.getName(),
7736                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7737    
7738                    SQLQuery q = session.createSQLQuery(sql);
7739    
7740                    q.setFirstResult(0);
7741                    q.setMaxResults(2);
7742    
7743                    if (getDB().isSupportsInlineDistinct()) {
7744                            q.addEntity(_FILTER_ENTITY_ALIAS, DLFolderImpl.class);
7745                    }
7746                    else {
7747                            q.addEntity(_FILTER_ENTITY_TABLE, DLFolderImpl.class);
7748                    }
7749    
7750                    QueryPos qPos = QueryPos.getInstance(q);
7751    
7752                    qPos.add(groupId);
7753    
7754                    qPos.add(mountPoint);
7755    
7756                    qPos.add(parentFolderId);
7757    
7758                    qPos.add(hidden);
7759    
7760                    qPos.add(status);
7761    
7762                    if (orderByComparator != null) {
7763                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
7764    
7765                            for (Object value : values) {
7766                                    qPos.add(value);
7767                            }
7768                    }
7769    
7770                    List<DLFolder> list = q.list();
7771    
7772                    if (list.size() == 2) {
7773                            return list.get(1);
7774                    }
7775                    else {
7776                            return null;
7777                    }
7778            }
7779    
7780            /**
7781             * Removes all the document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63; from the database.
7782             *
7783             * @param groupId the group ID
7784             * @param mountPoint the mount point
7785             * @param parentFolderId the parent folder ID
7786             * @param hidden the hidden
7787             * @param status the status
7788             * @throws SystemException if a system exception occurred
7789             */
7790            @Override
7791            public void removeByG_M_P_H_S(long groupId, boolean mountPoint,
7792                    long parentFolderId, boolean hidden, int status)
7793                    throws SystemException {
7794                    for (DLFolder dlFolder : findByG_M_P_H_S(groupId, mountPoint,
7795                                    parentFolderId, hidden, status, QueryUtil.ALL_POS,
7796                                    QueryUtil.ALL_POS, null)) {
7797                            remove(dlFolder);
7798                    }
7799            }
7800    
7801            /**
7802             * Returns the number of document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
7803             *
7804             * @param groupId the group ID
7805             * @param mountPoint the mount point
7806             * @param parentFolderId the parent folder ID
7807             * @param hidden the hidden
7808             * @param status the status
7809             * @return the number of matching document library folders
7810             * @throws SystemException if a system exception occurred
7811             */
7812            @Override
7813            public int countByG_M_P_H_S(long groupId, boolean mountPoint,
7814                    long parentFolderId, boolean hidden, int status)
7815                    throws SystemException {
7816                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_M_P_H_S;
7817    
7818                    Object[] finderArgs = new Object[] {
7819                                    groupId, mountPoint, parentFolderId, hidden, status
7820                            };
7821    
7822                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
7823                                    this);
7824    
7825                    if (count == null) {
7826                            StringBundler query = new StringBundler(6);
7827    
7828                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
7829    
7830                            query.append(_FINDER_COLUMN_G_M_P_H_S_GROUPID_2);
7831    
7832                            query.append(_FINDER_COLUMN_G_M_P_H_S_MOUNTPOINT_2);
7833    
7834                            query.append(_FINDER_COLUMN_G_M_P_H_S_PARENTFOLDERID_2);
7835    
7836                            query.append(_FINDER_COLUMN_G_M_P_H_S_HIDDEN_2);
7837    
7838                            query.append(_FINDER_COLUMN_G_M_P_H_S_STATUS_2);
7839    
7840                            String sql = query.toString();
7841    
7842                            Session session = null;
7843    
7844                            try {
7845                                    session = openSession();
7846    
7847                                    Query q = session.createQuery(sql);
7848    
7849                                    QueryPos qPos = QueryPos.getInstance(q);
7850    
7851                                    qPos.add(groupId);
7852    
7853                                    qPos.add(mountPoint);
7854    
7855                                    qPos.add(parentFolderId);
7856    
7857                                    qPos.add(hidden);
7858    
7859                                    qPos.add(status);
7860    
7861                                    count = (Long)q.uniqueResult();
7862    
7863                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
7864                            }
7865                            catch (Exception e) {
7866                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
7867    
7868                                    throw processException(e);
7869                            }
7870                            finally {
7871                                    closeSession(session);
7872                            }
7873                    }
7874    
7875                    return count.intValue();
7876            }
7877    
7878            /**
7879             * 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;.
7880             *
7881             * @param groupId the group ID
7882             * @param mountPoint the mount point
7883             * @param parentFolderId the parent folder ID
7884             * @param hidden the hidden
7885             * @param status the status
7886             * @return the number of matching document library folders that the user has permission to view
7887             * @throws SystemException if a system exception occurred
7888             */
7889            @Override
7890            public int filterCountByG_M_P_H_S(long groupId, boolean mountPoint,
7891                    long parentFolderId, boolean hidden, int status)
7892                    throws SystemException {
7893                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7894                            return countByG_M_P_H_S(groupId, mountPoint, parentFolderId,
7895                                    hidden, status);
7896                    }
7897    
7898                    StringBundler query = new StringBundler(6);
7899    
7900                    query.append(_FILTER_SQL_COUNT_DLFOLDER_WHERE);
7901    
7902                    query.append(_FINDER_COLUMN_G_M_P_H_S_GROUPID_2);
7903    
7904                    query.append(_FINDER_COLUMN_G_M_P_H_S_MOUNTPOINT_2);
7905    
7906                    query.append(_FINDER_COLUMN_G_M_P_H_S_PARENTFOLDERID_2);
7907    
7908                    query.append(_FINDER_COLUMN_G_M_P_H_S_HIDDEN_2_SQL);
7909    
7910                    query.append(_FINDER_COLUMN_G_M_P_H_S_STATUS_2);
7911    
7912                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7913                                    DLFolder.class.getName(),
7914                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7915    
7916                    Session session = null;
7917    
7918                    try {
7919                            session = openSession();
7920    
7921                            SQLQuery q = session.createSQLQuery(sql);
7922    
7923                            q.addScalar(COUNT_COLUMN_NAME,
7924                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
7925    
7926                            QueryPos qPos = QueryPos.getInstance(q);
7927    
7928                            qPos.add(groupId);
7929    
7930                            qPos.add(mountPoint);
7931    
7932                            qPos.add(parentFolderId);
7933    
7934                            qPos.add(hidden);
7935    
7936                            qPos.add(status);
7937    
7938                            Long count = (Long)q.uniqueResult();
7939    
7940                            return count.intValue();
7941                    }
7942                    catch (Exception e) {
7943                            throw processException(e);
7944                    }
7945                    finally {
7946                            closeSession(session);
7947                    }
7948            }
7949    
7950            private static final String _FINDER_COLUMN_G_M_P_H_S_GROUPID_2 = "dlFolder.groupId = ? AND ";
7951            private static final String _FINDER_COLUMN_G_M_P_H_S_MOUNTPOINT_2 = "dlFolder.mountPoint = ? AND ";
7952            private static final String _FINDER_COLUMN_G_M_P_H_S_PARENTFOLDERID_2 = "dlFolder.parentFolderId = ? AND ";
7953            private static final String _FINDER_COLUMN_G_M_P_H_S_HIDDEN_2 = "dlFolder.hidden = ? AND ";
7954            private static final String _FINDER_COLUMN_G_M_P_H_S_HIDDEN_2_SQL = "dlFolder.hidden_ = ? AND ";
7955            private static final String _FINDER_COLUMN_G_M_P_H_S_STATUS_2 = "dlFolder.status = ?";
7956    
7957            public DLFolderPersistenceImpl() {
7958                    setModelClass(DLFolder.class);
7959            }
7960    
7961            /**
7962             * Caches the document library folder in the entity cache if it is enabled.
7963             *
7964             * @param dlFolder the document library folder
7965             */
7966            @Override
7967            public void cacheResult(DLFolder dlFolder) {
7968                    EntityCacheUtil.putResult(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
7969                            DLFolderImpl.class, dlFolder.getPrimaryKey(), dlFolder);
7970    
7971                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
7972                            new Object[] { dlFolder.getUuid(), dlFolder.getGroupId() }, dlFolder);
7973    
7974                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_REPOSITORYID,
7975                            new Object[] { dlFolder.getRepositoryId() }, dlFolder);
7976    
7977                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_N,
7978                            new Object[] {
7979                                    dlFolder.getGroupId(), dlFolder.getParentFolderId(),
7980                                    dlFolder.getName()
7981                            }, dlFolder);
7982    
7983                    dlFolder.resetOriginalValues();
7984            }
7985    
7986            /**
7987             * Caches the document library folders in the entity cache if it is enabled.
7988             *
7989             * @param dlFolders the document library folders
7990             */
7991            @Override
7992            public void cacheResult(List<DLFolder> dlFolders) {
7993                    for (DLFolder dlFolder : dlFolders) {
7994                            if (EntityCacheUtil.getResult(
7995                                                    DLFolderModelImpl.ENTITY_CACHE_ENABLED,
7996                                                    DLFolderImpl.class, dlFolder.getPrimaryKey()) == null) {
7997                                    cacheResult(dlFolder);
7998                            }
7999                            else {
8000                                    dlFolder.resetOriginalValues();
8001                            }
8002                    }
8003            }
8004    
8005            /**
8006             * Clears the cache for all document library folders.
8007             *
8008             * <p>
8009             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
8010             * </p>
8011             */
8012            @Override
8013            public void clearCache() {
8014                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
8015                            CacheRegistryUtil.clear(DLFolderImpl.class.getName());
8016                    }
8017    
8018                    EntityCacheUtil.clearCache(DLFolderImpl.class.getName());
8019    
8020                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
8021                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
8022                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
8023            }
8024    
8025            /**
8026             * Clears the cache for the document library folder.
8027             *
8028             * <p>
8029             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
8030             * </p>
8031             */
8032            @Override
8033            public void clearCache(DLFolder dlFolder) {
8034                    EntityCacheUtil.removeResult(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
8035                            DLFolderImpl.class, dlFolder.getPrimaryKey());
8036    
8037                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
8038                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
8039    
8040                    clearUniqueFindersCache(dlFolder);
8041            }
8042    
8043            @Override
8044            public void clearCache(List<DLFolder> dlFolders) {
8045                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
8046                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
8047    
8048                    for (DLFolder dlFolder : dlFolders) {
8049                            EntityCacheUtil.removeResult(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
8050                                    DLFolderImpl.class, dlFolder.getPrimaryKey());
8051    
8052                            clearUniqueFindersCache(dlFolder);
8053                    }
8054            }
8055    
8056            protected void cacheUniqueFindersCache(DLFolder dlFolder) {
8057                    if (dlFolder.isNew()) {
8058                            Object[] args = new Object[] {
8059                                            dlFolder.getUuid(), dlFolder.getGroupId()
8060                                    };
8061    
8062                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
8063                                    Long.valueOf(1));
8064                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
8065                                    dlFolder);
8066    
8067                            args = new Object[] { dlFolder.getRepositoryId() };
8068    
8069                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_REPOSITORYID, args,
8070                                    Long.valueOf(1));
8071                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_REPOSITORYID, args,
8072                                    dlFolder);
8073    
8074                            args = new Object[] {
8075                                            dlFolder.getGroupId(), dlFolder.getParentFolderId(),
8076                                            dlFolder.getName()
8077                                    };
8078    
8079                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_P_N, args,
8080                                    Long.valueOf(1));
8081                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_N, args, dlFolder);
8082                    }
8083                    else {
8084                            DLFolderModelImpl dlFolderModelImpl = (DLFolderModelImpl)dlFolder;
8085    
8086                            if ((dlFolderModelImpl.getColumnBitmask() &
8087                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
8088                                    Object[] args = new Object[] {
8089                                                    dlFolder.getUuid(), dlFolder.getGroupId()
8090                                            };
8091    
8092                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
8093                                            Long.valueOf(1));
8094                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
8095                                            dlFolder);
8096                            }
8097    
8098                            if ((dlFolderModelImpl.getColumnBitmask() &
8099                                            FINDER_PATH_FETCH_BY_REPOSITORYID.getColumnBitmask()) != 0) {
8100                                    Object[] args = new Object[] { dlFolder.getRepositoryId() };
8101    
8102                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_REPOSITORYID,
8103                                            args, Long.valueOf(1));
8104                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_REPOSITORYID,
8105                                            args, dlFolder);
8106                            }
8107    
8108                            if ((dlFolderModelImpl.getColumnBitmask() &
8109                                            FINDER_PATH_FETCH_BY_G_P_N.getColumnBitmask()) != 0) {
8110                                    Object[] args = new Object[] {
8111                                                    dlFolder.getGroupId(), dlFolder.getParentFolderId(),
8112                                                    dlFolder.getName()
8113                                            };
8114    
8115                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_P_N, args,
8116                                            Long.valueOf(1));
8117                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_N, args,
8118                                            dlFolder);
8119                            }
8120                    }
8121            }
8122    
8123            protected void clearUniqueFindersCache(DLFolder dlFolder) {
8124                    DLFolderModelImpl dlFolderModelImpl = (DLFolderModelImpl)dlFolder;
8125    
8126                    Object[] args = new Object[] { dlFolder.getUuid(), dlFolder.getGroupId() };
8127    
8128                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
8129                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
8130    
8131                    if ((dlFolderModelImpl.getColumnBitmask() &
8132                                    FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
8133                            args = new Object[] {
8134                                            dlFolderModelImpl.getOriginalUuid(),
8135                                            dlFolderModelImpl.getOriginalGroupId()
8136                                    };
8137    
8138                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
8139                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
8140                    }
8141    
8142                    args = new Object[] { dlFolder.getRepositoryId() };
8143    
8144                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_REPOSITORYID, args);
8145                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_REPOSITORYID, args);
8146    
8147                    if ((dlFolderModelImpl.getColumnBitmask() &
8148                                    FINDER_PATH_FETCH_BY_REPOSITORYID.getColumnBitmask()) != 0) {
8149                            args = new Object[] { dlFolderModelImpl.getOriginalRepositoryId() };
8150    
8151                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_REPOSITORYID, args);
8152                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_REPOSITORYID, args);
8153                    }
8154    
8155                    args = new Object[] {
8156                                    dlFolder.getGroupId(), dlFolder.getParentFolderId(),
8157                                    dlFolder.getName()
8158                            };
8159    
8160                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_N, args);
8161                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P_N, args);
8162    
8163                    if ((dlFolderModelImpl.getColumnBitmask() &
8164                                    FINDER_PATH_FETCH_BY_G_P_N.getColumnBitmask()) != 0) {
8165                            args = new Object[] {
8166                                            dlFolderModelImpl.getOriginalGroupId(),
8167                                            dlFolderModelImpl.getOriginalParentFolderId(),
8168                                            dlFolderModelImpl.getOriginalName()
8169                                    };
8170    
8171                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_N, args);
8172                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P_N, args);
8173                    }
8174            }
8175    
8176            /**
8177             * Creates a new document library folder with the primary key. Does not add the document library folder to the database.
8178             *
8179             * @param folderId the primary key for the new document library folder
8180             * @return the new document library folder
8181             */
8182            @Override
8183            public DLFolder create(long folderId) {
8184                    DLFolder dlFolder = new DLFolderImpl();
8185    
8186                    dlFolder.setNew(true);
8187                    dlFolder.setPrimaryKey(folderId);
8188    
8189                    String uuid = PortalUUIDUtil.generate();
8190    
8191                    dlFolder.setUuid(uuid);
8192    
8193                    return dlFolder;
8194            }
8195    
8196            /**
8197             * Removes the document library folder with the primary key from the database. Also notifies the appropriate model listeners.
8198             *
8199             * @param folderId the primary key of the document library folder
8200             * @return the document library folder that was removed
8201             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
8202             * @throws SystemException if a system exception occurred
8203             */
8204            @Override
8205            public DLFolder remove(long folderId)
8206                    throws NoSuchFolderException, SystemException {
8207                    return remove((Serializable)folderId);
8208            }
8209    
8210            /**
8211             * Removes the document library folder with the primary key from the database. Also notifies the appropriate model listeners.
8212             *
8213             * @param primaryKey the primary key of the document library folder
8214             * @return the document library folder that was removed
8215             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
8216             * @throws SystemException if a system exception occurred
8217             */
8218            @Override
8219            public DLFolder remove(Serializable primaryKey)
8220                    throws NoSuchFolderException, SystemException {
8221                    Session session = null;
8222    
8223                    try {
8224                            session = openSession();
8225    
8226                            DLFolder dlFolder = (DLFolder)session.get(DLFolderImpl.class,
8227                                            primaryKey);
8228    
8229                            if (dlFolder == null) {
8230                                    if (_log.isWarnEnabled()) {
8231                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
8232                                    }
8233    
8234                                    throw new NoSuchFolderException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
8235                                            primaryKey);
8236                            }
8237    
8238                            return remove(dlFolder);
8239                    }
8240                    catch (NoSuchFolderException nsee) {
8241                            throw nsee;
8242                    }
8243                    catch (Exception e) {
8244                            throw processException(e);
8245                    }
8246                    finally {
8247                            closeSession(session);
8248                    }
8249            }
8250    
8251            @Override
8252            protected DLFolder removeImpl(DLFolder dlFolder) throws SystemException {
8253                    dlFolder = toUnwrappedModel(dlFolder);
8254    
8255                    dlFolderToDLFileEntryTypeTableMapper.deleteLeftPrimaryKeyTableMappings(dlFolder.getPrimaryKey());
8256    
8257                    Session session = null;
8258    
8259                    try {
8260                            session = openSession();
8261    
8262                            if (!session.contains(dlFolder)) {
8263                                    dlFolder = (DLFolder)session.get(DLFolderImpl.class,
8264                                                    dlFolder.getPrimaryKeyObj());
8265                            }
8266    
8267                            if (dlFolder != null) {
8268                                    session.delete(dlFolder);
8269                            }
8270                    }
8271                    catch (Exception e) {
8272                            throw processException(e);
8273                    }
8274                    finally {
8275                            closeSession(session);
8276                    }
8277    
8278                    if (dlFolder != null) {
8279                            clearCache(dlFolder);
8280                    }
8281    
8282                    return dlFolder;
8283            }
8284    
8285            @Override
8286            public DLFolder updateImpl(
8287                    com.liferay.portlet.documentlibrary.model.DLFolder dlFolder)
8288                    throws SystemException {
8289                    dlFolder = toUnwrappedModel(dlFolder);
8290    
8291                    boolean isNew = dlFolder.isNew();
8292    
8293                    DLFolderModelImpl dlFolderModelImpl = (DLFolderModelImpl)dlFolder;
8294    
8295                    if (Validator.isNull(dlFolder.getUuid())) {
8296                            String uuid = PortalUUIDUtil.generate();
8297    
8298                            dlFolder.setUuid(uuid);
8299                    }
8300    
8301                    Session session = null;
8302    
8303                    try {
8304                            session = openSession();
8305    
8306                            if (dlFolder.isNew()) {
8307                                    session.save(dlFolder);
8308    
8309                                    dlFolder.setNew(false);
8310                            }
8311                            else {
8312                                    session.merge(dlFolder);
8313                            }
8314                    }
8315                    catch (Exception e) {
8316                            throw processException(e);
8317                    }
8318                    finally {
8319                            closeSession(session);
8320                    }
8321    
8322                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
8323    
8324                    if (isNew || !DLFolderModelImpl.COLUMN_BITMASK_ENABLED) {
8325                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
8326                    }
8327    
8328                    else {
8329                            if ((dlFolderModelImpl.getColumnBitmask() &
8330                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
8331                                    Object[] args = new Object[] { dlFolderModelImpl.getOriginalUuid() };
8332    
8333                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
8334                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
8335                                            args);
8336    
8337                                    args = new Object[] { dlFolderModelImpl.getUuid() };
8338    
8339                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
8340                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
8341                                            args);
8342                            }
8343    
8344                            if ((dlFolderModelImpl.getColumnBitmask() &
8345                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
8346                                    Object[] args = new Object[] {
8347                                                    dlFolderModelImpl.getOriginalUuid(),
8348                                                    dlFolderModelImpl.getOriginalCompanyId()
8349                                            };
8350    
8351                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
8352                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
8353                                            args);
8354    
8355                                    args = new Object[] {
8356                                                    dlFolderModelImpl.getUuid(),
8357                                                    dlFolderModelImpl.getCompanyId()
8358                                            };
8359    
8360                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
8361                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
8362                                            args);
8363                            }
8364    
8365                            if ((dlFolderModelImpl.getColumnBitmask() &
8366                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
8367                                    Object[] args = new Object[] {
8368                                                    dlFolderModelImpl.getOriginalGroupId()
8369                                            };
8370    
8371                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
8372                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
8373                                            args);
8374    
8375                                    args = new Object[] { dlFolderModelImpl.getGroupId() };
8376    
8377                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
8378                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
8379                                            args);
8380                            }
8381    
8382                            if ((dlFolderModelImpl.getColumnBitmask() &
8383                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
8384                                    Object[] args = new Object[] {
8385                                                    dlFolderModelImpl.getOriginalCompanyId()
8386                                            };
8387    
8388                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
8389                                            args);
8390                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
8391                                            args);
8392    
8393                                    args = new Object[] { dlFolderModelImpl.getCompanyId() };
8394    
8395                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
8396                                            args);
8397                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
8398                                            args);
8399                            }
8400    
8401                            if ((dlFolderModelImpl.getColumnBitmask() &
8402                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P.getColumnBitmask()) != 0) {
8403                                    Object[] args = new Object[] {
8404                                                    dlFolderModelImpl.getOriginalGroupId(),
8405                                                    dlFolderModelImpl.getOriginalParentFolderId()
8406                                            };
8407    
8408                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P, args);
8409                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P,
8410                                            args);
8411    
8412                                    args = new Object[] {
8413                                                    dlFolderModelImpl.getGroupId(),
8414                                                    dlFolderModelImpl.getParentFolderId()
8415                                            };
8416    
8417                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P, args);
8418                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P,
8419                                            args);
8420                            }
8421    
8422                            if ((dlFolderModelImpl.getColumnBitmask() &
8423                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_N.getColumnBitmask()) != 0) {
8424                                    Object[] args = new Object[] {
8425                                                    dlFolderModelImpl.getOriginalParentFolderId(),
8426                                                    dlFolderModelImpl.getOriginalName()
8427                                            };
8428    
8429                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_P_N, args);
8430                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_N,
8431                                            args);
8432    
8433                                    args = new Object[] {
8434                                                    dlFolderModelImpl.getParentFolderId(),
8435                                                    dlFolderModelImpl.getName()
8436                                            };
8437    
8438                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_P_N, args);
8439                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_N,
8440                                            args);
8441                            }
8442    
8443                            if ((dlFolderModelImpl.getColumnBitmask() &
8444                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P_H.getColumnBitmask()) != 0) {
8445                                    Object[] args = new Object[] {
8446                                                    dlFolderModelImpl.getOriginalGroupId(),
8447                                                    dlFolderModelImpl.getOriginalMountPoint(),
8448                                                    dlFolderModelImpl.getOriginalParentFolderId(),
8449                                                    dlFolderModelImpl.getOriginalHidden()
8450                                            };
8451    
8452                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_M_P_H, args);
8453                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P_H,
8454                                            args);
8455    
8456                                    args = new Object[] {
8457                                                    dlFolderModelImpl.getGroupId(),
8458                                                    dlFolderModelImpl.getMountPoint(),
8459                                                    dlFolderModelImpl.getParentFolderId(),
8460                                                    dlFolderModelImpl.getHidden()
8461                                            };
8462    
8463                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_M_P_H, args);
8464                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P_H,
8465                                            args);
8466                            }
8467    
8468                            if ((dlFolderModelImpl.getColumnBitmask() &
8469                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_H_S.getColumnBitmask()) != 0) {
8470                                    Object[] args = new Object[] {
8471                                                    dlFolderModelImpl.getOriginalGroupId(),
8472                                                    dlFolderModelImpl.getOriginalParentFolderId(),
8473                                                    dlFolderModelImpl.getOriginalHidden(),
8474                                                    dlFolderModelImpl.getOriginalStatus()
8475                                            };
8476    
8477                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_H_S, args);
8478                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_H_S,
8479                                            args);
8480    
8481                                    args = new Object[] {
8482                                                    dlFolderModelImpl.getGroupId(),
8483                                                    dlFolderModelImpl.getParentFolderId(),
8484                                                    dlFolderModelImpl.getHidden(),
8485                                                    dlFolderModelImpl.getStatus()
8486                                            };
8487    
8488                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_H_S, args);
8489                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_H_S,
8490                                            args);
8491                            }
8492    
8493                            if ((dlFolderModelImpl.getColumnBitmask() &
8494                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P_H_S.getColumnBitmask()) != 0) {
8495                                    Object[] args = new Object[] {
8496                                                    dlFolderModelImpl.getOriginalGroupId(),
8497                                                    dlFolderModelImpl.getOriginalMountPoint(),
8498                                                    dlFolderModelImpl.getOriginalParentFolderId(),
8499                                                    dlFolderModelImpl.getOriginalHidden(),
8500                                                    dlFolderModelImpl.getOriginalStatus()
8501                                            };
8502    
8503                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_M_P_H_S,
8504                                            args);
8505                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P_H_S,
8506                                            args);
8507    
8508                                    args = new Object[] {
8509                                                    dlFolderModelImpl.getGroupId(),
8510                                                    dlFolderModelImpl.getMountPoint(),
8511                                                    dlFolderModelImpl.getParentFolderId(),
8512                                                    dlFolderModelImpl.getHidden(),
8513                                                    dlFolderModelImpl.getStatus()
8514                                            };
8515    
8516                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_M_P_H_S,
8517                                            args);
8518                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P_H_S,
8519                                            args);
8520                            }
8521                    }
8522    
8523                    EntityCacheUtil.putResult(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
8524                            DLFolderImpl.class, dlFolder.getPrimaryKey(), dlFolder);
8525    
8526                    clearUniqueFindersCache(dlFolder);
8527                    cacheUniqueFindersCache(dlFolder);
8528    
8529                    return dlFolder;
8530            }
8531    
8532            protected DLFolder toUnwrappedModel(DLFolder dlFolder) {
8533                    if (dlFolder instanceof DLFolderImpl) {
8534                            return dlFolder;
8535                    }
8536    
8537                    DLFolderImpl dlFolderImpl = new DLFolderImpl();
8538    
8539                    dlFolderImpl.setNew(dlFolder.isNew());
8540                    dlFolderImpl.setPrimaryKey(dlFolder.getPrimaryKey());
8541    
8542                    dlFolderImpl.setUuid(dlFolder.getUuid());
8543                    dlFolderImpl.setFolderId(dlFolder.getFolderId());
8544                    dlFolderImpl.setGroupId(dlFolder.getGroupId());
8545                    dlFolderImpl.setCompanyId(dlFolder.getCompanyId());
8546                    dlFolderImpl.setUserId(dlFolder.getUserId());
8547                    dlFolderImpl.setUserName(dlFolder.getUserName());
8548                    dlFolderImpl.setCreateDate(dlFolder.getCreateDate());
8549                    dlFolderImpl.setModifiedDate(dlFolder.getModifiedDate());
8550                    dlFolderImpl.setRepositoryId(dlFolder.getRepositoryId());
8551                    dlFolderImpl.setMountPoint(dlFolder.isMountPoint());
8552                    dlFolderImpl.setParentFolderId(dlFolder.getParentFolderId());
8553                    dlFolderImpl.setName(dlFolder.getName());
8554                    dlFolderImpl.setDescription(dlFolder.getDescription());
8555                    dlFolderImpl.setLastPostDate(dlFolder.getLastPostDate());
8556                    dlFolderImpl.setDefaultFileEntryTypeId(dlFolder.getDefaultFileEntryTypeId());
8557                    dlFolderImpl.setHidden(dlFolder.isHidden());
8558                    dlFolderImpl.setOverrideFileEntryTypes(dlFolder.isOverrideFileEntryTypes());
8559                    dlFolderImpl.setStatus(dlFolder.getStatus());
8560                    dlFolderImpl.setStatusByUserId(dlFolder.getStatusByUserId());
8561                    dlFolderImpl.setStatusByUserName(dlFolder.getStatusByUserName());
8562                    dlFolderImpl.setStatusDate(dlFolder.getStatusDate());
8563    
8564                    return dlFolderImpl;
8565            }
8566    
8567            /**
8568             * Returns the document library folder with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
8569             *
8570             * @param primaryKey the primary key of the document library folder
8571             * @return the document library folder
8572             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
8573             * @throws SystemException if a system exception occurred
8574             */
8575            @Override
8576            public DLFolder findByPrimaryKey(Serializable primaryKey)
8577                    throws NoSuchFolderException, SystemException {
8578                    DLFolder dlFolder = fetchByPrimaryKey(primaryKey);
8579    
8580                    if (dlFolder == null) {
8581                            if (_log.isWarnEnabled()) {
8582                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
8583                            }
8584    
8585                            throw new NoSuchFolderException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
8586                                    primaryKey);
8587                    }
8588    
8589                    return dlFolder;
8590            }
8591    
8592            /**
8593             * Returns the document library folder with the primary key or throws a {@link com.liferay.portlet.documentlibrary.NoSuchFolderException} if it could not be found.
8594             *
8595             * @param folderId the primary key of the document library folder
8596             * @return the document library folder
8597             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
8598             * @throws SystemException if a system exception occurred
8599             */
8600            @Override
8601            public DLFolder findByPrimaryKey(long folderId)
8602                    throws NoSuchFolderException, SystemException {
8603                    return findByPrimaryKey((Serializable)folderId);
8604            }
8605    
8606            /**
8607             * Returns the document library folder with the primary key or returns <code>null</code> if it could not be found.
8608             *
8609             * @param primaryKey the primary key of the document library folder
8610             * @return the document library folder, or <code>null</code> if a document library folder with the primary key could not be found
8611             * @throws SystemException if a system exception occurred
8612             */
8613            @Override
8614            public DLFolder fetchByPrimaryKey(Serializable primaryKey)
8615                    throws SystemException {
8616                    DLFolder dlFolder = (DLFolder)EntityCacheUtil.getResult(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
8617                                    DLFolderImpl.class, primaryKey);
8618    
8619                    if (dlFolder == _nullDLFolder) {
8620                            return null;
8621                    }
8622    
8623                    if (dlFolder == null) {
8624                            Session session = null;
8625    
8626                            try {
8627                                    session = openSession();
8628    
8629                                    dlFolder = (DLFolder)session.get(DLFolderImpl.class, primaryKey);
8630    
8631                                    if (dlFolder != null) {
8632                                            cacheResult(dlFolder);
8633                                    }
8634                                    else {
8635                                            EntityCacheUtil.putResult(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
8636                                                    DLFolderImpl.class, primaryKey, _nullDLFolder);
8637                                    }
8638                            }
8639                            catch (Exception e) {
8640                                    EntityCacheUtil.removeResult(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
8641                                            DLFolderImpl.class, primaryKey);
8642    
8643                                    throw processException(e);
8644                            }
8645                            finally {
8646                                    closeSession(session);
8647                            }
8648                    }
8649    
8650                    return dlFolder;
8651            }
8652    
8653            /**
8654             * Returns the document library folder with the primary key or returns <code>null</code> if it could not be found.
8655             *
8656             * @param folderId the primary key of the document library folder
8657             * @return the document library folder, or <code>null</code> if a document library folder with the primary key could not be found
8658             * @throws SystemException if a system exception occurred
8659             */
8660            @Override
8661            public DLFolder fetchByPrimaryKey(long folderId) throws SystemException {
8662                    return fetchByPrimaryKey((Serializable)folderId);
8663            }
8664    
8665            /**
8666             * Returns all the document library folders.
8667             *
8668             * @return the document library folders
8669             * @throws SystemException if a system exception occurred
8670             */
8671            @Override
8672            public List<DLFolder> findAll() throws SystemException {
8673                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
8674            }
8675    
8676            /**
8677             * Returns a range of all the document library folders.
8678             *
8679             * <p>
8680             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
8681             * </p>
8682             *
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             * @return the range of document library folders
8686             * @throws SystemException if a system exception occurred
8687             */
8688            @Override
8689            public List<DLFolder> findAll(int start, int end) throws SystemException {
8690                    return findAll(start, end, null);
8691            }
8692    
8693            /**
8694             * Returns an ordered range of all the document library folders.
8695             *
8696             * <p>
8697             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
8698             * </p>
8699             *
8700             * @param start the lower bound of the range of document library folders
8701             * @param end the upper bound of the range of document library folders (not inclusive)
8702             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8703             * @return the ordered range of document library folders
8704             * @throws SystemException if a system exception occurred
8705             */
8706            @Override
8707            public List<DLFolder> findAll(int start, int end,
8708                    OrderByComparator orderByComparator) throws SystemException {
8709                    boolean pagination = true;
8710                    FinderPath finderPath = null;
8711                    Object[] finderArgs = null;
8712    
8713                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8714                                    (orderByComparator == null)) {
8715                            pagination = false;
8716                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
8717                            finderArgs = FINDER_ARGS_EMPTY;
8718                    }
8719                    else {
8720                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
8721                            finderArgs = new Object[] { start, end, orderByComparator };
8722                    }
8723    
8724                    List<DLFolder> list = (List<DLFolder>)FinderCacheUtil.getResult(finderPath,
8725                                    finderArgs, this);
8726    
8727                    if (list == null) {
8728                            StringBundler query = null;
8729                            String sql = null;
8730    
8731                            if (orderByComparator != null) {
8732                                    query = new StringBundler(2 +
8733                                                    (orderByComparator.getOrderByFields().length * 3));
8734    
8735                                    query.append(_SQL_SELECT_DLFOLDER);
8736    
8737                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8738                                            orderByComparator);
8739    
8740                                    sql = query.toString();
8741                            }
8742                            else {
8743                                    sql = _SQL_SELECT_DLFOLDER;
8744    
8745                                    if (pagination) {
8746                                            sql = sql.concat(DLFolderModelImpl.ORDER_BY_JPQL);
8747                                    }
8748                            }
8749    
8750                            Session session = null;
8751    
8752                            try {
8753                                    session = openSession();
8754    
8755                                    Query q = session.createQuery(sql);
8756    
8757                                    if (!pagination) {
8758                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
8759                                                            start, end, false);
8760    
8761                                            Collections.sort(list);
8762    
8763                                            list = new UnmodifiableList<DLFolder>(list);
8764                                    }
8765                                    else {
8766                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
8767                                                            start, end);
8768                                    }
8769    
8770                                    cacheResult(list);
8771    
8772                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
8773                            }
8774                            catch (Exception e) {
8775                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
8776    
8777                                    throw processException(e);
8778                            }
8779                            finally {
8780                                    closeSession(session);
8781                            }
8782                    }
8783    
8784                    return list;
8785            }
8786    
8787            /**
8788             * Removes all the document library folders from the database.
8789             *
8790             * @throws SystemException if a system exception occurred
8791             */
8792            @Override
8793            public void removeAll() throws SystemException {
8794                    for (DLFolder dlFolder : findAll()) {
8795                            remove(dlFolder);
8796                    }
8797            }
8798    
8799            /**
8800             * Returns the number of document library folders.
8801             *
8802             * @return the number of document library folders
8803             * @throws SystemException if a system exception occurred
8804             */
8805            @Override
8806            public int countAll() throws SystemException {
8807                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
8808                                    FINDER_ARGS_EMPTY, this);
8809    
8810                    if (count == null) {
8811                            Session session = null;
8812    
8813                            try {
8814                                    session = openSession();
8815    
8816                                    Query q = session.createQuery(_SQL_COUNT_DLFOLDER);
8817    
8818                                    count = (Long)q.uniqueResult();
8819    
8820                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
8821                                            FINDER_ARGS_EMPTY, count);
8822                            }
8823                            catch (Exception e) {
8824                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
8825                                            FINDER_ARGS_EMPTY);
8826    
8827                                    throw processException(e);
8828                            }
8829                            finally {
8830                                    closeSession(session);
8831                            }
8832                    }
8833    
8834                    return count.intValue();
8835            }
8836    
8837            /**
8838             * Returns all the document library file entry types associated with the document library folder.
8839             *
8840             * @param pk the primary key of the document library folder
8841             * @return the document library file entry types associated with the document library folder
8842             * @throws SystemException if a system exception occurred
8843             */
8844            @Override
8845            public List<com.liferay.portlet.documentlibrary.model.DLFileEntryType> getDLFileEntryTypes(
8846                    long pk) throws SystemException {
8847                    return getDLFileEntryTypes(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
8848            }
8849    
8850            /**
8851             * Returns a range of all the document library file entry types associated with the document library folder.
8852             *
8853             * <p>
8854             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
8855             * </p>
8856             *
8857             * @param pk the primary key of the document library folder
8858             * @param start the lower bound of the range of document library folders
8859             * @param end the upper bound of the range of document library folders (not inclusive)
8860             * @return the range of document library file entry types associated with the document library folder
8861             * @throws SystemException if a system exception occurred
8862             */
8863            @Override
8864            public List<com.liferay.portlet.documentlibrary.model.DLFileEntryType> getDLFileEntryTypes(
8865                    long pk, int start, int end) throws SystemException {
8866                    return getDLFileEntryTypes(pk, start, end, null);
8867            }
8868    
8869            /**
8870             * Returns an ordered range of all the document library file entry types associated with the document library folder.
8871             *
8872             * <p>
8873             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
8874             * </p>
8875             *
8876             * @param pk the primary key of the document library folder
8877             * @param start the lower bound of the range of document library folders
8878             * @param end the upper bound of the range of document library folders (not inclusive)
8879             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8880             * @return the ordered range of document library file entry types associated with the document library folder
8881             * @throws SystemException if a system exception occurred
8882             */
8883            @Override
8884            public List<com.liferay.portlet.documentlibrary.model.DLFileEntryType> getDLFileEntryTypes(
8885                    long pk, int start, int end, OrderByComparator orderByComparator)
8886                    throws SystemException {
8887                    return dlFolderToDLFileEntryTypeTableMapper.getRightBaseModels(pk,
8888                            start, end, orderByComparator);
8889            }
8890    
8891            /**
8892             * Returns the number of document library file entry types associated with the document library folder.
8893             *
8894             * @param pk the primary key of the document library folder
8895             * @return the number of document library file entry types associated with the document library folder
8896             * @throws SystemException if a system exception occurred
8897             */
8898            @Override
8899            public int getDLFileEntryTypesSize(long pk) throws SystemException {
8900                    long[] pks = dlFolderToDLFileEntryTypeTableMapper.getRightPrimaryKeys(pk);
8901    
8902                    return pks.length;
8903            }
8904    
8905            /**
8906             * Returns <code>true</code> if the document library file entry type is associated with the document library folder.
8907             *
8908             * @param pk the primary key of the document library folder
8909             * @param dlFileEntryTypePK the primary key of the document library file entry type
8910             * @return <code>true</code> if the document library file entry type is associated with the document library folder; <code>false</code> otherwise
8911             * @throws SystemException if a system exception occurred
8912             */
8913            @Override
8914            public boolean containsDLFileEntryType(long pk, long dlFileEntryTypePK)
8915                    throws SystemException {
8916                    return dlFolderToDLFileEntryTypeTableMapper.containsTableMapping(pk,
8917                            dlFileEntryTypePK);
8918            }
8919    
8920            /**
8921             * Returns <code>true</code> if the document library folder has any document library file entry types associated with it.
8922             *
8923             * @param pk the primary key of the document library folder to check for associations with document library file entry types
8924             * @return <code>true</code> if the document library folder has any document library file entry types associated with it; <code>false</code> otherwise
8925             * @throws SystemException if a system exception occurred
8926             */
8927            @Override
8928            public boolean containsDLFileEntryTypes(long pk) throws SystemException {
8929                    if (getDLFileEntryTypesSize(pk) > 0) {
8930                            return true;
8931                    }
8932                    else {
8933                            return false;
8934                    }
8935            }
8936    
8937            /**
8938             * 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.
8939             *
8940             * @param pk the primary key of the document library folder
8941             * @param dlFileEntryTypePK the primary key of the document library file entry type
8942             * @throws SystemException if a system exception occurred
8943             */
8944            @Override
8945            public void addDLFileEntryType(long pk, long dlFileEntryTypePK)
8946                    throws SystemException {
8947                    dlFolderToDLFileEntryTypeTableMapper.addTableMapping(pk,
8948                            dlFileEntryTypePK);
8949            }
8950    
8951            /**
8952             * 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.
8953             *
8954             * @param pk the primary key of the document library folder
8955             * @param dlFileEntryType the document library file entry type
8956             * @throws SystemException if a system exception occurred
8957             */
8958            @Override
8959            public void addDLFileEntryType(long pk,
8960                    com.liferay.portlet.documentlibrary.model.DLFileEntryType dlFileEntryType)
8961                    throws SystemException {
8962                    dlFolderToDLFileEntryTypeTableMapper.addTableMapping(pk,
8963                            dlFileEntryType.getPrimaryKey());
8964            }
8965    
8966            /**
8967             * 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.
8968             *
8969             * @param pk the primary key of the document library folder
8970             * @param dlFileEntryTypePKs the primary keys of the document library file entry types
8971             * @throws SystemException if a system exception occurred
8972             */
8973            @Override
8974            public void addDLFileEntryTypes(long pk, long[] dlFileEntryTypePKs)
8975                    throws SystemException {
8976                    for (long dlFileEntryTypePK : dlFileEntryTypePKs) {
8977                            dlFolderToDLFileEntryTypeTableMapper.addTableMapping(pk,
8978                                    dlFileEntryTypePK);
8979                    }
8980            }
8981    
8982            /**
8983             * 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.
8984             *
8985             * @param pk the primary key of the document library folder
8986             * @param dlFileEntryTypes the document library file entry types
8987             * @throws SystemException if a system exception occurred
8988             */
8989            @Override
8990            public void addDLFileEntryTypes(long pk,
8991                    List<com.liferay.portlet.documentlibrary.model.DLFileEntryType> dlFileEntryTypes)
8992                    throws SystemException {
8993                    for (com.liferay.portlet.documentlibrary.model.DLFileEntryType dlFileEntryType : dlFileEntryTypes) {
8994                            dlFolderToDLFileEntryTypeTableMapper.addTableMapping(pk,
8995                                    dlFileEntryType.getPrimaryKey());
8996                    }
8997            }
8998    
8999            /**
9000             * 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.
9001             *
9002             * @param pk the primary key of the document library folder to clear the associated document library file entry types from
9003             * @throws SystemException if a system exception occurred
9004             */
9005            @Override
9006            public void clearDLFileEntryTypes(long pk) throws SystemException {
9007                    dlFolderToDLFileEntryTypeTableMapper.deleteLeftPrimaryKeyTableMappings(pk);
9008            }
9009    
9010            /**
9011             * 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.
9012             *
9013             * @param pk the primary key of the document library folder
9014             * @param dlFileEntryTypePK the primary key of the document library file entry type
9015             * @throws SystemException if a system exception occurred
9016             */
9017            @Override
9018            public void removeDLFileEntryType(long pk, long dlFileEntryTypePK)
9019                    throws SystemException {
9020                    dlFolderToDLFileEntryTypeTableMapper.deleteTableMapping(pk,
9021                            dlFileEntryTypePK);
9022            }
9023    
9024            /**
9025             * 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.
9026             *
9027             * @param pk the primary key of the document library folder
9028             * @param dlFileEntryType the document library file entry type
9029             * @throws SystemException if a system exception occurred
9030             */
9031            @Override
9032            public void removeDLFileEntryType(long pk,
9033                    com.liferay.portlet.documentlibrary.model.DLFileEntryType dlFileEntryType)
9034                    throws SystemException {
9035                    dlFolderToDLFileEntryTypeTableMapper.deleteTableMapping(pk,
9036                            dlFileEntryType.getPrimaryKey());
9037            }
9038    
9039            /**
9040             * 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.
9041             *
9042             * @param pk the primary key of the document library folder
9043             * @param dlFileEntryTypePKs the primary keys of the document library file entry types
9044             * @throws SystemException if a system exception occurred
9045             */
9046            @Override
9047            public void removeDLFileEntryTypes(long pk, long[] dlFileEntryTypePKs)
9048                    throws SystemException {
9049                    for (long dlFileEntryTypePK : dlFileEntryTypePKs) {
9050                            dlFolderToDLFileEntryTypeTableMapper.deleteTableMapping(pk,
9051                                    dlFileEntryTypePK);
9052                    }
9053            }
9054    
9055            /**
9056             * 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.
9057             *
9058             * @param pk the primary key of the document library folder
9059             * @param dlFileEntryTypes the document library file entry types
9060             * @throws SystemException if a system exception occurred
9061             */
9062            @Override
9063            public void removeDLFileEntryTypes(long pk,
9064                    List<com.liferay.portlet.documentlibrary.model.DLFileEntryType> dlFileEntryTypes)
9065                    throws SystemException {
9066                    for (com.liferay.portlet.documentlibrary.model.DLFileEntryType dlFileEntryType : dlFileEntryTypes) {
9067                            dlFolderToDLFileEntryTypeTableMapper.deleteTableMapping(pk,
9068                                    dlFileEntryType.getPrimaryKey());
9069                    }
9070            }
9071    
9072            /**
9073             * 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.
9074             *
9075             * @param pk the primary key of the document library folder
9076             * @param dlFileEntryTypePKs the primary keys of the document library file entry types to be associated with the document library folder
9077             * @throws SystemException if a system exception occurred
9078             */
9079            @Override
9080            public void setDLFileEntryTypes(long pk, long[] dlFileEntryTypePKs)
9081                    throws SystemException {
9082                    dlFolderToDLFileEntryTypeTableMapper.deleteLeftPrimaryKeyTableMappings(pk);
9083    
9084                    for (Long dlFileEntryTypePK : dlFileEntryTypePKs) {
9085                            dlFolderToDLFileEntryTypeTableMapper.addTableMapping(pk,
9086                                    dlFileEntryTypePK);
9087                    }
9088            }
9089    
9090            /**
9091             * 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.
9092             *
9093             * @param pk the primary key of the document library folder
9094             * @param dlFileEntryTypes the document library file entry types to be associated with the document library folder
9095             * @throws SystemException if a system exception occurred
9096             */
9097            @Override
9098            public void setDLFileEntryTypes(long pk,
9099                    List<com.liferay.portlet.documentlibrary.model.DLFileEntryType> dlFileEntryTypes)
9100                    throws SystemException {
9101                    try {
9102                            long[] dlFileEntryTypePKs = new long[dlFileEntryTypes.size()];
9103    
9104                            for (int i = 0; i < dlFileEntryTypes.size(); i++) {
9105                                    com.liferay.portlet.documentlibrary.model.DLFileEntryType dlFileEntryType =
9106                                            dlFileEntryTypes.get(i);
9107    
9108                                    dlFileEntryTypePKs[i] = dlFileEntryType.getPrimaryKey();
9109                            }
9110    
9111                            setDLFileEntryTypes(pk, dlFileEntryTypePKs);
9112                    }
9113                    catch (Exception e) {
9114                            throw processException(e);
9115                    }
9116                    finally {
9117                            FinderCacheUtil.clearCache(DLFolderModelImpl.MAPPING_TABLE_DLFILEENTRYTYPES_DLFOLDERS_NAME);
9118                    }
9119            }
9120    
9121            @Override
9122            protected Set<String> getBadColumnNames() {
9123                    return _badColumnNames;
9124            }
9125    
9126            /**
9127             * Initializes the document library folder persistence.
9128             */
9129            public void afterPropertiesSet() {
9130                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
9131                                            com.liferay.portal.util.PropsUtil.get(
9132                                                    "value.object.listener.com.liferay.portlet.documentlibrary.model.DLFolder")));
9133    
9134                    if (listenerClassNames.length > 0) {
9135                            try {
9136                                    List<ModelListener<DLFolder>> listenersList = new ArrayList<ModelListener<DLFolder>>();
9137    
9138                                    for (String listenerClassName : listenerClassNames) {
9139                                            listenersList.add((ModelListener<DLFolder>)InstanceFactory.newInstance(
9140                                                            getClassLoader(), listenerClassName));
9141                                    }
9142    
9143                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
9144                            }
9145                            catch (Exception e) {
9146                                    _log.error(e);
9147                            }
9148                    }
9149    
9150                    dlFolderToDLFileEntryTypeTableMapper = TableMapperFactory.getTableMapper("DLFileEntryTypes_DLFolders",
9151                                    "folderId", "fileEntryTypeId", this, dlFileEntryTypePersistence);
9152            }
9153    
9154            public void destroy() {
9155                    EntityCacheUtil.removeCache(DLFolderImpl.class.getName());
9156                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
9157                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
9158                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
9159            }
9160    
9161            @BeanReference(type = DLFileEntryTypePersistence.class)
9162            protected DLFileEntryTypePersistence dlFileEntryTypePersistence;
9163            protected TableMapper<DLFolder, com.liferay.portlet.documentlibrary.model.DLFileEntryType> dlFolderToDLFileEntryTypeTableMapper;
9164            private static final String _SQL_SELECT_DLFOLDER = "SELECT dlFolder FROM DLFolder dlFolder";
9165            private static final String _SQL_SELECT_DLFOLDER_WHERE = "SELECT dlFolder FROM DLFolder dlFolder WHERE ";
9166            private static final String _SQL_COUNT_DLFOLDER = "SELECT COUNT(dlFolder) FROM DLFolder dlFolder";
9167            private static final String _SQL_COUNT_DLFOLDER_WHERE = "SELECT COUNT(dlFolder) FROM DLFolder dlFolder WHERE ";
9168            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "dlFolder.folderId";
9169            private static final String _FILTER_SQL_SELECT_DLFOLDER_WHERE = "SELECT DISTINCT {dlFolder.*} FROM DLFolder dlFolder WHERE ";
9170            private static final String _FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1 =
9171                    "SELECT {DLFolder.*} FROM (SELECT DISTINCT dlFolder.folderId FROM DLFolder dlFolder WHERE ";
9172            private static final String _FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2 =
9173                    ") TEMP_TABLE INNER JOIN DLFolder ON TEMP_TABLE.folderId = DLFolder.folderId";
9174            private static final String _FILTER_SQL_COUNT_DLFOLDER_WHERE = "SELECT COUNT(DISTINCT dlFolder.folderId) AS COUNT_VALUE FROM DLFolder dlFolder WHERE ";
9175            private static final String _FILTER_ENTITY_ALIAS = "dlFolder";
9176            private static final String _FILTER_ENTITY_TABLE = "DLFolder";
9177            private static final String _ORDER_BY_ENTITY_ALIAS = "dlFolder.";
9178            private static final String _ORDER_BY_ENTITY_TABLE = "DLFolder.";
9179            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No DLFolder exists with the primary key ";
9180            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No DLFolder exists with the key {";
9181            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
9182            private static Log _log = LogFactoryUtil.getLog(DLFolderPersistenceImpl.class);
9183            private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
9184                                    "uuid", "hidden"
9185                            });
9186            private static DLFolder _nullDLFolder = new DLFolderImpl() {
9187                            @Override
9188                            public Object clone() {
9189                                    return this;
9190                            }
9191    
9192                            @Override
9193                            public CacheModel<DLFolder> toCacheModel() {
9194                                    return _nullDLFolderCacheModel;
9195                            }
9196                    };
9197    
9198            private static CacheModel<DLFolder> _nullDLFolderCacheModel = new CacheModel<DLFolder>() {
9199                            @Override
9200                            public DLFolder toEntityModel() {
9201                                    return _nullDLFolder;
9202                            }
9203                    };
9204    }