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_C_NOTS = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
3933                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
3934                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_NotS",
3935                            new String[] {
3936                                    Long.class.getName(), Integer.class.getName(),
3937                                    
3938                            Integer.class.getName(), Integer.class.getName(),
3939                                    OrderByComparator.class.getName()
3940                            });
3941            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_NOTS = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
3942                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
3943                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByC_NotS",
3944                            new String[] { Long.class.getName(), Integer.class.getName() });
3945    
3946            /**
3947             * Returns all the document library folders where companyId = &#63; and status &ne; &#63;.
3948             *
3949             * @param companyId the company ID
3950             * @param status the status
3951             * @return the matching document library folders
3952             * @throws SystemException if a system exception occurred
3953             */
3954            @Override
3955            public List<DLFolder> findByC_NotS(long companyId, int status)
3956                    throws SystemException {
3957                    return findByC_NotS(companyId, status, QueryUtil.ALL_POS,
3958                            QueryUtil.ALL_POS, null);
3959            }
3960    
3961            /**
3962             * Returns a range of all the document library folders where companyId = &#63; and status &ne; &#63;.
3963             *
3964             * <p>
3965             * 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.
3966             * </p>
3967             *
3968             * @param companyId the company ID
3969             * @param status the status
3970             * @param start the lower bound of the range of document library folders
3971             * @param end the upper bound of the range of document library folders (not inclusive)
3972             * @return the range of matching document library folders
3973             * @throws SystemException if a system exception occurred
3974             */
3975            @Override
3976            public List<DLFolder> findByC_NotS(long companyId, int status, int start,
3977                    int end) throws SystemException {
3978                    return findByC_NotS(companyId, status, start, end, null);
3979            }
3980    
3981            /**
3982             * Returns an ordered range of all the document library folders where companyId = &#63; and status &ne; &#63;.
3983             *
3984             * <p>
3985             * 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.
3986             * </p>
3987             *
3988             * @param companyId the company ID
3989             * @param status the status
3990             * @param start the lower bound of the range of document library folders
3991             * @param end the upper bound of the range of document library folders (not inclusive)
3992             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3993             * @return the ordered range of matching document library folders
3994             * @throws SystemException if a system exception occurred
3995             */
3996            @Override
3997            public List<DLFolder> findByC_NotS(long companyId, int status, int start,
3998                    int end, OrderByComparator orderByComparator) throws SystemException {
3999                    boolean pagination = true;
4000                    FinderPath finderPath = null;
4001                    Object[] finderArgs = null;
4002    
4003                    finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_NOTS;
4004                    finderArgs = new Object[] {
4005                                    companyId, status,
4006                                    
4007                                    start, end, orderByComparator
4008                            };
4009    
4010                    List<DLFolder> list = (List<DLFolder>)FinderCacheUtil.getResult(finderPath,
4011                                    finderArgs, this);
4012    
4013                    if ((list != null) && !list.isEmpty()) {
4014                            for (DLFolder dlFolder : list) {
4015                                    if ((companyId != dlFolder.getCompanyId()) ||
4016                                                    (status != dlFolder.getStatus())) {
4017                                            list = null;
4018    
4019                                            break;
4020                                    }
4021                            }
4022                    }
4023    
4024                    if (list == null) {
4025                            StringBundler query = null;
4026    
4027                            if (orderByComparator != null) {
4028                                    query = new StringBundler(4 +
4029                                                    (orderByComparator.getOrderByFields().length * 3));
4030                            }
4031                            else {
4032                                    query = new StringBundler(4);
4033                            }
4034    
4035                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
4036    
4037                            query.append(_FINDER_COLUMN_C_NOTS_COMPANYID_2);
4038    
4039                            query.append(_FINDER_COLUMN_C_NOTS_STATUS_2);
4040    
4041                            if (orderByComparator != null) {
4042                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4043                                            orderByComparator);
4044                            }
4045                            else
4046                             if (pagination) {
4047                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
4048                            }
4049    
4050                            String sql = query.toString();
4051    
4052                            Session session = null;
4053    
4054                            try {
4055                                    session = openSession();
4056    
4057                                    Query q = session.createQuery(sql);
4058    
4059                                    QueryPos qPos = QueryPos.getInstance(q);
4060    
4061                                    qPos.add(companyId);
4062    
4063                                    qPos.add(status);
4064    
4065                                    if (!pagination) {
4066                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
4067                                                            start, end, false);
4068    
4069                                            Collections.sort(list);
4070    
4071                                            list = new UnmodifiableList<DLFolder>(list);
4072                                    }
4073                                    else {
4074                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
4075                                                            start, end);
4076                                    }
4077    
4078                                    cacheResult(list);
4079    
4080                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
4081                            }
4082                            catch (Exception e) {
4083                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4084    
4085                                    throw processException(e);
4086                            }
4087                            finally {
4088                                    closeSession(session);
4089                            }
4090                    }
4091    
4092                    return list;
4093            }
4094    
4095            /**
4096             * Returns the first document library folder in the ordered set where companyId = &#63; and status &ne; &#63;.
4097             *
4098             * @param companyId the company ID
4099             * @param status the status
4100             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4101             * @return the first matching document library folder
4102             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
4103             * @throws SystemException if a system exception occurred
4104             */
4105            @Override
4106            public DLFolder findByC_NotS_First(long companyId, int status,
4107                    OrderByComparator orderByComparator)
4108                    throws NoSuchFolderException, SystemException {
4109                    DLFolder dlFolder = fetchByC_NotS_First(companyId, status,
4110                                    orderByComparator);
4111    
4112                    if (dlFolder != null) {
4113                            return dlFolder;
4114                    }
4115    
4116                    StringBundler msg = new StringBundler(6);
4117    
4118                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4119    
4120                    msg.append("companyId=");
4121                    msg.append(companyId);
4122    
4123                    msg.append(", status=");
4124                    msg.append(status);
4125    
4126                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4127    
4128                    throw new NoSuchFolderException(msg.toString());
4129            }
4130    
4131            /**
4132             * Returns the first document library folder in the ordered set where companyId = &#63; and status &ne; &#63;.
4133             *
4134             * @param companyId the company ID
4135             * @param status the status
4136             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4137             * @return the first matching document library folder, or <code>null</code> if a matching document library folder could not be found
4138             * @throws SystemException if a system exception occurred
4139             */
4140            @Override
4141            public DLFolder fetchByC_NotS_First(long companyId, int status,
4142                    OrderByComparator orderByComparator) throws SystemException {
4143                    List<DLFolder> list = findByC_NotS(companyId, status, 0, 1,
4144                                    orderByComparator);
4145    
4146                    if (!list.isEmpty()) {
4147                            return list.get(0);
4148                    }
4149    
4150                    return null;
4151            }
4152    
4153            /**
4154             * Returns the last document library folder in the ordered set where companyId = &#63; and status &ne; &#63;.
4155             *
4156             * @param companyId the company ID
4157             * @param status the status
4158             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4159             * @return the last matching document library folder
4160             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
4161             * @throws SystemException if a system exception occurred
4162             */
4163            @Override
4164            public DLFolder findByC_NotS_Last(long companyId, int status,
4165                    OrderByComparator orderByComparator)
4166                    throws NoSuchFolderException, SystemException {
4167                    DLFolder dlFolder = fetchByC_NotS_Last(companyId, status,
4168                                    orderByComparator);
4169    
4170                    if (dlFolder != null) {
4171                            return dlFolder;
4172                    }
4173    
4174                    StringBundler msg = new StringBundler(6);
4175    
4176                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4177    
4178                    msg.append("companyId=");
4179                    msg.append(companyId);
4180    
4181                    msg.append(", status=");
4182                    msg.append(status);
4183    
4184                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4185    
4186                    throw new NoSuchFolderException(msg.toString());
4187            }
4188    
4189            /**
4190             * Returns the last document library folder in the ordered set where companyId = &#63; and status &ne; &#63;.
4191             *
4192             * @param companyId the company ID
4193             * @param status the status
4194             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4195             * @return the last matching document library folder, or <code>null</code> if a matching document library folder could not be found
4196             * @throws SystemException if a system exception occurred
4197             */
4198            @Override
4199            public DLFolder fetchByC_NotS_Last(long companyId, int status,
4200                    OrderByComparator orderByComparator) throws SystemException {
4201                    int count = countByC_NotS(companyId, status);
4202    
4203                    if (count == 0) {
4204                            return null;
4205                    }
4206    
4207                    List<DLFolder> list = findByC_NotS(companyId, status, count - 1, count,
4208                                    orderByComparator);
4209    
4210                    if (!list.isEmpty()) {
4211                            return list.get(0);
4212                    }
4213    
4214                    return null;
4215            }
4216    
4217            /**
4218             * Returns the document library folders before and after the current document library folder in the ordered set where companyId = &#63; and status &ne; &#63;.
4219             *
4220             * @param folderId the primary key of the current document library folder
4221             * @param companyId the company ID
4222             * @param status the status
4223             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4224             * @return the previous, current, and next document library folder
4225             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
4226             * @throws SystemException if a system exception occurred
4227             */
4228            @Override
4229            public DLFolder[] findByC_NotS_PrevAndNext(long folderId, long companyId,
4230                    int status, OrderByComparator orderByComparator)
4231                    throws NoSuchFolderException, SystemException {
4232                    DLFolder dlFolder = findByPrimaryKey(folderId);
4233    
4234                    Session session = null;
4235    
4236                    try {
4237                            session = openSession();
4238    
4239                            DLFolder[] array = new DLFolderImpl[3];
4240    
4241                            array[0] = getByC_NotS_PrevAndNext(session, dlFolder, companyId,
4242                                            status, orderByComparator, true);
4243    
4244                            array[1] = dlFolder;
4245    
4246                            array[2] = getByC_NotS_PrevAndNext(session, dlFolder, companyId,
4247                                            status, orderByComparator, false);
4248    
4249                            return array;
4250                    }
4251                    catch (Exception e) {
4252                            throw processException(e);
4253                    }
4254                    finally {
4255                            closeSession(session);
4256                    }
4257            }
4258    
4259            protected DLFolder getByC_NotS_PrevAndNext(Session session,
4260                    DLFolder dlFolder, long companyId, int status,
4261                    OrderByComparator orderByComparator, boolean previous) {
4262                    StringBundler query = null;
4263    
4264                    if (orderByComparator != null) {
4265                            query = new StringBundler(6 +
4266                                            (orderByComparator.getOrderByFields().length * 6));
4267                    }
4268                    else {
4269                            query = new StringBundler(3);
4270                    }
4271    
4272                    query.append(_SQL_SELECT_DLFOLDER_WHERE);
4273    
4274                    query.append(_FINDER_COLUMN_C_NOTS_COMPANYID_2);
4275    
4276                    query.append(_FINDER_COLUMN_C_NOTS_STATUS_2);
4277    
4278                    if (orderByComparator != null) {
4279                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4280    
4281                            if (orderByConditionFields.length > 0) {
4282                                    query.append(WHERE_AND);
4283                            }
4284    
4285                            for (int i = 0; i < orderByConditionFields.length; i++) {
4286                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4287                                    query.append(orderByConditionFields[i]);
4288    
4289                                    if ((i + 1) < orderByConditionFields.length) {
4290                                            if (orderByComparator.isAscending() ^ previous) {
4291                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4292                                            }
4293                                            else {
4294                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4295                                            }
4296                                    }
4297                                    else {
4298                                            if (orderByComparator.isAscending() ^ previous) {
4299                                                    query.append(WHERE_GREATER_THAN);
4300                                            }
4301                                            else {
4302                                                    query.append(WHERE_LESSER_THAN);
4303                                            }
4304                                    }
4305                            }
4306    
4307                            query.append(ORDER_BY_CLAUSE);
4308    
4309                            String[] orderByFields = orderByComparator.getOrderByFields();
4310    
4311                            for (int i = 0; i < orderByFields.length; i++) {
4312                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4313                                    query.append(orderByFields[i]);
4314    
4315                                    if ((i + 1) < orderByFields.length) {
4316                                            if (orderByComparator.isAscending() ^ previous) {
4317                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4318                                            }
4319                                            else {
4320                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4321                                            }
4322                                    }
4323                                    else {
4324                                            if (orderByComparator.isAscending() ^ previous) {
4325                                                    query.append(ORDER_BY_ASC);
4326                                            }
4327                                            else {
4328                                                    query.append(ORDER_BY_DESC);
4329                                            }
4330                                    }
4331                            }
4332                    }
4333                    else {
4334                            query.append(DLFolderModelImpl.ORDER_BY_JPQL);
4335                    }
4336    
4337                    String sql = query.toString();
4338    
4339                    Query q = session.createQuery(sql);
4340    
4341                    q.setFirstResult(0);
4342                    q.setMaxResults(2);
4343    
4344                    QueryPos qPos = QueryPos.getInstance(q);
4345    
4346                    qPos.add(companyId);
4347    
4348                    qPos.add(status);
4349    
4350                    if (orderByComparator != null) {
4351                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
4352    
4353                            for (Object value : values) {
4354                                    qPos.add(value);
4355                            }
4356                    }
4357    
4358                    List<DLFolder> list = q.list();
4359    
4360                    if (list.size() == 2) {
4361                            return list.get(1);
4362                    }
4363                    else {
4364                            return null;
4365                    }
4366            }
4367    
4368            /**
4369             * Removes all the document library folders where companyId = &#63; and status &ne; &#63; from the database.
4370             *
4371             * @param companyId the company ID
4372             * @param status the status
4373             * @throws SystemException if a system exception occurred
4374             */
4375            @Override
4376            public void removeByC_NotS(long companyId, int status)
4377                    throws SystemException {
4378                    for (DLFolder dlFolder : findByC_NotS(companyId, status,
4379                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4380                            remove(dlFolder);
4381                    }
4382            }
4383    
4384            /**
4385             * Returns the number of document library folders where companyId = &#63; and status &ne; &#63;.
4386             *
4387             * @param companyId the company ID
4388             * @param status the status
4389             * @return the number of matching document library folders
4390             * @throws SystemException if a system exception occurred
4391             */
4392            @Override
4393            public int countByC_NotS(long companyId, int status)
4394                    throws SystemException {
4395                    FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_NOTS;
4396    
4397                    Object[] finderArgs = new Object[] { companyId, status };
4398    
4399                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4400                                    this);
4401    
4402                    if (count == null) {
4403                            StringBundler query = new StringBundler(3);
4404    
4405                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
4406    
4407                            query.append(_FINDER_COLUMN_C_NOTS_COMPANYID_2);
4408    
4409                            query.append(_FINDER_COLUMN_C_NOTS_STATUS_2);
4410    
4411                            String sql = query.toString();
4412    
4413                            Session session = null;
4414    
4415                            try {
4416                                    session = openSession();
4417    
4418                                    Query q = session.createQuery(sql);
4419    
4420                                    QueryPos qPos = QueryPos.getInstance(q);
4421    
4422                                    qPos.add(companyId);
4423    
4424                                    qPos.add(status);
4425    
4426                                    count = (Long)q.uniqueResult();
4427    
4428                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
4429                            }
4430                            catch (Exception e) {
4431                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4432    
4433                                    throw processException(e);
4434                            }
4435                            finally {
4436                                    closeSession(session);
4437                            }
4438                    }
4439    
4440                    return count.intValue();
4441            }
4442    
4443            private static final String _FINDER_COLUMN_C_NOTS_COMPANYID_2 = "dlFolder.companyId = ? AND ";
4444            private static final String _FINDER_COLUMN_C_NOTS_STATUS_2 = "dlFolder.status != ?";
4445            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_P_N = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
4446                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
4447                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByP_N",
4448                            new String[] {
4449                                    Long.class.getName(), String.class.getName(),
4450                                    
4451                            Integer.class.getName(), Integer.class.getName(),
4452                                    OrderByComparator.class.getName()
4453                            });
4454            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_N = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
4455                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
4456                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByP_N",
4457                            new String[] { Long.class.getName(), String.class.getName() },
4458                            DLFolderModelImpl.PARENTFOLDERID_COLUMN_BITMASK |
4459                            DLFolderModelImpl.NAME_COLUMN_BITMASK);
4460            public static final FinderPath FINDER_PATH_COUNT_BY_P_N = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
4461                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
4462                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByP_N",
4463                            new String[] { Long.class.getName(), String.class.getName() });
4464    
4465            /**
4466             * Returns all the document library folders where parentFolderId = &#63; and name = &#63;.
4467             *
4468             * @param parentFolderId the parent folder ID
4469             * @param name the name
4470             * @return the matching document library folders
4471             * @throws SystemException if a system exception occurred
4472             */
4473            @Override
4474            public List<DLFolder> findByP_N(long parentFolderId, String name)
4475                    throws SystemException {
4476                    return findByP_N(parentFolderId, name, QueryUtil.ALL_POS,
4477                            QueryUtil.ALL_POS, null);
4478            }
4479    
4480            /**
4481             * Returns a range of all the document library folders where parentFolderId = &#63; and name = &#63;.
4482             *
4483             * <p>
4484             * 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.
4485             * </p>
4486             *
4487             * @param parentFolderId the parent folder ID
4488             * @param name the name
4489             * @param start the lower bound of the range of document library folders
4490             * @param end the upper bound of the range of document library folders (not inclusive)
4491             * @return the range of matching document library folders
4492             * @throws SystemException if a system exception occurred
4493             */
4494            @Override
4495            public List<DLFolder> findByP_N(long parentFolderId, String name,
4496                    int start, int end) throws SystemException {
4497                    return findByP_N(parentFolderId, name, start, end, null);
4498            }
4499    
4500            /**
4501             * Returns an ordered range of all the document library folders where parentFolderId = &#63; and name = &#63;.
4502             *
4503             * <p>
4504             * 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.
4505             * </p>
4506             *
4507             * @param parentFolderId the parent folder ID
4508             * @param name the name
4509             * @param start the lower bound of the range of document library folders
4510             * @param end the upper bound of the range of document library folders (not inclusive)
4511             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4512             * @return the ordered range of matching document library folders
4513             * @throws SystemException if a system exception occurred
4514             */
4515            @Override
4516            public List<DLFolder> findByP_N(long parentFolderId, String name,
4517                    int start, int end, OrderByComparator orderByComparator)
4518                    throws SystemException {
4519                    boolean pagination = true;
4520                    FinderPath finderPath = null;
4521                    Object[] finderArgs = null;
4522    
4523                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4524                                    (orderByComparator == null)) {
4525                            pagination = false;
4526                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_N;
4527                            finderArgs = new Object[] { parentFolderId, name };
4528                    }
4529                    else {
4530                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_P_N;
4531                            finderArgs = new Object[] {
4532                                            parentFolderId, name,
4533                                            
4534                                            start, end, orderByComparator
4535                                    };
4536                    }
4537    
4538                    List<DLFolder> list = (List<DLFolder>)FinderCacheUtil.getResult(finderPath,
4539                                    finderArgs, this);
4540    
4541                    if ((list != null) && !list.isEmpty()) {
4542                            for (DLFolder dlFolder : list) {
4543                                    if ((parentFolderId != dlFolder.getParentFolderId()) ||
4544                                                    !Validator.equals(name, dlFolder.getName())) {
4545                                            list = null;
4546    
4547                                            break;
4548                                    }
4549                            }
4550                    }
4551    
4552                    if (list == null) {
4553                            StringBundler query = null;
4554    
4555                            if (orderByComparator != null) {
4556                                    query = new StringBundler(4 +
4557                                                    (orderByComparator.getOrderByFields().length * 3));
4558                            }
4559                            else {
4560                                    query = new StringBundler(4);
4561                            }
4562    
4563                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
4564    
4565                            query.append(_FINDER_COLUMN_P_N_PARENTFOLDERID_2);
4566    
4567                            boolean bindName = false;
4568    
4569                            if (name == null) {
4570                                    query.append(_FINDER_COLUMN_P_N_NAME_1);
4571                            }
4572                            else if (name.equals(StringPool.BLANK)) {
4573                                    query.append(_FINDER_COLUMN_P_N_NAME_3);
4574                            }
4575                            else {
4576                                    bindName = true;
4577    
4578                                    query.append(_FINDER_COLUMN_P_N_NAME_2);
4579                            }
4580    
4581                            if (orderByComparator != null) {
4582                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4583                                            orderByComparator);
4584                            }
4585                            else
4586                             if (pagination) {
4587                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
4588                            }
4589    
4590                            String sql = query.toString();
4591    
4592                            Session session = null;
4593    
4594                            try {
4595                                    session = openSession();
4596    
4597                                    Query q = session.createQuery(sql);
4598    
4599                                    QueryPos qPos = QueryPos.getInstance(q);
4600    
4601                                    qPos.add(parentFolderId);
4602    
4603                                    if (bindName) {
4604                                            qPos.add(name);
4605                                    }
4606    
4607                                    if (!pagination) {
4608                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
4609                                                            start, end, false);
4610    
4611                                            Collections.sort(list);
4612    
4613                                            list = new UnmodifiableList<DLFolder>(list);
4614                                    }
4615                                    else {
4616                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
4617                                                            start, end);
4618                                    }
4619    
4620                                    cacheResult(list);
4621    
4622                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
4623                            }
4624                            catch (Exception e) {
4625                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4626    
4627                                    throw processException(e);
4628                            }
4629                            finally {
4630                                    closeSession(session);
4631                            }
4632                    }
4633    
4634                    return list;
4635            }
4636    
4637            /**
4638             * Returns the first document library folder in the ordered set where parentFolderId = &#63; and name = &#63;.
4639             *
4640             * @param parentFolderId the parent folder ID
4641             * @param name the name
4642             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4643             * @return the first matching document library folder
4644             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
4645             * @throws SystemException if a system exception occurred
4646             */
4647            @Override
4648            public DLFolder findByP_N_First(long parentFolderId, String name,
4649                    OrderByComparator orderByComparator)
4650                    throws NoSuchFolderException, SystemException {
4651                    DLFolder dlFolder = fetchByP_N_First(parentFolderId, name,
4652                                    orderByComparator);
4653    
4654                    if (dlFolder != null) {
4655                            return dlFolder;
4656                    }
4657    
4658                    StringBundler msg = new StringBundler(6);
4659    
4660                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4661    
4662                    msg.append("parentFolderId=");
4663                    msg.append(parentFolderId);
4664    
4665                    msg.append(", name=");
4666                    msg.append(name);
4667    
4668                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4669    
4670                    throw new NoSuchFolderException(msg.toString());
4671            }
4672    
4673            /**
4674             * Returns the first document library folder in the ordered set where parentFolderId = &#63; and name = &#63;.
4675             *
4676             * @param parentFolderId the parent folder ID
4677             * @param name the name
4678             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4679             * @return the first matching document library folder, or <code>null</code> if a matching document library folder could not be found
4680             * @throws SystemException if a system exception occurred
4681             */
4682            @Override
4683            public DLFolder fetchByP_N_First(long parentFolderId, String name,
4684                    OrderByComparator orderByComparator) throws SystemException {
4685                    List<DLFolder> list = findByP_N(parentFolderId, name, 0, 1,
4686                                    orderByComparator);
4687    
4688                    if (!list.isEmpty()) {
4689                            return list.get(0);
4690                    }
4691    
4692                    return null;
4693            }
4694    
4695            /**
4696             * Returns the last document library folder in the ordered set where parentFolderId = &#63; and name = &#63;.
4697             *
4698             * @param parentFolderId the parent folder ID
4699             * @param name the name
4700             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4701             * @return the last matching document library folder
4702             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
4703             * @throws SystemException if a system exception occurred
4704             */
4705            @Override
4706            public DLFolder findByP_N_Last(long parentFolderId, String name,
4707                    OrderByComparator orderByComparator)
4708                    throws NoSuchFolderException, SystemException {
4709                    DLFolder dlFolder = fetchByP_N_Last(parentFolderId, name,
4710                                    orderByComparator);
4711    
4712                    if (dlFolder != null) {
4713                            return dlFolder;
4714                    }
4715    
4716                    StringBundler msg = new StringBundler(6);
4717    
4718                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4719    
4720                    msg.append("parentFolderId=");
4721                    msg.append(parentFolderId);
4722    
4723                    msg.append(", name=");
4724                    msg.append(name);
4725    
4726                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4727    
4728                    throw new NoSuchFolderException(msg.toString());
4729            }
4730    
4731            /**
4732             * Returns the last document library folder in the ordered set where parentFolderId = &#63; and name = &#63;.
4733             *
4734             * @param parentFolderId the parent folder ID
4735             * @param name the name
4736             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4737             * @return the last matching document library folder, or <code>null</code> if a matching document library folder could not be found
4738             * @throws SystemException if a system exception occurred
4739             */
4740            @Override
4741            public DLFolder fetchByP_N_Last(long parentFolderId, String name,
4742                    OrderByComparator orderByComparator) throws SystemException {
4743                    int count = countByP_N(parentFolderId, name);
4744    
4745                    if (count == 0) {
4746                            return null;
4747                    }
4748    
4749                    List<DLFolder> list = findByP_N(parentFolderId, name, count - 1, count,
4750                                    orderByComparator);
4751    
4752                    if (!list.isEmpty()) {
4753                            return list.get(0);
4754                    }
4755    
4756                    return null;
4757            }
4758    
4759            /**
4760             * Returns the document library folders before and after the current document library folder in the ordered set where parentFolderId = &#63; and name = &#63;.
4761             *
4762             * @param folderId the primary key of the current document library folder
4763             * @param parentFolderId the parent folder ID
4764             * @param name the name
4765             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4766             * @return the previous, current, and next document library folder
4767             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
4768             * @throws SystemException if a system exception occurred
4769             */
4770            @Override
4771            public DLFolder[] findByP_N_PrevAndNext(long folderId, long parentFolderId,
4772                    String name, OrderByComparator orderByComparator)
4773                    throws NoSuchFolderException, SystemException {
4774                    DLFolder dlFolder = findByPrimaryKey(folderId);
4775    
4776                    Session session = null;
4777    
4778                    try {
4779                            session = openSession();
4780    
4781                            DLFolder[] array = new DLFolderImpl[3];
4782    
4783                            array[0] = getByP_N_PrevAndNext(session, dlFolder, parentFolderId,
4784                                            name, orderByComparator, true);
4785    
4786                            array[1] = dlFolder;
4787    
4788                            array[2] = getByP_N_PrevAndNext(session, dlFolder, parentFolderId,
4789                                            name, orderByComparator, false);
4790    
4791                            return array;
4792                    }
4793                    catch (Exception e) {
4794                            throw processException(e);
4795                    }
4796                    finally {
4797                            closeSession(session);
4798                    }
4799            }
4800    
4801            protected DLFolder getByP_N_PrevAndNext(Session session, DLFolder dlFolder,
4802                    long parentFolderId, String name, OrderByComparator orderByComparator,
4803                    boolean previous) {
4804                    StringBundler query = null;
4805    
4806                    if (orderByComparator != null) {
4807                            query = new StringBundler(6 +
4808                                            (orderByComparator.getOrderByFields().length * 6));
4809                    }
4810                    else {
4811                            query = new StringBundler(3);
4812                    }
4813    
4814                    query.append(_SQL_SELECT_DLFOLDER_WHERE);
4815    
4816                    query.append(_FINDER_COLUMN_P_N_PARENTFOLDERID_2);
4817    
4818                    boolean bindName = false;
4819    
4820                    if (name == null) {
4821                            query.append(_FINDER_COLUMN_P_N_NAME_1);
4822                    }
4823                    else if (name.equals(StringPool.BLANK)) {
4824                            query.append(_FINDER_COLUMN_P_N_NAME_3);
4825                    }
4826                    else {
4827                            bindName = true;
4828    
4829                            query.append(_FINDER_COLUMN_P_N_NAME_2);
4830                    }
4831    
4832                    if (orderByComparator != null) {
4833                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4834    
4835                            if (orderByConditionFields.length > 0) {
4836                                    query.append(WHERE_AND);
4837                            }
4838    
4839                            for (int i = 0; i < orderByConditionFields.length; i++) {
4840                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4841                                    query.append(orderByConditionFields[i]);
4842    
4843                                    if ((i + 1) < orderByConditionFields.length) {
4844                                            if (orderByComparator.isAscending() ^ previous) {
4845                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4846                                            }
4847                                            else {
4848                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4849                                            }
4850                                    }
4851                                    else {
4852                                            if (orderByComparator.isAscending() ^ previous) {
4853                                                    query.append(WHERE_GREATER_THAN);
4854                                            }
4855                                            else {
4856                                                    query.append(WHERE_LESSER_THAN);
4857                                            }
4858                                    }
4859                            }
4860    
4861                            query.append(ORDER_BY_CLAUSE);
4862    
4863                            String[] orderByFields = orderByComparator.getOrderByFields();
4864    
4865                            for (int i = 0; i < orderByFields.length; i++) {
4866                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4867                                    query.append(orderByFields[i]);
4868    
4869                                    if ((i + 1) < orderByFields.length) {
4870                                            if (orderByComparator.isAscending() ^ previous) {
4871                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4872                                            }
4873                                            else {
4874                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4875                                            }
4876                                    }
4877                                    else {
4878                                            if (orderByComparator.isAscending() ^ previous) {
4879                                                    query.append(ORDER_BY_ASC);
4880                                            }
4881                                            else {
4882                                                    query.append(ORDER_BY_DESC);
4883                                            }
4884                                    }
4885                            }
4886                    }
4887                    else {
4888                            query.append(DLFolderModelImpl.ORDER_BY_JPQL);
4889                    }
4890    
4891                    String sql = query.toString();
4892    
4893                    Query q = session.createQuery(sql);
4894    
4895                    q.setFirstResult(0);
4896                    q.setMaxResults(2);
4897    
4898                    QueryPos qPos = QueryPos.getInstance(q);
4899    
4900                    qPos.add(parentFolderId);
4901    
4902                    if (bindName) {
4903                            qPos.add(name);
4904                    }
4905    
4906                    if (orderByComparator != null) {
4907                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
4908    
4909                            for (Object value : values) {
4910                                    qPos.add(value);
4911                            }
4912                    }
4913    
4914                    List<DLFolder> list = q.list();
4915    
4916                    if (list.size() == 2) {
4917                            return list.get(1);
4918                    }
4919                    else {
4920                            return null;
4921                    }
4922            }
4923    
4924            /**
4925             * Removes all the document library folders where parentFolderId = &#63; and name = &#63; from the database.
4926             *
4927             * @param parentFolderId the parent folder ID
4928             * @param name the name
4929             * @throws SystemException if a system exception occurred
4930             */
4931            @Override
4932            public void removeByP_N(long parentFolderId, String name)
4933                    throws SystemException {
4934                    for (DLFolder dlFolder : findByP_N(parentFolderId, name,
4935                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4936                            remove(dlFolder);
4937                    }
4938            }
4939    
4940            /**
4941             * Returns the number of document library folders where parentFolderId = &#63; and name = &#63;.
4942             *
4943             * @param parentFolderId the parent folder ID
4944             * @param name the name
4945             * @return the number of matching document library folders
4946             * @throws SystemException if a system exception occurred
4947             */
4948            @Override
4949            public int countByP_N(long parentFolderId, String name)
4950                    throws SystemException {
4951                    FinderPath finderPath = FINDER_PATH_COUNT_BY_P_N;
4952    
4953                    Object[] finderArgs = new Object[] { parentFolderId, name };
4954    
4955                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4956                                    this);
4957    
4958                    if (count == null) {
4959                            StringBundler query = new StringBundler(3);
4960    
4961                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
4962    
4963                            query.append(_FINDER_COLUMN_P_N_PARENTFOLDERID_2);
4964    
4965                            boolean bindName = false;
4966    
4967                            if (name == null) {
4968                                    query.append(_FINDER_COLUMN_P_N_NAME_1);
4969                            }
4970                            else if (name.equals(StringPool.BLANK)) {
4971                                    query.append(_FINDER_COLUMN_P_N_NAME_3);
4972                            }
4973                            else {
4974                                    bindName = true;
4975    
4976                                    query.append(_FINDER_COLUMN_P_N_NAME_2);
4977                            }
4978    
4979                            String sql = query.toString();
4980    
4981                            Session session = null;
4982    
4983                            try {
4984                                    session = openSession();
4985    
4986                                    Query q = session.createQuery(sql);
4987    
4988                                    QueryPos qPos = QueryPos.getInstance(q);
4989    
4990                                    qPos.add(parentFolderId);
4991    
4992                                    if (bindName) {
4993                                            qPos.add(name);
4994                                    }
4995    
4996                                    count = (Long)q.uniqueResult();
4997    
4998                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
4999                            }
5000                            catch (Exception e) {
5001                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5002    
5003                                    throw processException(e);
5004                            }
5005                            finally {
5006                                    closeSession(session);
5007                            }
5008                    }
5009    
5010                    return count.intValue();
5011            }
5012    
5013            private static final String _FINDER_COLUMN_P_N_PARENTFOLDERID_2 = "dlFolder.parentFolderId = ? AND ";
5014            private static final String _FINDER_COLUMN_P_N_NAME_1 = "dlFolder.name IS NULL";
5015            private static final String _FINDER_COLUMN_P_N_NAME_2 = "dlFolder.name = ?";
5016            private static final String _FINDER_COLUMN_P_N_NAME_3 = "(dlFolder.name IS NULL OR dlFolder.name = '')";
5017            public static final FinderPath FINDER_PATH_FETCH_BY_G_P_N = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
5018                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
5019                            FINDER_CLASS_NAME_ENTITY, "fetchByG_P_N",
5020                            new String[] {
5021                                    Long.class.getName(), Long.class.getName(),
5022                                    String.class.getName()
5023                            },
5024                            DLFolderModelImpl.GROUPID_COLUMN_BITMASK |
5025                            DLFolderModelImpl.PARENTFOLDERID_COLUMN_BITMASK |
5026                            DLFolderModelImpl.NAME_COLUMN_BITMASK);
5027            public static final FinderPath FINDER_PATH_COUNT_BY_G_P_N = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
5028                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
5029                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P_N",
5030                            new String[] {
5031                                    Long.class.getName(), Long.class.getName(),
5032                                    String.class.getName()
5033                            });
5034    
5035            /**
5036             * 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.
5037             *
5038             * @param groupId the group ID
5039             * @param parentFolderId the parent folder ID
5040             * @param name the name
5041             * @return the matching document library folder
5042             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
5043             * @throws SystemException if a system exception occurred
5044             */
5045            @Override
5046            public DLFolder findByG_P_N(long groupId, long parentFolderId, String name)
5047                    throws NoSuchFolderException, SystemException {
5048                    DLFolder dlFolder = fetchByG_P_N(groupId, parentFolderId, name);
5049    
5050                    if (dlFolder == null) {
5051                            StringBundler msg = new StringBundler(8);
5052    
5053                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5054    
5055                            msg.append("groupId=");
5056                            msg.append(groupId);
5057    
5058                            msg.append(", parentFolderId=");
5059                            msg.append(parentFolderId);
5060    
5061                            msg.append(", name=");
5062                            msg.append(name);
5063    
5064                            msg.append(StringPool.CLOSE_CURLY_BRACE);
5065    
5066                            if (_log.isWarnEnabled()) {
5067                                    _log.warn(msg.toString());
5068                            }
5069    
5070                            throw new NoSuchFolderException(msg.toString());
5071                    }
5072    
5073                    return dlFolder;
5074            }
5075    
5076            /**
5077             * 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.
5078             *
5079             * @param groupId the group ID
5080             * @param parentFolderId the parent folder ID
5081             * @param name the name
5082             * @return the matching document library folder, or <code>null</code> if a matching document library folder could not be found
5083             * @throws SystemException if a system exception occurred
5084             */
5085            @Override
5086            public DLFolder fetchByG_P_N(long groupId, long parentFolderId, String name)
5087                    throws SystemException {
5088                    return fetchByG_P_N(groupId, parentFolderId, name, true);
5089            }
5090    
5091            /**
5092             * 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.
5093             *
5094             * @param groupId the group ID
5095             * @param parentFolderId the parent folder ID
5096             * @param name the name
5097             * @param retrieveFromCache whether to use the finder cache
5098             * @return the matching document library folder, or <code>null</code> if a matching document library folder could not be found
5099             * @throws SystemException if a system exception occurred
5100             */
5101            @Override
5102            public DLFolder fetchByG_P_N(long groupId, long parentFolderId,
5103                    String name, boolean retrieveFromCache) throws SystemException {
5104                    Object[] finderArgs = new Object[] { groupId, parentFolderId, name };
5105    
5106                    Object result = null;
5107    
5108                    if (retrieveFromCache) {
5109                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_P_N,
5110                                            finderArgs, this);
5111                    }
5112    
5113                    if (result instanceof DLFolder) {
5114                            DLFolder dlFolder = (DLFolder)result;
5115    
5116                            if ((groupId != dlFolder.getGroupId()) ||
5117                                            (parentFolderId != dlFolder.getParentFolderId()) ||
5118                                            !Validator.equals(name, dlFolder.getName())) {
5119                                    result = null;
5120                            }
5121                    }
5122    
5123                    if (result == null) {
5124                            StringBundler query = new StringBundler(5);
5125    
5126                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
5127    
5128                            query.append(_FINDER_COLUMN_G_P_N_GROUPID_2);
5129    
5130                            query.append(_FINDER_COLUMN_G_P_N_PARENTFOLDERID_2);
5131    
5132                            boolean bindName = false;
5133    
5134                            if (name == null) {
5135                                    query.append(_FINDER_COLUMN_G_P_N_NAME_1);
5136                            }
5137                            else if (name.equals(StringPool.BLANK)) {
5138                                    query.append(_FINDER_COLUMN_G_P_N_NAME_3);
5139                            }
5140                            else {
5141                                    bindName = true;
5142    
5143                                    query.append(_FINDER_COLUMN_G_P_N_NAME_2);
5144                            }
5145    
5146                            String sql = query.toString();
5147    
5148                            Session session = null;
5149    
5150                            try {
5151                                    session = openSession();
5152    
5153                                    Query q = session.createQuery(sql);
5154    
5155                                    QueryPos qPos = QueryPos.getInstance(q);
5156    
5157                                    qPos.add(groupId);
5158    
5159                                    qPos.add(parentFolderId);
5160    
5161                                    if (bindName) {
5162                                            qPos.add(name);
5163                                    }
5164    
5165                                    List<DLFolder> list = q.list();
5166    
5167                                    if (list.isEmpty()) {
5168                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_N,
5169                                                    finderArgs, list);
5170                                    }
5171                                    else {
5172                                            DLFolder dlFolder = list.get(0);
5173    
5174                                            result = dlFolder;
5175    
5176                                            cacheResult(dlFolder);
5177    
5178                                            if ((dlFolder.getGroupId() != groupId) ||
5179                                                            (dlFolder.getParentFolderId() != parentFolderId) ||
5180                                                            (dlFolder.getName() == null) ||
5181                                                            !dlFolder.getName().equals(name)) {
5182                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_N,
5183                                                            finderArgs, dlFolder);
5184                                            }
5185                                    }
5186                            }
5187                            catch (Exception e) {
5188                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P_N,
5189                                            finderArgs);
5190    
5191                                    throw processException(e);
5192                            }
5193                            finally {
5194                                    closeSession(session);
5195                            }
5196                    }
5197    
5198                    if (result instanceof List<?>) {
5199                            return null;
5200                    }
5201                    else {
5202                            return (DLFolder)result;
5203                    }
5204            }
5205    
5206            /**
5207             * Removes the document library folder where groupId = &#63; and parentFolderId = &#63; and name = &#63; from the database.
5208             *
5209             * @param groupId the group ID
5210             * @param parentFolderId the parent folder ID
5211             * @param name the name
5212             * @return the document library folder that was removed
5213             * @throws SystemException if a system exception occurred
5214             */
5215            @Override
5216            public DLFolder removeByG_P_N(long groupId, long parentFolderId, String name)
5217                    throws NoSuchFolderException, SystemException {
5218                    DLFolder dlFolder = findByG_P_N(groupId, parentFolderId, name);
5219    
5220                    return remove(dlFolder);
5221            }
5222    
5223            /**
5224             * Returns the number of document library folders where groupId = &#63; and parentFolderId = &#63; and name = &#63;.
5225             *
5226             * @param groupId the group ID
5227             * @param parentFolderId the parent folder ID
5228             * @param name the name
5229             * @return the number of matching document library folders
5230             * @throws SystemException if a system exception occurred
5231             */
5232            @Override
5233            public int countByG_P_N(long groupId, long parentFolderId, String name)
5234                    throws SystemException {
5235                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_P_N;
5236    
5237                    Object[] finderArgs = new Object[] { groupId, parentFolderId, name };
5238    
5239                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5240                                    this);
5241    
5242                    if (count == null) {
5243                            StringBundler query = new StringBundler(4);
5244    
5245                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
5246    
5247                            query.append(_FINDER_COLUMN_G_P_N_GROUPID_2);
5248    
5249                            query.append(_FINDER_COLUMN_G_P_N_PARENTFOLDERID_2);
5250    
5251                            boolean bindName = false;
5252    
5253                            if (name == null) {
5254                                    query.append(_FINDER_COLUMN_G_P_N_NAME_1);
5255                            }
5256                            else if (name.equals(StringPool.BLANK)) {
5257                                    query.append(_FINDER_COLUMN_G_P_N_NAME_3);
5258                            }
5259                            else {
5260                                    bindName = true;
5261    
5262                                    query.append(_FINDER_COLUMN_G_P_N_NAME_2);
5263                            }
5264    
5265                            String sql = query.toString();
5266    
5267                            Session session = null;
5268    
5269                            try {
5270                                    session = openSession();
5271    
5272                                    Query q = session.createQuery(sql);
5273    
5274                                    QueryPos qPos = QueryPos.getInstance(q);
5275    
5276                                    qPos.add(groupId);
5277    
5278                                    qPos.add(parentFolderId);
5279    
5280                                    if (bindName) {
5281                                            qPos.add(name);
5282                                    }
5283    
5284                                    count = (Long)q.uniqueResult();
5285    
5286                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
5287                            }
5288                            catch (Exception e) {
5289                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5290    
5291                                    throw processException(e);
5292                            }
5293                            finally {
5294                                    closeSession(session);
5295                            }
5296                    }
5297    
5298                    return count.intValue();
5299            }
5300    
5301            private static final String _FINDER_COLUMN_G_P_N_GROUPID_2 = "dlFolder.groupId = ? AND ";
5302            private static final String _FINDER_COLUMN_G_P_N_PARENTFOLDERID_2 = "dlFolder.parentFolderId = ? AND ";
5303            private static final String _FINDER_COLUMN_G_P_N_NAME_1 = "dlFolder.name IS NULL";
5304            private static final String _FINDER_COLUMN_G_P_N_NAME_2 = "dlFolder.name = ?";
5305            private static final String _FINDER_COLUMN_G_P_N_NAME_3 = "(dlFolder.name IS NULL OR dlFolder.name = '')";
5306            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_M_P_H = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
5307                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
5308                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_M_P_H",
5309                            new String[] {
5310                                    Long.class.getName(), Boolean.class.getName(),
5311                                    Long.class.getName(), Boolean.class.getName(),
5312                                    
5313                            Integer.class.getName(), Integer.class.getName(),
5314                                    OrderByComparator.class.getName()
5315                            });
5316            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P_H =
5317                    new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
5318                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
5319                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_M_P_H",
5320                            new String[] {
5321                                    Long.class.getName(), Boolean.class.getName(),
5322                                    Long.class.getName(), Boolean.class.getName()
5323                            },
5324                            DLFolderModelImpl.GROUPID_COLUMN_BITMASK |
5325                            DLFolderModelImpl.MOUNTPOINT_COLUMN_BITMASK |
5326                            DLFolderModelImpl.PARENTFOLDERID_COLUMN_BITMASK |
5327                            DLFolderModelImpl.HIDDEN_COLUMN_BITMASK |
5328                            DLFolderModelImpl.NAME_COLUMN_BITMASK);
5329            public static final FinderPath FINDER_PATH_COUNT_BY_G_M_P_H = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
5330                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
5331                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_M_P_H",
5332                            new String[] {
5333                                    Long.class.getName(), Boolean.class.getName(),
5334                                    Long.class.getName(), Boolean.class.getName()
5335                            });
5336    
5337            /**
5338             * Returns all the document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63;.
5339             *
5340             * @param groupId the group ID
5341             * @param mountPoint the mount point
5342             * @param parentFolderId the parent folder ID
5343             * @param hidden the hidden
5344             * @return the matching document library folders
5345             * @throws SystemException if a system exception occurred
5346             */
5347            @Override
5348            public List<DLFolder> findByG_M_P_H(long groupId, boolean mountPoint,
5349                    long parentFolderId, boolean hidden) throws SystemException {
5350                    return findByG_M_P_H(groupId, mountPoint, parentFolderId, hidden,
5351                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
5352            }
5353    
5354            /**
5355             * Returns a range of all the document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63;.
5356             *
5357             * <p>
5358             * 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.
5359             * </p>
5360             *
5361             * @param groupId the group ID
5362             * @param mountPoint the mount point
5363             * @param parentFolderId the parent folder ID
5364             * @param hidden the hidden
5365             * @param start the lower bound of the range of document library folders
5366             * @param end the upper bound of the range of document library folders (not inclusive)
5367             * @return the range of matching document library folders
5368             * @throws SystemException if a system exception occurred
5369             */
5370            @Override
5371            public List<DLFolder> findByG_M_P_H(long groupId, boolean mountPoint,
5372                    long parentFolderId, boolean hidden, int start, int end)
5373                    throws SystemException {
5374                    return findByG_M_P_H(groupId, mountPoint, parentFolderId, hidden,
5375                            start, end, null);
5376            }
5377    
5378            /**
5379             * Returns an ordered range of all the document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63;.
5380             *
5381             * <p>
5382             * 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.
5383             * </p>
5384             *
5385             * @param groupId the group ID
5386             * @param mountPoint the mount point
5387             * @param parentFolderId the parent folder ID
5388             * @param hidden the hidden
5389             * @param start the lower bound of the range of document library folders
5390             * @param end the upper bound of the range of document library folders (not inclusive)
5391             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5392             * @return the ordered range of matching document library folders
5393             * @throws SystemException if a system exception occurred
5394             */
5395            @Override
5396            public List<DLFolder> findByG_M_P_H(long groupId, boolean mountPoint,
5397                    long parentFolderId, boolean hidden, int start, int end,
5398                    OrderByComparator orderByComparator) throws SystemException {
5399                    boolean pagination = true;
5400                    FinderPath finderPath = null;
5401                    Object[] finderArgs = null;
5402    
5403                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5404                                    (orderByComparator == null)) {
5405                            pagination = false;
5406                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P_H;
5407                            finderArgs = new Object[] {
5408                                            groupId, mountPoint, parentFolderId, hidden
5409                                    };
5410                    }
5411                    else {
5412                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_M_P_H;
5413                            finderArgs = new Object[] {
5414                                            groupId, mountPoint, parentFolderId, hidden,
5415                                            
5416                                            start, end, orderByComparator
5417                                    };
5418                    }
5419    
5420                    List<DLFolder> list = (List<DLFolder>)FinderCacheUtil.getResult(finderPath,
5421                                    finderArgs, this);
5422    
5423                    if ((list != null) && !list.isEmpty()) {
5424                            for (DLFolder dlFolder : list) {
5425                                    if ((groupId != dlFolder.getGroupId()) ||
5426                                                    (mountPoint != dlFolder.getMountPoint()) ||
5427                                                    (parentFolderId != dlFolder.getParentFolderId()) ||
5428                                                    (hidden != dlFolder.getHidden())) {
5429                                            list = null;
5430    
5431                                            break;
5432                                    }
5433                            }
5434                    }
5435    
5436                    if (list == null) {
5437                            StringBundler query = null;
5438    
5439                            if (orderByComparator != null) {
5440                                    query = new StringBundler(6 +
5441                                                    (orderByComparator.getOrderByFields().length * 3));
5442                            }
5443                            else {
5444                                    query = new StringBundler(6);
5445                            }
5446    
5447                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
5448    
5449                            query.append(_FINDER_COLUMN_G_M_P_H_GROUPID_2);
5450    
5451                            query.append(_FINDER_COLUMN_G_M_P_H_MOUNTPOINT_2);
5452    
5453                            query.append(_FINDER_COLUMN_G_M_P_H_PARENTFOLDERID_2);
5454    
5455                            query.append(_FINDER_COLUMN_G_M_P_H_HIDDEN_2);
5456    
5457                            if (orderByComparator != null) {
5458                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5459                                            orderByComparator);
5460                            }
5461                            else
5462                             if (pagination) {
5463                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
5464                            }
5465    
5466                            String sql = query.toString();
5467    
5468                            Session session = null;
5469    
5470                            try {
5471                                    session = openSession();
5472    
5473                                    Query q = session.createQuery(sql);
5474    
5475                                    QueryPos qPos = QueryPos.getInstance(q);
5476    
5477                                    qPos.add(groupId);
5478    
5479                                    qPos.add(mountPoint);
5480    
5481                                    qPos.add(parentFolderId);
5482    
5483                                    qPos.add(hidden);
5484    
5485                                    if (!pagination) {
5486                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
5487                                                            start, end, false);
5488    
5489                                            Collections.sort(list);
5490    
5491                                            list = new UnmodifiableList<DLFolder>(list);
5492                                    }
5493                                    else {
5494                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
5495                                                            start, end);
5496                                    }
5497    
5498                                    cacheResult(list);
5499    
5500                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
5501                            }
5502                            catch (Exception e) {
5503                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5504    
5505                                    throw processException(e);
5506                            }
5507                            finally {
5508                                    closeSession(session);
5509                            }
5510                    }
5511    
5512                    return list;
5513            }
5514    
5515            /**
5516             * Returns the first document library folder in the ordered set where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63;.
5517             *
5518             * @param groupId the group ID
5519             * @param mountPoint the mount point
5520             * @param parentFolderId the parent folder ID
5521             * @param hidden the hidden
5522             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5523             * @return the first matching document library folder
5524             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
5525             * @throws SystemException if a system exception occurred
5526             */
5527            @Override
5528            public DLFolder findByG_M_P_H_First(long groupId, boolean mountPoint,
5529                    long parentFolderId, boolean hidden, OrderByComparator orderByComparator)
5530                    throws NoSuchFolderException, SystemException {
5531                    DLFolder dlFolder = fetchByG_M_P_H_First(groupId, mountPoint,
5532                                    parentFolderId, hidden, orderByComparator);
5533    
5534                    if (dlFolder != null) {
5535                            return dlFolder;
5536                    }
5537    
5538                    StringBundler msg = new StringBundler(10);
5539    
5540                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5541    
5542                    msg.append("groupId=");
5543                    msg.append(groupId);
5544    
5545                    msg.append(", mountPoint=");
5546                    msg.append(mountPoint);
5547    
5548                    msg.append(", parentFolderId=");
5549                    msg.append(parentFolderId);
5550    
5551                    msg.append(", hidden=");
5552                    msg.append(hidden);
5553    
5554                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5555    
5556                    throw new NoSuchFolderException(msg.toString());
5557            }
5558    
5559            /**
5560             * Returns the first document library folder in the ordered set where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63;.
5561             *
5562             * @param groupId the group ID
5563             * @param mountPoint the mount point
5564             * @param parentFolderId the parent folder ID
5565             * @param hidden the hidden
5566             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5567             * @return the first matching document library folder, or <code>null</code> if a matching document library folder could not be found
5568             * @throws SystemException if a system exception occurred
5569             */
5570            @Override
5571            public DLFolder fetchByG_M_P_H_First(long groupId, boolean mountPoint,
5572                    long parentFolderId, boolean hidden, OrderByComparator orderByComparator)
5573                    throws SystemException {
5574                    List<DLFolder> list = findByG_M_P_H(groupId, mountPoint,
5575                                    parentFolderId, hidden, 0, 1, orderByComparator);
5576    
5577                    if (!list.isEmpty()) {
5578                            return list.get(0);
5579                    }
5580    
5581                    return null;
5582            }
5583    
5584            /**
5585             * Returns the last document library folder in the ordered set where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63;.
5586             *
5587             * @param groupId the group ID
5588             * @param mountPoint the mount point
5589             * @param parentFolderId the parent folder ID
5590             * @param hidden the hidden
5591             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5592             * @return the last matching document library folder
5593             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
5594             * @throws SystemException if a system exception occurred
5595             */
5596            @Override
5597            public DLFolder findByG_M_P_H_Last(long groupId, boolean mountPoint,
5598                    long parentFolderId, boolean hidden, OrderByComparator orderByComparator)
5599                    throws NoSuchFolderException, SystemException {
5600                    DLFolder dlFolder = fetchByG_M_P_H_Last(groupId, mountPoint,
5601                                    parentFolderId, hidden, orderByComparator);
5602    
5603                    if (dlFolder != null) {
5604                            return dlFolder;
5605                    }
5606    
5607                    StringBundler msg = new StringBundler(10);
5608    
5609                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5610    
5611                    msg.append("groupId=");
5612                    msg.append(groupId);
5613    
5614                    msg.append(", mountPoint=");
5615                    msg.append(mountPoint);
5616    
5617                    msg.append(", parentFolderId=");
5618                    msg.append(parentFolderId);
5619    
5620                    msg.append(", hidden=");
5621                    msg.append(hidden);
5622    
5623                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5624    
5625                    throw new NoSuchFolderException(msg.toString());
5626            }
5627    
5628            /**
5629             * Returns the last document library folder in the ordered set where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63;.
5630             *
5631             * @param groupId the group ID
5632             * @param mountPoint the mount point
5633             * @param parentFolderId the parent folder ID
5634             * @param hidden the hidden
5635             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5636             * @return the last matching document library folder, or <code>null</code> if a matching document library folder could not be found
5637             * @throws SystemException if a system exception occurred
5638             */
5639            @Override
5640            public DLFolder fetchByG_M_P_H_Last(long groupId, boolean mountPoint,
5641                    long parentFolderId, boolean hidden, OrderByComparator orderByComparator)
5642                    throws SystemException {
5643                    int count = countByG_M_P_H(groupId, mountPoint, parentFolderId, hidden);
5644    
5645                    if (count == 0) {
5646                            return null;
5647                    }
5648    
5649                    List<DLFolder> list = findByG_M_P_H(groupId, mountPoint,
5650                                    parentFolderId, hidden, count - 1, count, orderByComparator);
5651    
5652                    if (!list.isEmpty()) {
5653                            return list.get(0);
5654                    }
5655    
5656                    return null;
5657            }
5658    
5659            /**
5660             * 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;.
5661             *
5662             * @param folderId the primary key of the current document library folder
5663             * @param groupId the group ID
5664             * @param mountPoint the mount point
5665             * @param parentFolderId the parent folder ID
5666             * @param hidden the hidden
5667             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5668             * @return the previous, current, and next document library folder
5669             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
5670             * @throws SystemException if a system exception occurred
5671             */
5672            @Override
5673            public DLFolder[] findByG_M_P_H_PrevAndNext(long folderId, long groupId,
5674                    boolean mountPoint, long parentFolderId, boolean hidden,
5675                    OrderByComparator orderByComparator)
5676                    throws NoSuchFolderException, SystemException {
5677                    DLFolder dlFolder = findByPrimaryKey(folderId);
5678    
5679                    Session session = null;
5680    
5681                    try {
5682                            session = openSession();
5683    
5684                            DLFolder[] array = new DLFolderImpl[3];
5685    
5686                            array[0] = getByG_M_P_H_PrevAndNext(session, dlFolder, groupId,
5687                                            mountPoint, parentFolderId, hidden, orderByComparator, true);
5688    
5689                            array[1] = dlFolder;
5690    
5691                            array[2] = getByG_M_P_H_PrevAndNext(session, dlFolder, groupId,
5692                                            mountPoint, parentFolderId, hidden, orderByComparator, false);
5693    
5694                            return array;
5695                    }
5696                    catch (Exception e) {
5697                            throw processException(e);
5698                    }
5699                    finally {
5700                            closeSession(session);
5701                    }
5702            }
5703    
5704            protected DLFolder getByG_M_P_H_PrevAndNext(Session session,
5705                    DLFolder dlFolder, long groupId, boolean mountPoint,
5706                    long parentFolderId, boolean hidden,
5707                    OrderByComparator orderByComparator, boolean previous) {
5708                    StringBundler query = null;
5709    
5710                    if (orderByComparator != null) {
5711                            query = new StringBundler(6 +
5712                                            (orderByComparator.getOrderByFields().length * 6));
5713                    }
5714                    else {
5715                            query = new StringBundler(3);
5716                    }
5717    
5718                    query.append(_SQL_SELECT_DLFOLDER_WHERE);
5719    
5720                    query.append(_FINDER_COLUMN_G_M_P_H_GROUPID_2);
5721    
5722                    query.append(_FINDER_COLUMN_G_M_P_H_MOUNTPOINT_2);
5723    
5724                    query.append(_FINDER_COLUMN_G_M_P_H_PARENTFOLDERID_2);
5725    
5726                    query.append(_FINDER_COLUMN_G_M_P_H_HIDDEN_2);
5727    
5728                    if (orderByComparator != null) {
5729                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5730    
5731                            if (orderByConditionFields.length > 0) {
5732                                    query.append(WHERE_AND);
5733                            }
5734    
5735                            for (int i = 0; i < orderByConditionFields.length; i++) {
5736                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5737                                    query.append(orderByConditionFields[i]);
5738    
5739                                    if ((i + 1) < orderByConditionFields.length) {
5740                                            if (orderByComparator.isAscending() ^ previous) {
5741                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5742                                            }
5743                                            else {
5744                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5745                                            }
5746                                    }
5747                                    else {
5748                                            if (orderByComparator.isAscending() ^ previous) {
5749                                                    query.append(WHERE_GREATER_THAN);
5750                                            }
5751                                            else {
5752                                                    query.append(WHERE_LESSER_THAN);
5753                                            }
5754                                    }
5755                            }
5756    
5757                            query.append(ORDER_BY_CLAUSE);
5758    
5759                            String[] orderByFields = orderByComparator.getOrderByFields();
5760    
5761                            for (int i = 0; i < orderByFields.length; i++) {
5762                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5763                                    query.append(orderByFields[i]);
5764    
5765                                    if ((i + 1) < orderByFields.length) {
5766                                            if (orderByComparator.isAscending() ^ previous) {
5767                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5768                                            }
5769                                            else {
5770                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5771                                            }
5772                                    }
5773                                    else {
5774                                            if (orderByComparator.isAscending() ^ previous) {
5775                                                    query.append(ORDER_BY_ASC);
5776                                            }
5777                                            else {
5778                                                    query.append(ORDER_BY_DESC);
5779                                            }
5780                                    }
5781                            }
5782                    }
5783                    else {
5784                            query.append(DLFolderModelImpl.ORDER_BY_JPQL);
5785                    }
5786    
5787                    String sql = query.toString();
5788    
5789                    Query q = session.createQuery(sql);
5790    
5791                    q.setFirstResult(0);
5792                    q.setMaxResults(2);
5793    
5794                    QueryPos qPos = QueryPos.getInstance(q);
5795    
5796                    qPos.add(groupId);
5797    
5798                    qPos.add(mountPoint);
5799    
5800                    qPos.add(parentFolderId);
5801    
5802                    qPos.add(hidden);
5803    
5804                    if (orderByComparator != null) {
5805                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
5806    
5807                            for (Object value : values) {
5808                                    qPos.add(value);
5809                            }
5810                    }
5811    
5812                    List<DLFolder> list = q.list();
5813    
5814                    if (list.size() == 2) {
5815                            return list.get(1);
5816                    }
5817                    else {
5818                            return null;
5819                    }
5820            }
5821    
5822            /**
5823             * 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;.
5824             *
5825             * @param groupId the group ID
5826             * @param mountPoint the mount point
5827             * @param parentFolderId the parent folder ID
5828             * @param hidden the hidden
5829             * @return the matching document library folders that the user has permission to view
5830             * @throws SystemException if a system exception occurred
5831             */
5832            @Override
5833            public List<DLFolder> filterFindByG_M_P_H(long groupId, boolean mountPoint,
5834                    long parentFolderId, boolean hidden) throws SystemException {
5835                    return filterFindByG_M_P_H(groupId, mountPoint, parentFolderId, hidden,
5836                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
5837            }
5838    
5839            /**
5840             * 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;.
5841             *
5842             * <p>
5843             * 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.
5844             * </p>
5845             *
5846             * @param groupId the group ID
5847             * @param mountPoint the mount point
5848             * @param parentFolderId the parent folder ID
5849             * @param hidden the hidden
5850             * @param start the lower bound of the range of document library folders
5851             * @param end the upper bound of the range of document library folders (not inclusive)
5852             * @return the range of matching document library folders that the user has permission to view
5853             * @throws SystemException if a system exception occurred
5854             */
5855            @Override
5856            public List<DLFolder> filterFindByG_M_P_H(long groupId, boolean mountPoint,
5857                    long parentFolderId, boolean hidden, int start, int end)
5858                    throws SystemException {
5859                    return filterFindByG_M_P_H(groupId, mountPoint, parentFolderId, hidden,
5860                            start, end, null);
5861            }
5862    
5863            /**
5864             * 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;.
5865             *
5866             * <p>
5867             * 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.
5868             * </p>
5869             *
5870             * @param groupId the group ID
5871             * @param mountPoint the mount point
5872             * @param parentFolderId the parent folder ID
5873             * @param hidden the hidden
5874             * @param start the lower bound of the range of document library folders
5875             * @param end the upper bound of the range of document library folders (not inclusive)
5876             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5877             * @return the ordered range of matching document library folders that the user has permission to view
5878             * @throws SystemException if a system exception occurred
5879             */
5880            @Override
5881            public List<DLFolder> filterFindByG_M_P_H(long groupId, boolean mountPoint,
5882                    long parentFolderId, boolean hidden, int start, int end,
5883                    OrderByComparator orderByComparator) throws SystemException {
5884                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5885                            return findByG_M_P_H(groupId, mountPoint, parentFolderId, hidden,
5886                                    start, end, orderByComparator);
5887                    }
5888    
5889                    StringBundler query = null;
5890    
5891                    if (orderByComparator != null) {
5892                            query = new StringBundler(6 +
5893                                            (orderByComparator.getOrderByFields().length * 3));
5894                    }
5895                    else {
5896                            query = new StringBundler(6);
5897                    }
5898    
5899                    if (getDB().isSupportsInlineDistinct()) {
5900                            query.append(_FILTER_SQL_SELECT_DLFOLDER_WHERE);
5901                    }
5902                    else {
5903                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1);
5904                    }
5905    
5906                    query.append(_FINDER_COLUMN_G_M_P_H_GROUPID_2);
5907    
5908                    query.append(_FINDER_COLUMN_G_M_P_H_MOUNTPOINT_2);
5909    
5910                    query.append(_FINDER_COLUMN_G_M_P_H_PARENTFOLDERID_2);
5911    
5912                    query.append(_FINDER_COLUMN_G_M_P_H_HIDDEN_2_SQL);
5913    
5914                    if (!getDB().isSupportsInlineDistinct()) {
5915                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2);
5916                    }
5917    
5918                    if (orderByComparator != null) {
5919                            if (getDB().isSupportsInlineDistinct()) {
5920                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5921                                            orderByComparator, true);
5922                            }
5923                            else {
5924                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
5925                                            orderByComparator, true);
5926                            }
5927                    }
5928                    else {
5929                            if (getDB().isSupportsInlineDistinct()) {
5930                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
5931                            }
5932                            else {
5933                                    query.append(DLFolderModelImpl.ORDER_BY_SQL);
5934                            }
5935                    }
5936    
5937                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5938                                    DLFolder.class.getName(),
5939                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5940    
5941                    Session session = null;
5942    
5943                    try {
5944                            session = openSession();
5945    
5946                            SQLQuery q = session.createSQLQuery(sql);
5947    
5948                            if (getDB().isSupportsInlineDistinct()) {
5949                                    q.addEntity(_FILTER_ENTITY_ALIAS, DLFolderImpl.class);
5950                            }
5951                            else {
5952                                    q.addEntity(_FILTER_ENTITY_TABLE, DLFolderImpl.class);
5953                            }
5954    
5955                            QueryPos qPos = QueryPos.getInstance(q);
5956    
5957                            qPos.add(groupId);
5958    
5959                            qPos.add(mountPoint);
5960    
5961                            qPos.add(parentFolderId);
5962    
5963                            qPos.add(hidden);
5964    
5965                            return (List<DLFolder>)QueryUtil.list(q, getDialect(), start, end);
5966                    }
5967                    catch (Exception e) {
5968                            throw processException(e);
5969                    }
5970                    finally {
5971                            closeSession(session);
5972                    }
5973            }
5974    
5975            /**
5976             * 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;.
5977             *
5978             * @param folderId the primary key of the current document library folder
5979             * @param groupId the group ID
5980             * @param mountPoint the mount point
5981             * @param parentFolderId the parent folder ID
5982             * @param hidden the hidden
5983             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5984             * @return the previous, current, and next document library folder
5985             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
5986             * @throws SystemException if a system exception occurred
5987             */
5988            @Override
5989            public DLFolder[] filterFindByG_M_P_H_PrevAndNext(long folderId,
5990                    long groupId, boolean mountPoint, long parentFolderId, boolean hidden,
5991                    OrderByComparator orderByComparator)
5992                    throws NoSuchFolderException, SystemException {
5993                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5994                            return findByG_M_P_H_PrevAndNext(folderId, groupId, mountPoint,
5995                                    parentFolderId, hidden, orderByComparator);
5996                    }
5997    
5998                    DLFolder dlFolder = findByPrimaryKey(folderId);
5999    
6000                    Session session = null;
6001    
6002                    try {
6003                            session = openSession();
6004    
6005                            DLFolder[] array = new DLFolderImpl[3];
6006    
6007                            array[0] = filterGetByG_M_P_H_PrevAndNext(session, dlFolder,
6008                                            groupId, mountPoint, parentFolderId, hidden,
6009                                            orderByComparator, true);
6010    
6011                            array[1] = dlFolder;
6012    
6013                            array[2] = filterGetByG_M_P_H_PrevAndNext(session, dlFolder,
6014                                            groupId, mountPoint, parentFolderId, hidden,
6015                                            orderByComparator, false);
6016    
6017                            return array;
6018                    }
6019                    catch (Exception e) {
6020                            throw processException(e);
6021                    }
6022                    finally {
6023                            closeSession(session);
6024                    }
6025            }
6026    
6027            protected DLFolder filterGetByG_M_P_H_PrevAndNext(Session session,
6028                    DLFolder dlFolder, long groupId, boolean mountPoint,
6029                    long parentFolderId, boolean hidden,
6030                    OrderByComparator orderByComparator, boolean previous) {
6031                    StringBundler query = null;
6032    
6033                    if (orderByComparator != null) {
6034                            query = new StringBundler(6 +
6035                                            (orderByComparator.getOrderByFields().length * 6));
6036                    }
6037                    else {
6038                            query = new StringBundler(3);
6039                    }
6040    
6041                    if (getDB().isSupportsInlineDistinct()) {
6042                            query.append(_FILTER_SQL_SELECT_DLFOLDER_WHERE);
6043                    }
6044                    else {
6045                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1);
6046                    }
6047    
6048                    query.append(_FINDER_COLUMN_G_M_P_H_GROUPID_2);
6049    
6050                    query.append(_FINDER_COLUMN_G_M_P_H_MOUNTPOINT_2);
6051    
6052                    query.append(_FINDER_COLUMN_G_M_P_H_PARENTFOLDERID_2);
6053    
6054                    query.append(_FINDER_COLUMN_G_M_P_H_HIDDEN_2_SQL);
6055    
6056                    if (!getDB().isSupportsInlineDistinct()) {
6057                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2);
6058                    }
6059    
6060                    if (orderByComparator != null) {
6061                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6062    
6063                            if (orderByConditionFields.length > 0) {
6064                                    query.append(WHERE_AND);
6065                            }
6066    
6067                            for (int i = 0; i < orderByConditionFields.length; i++) {
6068                                    if (getDB().isSupportsInlineDistinct()) {
6069                                            query.append(_ORDER_BY_ENTITY_ALIAS);
6070                                    }
6071                                    else {
6072                                            query.append(_ORDER_BY_ENTITY_TABLE);
6073                                    }
6074    
6075                                    query.append(orderByConditionFields[i]);
6076    
6077                                    if ((i + 1) < orderByConditionFields.length) {
6078                                            if (orderByComparator.isAscending() ^ previous) {
6079                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6080                                            }
6081                                            else {
6082                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6083                                            }
6084                                    }
6085                                    else {
6086                                            if (orderByComparator.isAscending() ^ previous) {
6087                                                    query.append(WHERE_GREATER_THAN);
6088                                            }
6089                                            else {
6090                                                    query.append(WHERE_LESSER_THAN);
6091                                            }
6092                                    }
6093                            }
6094    
6095                            query.append(ORDER_BY_CLAUSE);
6096    
6097                            String[] orderByFields = orderByComparator.getOrderByFields();
6098    
6099                            for (int i = 0; i < orderByFields.length; i++) {
6100                                    if (getDB().isSupportsInlineDistinct()) {
6101                                            query.append(_ORDER_BY_ENTITY_ALIAS);
6102                                    }
6103                                    else {
6104                                            query.append(_ORDER_BY_ENTITY_TABLE);
6105                                    }
6106    
6107                                    query.append(orderByFields[i]);
6108    
6109                                    if ((i + 1) < orderByFields.length) {
6110                                            if (orderByComparator.isAscending() ^ previous) {
6111                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6112                                            }
6113                                            else {
6114                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6115                                            }
6116                                    }
6117                                    else {
6118                                            if (orderByComparator.isAscending() ^ previous) {
6119                                                    query.append(ORDER_BY_ASC);
6120                                            }
6121                                            else {
6122                                                    query.append(ORDER_BY_DESC);
6123                                            }
6124                                    }
6125                            }
6126                    }
6127                    else {
6128                            if (getDB().isSupportsInlineDistinct()) {
6129                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
6130                            }
6131                            else {
6132                                    query.append(DLFolderModelImpl.ORDER_BY_SQL);
6133                            }
6134                    }
6135    
6136                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6137                                    DLFolder.class.getName(),
6138                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6139    
6140                    SQLQuery q = session.createSQLQuery(sql);
6141    
6142                    q.setFirstResult(0);
6143                    q.setMaxResults(2);
6144    
6145                    if (getDB().isSupportsInlineDistinct()) {
6146                            q.addEntity(_FILTER_ENTITY_ALIAS, DLFolderImpl.class);
6147                    }
6148                    else {
6149                            q.addEntity(_FILTER_ENTITY_TABLE, DLFolderImpl.class);
6150                    }
6151    
6152                    QueryPos qPos = QueryPos.getInstance(q);
6153    
6154                    qPos.add(groupId);
6155    
6156                    qPos.add(mountPoint);
6157    
6158                    qPos.add(parentFolderId);
6159    
6160                    qPos.add(hidden);
6161    
6162                    if (orderByComparator != null) {
6163                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
6164    
6165                            for (Object value : values) {
6166                                    qPos.add(value);
6167                            }
6168                    }
6169    
6170                    List<DLFolder> list = q.list();
6171    
6172                    if (list.size() == 2) {
6173                            return list.get(1);
6174                    }
6175                    else {
6176                            return null;
6177                    }
6178            }
6179    
6180            /**
6181             * Removes all the document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63; from the database.
6182             *
6183             * @param groupId the group ID
6184             * @param mountPoint the mount point
6185             * @param parentFolderId the parent folder ID
6186             * @param hidden the hidden
6187             * @throws SystemException if a system exception occurred
6188             */
6189            @Override
6190            public void removeByG_M_P_H(long groupId, boolean mountPoint,
6191                    long parentFolderId, boolean hidden) throws SystemException {
6192                    for (DLFolder dlFolder : findByG_M_P_H(groupId, mountPoint,
6193                                    parentFolderId, hidden, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
6194                                    null)) {
6195                            remove(dlFolder);
6196                    }
6197            }
6198    
6199            /**
6200             * Returns the number of document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63;.
6201             *
6202             * @param groupId the group ID
6203             * @param mountPoint the mount point
6204             * @param parentFolderId the parent folder ID
6205             * @param hidden the hidden
6206             * @return the number of matching document library folders
6207             * @throws SystemException if a system exception occurred
6208             */
6209            @Override
6210            public int countByG_M_P_H(long groupId, boolean mountPoint,
6211                    long parentFolderId, boolean hidden) throws SystemException {
6212                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_M_P_H;
6213    
6214                    Object[] finderArgs = new Object[] {
6215                                    groupId, mountPoint, parentFolderId, hidden
6216                            };
6217    
6218                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
6219                                    this);
6220    
6221                    if (count == null) {
6222                            StringBundler query = new StringBundler(5);
6223    
6224                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
6225    
6226                            query.append(_FINDER_COLUMN_G_M_P_H_GROUPID_2);
6227    
6228                            query.append(_FINDER_COLUMN_G_M_P_H_MOUNTPOINT_2);
6229    
6230                            query.append(_FINDER_COLUMN_G_M_P_H_PARENTFOLDERID_2);
6231    
6232                            query.append(_FINDER_COLUMN_G_M_P_H_HIDDEN_2);
6233    
6234                            String sql = query.toString();
6235    
6236                            Session session = null;
6237    
6238                            try {
6239                                    session = openSession();
6240    
6241                                    Query q = session.createQuery(sql);
6242    
6243                                    QueryPos qPos = QueryPos.getInstance(q);
6244    
6245                                    qPos.add(groupId);
6246    
6247                                    qPos.add(mountPoint);
6248    
6249                                    qPos.add(parentFolderId);
6250    
6251                                    qPos.add(hidden);
6252    
6253                                    count = (Long)q.uniqueResult();
6254    
6255                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
6256                            }
6257                            catch (Exception e) {
6258                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6259    
6260                                    throw processException(e);
6261                            }
6262                            finally {
6263                                    closeSession(session);
6264                            }
6265                    }
6266    
6267                    return count.intValue();
6268            }
6269    
6270            /**
6271             * 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;.
6272             *
6273             * @param groupId the group ID
6274             * @param mountPoint the mount point
6275             * @param parentFolderId the parent folder ID
6276             * @param hidden the hidden
6277             * @return the number of matching document library folders that the user has permission to view
6278             * @throws SystemException if a system exception occurred
6279             */
6280            @Override
6281            public int filterCountByG_M_P_H(long groupId, boolean mountPoint,
6282                    long parentFolderId, boolean hidden) throws SystemException {
6283                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6284                            return countByG_M_P_H(groupId, mountPoint, parentFolderId, hidden);
6285                    }
6286    
6287                    StringBundler query = new StringBundler(5);
6288    
6289                    query.append(_FILTER_SQL_COUNT_DLFOLDER_WHERE);
6290    
6291                    query.append(_FINDER_COLUMN_G_M_P_H_GROUPID_2);
6292    
6293                    query.append(_FINDER_COLUMN_G_M_P_H_MOUNTPOINT_2);
6294    
6295                    query.append(_FINDER_COLUMN_G_M_P_H_PARENTFOLDERID_2);
6296    
6297                    query.append(_FINDER_COLUMN_G_M_P_H_HIDDEN_2_SQL);
6298    
6299                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6300                                    DLFolder.class.getName(),
6301                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6302    
6303                    Session session = null;
6304    
6305                    try {
6306                            session = openSession();
6307    
6308                            SQLQuery q = session.createSQLQuery(sql);
6309    
6310                            q.addScalar(COUNT_COLUMN_NAME,
6311                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
6312    
6313                            QueryPos qPos = QueryPos.getInstance(q);
6314    
6315                            qPos.add(groupId);
6316    
6317                            qPos.add(mountPoint);
6318    
6319                            qPos.add(parentFolderId);
6320    
6321                            qPos.add(hidden);
6322    
6323                            Long count = (Long)q.uniqueResult();
6324    
6325                            return count.intValue();
6326                    }
6327                    catch (Exception e) {
6328                            throw processException(e);
6329                    }
6330                    finally {
6331                            closeSession(session);
6332                    }
6333            }
6334    
6335            private static final String _FINDER_COLUMN_G_M_P_H_GROUPID_2 = "dlFolder.groupId = ? AND ";
6336            private static final String _FINDER_COLUMN_G_M_P_H_MOUNTPOINT_2 = "dlFolder.mountPoint = ? AND ";
6337            private static final String _FINDER_COLUMN_G_M_P_H_PARENTFOLDERID_2 = "dlFolder.parentFolderId = ? AND ";
6338            private static final String _FINDER_COLUMN_G_M_P_H_HIDDEN_2 = "dlFolder.hidden = ?";
6339            private static final String _FINDER_COLUMN_G_M_P_H_HIDDEN_2_SQL = "dlFolder.hidden_ = ?";
6340            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_H_S = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
6341                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
6342                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_P_H_S",
6343                            new String[] {
6344                                    Long.class.getName(), Long.class.getName(),
6345                                    Boolean.class.getName(), Integer.class.getName(),
6346                                    
6347                            Integer.class.getName(), Integer.class.getName(),
6348                                    OrderByComparator.class.getName()
6349                            });
6350            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_H_S =
6351                    new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
6352                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
6353                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_P_H_S",
6354                            new String[] {
6355                                    Long.class.getName(), Long.class.getName(),
6356                                    Boolean.class.getName(), Integer.class.getName()
6357                            },
6358                            DLFolderModelImpl.GROUPID_COLUMN_BITMASK |
6359                            DLFolderModelImpl.PARENTFOLDERID_COLUMN_BITMASK |
6360                            DLFolderModelImpl.HIDDEN_COLUMN_BITMASK |
6361                            DLFolderModelImpl.STATUS_COLUMN_BITMASK |
6362                            DLFolderModelImpl.NAME_COLUMN_BITMASK);
6363            public static final FinderPath FINDER_PATH_COUNT_BY_G_P_H_S = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
6364                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
6365                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P_H_S",
6366                            new String[] {
6367                                    Long.class.getName(), Long.class.getName(),
6368                                    Boolean.class.getName(), Integer.class.getName()
6369                            });
6370    
6371            /**
6372             * Returns all the document library folders where groupId = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
6373             *
6374             * @param groupId the group ID
6375             * @param parentFolderId the parent folder ID
6376             * @param hidden the hidden
6377             * @param status the status
6378             * @return the matching document library folders
6379             * @throws SystemException if a system exception occurred
6380             */
6381            @Override
6382            public List<DLFolder> findByG_P_H_S(long groupId, long parentFolderId,
6383                    boolean hidden, int status) throws SystemException {
6384                    return findByG_P_H_S(groupId, parentFolderId, hidden, status,
6385                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
6386            }
6387    
6388            /**
6389             * Returns a range of all the document library folders where groupId = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
6390             *
6391             * <p>
6392             * 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.
6393             * </p>
6394             *
6395             * @param groupId the group ID
6396             * @param parentFolderId the parent folder ID
6397             * @param hidden the hidden
6398             * @param status the status
6399             * @param start the lower bound of the range of document library folders
6400             * @param end the upper bound of the range of document library folders (not inclusive)
6401             * @return the range of matching document library folders
6402             * @throws SystemException if a system exception occurred
6403             */
6404            @Override
6405            public List<DLFolder> findByG_P_H_S(long groupId, long parentFolderId,
6406                    boolean hidden, int status, int start, int end)
6407                    throws SystemException {
6408                    return findByG_P_H_S(groupId, parentFolderId, hidden, status, start,
6409                            end, null);
6410            }
6411    
6412            /**
6413             * Returns an ordered range of all the document library folders where groupId = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
6414             *
6415             * <p>
6416             * 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.
6417             * </p>
6418             *
6419             * @param groupId the group ID
6420             * @param parentFolderId the parent folder ID
6421             * @param hidden the hidden
6422             * @param status the status
6423             * @param start the lower bound of the range of document library folders
6424             * @param end the upper bound of the range of document library folders (not inclusive)
6425             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6426             * @return the ordered range of matching document library folders
6427             * @throws SystemException if a system exception occurred
6428             */
6429            @Override
6430            public List<DLFolder> findByG_P_H_S(long groupId, long parentFolderId,
6431                    boolean hidden, int status, int start, int end,
6432                    OrderByComparator orderByComparator) throws SystemException {
6433                    boolean pagination = true;
6434                    FinderPath finderPath = null;
6435                    Object[] finderArgs = null;
6436    
6437                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6438                                    (orderByComparator == null)) {
6439                            pagination = false;
6440                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_H_S;
6441                            finderArgs = new Object[] { groupId, parentFolderId, hidden, status };
6442                    }
6443                    else {
6444                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_H_S;
6445                            finderArgs = new Object[] {
6446                                            groupId, parentFolderId, hidden, status,
6447                                            
6448                                            start, end, orderByComparator
6449                                    };
6450                    }
6451    
6452                    List<DLFolder> list = (List<DLFolder>)FinderCacheUtil.getResult(finderPath,
6453                                    finderArgs, this);
6454    
6455                    if ((list != null) && !list.isEmpty()) {
6456                            for (DLFolder dlFolder : list) {
6457                                    if ((groupId != dlFolder.getGroupId()) ||
6458                                                    (parentFolderId != dlFolder.getParentFolderId()) ||
6459                                                    (hidden != dlFolder.getHidden()) ||
6460                                                    (status != dlFolder.getStatus())) {
6461                                            list = null;
6462    
6463                                            break;
6464                                    }
6465                            }
6466                    }
6467    
6468                    if (list == null) {
6469                            StringBundler query = null;
6470    
6471                            if (orderByComparator != null) {
6472                                    query = new StringBundler(6 +
6473                                                    (orderByComparator.getOrderByFields().length * 3));
6474                            }
6475                            else {
6476                                    query = new StringBundler(6);
6477                            }
6478    
6479                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
6480    
6481                            query.append(_FINDER_COLUMN_G_P_H_S_GROUPID_2);
6482    
6483                            query.append(_FINDER_COLUMN_G_P_H_S_PARENTFOLDERID_2);
6484    
6485                            query.append(_FINDER_COLUMN_G_P_H_S_HIDDEN_2);
6486    
6487                            query.append(_FINDER_COLUMN_G_P_H_S_STATUS_2);
6488    
6489                            if (orderByComparator != null) {
6490                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6491                                            orderByComparator);
6492                            }
6493                            else
6494                             if (pagination) {
6495                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
6496                            }
6497    
6498                            String sql = query.toString();
6499    
6500                            Session session = null;
6501    
6502                            try {
6503                                    session = openSession();
6504    
6505                                    Query q = session.createQuery(sql);
6506    
6507                                    QueryPos qPos = QueryPos.getInstance(q);
6508    
6509                                    qPos.add(groupId);
6510    
6511                                    qPos.add(parentFolderId);
6512    
6513                                    qPos.add(hidden);
6514    
6515                                    qPos.add(status);
6516    
6517                                    if (!pagination) {
6518                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
6519                                                            start, end, false);
6520    
6521                                            Collections.sort(list);
6522    
6523                                            list = new UnmodifiableList<DLFolder>(list);
6524                                    }
6525                                    else {
6526                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
6527                                                            start, end);
6528                                    }
6529    
6530                                    cacheResult(list);
6531    
6532                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
6533                            }
6534                            catch (Exception e) {
6535                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6536    
6537                                    throw processException(e);
6538                            }
6539                            finally {
6540                                    closeSession(session);
6541                            }
6542                    }
6543    
6544                    return list;
6545            }
6546    
6547            /**
6548             * Returns the first document library folder in the ordered set where groupId = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
6549             *
6550             * @param groupId the group ID
6551             * @param parentFolderId the parent folder ID
6552             * @param hidden the hidden
6553             * @param status the status
6554             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6555             * @return the first matching document library folder
6556             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
6557             * @throws SystemException if a system exception occurred
6558             */
6559            @Override
6560            public DLFolder findByG_P_H_S_First(long groupId, long parentFolderId,
6561                    boolean hidden, int status, OrderByComparator orderByComparator)
6562                    throws NoSuchFolderException, SystemException {
6563                    DLFolder dlFolder = fetchByG_P_H_S_First(groupId, parentFolderId,
6564                                    hidden, status, orderByComparator);
6565    
6566                    if (dlFolder != null) {
6567                            return dlFolder;
6568                    }
6569    
6570                    StringBundler msg = new StringBundler(10);
6571    
6572                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6573    
6574                    msg.append("groupId=");
6575                    msg.append(groupId);
6576    
6577                    msg.append(", parentFolderId=");
6578                    msg.append(parentFolderId);
6579    
6580                    msg.append(", hidden=");
6581                    msg.append(hidden);
6582    
6583                    msg.append(", status=");
6584                    msg.append(status);
6585    
6586                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6587    
6588                    throw new NoSuchFolderException(msg.toString());
6589            }
6590    
6591            /**
6592             * Returns the first document library folder in the ordered set where groupId = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
6593             *
6594             * @param groupId the group ID
6595             * @param parentFolderId the parent folder ID
6596             * @param hidden the hidden
6597             * @param status the status
6598             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6599             * @return the first matching document library folder, or <code>null</code> if a matching document library folder could not be found
6600             * @throws SystemException if a system exception occurred
6601             */
6602            @Override
6603            public DLFolder fetchByG_P_H_S_First(long groupId, long parentFolderId,
6604                    boolean hidden, int status, OrderByComparator orderByComparator)
6605                    throws SystemException {
6606                    List<DLFolder> list = findByG_P_H_S(groupId, parentFolderId, hidden,
6607                                    status, 0, 1, orderByComparator);
6608    
6609                    if (!list.isEmpty()) {
6610                            return list.get(0);
6611                    }
6612    
6613                    return null;
6614            }
6615    
6616            /**
6617             * Returns the last document library folder in the ordered set where groupId = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
6618             *
6619             * @param groupId the group ID
6620             * @param parentFolderId the parent folder ID
6621             * @param hidden the hidden
6622             * @param status the status
6623             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6624             * @return the last matching document library folder
6625             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
6626             * @throws SystemException if a system exception occurred
6627             */
6628            @Override
6629            public DLFolder findByG_P_H_S_Last(long groupId, long parentFolderId,
6630                    boolean hidden, int status, OrderByComparator orderByComparator)
6631                    throws NoSuchFolderException, SystemException {
6632                    DLFolder dlFolder = fetchByG_P_H_S_Last(groupId, parentFolderId,
6633                                    hidden, status, orderByComparator);
6634    
6635                    if (dlFolder != null) {
6636                            return dlFolder;
6637                    }
6638    
6639                    StringBundler msg = new StringBundler(10);
6640    
6641                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6642    
6643                    msg.append("groupId=");
6644                    msg.append(groupId);
6645    
6646                    msg.append(", parentFolderId=");
6647                    msg.append(parentFolderId);
6648    
6649                    msg.append(", hidden=");
6650                    msg.append(hidden);
6651    
6652                    msg.append(", status=");
6653                    msg.append(status);
6654    
6655                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6656    
6657                    throw new NoSuchFolderException(msg.toString());
6658            }
6659    
6660            /**
6661             * Returns the last document library folder in the ordered set where groupId = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
6662             *
6663             * @param groupId the group ID
6664             * @param parentFolderId the parent folder ID
6665             * @param hidden the hidden
6666             * @param status the status
6667             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6668             * @return the last matching document library folder, or <code>null</code> if a matching document library folder could not be found
6669             * @throws SystemException if a system exception occurred
6670             */
6671            @Override
6672            public DLFolder fetchByG_P_H_S_Last(long groupId, long parentFolderId,
6673                    boolean hidden, int status, OrderByComparator orderByComparator)
6674                    throws SystemException {
6675                    int count = countByG_P_H_S(groupId, parentFolderId, hidden, status);
6676    
6677                    if (count == 0) {
6678                            return null;
6679                    }
6680    
6681                    List<DLFolder> list = findByG_P_H_S(groupId, parentFolderId, hidden,
6682                                    status, count - 1, count, orderByComparator);
6683    
6684                    if (!list.isEmpty()) {
6685                            return list.get(0);
6686                    }
6687    
6688                    return null;
6689            }
6690    
6691            /**
6692             * 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;.
6693             *
6694             * @param folderId the primary key of the current document library folder
6695             * @param groupId the group ID
6696             * @param parentFolderId the parent folder ID
6697             * @param hidden the hidden
6698             * @param status the status
6699             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6700             * @return the previous, current, and next document library folder
6701             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
6702             * @throws SystemException if a system exception occurred
6703             */
6704            @Override
6705            public DLFolder[] findByG_P_H_S_PrevAndNext(long folderId, long groupId,
6706                    long parentFolderId, boolean hidden, int status,
6707                    OrderByComparator orderByComparator)
6708                    throws NoSuchFolderException, SystemException {
6709                    DLFolder dlFolder = findByPrimaryKey(folderId);
6710    
6711                    Session session = null;
6712    
6713                    try {
6714                            session = openSession();
6715    
6716                            DLFolder[] array = new DLFolderImpl[3];
6717    
6718                            array[0] = getByG_P_H_S_PrevAndNext(session, dlFolder, groupId,
6719                                            parentFolderId, hidden, status, orderByComparator, true);
6720    
6721                            array[1] = dlFolder;
6722    
6723                            array[2] = getByG_P_H_S_PrevAndNext(session, dlFolder, groupId,
6724                                            parentFolderId, hidden, status, orderByComparator, false);
6725    
6726                            return array;
6727                    }
6728                    catch (Exception e) {
6729                            throw processException(e);
6730                    }
6731                    finally {
6732                            closeSession(session);
6733                    }
6734            }
6735    
6736            protected DLFolder getByG_P_H_S_PrevAndNext(Session session,
6737                    DLFolder dlFolder, long groupId, long parentFolderId, boolean hidden,
6738                    int status, OrderByComparator orderByComparator, boolean previous) {
6739                    StringBundler query = null;
6740    
6741                    if (orderByComparator != null) {
6742                            query = new StringBundler(6 +
6743                                            (orderByComparator.getOrderByFields().length * 6));
6744                    }
6745                    else {
6746                            query = new StringBundler(3);
6747                    }
6748    
6749                    query.append(_SQL_SELECT_DLFOLDER_WHERE);
6750    
6751                    query.append(_FINDER_COLUMN_G_P_H_S_GROUPID_2);
6752    
6753                    query.append(_FINDER_COLUMN_G_P_H_S_PARENTFOLDERID_2);
6754    
6755                    query.append(_FINDER_COLUMN_G_P_H_S_HIDDEN_2);
6756    
6757                    query.append(_FINDER_COLUMN_G_P_H_S_STATUS_2);
6758    
6759                    if (orderByComparator != null) {
6760                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6761    
6762                            if (orderByConditionFields.length > 0) {
6763                                    query.append(WHERE_AND);
6764                            }
6765    
6766                            for (int i = 0; i < orderByConditionFields.length; i++) {
6767                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6768                                    query.append(orderByConditionFields[i]);
6769    
6770                                    if ((i + 1) < orderByConditionFields.length) {
6771                                            if (orderByComparator.isAscending() ^ previous) {
6772                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6773                                            }
6774                                            else {
6775                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6776                                            }
6777                                    }
6778                                    else {
6779                                            if (orderByComparator.isAscending() ^ previous) {
6780                                                    query.append(WHERE_GREATER_THAN);
6781                                            }
6782                                            else {
6783                                                    query.append(WHERE_LESSER_THAN);
6784                                            }
6785                                    }
6786                            }
6787    
6788                            query.append(ORDER_BY_CLAUSE);
6789    
6790                            String[] orderByFields = orderByComparator.getOrderByFields();
6791    
6792                            for (int i = 0; i < orderByFields.length; i++) {
6793                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6794                                    query.append(orderByFields[i]);
6795    
6796                                    if ((i + 1) < orderByFields.length) {
6797                                            if (orderByComparator.isAscending() ^ previous) {
6798                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6799                                            }
6800                                            else {
6801                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6802                                            }
6803                                    }
6804                                    else {
6805                                            if (orderByComparator.isAscending() ^ previous) {
6806                                                    query.append(ORDER_BY_ASC);
6807                                            }
6808                                            else {
6809                                                    query.append(ORDER_BY_DESC);
6810                                            }
6811                                    }
6812                            }
6813                    }
6814                    else {
6815                            query.append(DLFolderModelImpl.ORDER_BY_JPQL);
6816                    }
6817    
6818                    String sql = query.toString();
6819    
6820                    Query q = session.createQuery(sql);
6821    
6822                    q.setFirstResult(0);
6823                    q.setMaxResults(2);
6824    
6825                    QueryPos qPos = QueryPos.getInstance(q);
6826    
6827                    qPos.add(groupId);
6828    
6829                    qPos.add(parentFolderId);
6830    
6831                    qPos.add(hidden);
6832    
6833                    qPos.add(status);
6834    
6835                    if (orderByComparator != null) {
6836                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
6837    
6838                            for (Object value : values) {
6839                                    qPos.add(value);
6840                            }
6841                    }
6842    
6843                    List<DLFolder> list = q.list();
6844    
6845                    if (list.size() == 2) {
6846                            return list.get(1);
6847                    }
6848                    else {
6849                            return null;
6850                    }
6851            }
6852    
6853            /**
6854             * 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;.
6855             *
6856             * @param groupId the group ID
6857             * @param parentFolderId the parent folder ID
6858             * @param hidden the hidden
6859             * @param status the status
6860             * @return the matching document library folders that the user has permission to view
6861             * @throws SystemException if a system exception occurred
6862             */
6863            @Override
6864            public List<DLFolder> filterFindByG_P_H_S(long groupId,
6865                    long parentFolderId, boolean hidden, int status)
6866                    throws SystemException {
6867                    return filterFindByG_P_H_S(groupId, parentFolderId, hidden, status,
6868                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
6869            }
6870    
6871            /**
6872             * 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;.
6873             *
6874             * <p>
6875             * 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.
6876             * </p>
6877             *
6878             * @param groupId the group ID
6879             * @param parentFolderId the parent folder ID
6880             * @param hidden the hidden
6881             * @param status the status
6882             * @param start the lower bound of the range of document library folders
6883             * @param end the upper bound of the range of document library folders (not inclusive)
6884             * @return the range of matching document library folders that the user has permission to view
6885             * @throws SystemException if a system exception occurred
6886             */
6887            @Override
6888            public List<DLFolder> filterFindByG_P_H_S(long groupId,
6889                    long parentFolderId, boolean hidden, int status, int start, int end)
6890                    throws SystemException {
6891                    return filterFindByG_P_H_S(groupId, parentFolderId, hidden, status,
6892                            start, end, null);
6893            }
6894    
6895            /**
6896             * 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;.
6897             *
6898             * <p>
6899             * 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.
6900             * </p>
6901             *
6902             * @param groupId the group ID
6903             * @param parentFolderId the parent folder ID
6904             * @param hidden the hidden
6905             * @param status the status
6906             * @param start the lower bound of the range of document library folders
6907             * @param end the upper bound of the range of document library folders (not inclusive)
6908             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6909             * @return the ordered range of matching document library folders that the user has permission to view
6910             * @throws SystemException if a system exception occurred
6911             */
6912            @Override
6913            public List<DLFolder> filterFindByG_P_H_S(long groupId,
6914                    long parentFolderId, boolean hidden, int status, int start, int end,
6915                    OrderByComparator orderByComparator) throws SystemException {
6916                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6917                            return findByG_P_H_S(groupId, parentFolderId, hidden, status,
6918                                    start, end, orderByComparator);
6919                    }
6920    
6921                    StringBundler query = null;
6922    
6923                    if (orderByComparator != null) {
6924                            query = new StringBundler(6 +
6925                                            (orderByComparator.getOrderByFields().length * 3));
6926                    }
6927                    else {
6928                            query = new StringBundler(6);
6929                    }
6930    
6931                    if (getDB().isSupportsInlineDistinct()) {
6932                            query.append(_FILTER_SQL_SELECT_DLFOLDER_WHERE);
6933                    }
6934                    else {
6935                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1);
6936                    }
6937    
6938                    query.append(_FINDER_COLUMN_G_P_H_S_GROUPID_2);
6939    
6940                    query.append(_FINDER_COLUMN_G_P_H_S_PARENTFOLDERID_2);
6941    
6942                    query.append(_FINDER_COLUMN_G_P_H_S_HIDDEN_2_SQL);
6943    
6944                    query.append(_FINDER_COLUMN_G_P_H_S_STATUS_2);
6945    
6946                    if (!getDB().isSupportsInlineDistinct()) {
6947                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2);
6948                    }
6949    
6950                    if (orderByComparator != null) {
6951                            if (getDB().isSupportsInlineDistinct()) {
6952                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6953                                            orderByComparator, true);
6954                            }
6955                            else {
6956                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
6957                                            orderByComparator, true);
6958                            }
6959                    }
6960                    else {
6961                            if (getDB().isSupportsInlineDistinct()) {
6962                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
6963                            }
6964                            else {
6965                                    query.append(DLFolderModelImpl.ORDER_BY_SQL);
6966                            }
6967                    }
6968    
6969                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6970                                    DLFolder.class.getName(),
6971                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6972    
6973                    Session session = null;
6974    
6975                    try {
6976                            session = openSession();
6977    
6978                            SQLQuery q = session.createSQLQuery(sql);
6979    
6980                            if (getDB().isSupportsInlineDistinct()) {
6981                                    q.addEntity(_FILTER_ENTITY_ALIAS, DLFolderImpl.class);
6982                            }
6983                            else {
6984                                    q.addEntity(_FILTER_ENTITY_TABLE, DLFolderImpl.class);
6985                            }
6986    
6987                            QueryPos qPos = QueryPos.getInstance(q);
6988    
6989                            qPos.add(groupId);
6990    
6991                            qPos.add(parentFolderId);
6992    
6993                            qPos.add(hidden);
6994    
6995                            qPos.add(status);
6996    
6997                            return (List<DLFolder>)QueryUtil.list(q, getDialect(), start, end);
6998                    }
6999                    catch (Exception e) {
7000                            throw processException(e);
7001                    }
7002                    finally {
7003                            closeSession(session);
7004                    }
7005            }
7006    
7007            /**
7008             * 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;.
7009             *
7010             * @param folderId the primary key of the current document library folder
7011             * @param groupId the group ID
7012             * @param parentFolderId the parent folder ID
7013             * @param hidden the hidden
7014             * @param status the status
7015             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7016             * @return the previous, current, and next document library folder
7017             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
7018             * @throws SystemException if a system exception occurred
7019             */
7020            @Override
7021            public DLFolder[] filterFindByG_P_H_S_PrevAndNext(long folderId,
7022                    long groupId, long parentFolderId, boolean hidden, int status,
7023                    OrderByComparator orderByComparator)
7024                    throws NoSuchFolderException, SystemException {
7025                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7026                            return findByG_P_H_S_PrevAndNext(folderId, groupId, parentFolderId,
7027                                    hidden, status, orderByComparator);
7028                    }
7029    
7030                    DLFolder dlFolder = findByPrimaryKey(folderId);
7031    
7032                    Session session = null;
7033    
7034                    try {
7035                            session = openSession();
7036    
7037                            DLFolder[] array = new DLFolderImpl[3];
7038    
7039                            array[0] = filterGetByG_P_H_S_PrevAndNext(session, dlFolder,
7040                                            groupId, parentFolderId, hidden, status, orderByComparator,
7041                                            true);
7042    
7043                            array[1] = dlFolder;
7044    
7045                            array[2] = filterGetByG_P_H_S_PrevAndNext(session, dlFolder,
7046                                            groupId, parentFolderId, hidden, status, orderByComparator,
7047                                            false);
7048    
7049                            return array;
7050                    }
7051                    catch (Exception e) {
7052                            throw processException(e);
7053                    }
7054                    finally {
7055                            closeSession(session);
7056                    }
7057            }
7058    
7059            protected DLFolder filterGetByG_P_H_S_PrevAndNext(Session session,
7060                    DLFolder dlFolder, long groupId, long parentFolderId, boolean hidden,
7061                    int status, OrderByComparator orderByComparator, boolean previous) {
7062                    StringBundler query = null;
7063    
7064                    if (orderByComparator != null) {
7065                            query = new StringBundler(6 +
7066                                            (orderByComparator.getOrderByFields().length * 6));
7067                    }
7068                    else {
7069                            query = new StringBundler(3);
7070                    }
7071    
7072                    if (getDB().isSupportsInlineDistinct()) {
7073                            query.append(_FILTER_SQL_SELECT_DLFOLDER_WHERE);
7074                    }
7075                    else {
7076                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1);
7077                    }
7078    
7079                    query.append(_FINDER_COLUMN_G_P_H_S_GROUPID_2);
7080    
7081                    query.append(_FINDER_COLUMN_G_P_H_S_PARENTFOLDERID_2);
7082    
7083                    query.append(_FINDER_COLUMN_G_P_H_S_HIDDEN_2_SQL);
7084    
7085                    query.append(_FINDER_COLUMN_G_P_H_S_STATUS_2);
7086    
7087                    if (!getDB().isSupportsInlineDistinct()) {
7088                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2);
7089                    }
7090    
7091                    if (orderByComparator != null) {
7092                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7093    
7094                            if (orderByConditionFields.length > 0) {
7095                                    query.append(WHERE_AND);
7096                            }
7097    
7098                            for (int i = 0; i < orderByConditionFields.length; i++) {
7099                                    if (getDB().isSupportsInlineDistinct()) {
7100                                            query.append(_ORDER_BY_ENTITY_ALIAS);
7101                                    }
7102                                    else {
7103                                            query.append(_ORDER_BY_ENTITY_TABLE);
7104                                    }
7105    
7106                                    query.append(orderByConditionFields[i]);
7107    
7108                                    if ((i + 1) < orderByConditionFields.length) {
7109                                            if (orderByComparator.isAscending() ^ previous) {
7110                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
7111                                            }
7112                                            else {
7113                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
7114                                            }
7115                                    }
7116                                    else {
7117                                            if (orderByComparator.isAscending() ^ previous) {
7118                                                    query.append(WHERE_GREATER_THAN);
7119                                            }
7120                                            else {
7121                                                    query.append(WHERE_LESSER_THAN);
7122                                            }
7123                                    }
7124                            }
7125    
7126                            query.append(ORDER_BY_CLAUSE);
7127    
7128                            String[] orderByFields = orderByComparator.getOrderByFields();
7129    
7130                            for (int i = 0; i < orderByFields.length; i++) {
7131                                    if (getDB().isSupportsInlineDistinct()) {
7132                                            query.append(_ORDER_BY_ENTITY_ALIAS);
7133                                    }
7134                                    else {
7135                                            query.append(_ORDER_BY_ENTITY_TABLE);
7136                                    }
7137    
7138                                    query.append(orderByFields[i]);
7139    
7140                                    if ((i + 1) < orderByFields.length) {
7141                                            if (orderByComparator.isAscending() ^ previous) {
7142                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
7143                                            }
7144                                            else {
7145                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
7146                                            }
7147                                    }
7148                                    else {
7149                                            if (orderByComparator.isAscending() ^ previous) {
7150                                                    query.append(ORDER_BY_ASC);
7151                                            }
7152                                            else {
7153                                                    query.append(ORDER_BY_DESC);
7154                                            }
7155                                    }
7156                            }
7157                    }
7158                    else {
7159                            if (getDB().isSupportsInlineDistinct()) {
7160                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
7161                            }
7162                            else {
7163                                    query.append(DLFolderModelImpl.ORDER_BY_SQL);
7164                            }
7165                    }
7166    
7167                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7168                                    DLFolder.class.getName(),
7169                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7170    
7171                    SQLQuery q = session.createSQLQuery(sql);
7172    
7173                    q.setFirstResult(0);
7174                    q.setMaxResults(2);
7175    
7176                    if (getDB().isSupportsInlineDistinct()) {
7177                            q.addEntity(_FILTER_ENTITY_ALIAS, DLFolderImpl.class);
7178                    }
7179                    else {
7180                            q.addEntity(_FILTER_ENTITY_TABLE, DLFolderImpl.class);
7181                    }
7182    
7183                    QueryPos qPos = QueryPos.getInstance(q);
7184    
7185                    qPos.add(groupId);
7186    
7187                    qPos.add(parentFolderId);
7188    
7189                    qPos.add(hidden);
7190    
7191                    qPos.add(status);
7192    
7193                    if (orderByComparator != null) {
7194                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
7195    
7196                            for (Object value : values) {
7197                                    qPos.add(value);
7198                            }
7199                    }
7200    
7201                    List<DLFolder> list = q.list();
7202    
7203                    if (list.size() == 2) {
7204                            return list.get(1);
7205                    }
7206                    else {
7207                            return null;
7208                    }
7209            }
7210    
7211            /**
7212             * Removes all the document library folders where groupId = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63; from the database.
7213             *
7214             * @param groupId the group ID
7215             * @param parentFolderId the parent folder ID
7216             * @param hidden the hidden
7217             * @param status the status
7218             * @throws SystemException if a system exception occurred
7219             */
7220            @Override
7221            public void removeByG_P_H_S(long groupId, long parentFolderId,
7222                    boolean hidden, int status) throws SystemException {
7223                    for (DLFolder dlFolder : findByG_P_H_S(groupId, parentFolderId, hidden,
7224                                    status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
7225                            remove(dlFolder);
7226                    }
7227            }
7228    
7229            /**
7230             * Returns the number of document library folders where groupId = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
7231             *
7232             * @param groupId the group ID
7233             * @param parentFolderId the parent folder ID
7234             * @param hidden the hidden
7235             * @param status the status
7236             * @return the number of matching document library folders
7237             * @throws SystemException if a system exception occurred
7238             */
7239            @Override
7240            public int countByG_P_H_S(long groupId, long parentFolderId,
7241                    boolean hidden, int status) throws SystemException {
7242                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_P_H_S;
7243    
7244                    Object[] finderArgs = new Object[] {
7245                                    groupId, parentFolderId, hidden, status
7246                            };
7247    
7248                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
7249                                    this);
7250    
7251                    if (count == null) {
7252                            StringBundler query = new StringBundler(5);
7253    
7254                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
7255    
7256                            query.append(_FINDER_COLUMN_G_P_H_S_GROUPID_2);
7257    
7258                            query.append(_FINDER_COLUMN_G_P_H_S_PARENTFOLDERID_2);
7259    
7260                            query.append(_FINDER_COLUMN_G_P_H_S_HIDDEN_2);
7261    
7262                            query.append(_FINDER_COLUMN_G_P_H_S_STATUS_2);
7263    
7264                            String sql = query.toString();
7265    
7266                            Session session = null;
7267    
7268                            try {
7269                                    session = openSession();
7270    
7271                                    Query q = session.createQuery(sql);
7272    
7273                                    QueryPos qPos = QueryPos.getInstance(q);
7274    
7275                                    qPos.add(groupId);
7276    
7277                                    qPos.add(parentFolderId);
7278    
7279                                    qPos.add(hidden);
7280    
7281                                    qPos.add(status);
7282    
7283                                    count = (Long)q.uniqueResult();
7284    
7285                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
7286                            }
7287                            catch (Exception e) {
7288                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
7289    
7290                                    throw processException(e);
7291                            }
7292                            finally {
7293                                    closeSession(session);
7294                            }
7295                    }
7296    
7297                    return count.intValue();
7298            }
7299    
7300            /**
7301             * 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;.
7302             *
7303             * @param groupId the group ID
7304             * @param parentFolderId the parent folder ID
7305             * @param hidden the hidden
7306             * @param status the status
7307             * @return the number of matching document library folders that the user has permission to view
7308             * @throws SystemException if a system exception occurred
7309             */
7310            @Override
7311            public int filterCountByG_P_H_S(long groupId, long parentFolderId,
7312                    boolean hidden, int status) throws SystemException {
7313                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7314                            return countByG_P_H_S(groupId, parentFolderId, hidden, status);
7315                    }
7316    
7317                    StringBundler query = new StringBundler(5);
7318    
7319                    query.append(_FILTER_SQL_COUNT_DLFOLDER_WHERE);
7320    
7321                    query.append(_FINDER_COLUMN_G_P_H_S_GROUPID_2);
7322    
7323                    query.append(_FINDER_COLUMN_G_P_H_S_PARENTFOLDERID_2);
7324    
7325                    query.append(_FINDER_COLUMN_G_P_H_S_HIDDEN_2_SQL);
7326    
7327                    query.append(_FINDER_COLUMN_G_P_H_S_STATUS_2);
7328    
7329                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7330                                    DLFolder.class.getName(),
7331                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7332    
7333                    Session session = null;
7334    
7335                    try {
7336                            session = openSession();
7337    
7338                            SQLQuery q = session.createSQLQuery(sql);
7339    
7340                            q.addScalar(COUNT_COLUMN_NAME,
7341                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
7342    
7343                            QueryPos qPos = QueryPos.getInstance(q);
7344    
7345                            qPos.add(groupId);
7346    
7347                            qPos.add(parentFolderId);
7348    
7349                            qPos.add(hidden);
7350    
7351                            qPos.add(status);
7352    
7353                            Long count = (Long)q.uniqueResult();
7354    
7355                            return count.intValue();
7356                    }
7357                    catch (Exception e) {
7358                            throw processException(e);
7359                    }
7360                    finally {
7361                            closeSession(session);
7362                    }
7363            }
7364    
7365            private static final String _FINDER_COLUMN_G_P_H_S_GROUPID_2 = "dlFolder.groupId = ? AND ";
7366            private static final String _FINDER_COLUMN_G_P_H_S_PARENTFOLDERID_2 = "dlFolder.parentFolderId = ? AND ";
7367            private static final String _FINDER_COLUMN_G_P_H_S_HIDDEN_2 = "dlFolder.hidden = ? AND ";
7368            private static final String _FINDER_COLUMN_G_P_H_S_HIDDEN_2_SQL = "dlFolder.hidden_ = ? AND ";
7369            private static final String _FINDER_COLUMN_G_P_H_S_STATUS_2 = "dlFolder.status = ?";
7370            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_M_P_H_S =
7371                    new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
7372                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
7373                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_M_P_H_S",
7374                            new String[] {
7375                                    Long.class.getName(), Boolean.class.getName(),
7376                                    Long.class.getName(), Boolean.class.getName(),
7377                                    Integer.class.getName(),
7378                                    
7379                            Integer.class.getName(), Integer.class.getName(),
7380                                    OrderByComparator.class.getName()
7381                            });
7382            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P_H_S =
7383                    new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
7384                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
7385                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_M_P_H_S",
7386                            new String[] {
7387                                    Long.class.getName(), Boolean.class.getName(),
7388                                    Long.class.getName(), Boolean.class.getName(),
7389                                    Integer.class.getName()
7390                            },
7391                            DLFolderModelImpl.GROUPID_COLUMN_BITMASK |
7392                            DLFolderModelImpl.MOUNTPOINT_COLUMN_BITMASK |
7393                            DLFolderModelImpl.PARENTFOLDERID_COLUMN_BITMASK |
7394                            DLFolderModelImpl.HIDDEN_COLUMN_BITMASK |
7395                            DLFolderModelImpl.STATUS_COLUMN_BITMASK |
7396                            DLFolderModelImpl.NAME_COLUMN_BITMASK);
7397            public static final FinderPath FINDER_PATH_COUNT_BY_G_M_P_H_S = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
7398                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
7399                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_M_P_H_S",
7400                            new String[] {
7401                                    Long.class.getName(), Boolean.class.getName(),
7402                                    Long.class.getName(), Boolean.class.getName(),
7403                                    Integer.class.getName()
7404                            });
7405    
7406            /**
7407             * Returns all the document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
7408             *
7409             * @param groupId the group ID
7410             * @param mountPoint the mount point
7411             * @param parentFolderId the parent folder ID
7412             * @param hidden the hidden
7413             * @param status the status
7414             * @return the matching document library folders
7415             * @throws SystemException if a system exception occurred
7416             */
7417            @Override
7418            public List<DLFolder> findByG_M_P_H_S(long groupId, boolean mountPoint,
7419                    long parentFolderId, boolean hidden, int status)
7420                    throws SystemException {
7421                    return findByG_M_P_H_S(groupId, mountPoint, parentFolderId, hidden,
7422                            status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
7423            }
7424    
7425            /**
7426             * Returns a range of all the document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
7427             *
7428             * <p>
7429             * 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.
7430             * </p>
7431             *
7432             * @param groupId the group ID
7433             * @param mountPoint the mount point
7434             * @param parentFolderId the parent folder ID
7435             * @param hidden the hidden
7436             * @param status the status
7437             * @param start the lower bound of the range of document library folders
7438             * @param end the upper bound of the range of document library folders (not inclusive)
7439             * @return the range of matching document library folders
7440             * @throws SystemException if a system exception occurred
7441             */
7442            @Override
7443            public List<DLFolder> findByG_M_P_H_S(long groupId, boolean mountPoint,
7444                    long parentFolderId, boolean hidden, int status, int start, int end)
7445                    throws SystemException {
7446                    return findByG_M_P_H_S(groupId, mountPoint, parentFolderId, hidden,
7447                            status, start, end, null);
7448            }
7449    
7450            /**
7451             * 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;.
7452             *
7453             * <p>
7454             * 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.
7455             * </p>
7456             *
7457             * @param groupId the group ID
7458             * @param mountPoint the mount point
7459             * @param parentFolderId the parent folder ID
7460             * @param hidden the hidden
7461             * @param status the status
7462             * @param start the lower bound of the range of document library folders
7463             * @param end the upper bound of the range of document library folders (not inclusive)
7464             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7465             * @return the ordered range of matching document library folders
7466             * @throws SystemException if a system exception occurred
7467             */
7468            @Override
7469            public List<DLFolder> findByG_M_P_H_S(long groupId, boolean mountPoint,
7470                    long parentFolderId, boolean hidden, int status, int start, int end,
7471                    OrderByComparator orderByComparator) throws SystemException {
7472                    boolean pagination = true;
7473                    FinderPath finderPath = null;
7474                    Object[] finderArgs = null;
7475    
7476                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7477                                    (orderByComparator == null)) {
7478                            pagination = false;
7479                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P_H_S;
7480                            finderArgs = new Object[] {
7481                                            groupId, mountPoint, parentFolderId, hidden, status
7482                                    };
7483                    }
7484                    else {
7485                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_M_P_H_S;
7486                            finderArgs = new Object[] {
7487                                            groupId, mountPoint, parentFolderId, hidden, status,
7488                                            
7489                                            start, end, orderByComparator
7490                                    };
7491                    }
7492    
7493                    List<DLFolder> list = (List<DLFolder>)FinderCacheUtil.getResult(finderPath,
7494                                    finderArgs, this);
7495    
7496                    if ((list != null) && !list.isEmpty()) {
7497                            for (DLFolder dlFolder : list) {
7498                                    if ((groupId != dlFolder.getGroupId()) ||
7499                                                    (mountPoint != dlFolder.getMountPoint()) ||
7500                                                    (parentFolderId != dlFolder.getParentFolderId()) ||
7501                                                    (hidden != dlFolder.getHidden()) ||
7502                                                    (status != dlFolder.getStatus())) {
7503                                            list = null;
7504    
7505                                            break;
7506                                    }
7507                            }
7508                    }
7509    
7510                    if (list == null) {
7511                            StringBundler query = null;
7512    
7513                            if (orderByComparator != null) {
7514                                    query = new StringBundler(7 +
7515                                                    (orderByComparator.getOrderByFields().length * 3));
7516                            }
7517                            else {
7518                                    query = new StringBundler(7);
7519                            }
7520    
7521                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
7522    
7523                            query.append(_FINDER_COLUMN_G_M_P_H_S_GROUPID_2);
7524    
7525                            query.append(_FINDER_COLUMN_G_M_P_H_S_MOUNTPOINT_2);
7526    
7527                            query.append(_FINDER_COLUMN_G_M_P_H_S_PARENTFOLDERID_2);
7528    
7529                            query.append(_FINDER_COLUMN_G_M_P_H_S_HIDDEN_2);
7530    
7531                            query.append(_FINDER_COLUMN_G_M_P_H_S_STATUS_2);
7532    
7533                            if (orderByComparator != null) {
7534                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7535                                            orderByComparator);
7536                            }
7537                            else
7538                             if (pagination) {
7539                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
7540                            }
7541    
7542                            String sql = query.toString();
7543    
7544                            Session session = null;
7545    
7546                            try {
7547                                    session = openSession();
7548    
7549                                    Query q = session.createQuery(sql);
7550    
7551                                    QueryPos qPos = QueryPos.getInstance(q);
7552    
7553                                    qPos.add(groupId);
7554    
7555                                    qPos.add(mountPoint);
7556    
7557                                    qPos.add(parentFolderId);
7558    
7559                                    qPos.add(hidden);
7560    
7561                                    qPos.add(status);
7562    
7563                                    if (!pagination) {
7564                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
7565                                                            start, end, false);
7566    
7567                                            Collections.sort(list);
7568    
7569                                            list = new UnmodifiableList<DLFolder>(list);
7570                                    }
7571                                    else {
7572                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
7573                                                            start, end);
7574                                    }
7575    
7576                                    cacheResult(list);
7577    
7578                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
7579                            }
7580                            catch (Exception e) {
7581                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
7582    
7583                                    throw processException(e);
7584                            }
7585                            finally {
7586                                    closeSession(session);
7587                            }
7588                    }
7589    
7590                    return list;
7591            }
7592    
7593            /**
7594             * 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;.
7595             *
7596             * @param groupId the group ID
7597             * @param mountPoint the mount point
7598             * @param parentFolderId the parent folder ID
7599             * @param hidden the hidden
7600             * @param status the status
7601             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7602             * @return the first matching document library folder
7603             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
7604             * @throws SystemException if a system exception occurred
7605             */
7606            @Override
7607            public DLFolder findByG_M_P_H_S_First(long groupId, boolean mountPoint,
7608                    long parentFolderId, boolean hidden, int status,
7609                    OrderByComparator orderByComparator)
7610                    throws NoSuchFolderException, SystemException {
7611                    DLFolder dlFolder = fetchByG_M_P_H_S_First(groupId, mountPoint,
7612                                    parentFolderId, hidden, status, orderByComparator);
7613    
7614                    if (dlFolder != null) {
7615                            return dlFolder;
7616                    }
7617    
7618                    StringBundler msg = new StringBundler(12);
7619    
7620                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7621    
7622                    msg.append("groupId=");
7623                    msg.append(groupId);
7624    
7625                    msg.append(", mountPoint=");
7626                    msg.append(mountPoint);
7627    
7628                    msg.append(", parentFolderId=");
7629                    msg.append(parentFolderId);
7630    
7631                    msg.append(", hidden=");
7632                    msg.append(hidden);
7633    
7634                    msg.append(", status=");
7635                    msg.append(status);
7636    
7637                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7638    
7639                    throw new NoSuchFolderException(msg.toString());
7640            }
7641    
7642            /**
7643             * 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;.
7644             *
7645             * @param groupId the group ID
7646             * @param mountPoint the mount point
7647             * @param parentFolderId the parent folder ID
7648             * @param hidden the hidden
7649             * @param status the status
7650             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7651             * @return the first matching document library folder, or <code>null</code> if a matching document library folder could not be found
7652             * @throws SystemException if a system exception occurred
7653             */
7654            @Override
7655            public DLFolder fetchByG_M_P_H_S_First(long groupId, boolean mountPoint,
7656                    long parentFolderId, boolean hidden, int status,
7657                    OrderByComparator orderByComparator) throws SystemException {
7658                    List<DLFolder> list = findByG_M_P_H_S(groupId, mountPoint,
7659                                    parentFolderId, hidden, status, 0, 1, orderByComparator);
7660    
7661                    if (!list.isEmpty()) {
7662                            return list.get(0);
7663                    }
7664    
7665                    return null;
7666            }
7667    
7668            /**
7669             * 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;.
7670             *
7671             * @param groupId the group ID
7672             * @param mountPoint the mount point
7673             * @param parentFolderId the parent folder ID
7674             * @param hidden the hidden
7675             * @param status the status
7676             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7677             * @return the last matching document library folder
7678             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
7679             * @throws SystemException if a system exception occurred
7680             */
7681            @Override
7682            public DLFolder findByG_M_P_H_S_Last(long groupId, boolean mountPoint,
7683                    long parentFolderId, boolean hidden, int status,
7684                    OrderByComparator orderByComparator)
7685                    throws NoSuchFolderException, SystemException {
7686                    DLFolder dlFolder = fetchByG_M_P_H_S_Last(groupId, mountPoint,
7687                                    parentFolderId, hidden, status, orderByComparator);
7688    
7689                    if (dlFolder != null) {
7690                            return dlFolder;
7691                    }
7692    
7693                    StringBundler msg = new StringBundler(12);
7694    
7695                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7696    
7697                    msg.append("groupId=");
7698                    msg.append(groupId);
7699    
7700                    msg.append(", mountPoint=");
7701                    msg.append(mountPoint);
7702    
7703                    msg.append(", parentFolderId=");
7704                    msg.append(parentFolderId);
7705    
7706                    msg.append(", hidden=");
7707                    msg.append(hidden);
7708    
7709                    msg.append(", status=");
7710                    msg.append(status);
7711    
7712                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7713    
7714                    throw new NoSuchFolderException(msg.toString());
7715            }
7716    
7717            /**
7718             * 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;.
7719             *
7720             * @param groupId the group ID
7721             * @param mountPoint the mount point
7722             * @param parentFolderId the parent folder ID
7723             * @param hidden the hidden
7724             * @param status the status
7725             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7726             * @return the last matching document library folder, or <code>null</code> if a matching document library folder could not be found
7727             * @throws SystemException if a system exception occurred
7728             */
7729            @Override
7730            public DLFolder fetchByG_M_P_H_S_Last(long groupId, boolean mountPoint,
7731                    long parentFolderId, boolean hidden, int status,
7732                    OrderByComparator orderByComparator) throws SystemException {
7733                    int count = countByG_M_P_H_S(groupId, mountPoint, parentFolderId,
7734                                    hidden, status);
7735    
7736                    if (count == 0) {
7737                            return null;
7738                    }
7739    
7740                    List<DLFolder> list = findByG_M_P_H_S(groupId, mountPoint,
7741                                    parentFolderId, hidden, status, count - 1, count,
7742                                    orderByComparator);
7743    
7744                    if (!list.isEmpty()) {
7745                            return list.get(0);
7746                    }
7747    
7748                    return null;
7749            }
7750    
7751            /**
7752             * 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;.
7753             *
7754             * @param folderId the primary key of the current document library folder
7755             * @param groupId the group ID
7756             * @param mountPoint the mount point
7757             * @param parentFolderId the parent folder ID
7758             * @param hidden the hidden
7759             * @param status the status
7760             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7761             * @return the previous, current, and next document library folder
7762             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
7763             * @throws SystemException if a system exception occurred
7764             */
7765            @Override
7766            public DLFolder[] findByG_M_P_H_S_PrevAndNext(long folderId, long groupId,
7767                    boolean mountPoint, long parentFolderId, boolean hidden, int status,
7768                    OrderByComparator orderByComparator)
7769                    throws NoSuchFolderException, SystemException {
7770                    DLFolder dlFolder = findByPrimaryKey(folderId);
7771    
7772                    Session session = null;
7773    
7774                    try {
7775                            session = openSession();
7776    
7777                            DLFolder[] array = new DLFolderImpl[3];
7778    
7779                            array[0] = getByG_M_P_H_S_PrevAndNext(session, dlFolder, groupId,
7780                                            mountPoint, parentFolderId, hidden, status,
7781                                            orderByComparator, true);
7782    
7783                            array[1] = dlFolder;
7784    
7785                            array[2] = getByG_M_P_H_S_PrevAndNext(session, dlFolder, groupId,
7786                                            mountPoint, parentFolderId, hidden, status,
7787                                            orderByComparator, false);
7788    
7789                            return array;
7790                    }
7791                    catch (Exception e) {
7792                            throw processException(e);
7793                    }
7794                    finally {
7795                            closeSession(session);
7796                    }
7797            }
7798    
7799            protected DLFolder getByG_M_P_H_S_PrevAndNext(Session session,
7800                    DLFolder dlFolder, long groupId, boolean mountPoint,
7801                    long parentFolderId, boolean hidden, int status,
7802                    OrderByComparator orderByComparator, boolean previous) {
7803                    StringBundler query = null;
7804    
7805                    if (orderByComparator != null) {
7806                            query = new StringBundler(6 +
7807                                            (orderByComparator.getOrderByFields().length * 6));
7808                    }
7809                    else {
7810                            query = new StringBundler(3);
7811                    }
7812    
7813                    query.append(_SQL_SELECT_DLFOLDER_WHERE);
7814    
7815                    query.append(_FINDER_COLUMN_G_M_P_H_S_GROUPID_2);
7816    
7817                    query.append(_FINDER_COLUMN_G_M_P_H_S_MOUNTPOINT_2);
7818    
7819                    query.append(_FINDER_COLUMN_G_M_P_H_S_PARENTFOLDERID_2);
7820    
7821                    query.append(_FINDER_COLUMN_G_M_P_H_S_HIDDEN_2);
7822    
7823                    query.append(_FINDER_COLUMN_G_M_P_H_S_STATUS_2);
7824    
7825                    if (orderByComparator != null) {
7826                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7827    
7828                            if (orderByConditionFields.length > 0) {
7829                                    query.append(WHERE_AND);
7830                            }
7831    
7832                            for (int i = 0; i < orderByConditionFields.length; i++) {
7833                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7834                                    query.append(orderByConditionFields[i]);
7835    
7836                                    if ((i + 1) < orderByConditionFields.length) {
7837                                            if (orderByComparator.isAscending() ^ previous) {
7838                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
7839                                            }
7840                                            else {
7841                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
7842                                            }
7843                                    }
7844                                    else {
7845                                            if (orderByComparator.isAscending() ^ previous) {
7846                                                    query.append(WHERE_GREATER_THAN);
7847                                            }
7848                                            else {
7849                                                    query.append(WHERE_LESSER_THAN);
7850                                            }
7851                                    }
7852                            }
7853    
7854                            query.append(ORDER_BY_CLAUSE);
7855    
7856                            String[] orderByFields = orderByComparator.getOrderByFields();
7857    
7858                            for (int i = 0; i < orderByFields.length; i++) {
7859                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7860                                    query.append(orderByFields[i]);
7861    
7862                                    if ((i + 1) < orderByFields.length) {
7863                                            if (orderByComparator.isAscending() ^ previous) {
7864                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
7865                                            }
7866                                            else {
7867                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
7868                                            }
7869                                    }
7870                                    else {
7871                                            if (orderByComparator.isAscending() ^ previous) {
7872                                                    query.append(ORDER_BY_ASC);
7873                                            }
7874                                            else {
7875                                                    query.append(ORDER_BY_DESC);
7876                                            }
7877                                    }
7878                            }
7879                    }
7880                    else {
7881                            query.append(DLFolderModelImpl.ORDER_BY_JPQL);
7882                    }
7883    
7884                    String sql = query.toString();
7885    
7886                    Query q = session.createQuery(sql);
7887    
7888                    q.setFirstResult(0);
7889                    q.setMaxResults(2);
7890    
7891                    QueryPos qPos = QueryPos.getInstance(q);
7892    
7893                    qPos.add(groupId);
7894    
7895                    qPos.add(mountPoint);
7896    
7897                    qPos.add(parentFolderId);
7898    
7899                    qPos.add(hidden);
7900    
7901                    qPos.add(status);
7902    
7903                    if (orderByComparator != null) {
7904                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
7905    
7906                            for (Object value : values) {
7907                                    qPos.add(value);
7908                            }
7909                    }
7910    
7911                    List<DLFolder> list = q.list();
7912    
7913                    if (list.size() == 2) {
7914                            return list.get(1);
7915                    }
7916                    else {
7917                            return null;
7918                    }
7919            }
7920    
7921            /**
7922             * 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;.
7923             *
7924             * @param groupId the group ID
7925             * @param mountPoint the mount point
7926             * @param parentFolderId the parent folder ID
7927             * @param hidden the hidden
7928             * @param status the status
7929             * @return the matching document library folders that the user has permission to view
7930             * @throws SystemException if a system exception occurred
7931             */
7932            @Override
7933            public List<DLFolder> filterFindByG_M_P_H_S(long groupId,
7934                    boolean mountPoint, long parentFolderId, boolean hidden, int status)
7935                    throws SystemException {
7936                    return filterFindByG_M_P_H_S(groupId, mountPoint, parentFolderId,
7937                            hidden, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
7938            }
7939    
7940            /**
7941             * 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;.
7942             *
7943             * <p>
7944             * 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.
7945             * </p>
7946             *
7947             * @param groupId the group ID
7948             * @param mountPoint the mount point
7949             * @param parentFolderId the parent folder ID
7950             * @param hidden the hidden
7951             * @param status the status
7952             * @param start the lower bound of the range of document library folders
7953             * @param end the upper bound of the range of document library folders (not inclusive)
7954             * @return the range of matching document library folders that the user has permission to view
7955             * @throws SystemException if a system exception occurred
7956             */
7957            @Override
7958            public List<DLFolder> filterFindByG_M_P_H_S(long groupId,
7959                    boolean mountPoint, long parentFolderId, boolean hidden, int status,
7960                    int start, int end) throws SystemException {
7961                    return filterFindByG_M_P_H_S(groupId, mountPoint, parentFolderId,
7962                            hidden, status, start, end, null);
7963            }
7964    
7965            /**
7966             * 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;.
7967             *
7968             * <p>
7969             * 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.
7970             * </p>
7971             *
7972             * @param groupId the group ID
7973             * @param mountPoint the mount point
7974             * @param parentFolderId the parent folder ID
7975             * @param hidden the hidden
7976             * @param status the status
7977             * @param start the lower bound of the range of document library folders
7978             * @param end the upper bound of the range of document library folders (not inclusive)
7979             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7980             * @return the ordered range of matching document library folders that the user has permission to view
7981             * @throws SystemException if a system exception occurred
7982             */
7983            @Override
7984            public List<DLFolder> filterFindByG_M_P_H_S(long groupId,
7985                    boolean mountPoint, long parentFolderId, boolean hidden, int status,
7986                    int start, int end, OrderByComparator orderByComparator)
7987                    throws SystemException {
7988                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7989                            return findByG_M_P_H_S(groupId, mountPoint, parentFolderId, hidden,
7990                                    status, start, end, orderByComparator);
7991                    }
7992    
7993                    StringBundler query = null;
7994    
7995                    if (orderByComparator != null) {
7996                            query = new StringBundler(7 +
7997                                            (orderByComparator.getOrderByFields().length * 3));
7998                    }
7999                    else {
8000                            query = new StringBundler(7);
8001                    }
8002    
8003                    if (getDB().isSupportsInlineDistinct()) {
8004                            query.append(_FILTER_SQL_SELECT_DLFOLDER_WHERE);
8005                    }
8006                    else {
8007                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1);
8008                    }
8009    
8010                    query.append(_FINDER_COLUMN_G_M_P_H_S_GROUPID_2);
8011    
8012                    query.append(_FINDER_COLUMN_G_M_P_H_S_MOUNTPOINT_2);
8013    
8014                    query.append(_FINDER_COLUMN_G_M_P_H_S_PARENTFOLDERID_2);
8015    
8016                    query.append(_FINDER_COLUMN_G_M_P_H_S_HIDDEN_2_SQL);
8017    
8018                    query.append(_FINDER_COLUMN_G_M_P_H_S_STATUS_2);
8019    
8020                    if (!getDB().isSupportsInlineDistinct()) {
8021                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2);
8022                    }
8023    
8024                    if (orderByComparator != null) {
8025                            if (getDB().isSupportsInlineDistinct()) {
8026                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8027                                            orderByComparator, true);
8028                            }
8029                            else {
8030                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
8031                                            orderByComparator, true);
8032                            }
8033                    }
8034                    else {
8035                            if (getDB().isSupportsInlineDistinct()) {
8036                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
8037                            }
8038                            else {
8039                                    query.append(DLFolderModelImpl.ORDER_BY_SQL);
8040                            }
8041                    }
8042    
8043                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8044                                    DLFolder.class.getName(),
8045                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8046    
8047                    Session session = null;
8048    
8049                    try {
8050                            session = openSession();
8051    
8052                            SQLQuery q = session.createSQLQuery(sql);
8053    
8054                            if (getDB().isSupportsInlineDistinct()) {
8055                                    q.addEntity(_FILTER_ENTITY_ALIAS, DLFolderImpl.class);
8056                            }
8057                            else {
8058                                    q.addEntity(_FILTER_ENTITY_TABLE, DLFolderImpl.class);
8059                            }
8060    
8061                            QueryPos qPos = QueryPos.getInstance(q);
8062    
8063                            qPos.add(groupId);
8064    
8065                            qPos.add(mountPoint);
8066    
8067                            qPos.add(parentFolderId);
8068    
8069                            qPos.add(hidden);
8070    
8071                            qPos.add(status);
8072    
8073                            return (List<DLFolder>)QueryUtil.list(q, getDialect(), start, end);
8074                    }
8075                    catch (Exception e) {
8076                            throw processException(e);
8077                    }
8078                    finally {
8079                            closeSession(session);
8080                    }
8081            }
8082    
8083            /**
8084             * 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;.
8085             *
8086             * @param folderId the primary key of the current document library folder
8087             * @param groupId the group ID
8088             * @param mountPoint the mount point
8089             * @param parentFolderId the parent folder ID
8090             * @param hidden the hidden
8091             * @param status the status
8092             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8093             * @return the previous, current, and next document library folder
8094             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
8095             * @throws SystemException if a system exception occurred
8096             */
8097            @Override
8098            public DLFolder[] filterFindByG_M_P_H_S_PrevAndNext(long folderId,
8099                    long groupId, boolean mountPoint, long parentFolderId, boolean hidden,
8100                    int status, OrderByComparator orderByComparator)
8101                    throws NoSuchFolderException, SystemException {
8102                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8103                            return findByG_M_P_H_S_PrevAndNext(folderId, groupId, mountPoint,
8104                                    parentFolderId, hidden, status, orderByComparator);
8105                    }
8106    
8107                    DLFolder dlFolder = findByPrimaryKey(folderId);
8108    
8109                    Session session = null;
8110    
8111                    try {
8112                            session = openSession();
8113    
8114                            DLFolder[] array = new DLFolderImpl[3];
8115    
8116                            array[0] = filterGetByG_M_P_H_S_PrevAndNext(session, dlFolder,
8117                                            groupId, mountPoint, parentFolderId, hidden, status,
8118                                            orderByComparator, true);
8119    
8120                            array[1] = dlFolder;
8121    
8122                            array[2] = filterGetByG_M_P_H_S_PrevAndNext(session, dlFolder,
8123                                            groupId, mountPoint, parentFolderId, hidden, status,
8124                                            orderByComparator, false);
8125    
8126                            return array;
8127                    }
8128                    catch (Exception e) {
8129                            throw processException(e);
8130                    }
8131                    finally {
8132                            closeSession(session);
8133                    }
8134            }
8135    
8136            protected DLFolder filterGetByG_M_P_H_S_PrevAndNext(Session session,
8137                    DLFolder dlFolder, long groupId, boolean mountPoint,
8138                    long parentFolderId, boolean hidden, int status,
8139                    OrderByComparator orderByComparator, boolean previous) {
8140                    StringBundler query = null;
8141    
8142                    if (orderByComparator != null) {
8143                            query = new StringBundler(6 +
8144                                            (orderByComparator.getOrderByFields().length * 6));
8145                    }
8146                    else {
8147                            query = new StringBundler(3);
8148                    }
8149    
8150                    if (getDB().isSupportsInlineDistinct()) {
8151                            query.append(_FILTER_SQL_SELECT_DLFOLDER_WHERE);
8152                    }
8153                    else {
8154                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1);
8155                    }
8156    
8157                    query.append(_FINDER_COLUMN_G_M_P_H_S_GROUPID_2);
8158    
8159                    query.append(_FINDER_COLUMN_G_M_P_H_S_MOUNTPOINT_2);
8160    
8161                    query.append(_FINDER_COLUMN_G_M_P_H_S_PARENTFOLDERID_2);
8162    
8163                    query.append(_FINDER_COLUMN_G_M_P_H_S_HIDDEN_2_SQL);
8164    
8165                    query.append(_FINDER_COLUMN_G_M_P_H_S_STATUS_2);
8166    
8167                    if (!getDB().isSupportsInlineDistinct()) {
8168                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2);
8169                    }
8170    
8171                    if (orderByComparator != null) {
8172                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
8173    
8174                            if (orderByConditionFields.length > 0) {
8175                                    query.append(WHERE_AND);
8176                            }
8177    
8178                            for (int i = 0; i < orderByConditionFields.length; i++) {
8179                                    if (getDB().isSupportsInlineDistinct()) {
8180                                            query.append(_ORDER_BY_ENTITY_ALIAS);
8181                                    }
8182                                    else {
8183                                            query.append(_ORDER_BY_ENTITY_TABLE);
8184                                    }
8185    
8186                                    query.append(orderByConditionFields[i]);
8187    
8188                                    if ((i + 1) < orderByConditionFields.length) {
8189                                            if (orderByComparator.isAscending() ^ previous) {
8190                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
8191                                            }
8192                                            else {
8193                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
8194                                            }
8195                                    }
8196                                    else {
8197                                            if (orderByComparator.isAscending() ^ previous) {
8198                                                    query.append(WHERE_GREATER_THAN);
8199                                            }
8200                                            else {
8201                                                    query.append(WHERE_LESSER_THAN);
8202                                            }
8203                                    }
8204                            }
8205    
8206                            query.append(ORDER_BY_CLAUSE);
8207    
8208                            String[] orderByFields = orderByComparator.getOrderByFields();
8209    
8210                            for (int i = 0; i < orderByFields.length; i++) {
8211                                    if (getDB().isSupportsInlineDistinct()) {
8212                                            query.append(_ORDER_BY_ENTITY_ALIAS);
8213                                    }
8214                                    else {
8215                                            query.append(_ORDER_BY_ENTITY_TABLE);
8216                                    }
8217    
8218                                    query.append(orderByFields[i]);
8219    
8220                                    if ((i + 1) < orderByFields.length) {
8221                                            if (orderByComparator.isAscending() ^ previous) {
8222                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
8223                                            }
8224                                            else {
8225                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
8226                                            }
8227                                    }
8228                                    else {
8229                                            if (orderByComparator.isAscending() ^ previous) {
8230                                                    query.append(ORDER_BY_ASC);
8231                                            }
8232                                            else {
8233                                                    query.append(ORDER_BY_DESC);
8234                                            }
8235                                    }
8236                            }
8237                    }
8238                    else {
8239                            if (getDB().isSupportsInlineDistinct()) {
8240                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
8241                            }
8242                            else {
8243                                    query.append(DLFolderModelImpl.ORDER_BY_SQL);
8244                            }
8245                    }
8246    
8247                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8248                                    DLFolder.class.getName(),
8249                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8250    
8251                    SQLQuery q = session.createSQLQuery(sql);
8252    
8253                    q.setFirstResult(0);
8254                    q.setMaxResults(2);
8255    
8256                    if (getDB().isSupportsInlineDistinct()) {
8257                            q.addEntity(_FILTER_ENTITY_ALIAS, DLFolderImpl.class);
8258                    }
8259                    else {
8260                            q.addEntity(_FILTER_ENTITY_TABLE, DLFolderImpl.class);
8261                    }
8262    
8263                    QueryPos qPos = QueryPos.getInstance(q);
8264    
8265                    qPos.add(groupId);
8266    
8267                    qPos.add(mountPoint);
8268    
8269                    qPos.add(parentFolderId);
8270    
8271                    qPos.add(hidden);
8272    
8273                    qPos.add(status);
8274    
8275                    if (orderByComparator != null) {
8276                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
8277    
8278                            for (Object value : values) {
8279                                    qPos.add(value);
8280                            }
8281                    }
8282    
8283                    List<DLFolder> list = q.list();
8284    
8285                    if (list.size() == 2) {
8286                            return list.get(1);
8287                    }
8288                    else {
8289                            return null;
8290                    }
8291            }
8292    
8293            /**
8294             * Removes all the document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63; from the database.
8295             *
8296             * @param groupId the group ID
8297             * @param mountPoint the mount point
8298             * @param parentFolderId the parent folder ID
8299             * @param hidden the hidden
8300             * @param status the status
8301             * @throws SystemException if a system exception occurred
8302             */
8303            @Override
8304            public void removeByG_M_P_H_S(long groupId, boolean mountPoint,
8305                    long parentFolderId, boolean hidden, int status)
8306                    throws SystemException {
8307                    for (DLFolder dlFolder : findByG_M_P_H_S(groupId, mountPoint,
8308                                    parentFolderId, hidden, status, QueryUtil.ALL_POS,
8309                                    QueryUtil.ALL_POS, null)) {
8310                            remove(dlFolder);
8311                    }
8312            }
8313    
8314            /**
8315             * Returns the number of document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
8316             *
8317             * @param groupId the group ID
8318             * @param mountPoint the mount point
8319             * @param parentFolderId the parent folder ID
8320             * @param hidden the hidden
8321             * @param status the status
8322             * @return the number of matching document library folders
8323             * @throws SystemException if a system exception occurred
8324             */
8325            @Override
8326            public int countByG_M_P_H_S(long groupId, boolean mountPoint,
8327                    long parentFolderId, boolean hidden, int status)
8328                    throws SystemException {
8329                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_M_P_H_S;
8330    
8331                    Object[] finderArgs = new Object[] {
8332                                    groupId, mountPoint, parentFolderId, hidden, status
8333                            };
8334    
8335                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
8336                                    this);
8337    
8338                    if (count == null) {
8339                            StringBundler query = new StringBundler(6);
8340    
8341                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
8342    
8343                            query.append(_FINDER_COLUMN_G_M_P_H_S_GROUPID_2);
8344    
8345                            query.append(_FINDER_COLUMN_G_M_P_H_S_MOUNTPOINT_2);
8346    
8347                            query.append(_FINDER_COLUMN_G_M_P_H_S_PARENTFOLDERID_2);
8348    
8349                            query.append(_FINDER_COLUMN_G_M_P_H_S_HIDDEN_2);
8350    
8351                            query.append(_FINDER_COLUMN_G_M_P_H_S_STATUS_2);
8352    
8353                            String sql = query.toString();
8354    
8355                            Session session = null;
8356    
8357                            try {
8358                                    session = openSession();
8359    
8360                                    Query q = session.createQuery(sql);
8361    
8362                                    QueryPos qPos = QueryPos.getInstance(q);
8363    
8364                                    qPos.add(groupId);
8365    
8366                                    qPos.add(mountPoint);
8367    
8368                                    qPos.add(parentFolderId);
8369    
8370                                    qPos.add(hidden);
8371    
8372                                    qPos.add(status);
8373    
8374                                    count = (Long)q.uniqueResult();
8375    
8376                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
8377                            }
8378                            catch (Exception e) {
8379                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
8380    
8381                                    throw processException(e);
8382                            }
8383                            finally {
8384                                    closeSession(session);
8385                            }
8386                    }
8387    
8388                    return count.intValue();
8389            }
8390    
8391            /**
8392             * 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;.
8393             *
8394             * @param groupId the group ID
8395             * @param mountPoint the mount point
8396             * @param parentFolderId the parent folder ID
8397             * @param hidden the hidden
8398             * @param status the status
8399             * @return the number of matching document library folders that the user has permission to view
8400             * @throws SystemException if a system exception occurred
8401             */
8402            @Override
8403            public int filterCountByG_M_P_H_S(long groupId, boolean mountPoint,
8404                    long parentFolderId, boolean hidden, int status)
8405                    throws SystemException {
8406                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8407                            return countByG_M_P_H_S(groupId, mountPoint, parentFolderId,
8408                                    hidden, status);
8409                    }
8410    
8411                    StringBundler query = new StringBundler(6);
8412    
8413                    query.append(_FILTER_SQL_COUNT_DLFOLDER_WHERE);
8414    
8415                    query.append(_FINDER_COLUMN_G_M_P_H_S_GROUPID_2);
8416    
8417                    query.append(_FINDER_COLUMN_G_M_P_H_S_MOUNTPOINT_2);
8418    
8419                    query.append(_FINDER_COLUMN_G_M_P_H_S_PARENTFOLDERID_2);
8420    
8421                    query.append(_FINDER_COLUMN_G_M_P_H_S_HIDDEN_2_SQL);
8422    
8423                    query.append(_FINDER_COLUMN_G_M_P_H_S_STATUS_2);
8424    
8425                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8426                                    DLFolder.class.getName(),
8427                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8428    
8429                    Session session = null;
8430    
8431                    try {
8432                            session = openSession();
8433    
8434                            SQLQuery q = session.createSQLQuery(sql);
8435    
8436                            q.addScalar(COUNT_COLUMN_NAME,
8437                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
8438    
8439                            QueryPos qPos = QueryPos.getInstance(q);
8440    
8441                            qPos.add(groupId);
8442    
8443                            qPos.add(mountPoint);
8444    
8445                            qPos.add(parentFolderId);
8446    
8447                            qPos.add(hidden);
8448    
8449                            qPos.add(status);
8450    
8451                            Long count = (Long)q.uniqueResult();
8452    
8453                            return count.intValue();
8454                    }
8455                    catch (Exception e) {
8456                            throw processException(e);
8457                    }
8458                    finally {
8459                            closeSession(session);
8460                    }
8461            }
8462    
8463            private static final String _FINDER_COLUMN_G_M_P_H_S_GROUPID_2 = "dlFolder.groupId = ? AND ";
8464            private static final String _FINDER_COLUMN_G_M_P_H_S_MOUNTPOINT_2 = "dlFolder.mountPoint = ? AND ";
8465            private static final String _FINDER_COLUMN_G_M_P_H_S_PARENTFOLDERID_2 = "dlFolder.parentFolderId = ? AND ";
8466            private static final String _FINDER_COLUMN_G_M_P_H_S_HIDDEN_2 = "dlFolder.hidden = ? AND ";
8467            private static final String _FINDER_COLUMN_G_M_P_H_S_HIDDEN_2_SQL = "dlFolder.hidden_ = ? AND ";
8468            private static final String _FINDER_COLUMN_G_M_P_H_S_STATUS_2 = "dlFolder.status = ?";
8469    
8470            public DLFolderPersistenceImpl() {
8471                    setModelClass(DLFolder.class);
8472            }
8473    
8474            /**
8475             * Caches the document library folder in the entity cache if it is enabled.
8476             *
8477             * @param dlFolder the document library folder
8478             */
8479            @Override
8480            public void cacheResult(DLFolder dlFolder) {
8481                    EntityCacheUtil.putResult(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
8482                            DLFolderImpl.class, dlFolder.getPrimaryKey(), dlFolder);
8483    
8484                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
8485                            new Object[] { dlFolder.getUuid(), dlFolder.getGroupId() }, dlFolder);
8486    
8487                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_REPOSITORYID,
8488                            new Object[] { dlFolder.getRepositoryId() }, dlFolder);
8489    
8490                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_N,
8491                            new Object[] {
8492                                    dlFolder.getGroupId(), dlFolder.getParentFolderId(),
8493                                    dlFolder.getName()
8494                            }, dlFolder);
8495    
8496                    dlFolder.resetOriginalValues();
8497            }
8498    
8499            /**
8500             * Caches the document library folders in the entity cache if it is enabled.
8501             *
8502             * @param dlFolders the document library folders
8503             */
8504            @Override
8505            public void cacheResult(List<DLFolder> dlFolders) {
8506                    for (DLFolder dlFolder : dlFolders) {
8507                            if (EntityCacheUtil.getResult(
8508                                                    DLFolderModelImpl.ENTITY_CACHE_ENABLED,
8509                                                    DLFolderImpl.class, dlFolder.getPrimaryKey()) == null) {
8510                                    cacheResult(dlFolder);
8511                            }
8512                            else {
8513                                    dlFolder.resetOriginalValues();
8514                            }
8515                    }
8516            }
8517    
8518            /**
8519             * Clears the cache for all document library folders.
8520             *
8521             * <p>
8522             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
8523             * </p>
8524             */
8525            @Override
8526            public void clearCache() {
8527                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
8528                            CacheRegistryUtil.clear(DLFolderImpl.class.getName());
8529                    }
8530    
8531                    EntityCacheUtil.clearCache(DLFolderImpl.class.getName());
8532    
8533                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
8534                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
8535                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
8536            }
8537    
8538            /**
8539             * Clears the cache for the document library folder.
8540             *
8541             * <p>
8542             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
8543             * </p>
8544             */
8545            @Override
8546            public void clearCache(DLFolder dlFolder) {
8547                    EntityCacheUtil.removeResult(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
8548                            DLFolderImpl.class, dlFolder.getPrimaryKey());
8549    
8550                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
8551                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
8552    
8553                    clearUniqueFindersCache(dlFolder);
8554            }
8555    
8556            @Override
8557            public void clearCache(List<DLFolder> dlFolders) {
8558                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
8559                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
8560    
8561                    for (DLFolder dlFolder : dlFolders) {
8562                            EntityCacheUtil.removeResult(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
8563                                    DLFolderImpl.class, dlFolder.getPrimaryKey());
8564    
8565                            clearUniqueFindersCache(dlFolder);
8566                    }
8567            }
8568    
8569            protected void cacheUniqueFindersCache(DLFolder dlFolder) {
8570                    if (dlFolder.isNew()) {
8571                            Object[] args = new Object[] {
8572                                            dlFolder.getUuid(), dlFolder.getGroupId()
8573                                    };
8574    
8575                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
8576                                    Long.valueOf(1));
8577                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
8578                                    dlFolder);
8579    
8580                            args = new Object[] { dlFolder.getRepositoryId() };
8581    
8582                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_REPOSITORYID, args,
8583                                    Long.valueOf(1));
8584                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_REPOSITORYID, args,
8585                                    dlFolder);
8586    
8587                            args = new Object[] {
8588                                            dlFolder.getGroupId(), dlFolder.getParentFolderId(),
8589                                            dlFolder.getName()
8590                                    };
8591    
8592                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_P_N, args,
8593                                    Long.valueOf(1));
8594                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_N, args, dlFolder);
8595                    }
8596                    else {
8597                            DLFolderModelImpl dlFolderModelImpl = (DLFolderModelImpl)dlFolder;
8598    
8599                            if ((dlFolderModelImpl.getColumnBitmask() &
8600                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
8601                                    Object[] args = new Object[] {
8602                                                    dlFolder.getUuid(), dlFolder.getGroupId()
8603                                            };
8604    
8605                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
8606                                            Long.valueOf(1));
8607                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
8608                                            dlFolder);
8609                            }
8610    
8611                            if ((dlFolderModelImpl.getColumnBitmask() &
8612                                            FINDER_PATH_FETCH_BY_REPOSITORYID.getColumnBitmask()) != 0) {
8613                                    Object[] args = new Object[] { dlFolder.getRepositoryId() };
8614    
8615                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_REPOSITORYID,
8616                                            args, Long.valueOf(1));
8617                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_REPOSITORYID,
8618                                            args, dlFolder);
8619                            }
8620    
8621                            if ((dlFolderModelImpl.getColumnBitmask() &
8622                                            FINDER_PATH_FETCH_BY_G_P_N.getColumnBitmask()) != 0) {
8623                                    Object[] args = new Object[] {
8624                                                    dlFolder.getGroupId(), dlFolder.getParentFolderId(),
8625                                                    dlFolder.getName()
8626                                            };
8627    
8628                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_P_N, args,
8629                                            Long.valueOf(1));
8630                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_N, args,
8631                                            dlFolder);
8632                            }
8633                    }
8634            }
8635    
8636            protected void clearUniqueFindersCache(DLFolder dlFolder) {
8637                    DLFolderModelImpl dlFolderModelImpl = (DLFolderModelImpl)dlFolder;
8638    
8639                    Object[] args = new Object[] { dlFolder.getUuid(), dlFolder.getGroupId() };
8640    
8641                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
8642                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
8643    
8644                    if ((dlFolderModelImpl.getColumnBitmask() &
8645                                    FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
8646                            args = new Object[] {
8647                                            dlFolderModelImpl.getOriginalUuid(),
8648                                            dlFolderModelImpl.getOriginalGroupId()
8649                                    };
8650    
8651                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
8652                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
8653                    }
8654    
8655                    args = new Object[] { dlFolder.getRepositoryId() };
8656    
8657                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_REPOSITORYID, args);
8658                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_REPOSITORYID, args);
8659    
8660                    if ((dlFolderModelImpl.getColumnBitmask() &
8661                                    FINDER_PATH_FETCH_BY_REPOSITORYID.getColumnBitmask()) != 0) {
8662                            args = new Object[] { dlFolderModelImpl.getOriginalRepositoryId() };
8663    
8664                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_REPOSITORYID, args);
8665                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_REPOSITORYID, args);
8666                    }
8667    
8668                    args = new Object[] {
8669                                    dlFolder.getGroupId(), dlFolder.getParentFolderId(),
8670                                    dlFolder.getName()
8671                            };
8672    
8673                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_N, args);
8674                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P_N, args);
8675    
8676                    if ((dlFolderModelImpl.getColumnBitmask() &
8677                                    FINDER_PATH_FETCH_BY_G_P_N.getColumnBitmask()) != 0) {
8678                            args = new Object[] {
8679                                            dlFolderModelImpl.getOriginalGroupId(),
8680                                            dlFolderModelImpl.getOriginalParentFolderId(),
8681                                            dlFolderModelImpl.getOriginalName()
8682                                    };
8683    
8684                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_N, args);
8685                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P_N, args);
8686                    }
8687            }
8688    
8689            /**
8690             * Creates a new document library folder with the primary key. Does not add the document library folder to the database.
8691             *
8692             * @param folderId the primary key for the new document library folder
8693             * @return the new document library folder
8694             */
8695            @Override
8696            public DLFolder create(long folderId) {
8697                    DLFolder dlFolder = new DLFolderImpl();
8698    
8699                    dlFolder.setNew(true);
8700                    dlFolder.setPrimaryKey(folderId);
8701    
8702                    String uuid = PortalUUIDUtil.generate();
8703    
8704                    dlFolder.setUuid(uuid);
8705    
8706                    return dlFolder;
8707            }
8708    
8709            /**
8710             * Removes the document library folder with the primary key from the database. Also notifies the appropriate model listeners.
8711             *
8712             * @param folderId the primary key of the document library folder
8713             * @return the document library folder that was removed
8714             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
8715             * @throws SystemException if a system exception occurred
8716             */
8717            @Override
8718            public DLFolder remove(long folderId)
8719                    throws NoSuchFolderException, SystemException {
8720                    return remove((Serializable)folderId);
8721            }
8722    
8723            /**
8724             * Removes the document library folder with the primary key from the database. Also notifies the appropriate model listeners.
8725             *
8726             * @param primaryKey the primary key of the document library folder
8727             * @return the document library folder that was removed
8728             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
8729             * @throws SystemException if a system exception occurred
8730             */
8731            @Override
8732            public DLFolder remove(Serializable primaryKey)
8733                    throws NoSuchFolderException, SystemException {
8734                    Session session = null;
8735    
8736                    try {
8737                            session = openSession();
8738    
8739                            DLFolder dlFolder = (DLFolder)session.get(DLFolderImpl.class,
8740                                            primaryKey);
8741    
8742                            if (dlFolder == null) {
8743                                    if (_log.isWarnEnabled()) {
8744                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
8745                                    }
8746    
8747                                    throw new NoSuchFolderException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
8748                                            primaryKey);
8749                            }
8750    
8751                            return remove(dlFolder);
8752                    }
8753                    catch (NoSuchFolderException nsee) {
8754                            throw nsee;
8755                    }
8756                    catch (Exception e) {
8757                            throw processException(e);
8758                    }
8759                    finally {
8760                            closeSession(session);
8761                    }
8762            }
8763    
8764            @Override
8765            protected DLFolder removeImpl(DLFolder dlFolder) throws SystemException {
8766                    dlFolder = toUnwrappedModel(dlFolder);
8767    
8768                    dlFolderToDLFileEntryTypeTableMapper.deleteLeftPrimaryKeyTableMappings(dlFolder.getPrimaryKey());
8769    
8770                    Session session = null;
8771    
8772                    try {
8773                            session = openSession();
8774    
8775                            if (!session.contains(dlFolder)) {
8776                                    dlFolder = (DLFolder)session.get(DLFolderImpl.class,
8777                                                    dlFolder.getPrimaryKeyObj());
8778                            }
8779    
8780                            if (dlFolder != null) {
8781                                    session.delete(dlFolder);
8782                            }
8783                    }
8784                    catch (Exception e) {
8785                            throw processException(e);
8786                    }
8787                    finally {
8788                            closeSession(session);
8789                    }
8790    
8791                    if (dlFolder != null) {
8792                            clearCache(dlFolder);
8793                    }
8794    
8795                    return dlFolder;
8796            }
8797    
8798            @Override
8799            public DLFolder updateImpl(
8800                    com.liferay.portlet.documentlibrary.model.DLFolder dlFolder)
8801                    throws SystemException {
8802                    dlFolder = toUnwrappedModel(dlFolder);
8803    
8804                    boolean isNew = dlFolder.isNew();
8805    
8806                    DLFolderModelImpl dlFolderModelImpl = (DLFolderModelImpl)dlFolder;
8807    
8808                    if (Validator.isNull(dlFolder.getUuid())) {
8809                            String uuid = PortalUUIDUtil.generate();
8810    
8811                            dlFolder.setUuid(uuid);
8812                    }
8813    
8814                    Session session = null;
8815    
8816                    try {
8817                            session = openSession();
8818    
8819                            if (dlFolder.isNew()) {
8820                                    session.save(dlFolder);
8821    
8822                                    dlFolder.setNew(false);
8823                            }
8824                            else {
8825                                    session.merge(dlFolder);
8826                            }
8827                    }
8828                    catch (Exception e) {
8829                            throw processException(e);
8830                    }
8831                    finally {
8832                            closeSession(session);
8833                    }
8834    
8835                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
8836    
8837                    if (isNew || !DLFolderModelImpl.COLUMN_BITMASK_ENABLED) {
8838                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
8839                    }
8840    
8841                    else {
8842                            if ((dlFolderModelImpl.getColumnBitmask() &
8843                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
8844                                    Object[] args = new Object[] { dlFolderModelImpl.getOriginalUuid() };
8845    
8846                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
8847                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
8848                                            args);
8849    
8850                                    args = new Object[] { dlFolderModelImpl.getUuid() };
8851    
8852                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
8853                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
8854                                            args);
8855                            }
8856    
8857                            if ((dlFolderModelImpl.getColumnBitmask() &
8858                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
8859                                    Object[] args = new Object[] {
8860                                                    dlFolderModelImpl.getOriginalUuid(),
8861                                                    dlFolderModelImpl.getOriginalCompanyId()
8862                                            };
8863    
8864                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
8865                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
8866                                            args);
8867    
8868                                    args = new Object[] {
8869                                                    dlFolderModelImpl.getUuid(),
8870                                                    dlFolderModelImpl.getCompanyId()
8871                                            };
8872    
8873                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
8874                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
8875                                            args);
8876                            }
8877    
8878                            if ((dlFolderModelImpl.getColumnBitmask() &
8879                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
8880                                    Object[] args = new Object[] {
8881                                                    dlFolderModelImpl.getOriginalGroupId()
8882                                            };
8883    
8884                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
8885                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
8886                                            args);
8887    
8888                                    args = new Object[] { dlFolderModelImpl.getGroupId() };
8889    
8890                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
8891                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
8892                                            args);
8893                            }
8894    
8895                            if ((dlFolderModelImpl.getColumnBitmask() &
8896                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
8897                                    Object[] args = new Object[] {
8898                                                    dlFolderModelImpl.getOriginalCompanyId()
8899                                            };
8900    
8901                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
8902                                            args);
8903                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
8904                                            args);
8905    
8906                                    args = new Object[] { dlFolderModelImpl.getCompanyId() };
8907    
8908                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
8909                                            args);
8910                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
8911                                            args);
8912                            }
8913    
8914                            if ((dlFolderModelImpl.getColumnBitmask() &
8915                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P.getColumnBitmask()) != 0) {
8916                                    Object[] args = new Object[] {
8917                                                    dlFolderModelImpl.getOriginalGroupId(),
8918                                                    dlFolderModelImpl.getOriginalParentFolderId()
8919                                            };
8920    
8921                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P, args);
8922                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P,
8923                                            args);
8924    
8925                                    args = new Object[] {
8926                                                    dlFolderModelImpl.getGroupId(),
8927                                                    dlFolderModelImpl.getParentFolderId()
8928                                            };
8929    
8930                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P, args);
8931                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P,
8932                                            args);
8933                            }
8934    
8935                            if ((dlFolderModelImpl.getColumnBitmask() &
8936                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_N.getColumnBitmask()) != 0) {
8937                                    Object[] args = new Object[] {
8938                                                    dlFolderModelImpl.getOriginalParentFolderId(),
8939                                                    dlFolderModelImpl.getOriginalName()
8940                                            };
8941    
8942                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_P_N, args);
8943                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_N,
8944                                            args);
8945    
8946                                    args = new Object[] {
8947                                                    dlFolderModelImpl.getParentFolderId(),
8948                                                    dlFolderModelImpl.getName()
8949                                            };
8950    
8951                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_P_N, args);
8952                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_N,
8953                                            args);
8954                            }
8955    
8956                            if ((dlFolderModelImpl.getColumnBitmask() &
8957                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P_H.getColumnBitmask()) != 0) {
8958                                    Object[] args = new Object[] {
8959                                                    dlFolderModelImpl.getOriginalGroupId(),
8960                                                    dlFolderModelImpl.getOriginalMountPoint(),
8961                                                    dlFolderModelImpl.getOriginalParentFolderId(),
8962                                                    dlFolderModelImpl.getOriginalHidden()
8963                                            };
8964    
8965                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_M_P_H, args);
8966                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P_H,
8967                                            args);
8968    
8969                                    args = new Object[] {
8970                                                    dlFolderModelImpl.getGroupId(),
8971                                                    dlFolderModelImpl.getMountPoint(),
8972                                                    dlFolderModelImpl.getParentFolderId(),
8973                                                    dlFolderModelImpl.getHidden()
8974                                            };
8975    
8976                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_M_P_H, args);
8977                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P_H,
8978                                            args);
8979                            }
8980    
8981                            if ((dlFolderModelImpl.getColumnBitmask() &
8982                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_H_S.getColumnBitmask()) != 0) {
8983                                    Object[] args = new Object[] {
8984                                                    dlFolderModelImpl.getOriginalGroupId(),
8985                                                    dlFolderModelImpl.getOriginalParentFolderId(),
8986                                                    dlFolderModelImpl.getOriginalHidden(),
8987                                                    dlFolderModelImpl.getOriginalStatus()
8988                                            };
8989    
8990                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_H_S, args);
8991                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_H_S,
8992                                            args);
8993    
8994                                    args = new Object[] {
8995                                                    dlFolderModelImpl.getGroupId(),
8996                                                    dlFolderModelImpl.getParentFolderId(),
8997                                                    dlFolderModelImpl.getHidden(),
8998                                                    dlFolderModelImpl.getStatus()
8999                                            };
9000    
9001                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_H_S, args);
9002                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_H_S,
9003                                            args);
9004                            }
9005    
9006                            if ((dlFolderModelImpl.getColumnBitmask() &
9007                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P_H_S.getColumnBitmask()) != 0) {
9008                                    Object[] args = new Object[] {
9009                                                    dlFolderModelImpl.getOriginalGroupId(),
9010                                                    dlFolderModelImpl.getOriginalMountPoint(),
9011                                                    dlFolderModelImpl.getOriginalParentFolderId(),
9012                                                    dlFolderModelImpl.getOriginalHidden(),
9013                                                    dlFolderModelImpl.getOriginalStatus()
9014                                            };
9015    
9016                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_M_P_H_S,
9017                                            args);
9018                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P_H_S,
9019                                            args);
9020    
9021                                    args = new Object[] {
9022                                                    dlFolderModelImpl.getGroupId(),
9023                                                    dlFolderModelImpl.getMountPoint(),
9024                                                    dlFolderModelImpl.getParentFolderId(),
9025                                                    dlFolderModelImpl.getHidden(),
9026                                                    dlFolderModelImpl.getStatus()
9027                                            };
9028    
9029                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_M_P_H_S,
9030                                            args);
9031                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P_H_S,
9032                                            args);
9033                            }
9034                    }
9035    
9036                    EntityCacheUtil.putResult(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
9037                            DLFolderImpl.class, dlFolder.getPrimaryKey(), dlFolder);
9038    
9039                    clearUniqueFindersCache(dlFolder);
9040                    cacheUniqueFindersCache(dlFolder);
9041    
9042                    return dlFolder;
9043            }
9044    
9045            protected DLFolder toUnwrappedModel(DLFolder dlFolder) {
9046                    if (dlFolder instanceof DLFolderImpl) {
9047                            return dlFolder;
9048                    }
9049    
9050                    DLFolderImpl dlFolderImpl = new DLFolderImpl();
9051    
9052                    dlFolderImpl.setNew(dlFolder.isNew());
9053                    dlFolderImpl.setPrimaryKey(dlFolder.getPrimaryKey());
9054    
9055                    dlFolderImpl.setUuid(dlFolder.getUuid());
9056                    dlFolderImpl.setFolderId(dlFolder.getFolderId());
9057                    dlFolderImpl.setGroupId(dlFolder.getGroupId());
9058                    dlFolderImpl.setCompanyId(dlFolder.getCompanyId());
9059                    dlFolderImpl.setUserId(dlFolder.getUserId());
9060                    dlFolderImpl.setUserName(dlFolder.getUserName());
9061                    dlFolderImpl.setCreateDate(dlFolder.getCreateDate());
9062                    dlFolderImpl.setModifiedDate(dlFolder.getModifiedDate());
9063                    dlFolderImpl.setRepositoryId(dlFolder.getRepositoryId());
9064                    dlFolderImpl.setMountPoint(dlFolder.isMountPoint());
9065                    dlFolderImpl.setParentFolderId(dlFolder.getParentFolderId());
9066                    dlFolderImpl.setTreePath(dlFolder.getTreePath());
9067                    dlFolderImpl.setName(dlFolder.getName());
9068                    dlFolderImpl.setDescription(dlFolder.getDescription());
9069                    dlFolderImpl.setLastPostDate(dlFolder.getLastPostDate());
9070                    dlFolderImpl.setDefaultFileEntryTypeId(dlFolder.getDefaultFileEntryTypeId());
9071                    dlFolderImpl.setHidden(dlFolder.isHidden());
9072                    dlFolderImpl.setOverrideFileEntryTypes(dlFolder.isOverrideFileEntryTypes());
9073                    dlFolderImpl.setStatus(dlFolder.getStatus());
9074                    dlFolderImpl.setStatusByUserId(dlFolder.getStatusByUserId());
9075                    dlFolderImpl.setStatusByUserName(dlFolder.getStatusByUserName());
9076                    dlFolderImpl.setStatusDate(dlFolder.getStatusDate());
9077    
9078                    return dlFolderImpl;
9079            }
9080    
9081            /**
9082             * Returns the document library folder with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
9083             *
9084             * @param primaryKey the primary key of the document library folder
9085             * @return the document library folder
9086             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
9087             * @throws SystemException if a system exception occurred
9088             */
9089            @Override
9090            public DLFolder findByPrimaryKey(Serializable primaryKey)
9091                    throws NoSuchFolderException, SystemException {
9092                    DLFolder dlFolder = fetchByPrimaryKey(primaryKey);
9093    
9094                    if (dlFolder == null) {
9095                            if (_log.isWarnEnabled()) {
9096                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
9097                            }
9098    
9099                            throw new NoSuchFolderException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
9100                                    primaryKey);
9101                    }
9102    
9103                    return dlFolder;
9104            }
9105    
9106            /**
9107             * Returns the document library folder with the primary key or throws a {@link com.liferay.portlet.documentlibrary.NoSuchFolderException} if it could not be found.
9108             *
9109             * @param folderId the primary key of the document library folder
9110             * @return the document library folder
9111             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
9112             * @throws SystemException if a system exception occurred
9113             */
9114            @Override
9115            public DLFolder findByPrimaryKey(long folderId)
9116                    throws NoSuchFolderException, SystemException {
9117                    return findByPrimaryKey((Serializable)folderId);
9118            }
9119    
9120            /**
9121             * Returns the document library folder with the primary key or returns <code>null</code> if it could not be found.
9122             *
9123             * @param primaryKey the primary key of the document library folder
9124             * @return the document library folder, or <code>null</code> if a document library folder with the primary key could not be found
9125             * @throws SystemException if a system exception occurred
9126             */
9127            @Override
9128            public DLFolder fetchByPrimaryKey(Serializable primaryKey)
9129                    throws SystemException {
9130                    DLFolder dlFolder = (DLFolder)EntityCacheUtil.getResult(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
9131                                    DLFolderImpl.class, primaryKey);
9132    
9133                    if (dlFolder == _nullDLFolder) {
9134                            return null;
9135                    }
9136    
9137                    if (dlFolder == null) {
9138                            Session session = null;
9139    
9140                            try {
9141                                    session = openSession();
9142    
9143                                    dlFolder = (DLFolder)session.get(DLFolderImpl.class, primaryKey);
9144    
9145                                    if (dlFolder != null) {
9146                                            cacheResult(dlFolder);
9147                                    }
9148                                    else {
9149                                            EntityCacheUtil.putResult(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
9150                                                    DLFolderImpl.class, primaryKey, _nullDLFolder);
9151                                    }
9152                            }
9153                            catch (Exception e) {
9154                                    EntityCacheUtil.removeResult(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
9155                                            DLFolderImpl.class, primaryKey);
9156    
9157                                    throw processException(e);
9158                            }
9159                            finally {
9160                                    closeSession(session);
9161                            }
9162                    }
9163    
9164                    return dlFolder;
9165            }
9166    
9167            /**
9168             * Returns the document library folder with the primary key or returns <code>null</code> if it could not be found.
9169             *
9170             * @param folderId the primary key of the document library folder
9171             * @return the document library folder, or <code>null</code> if a document library folder with the primary key could not be found
9172             * @throws SystemException if a system exception occurred
9173             */
9174            @Override
9175            public DLFolder fetchByPrimaryKey(long folderId) throws SystemException {
9176                    return fetchByPrimaryKey((Serializable)folderId);
9177            }
9178    
9179            /**
9180             * Returns all the document library folders.
9181             *
9182             * @return the document library folders
9183             * @throws SystemException if a system exception occurred
9184             */
9185            @Override
9186            public List<DLFolder> findAll() throws SystemException {
9187                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
9188            }
9189    
9190            /**
9191             * Returns a range of all the document library folders.
9192             *
9193             * <p>
9194             * 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.
9195             * </p>
9196             *
9197             * @param start the lower bound of the range of document library folders
9198             * @param end the upper bound of the range of document library folders (not inclusive)
9199             * @return the range of document library folders
9200             * @throws SystemException if a system exception occurred
9201             */
9202            @Override
9203            public List<DLFolder> findAll(int start, int end) throws SystemException {
9204                    return findAll(start, end, null);
9205            }
9206    
9207            /**
9208             * Returns an ordered range of all the document library folders.
9209             *
9210             * <p>
9211             * 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.
9212             * </p>
9213             *
9214             * @param start the lower bound of the range of document library folders
9215             * @param end the upper bound of the range of document library folders (not inclusive)
9216             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9217             * @return the ordered range of document library folders
9218             * @throws SystemException if a system exception occurred
9219             */
9220            @Override
9221            public List<DLFolder> findAll(int start, int end,
9222                    OrderByComparator orderByComparator) throws SystemException {
9223                    boolean pagination = true;
9224                    FinderPath finderPath = null;
9225                    Object[] finderArgs = null;
9226    
9227                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
9228                                    (orderByComparator == null)) {
9229                            pagination = false;
9230                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
9231                            finderArgs = FINDER_ARGS_EMPTY;
9232                    }
9233                    else {
9234                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
9235                            finderArgs = new Object[] { start, end, orderByComparator };
9236                    }
9237    
9238                    List<DLFolder> list = (List<DLFolder>)FinderCacheUtil.getResult(finderPath,
9239                                    finderArgs, this);
9240    
9241                    if (list == null) {
9242                            StringBundler query = null;
9243                            String sql = null;
9244    
9245                            if (orderByComparator != null) {
9246                                    query = new StringBundler(2 +
9247                                                    (orderByComparator.getOrderByFields().length * 3));
9248    
9249                                    query.append(_SQL_SELECT_DLFOLDER);
9250    
9251                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9252                                            orderByComparator);
9253    
9254                                    sql = query.toString();
9255                            }
9256                            else {
9257                                    sql = _SQL_SELECT_DLFOLDER;
9258    
9259                                    if (pagination) {
9260                                            sql = sql.concat(DLFolderModelImpl.ORDER_BY_JPQL);
9261                                    }
9262                            }
9263    
9264                            Session session = null;
9265    
9266                            try {
9267                                    session = openSession();
9268    
9269                                    Query q = session.createQuery(sql);
9270    
9271                                    if (!pagination) {
9272                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
9273                                                            start, end, false);
9274    
9275                                            Collections.sort(list);
9276    
9277                                            list = new UnmodifiableList<DLFolder>(list);
9278                                    }
9279                                    else {
9280                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
9281                                                            start, end);
9282                                    }
9283    
9284                                    cacheResult(list);
9285    
9286                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
9287                            }
9288                            catch (Exception e) {
9289                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
9290    
9291                                    throw processException(e);
9292                            }
9293                            finally {
9294                                    closeSession(session);
9295                            }
9296                    }
9297    
9298                    return list;
9299            }
9300    
9301            /**
9302             * Removes all the document library folders from the database.
9303             *
9304             * @throws SystemException if a system exception occurred
9305             */
9306            @Override
9307            public void removeAll() throws SystemException {
9308                    for (DLFolder dlFolder : findAll()) {
9309                            remove(dlFolder);
9310                    }
9311            }
9312    
9313            /**
9314             * Returns the number of document library folders.
9315             *
9316             * @return the number of document library folders
9317             * @throws SystemException if a system exception occurred
9318             */
9319            @Override
9320            public int countAll() throws SystemException {
9321                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
9322                                    FINDER_ARGS_EMPTY, this);
9323    
9324                    if (count == null) {
9325                            Session session = null;
9326    
9327                            try {
9328                                    session = openSession();
9329    
9330                                    Query q = session.createQuery(_SQL_COUNT_DLFOLDER);
9331    
9332                                    count = (Long)q.uniqueResult();
9333    
9334                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
9335                                            FINDER_ARGS_EMPTY, count);
9336                            }
9337                            catch (Exception e) {
9338                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
9339                                            FINDER_ARGS_EMPTY);
9340    
9341                                    throw processException(e);
9342                            }
9343                            finally {
9344                                    closeSession(session);
9345                            }
9346                    }
9347    
9348                    return count.intValue();
9349            }
9350    
9351            /**
9352             * Returns all the document library file entry types associated with the document library folder.
9353             *
9354             * @param pk the primary key of the document library folder
9355             * @return the document library file entry types associated with the document library folder
9356             * @throws SystemException if a system exception occurred
9357             */
9358            @Override
9359            public List<com.liferay.portlet.documentlibrary.model.DLFileEntryType> getDLFileEntryTypes(
9360                    long pk) throws SystemException {
9361                    return getDLFileEntryTypes(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
9362            }
9363    
9364            /**
9365             * Returns a range of all the document library file entry types associated with the document library folder.
9366             *
9367             * <p>
9368             * 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.
9369             * </p>
9370             *
9371             * @param pk the primary key of the document library folder
9372             * @param start the lower bound of the range of document library folders
9373             * @param end the upper bound of the range of document library folders (not inclusive)
9374             * @return the range of document library file entry types associated with the document library folder
9375             * @throws SystemException if a system exception occurred
9376             */
9377            @Override
9378            public List<com.liferay.portlet.documentlibrary.model.DLFileEntryType> getDLFileEntryTypes(
9379                    long pk, int start, int end) throws SystemException {
9380                    return getDLFileEntryTypes(pk, start, end, null);
9381            }
9382    
9383            /**
9384             * Returns an ordered range of all the document library file entry types associated with the document library folder.
9385             *
9386             * <p>
9387             * 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.
9388             * </p>
9389             *
9390             * @param pk the primary key of the document library folder
9391             * @param start the lower bound of the range of document library folders
9392             * @param end the upper bound of the range of document library folders (not inclusive)
9393             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9394             * @return the ordered range of document library file entry types associated with the document library folder
9395             * @throws SystemException if a system exception occurred
9396             */
9397            @Override
9398            public List<com.liferay.portlet.documentlibrary.model.DLFileEntryType> getDLFileEntryTypes(
9399                    long pk, int start, int end, OrderByComparator orderByComparator)
9400                    throws SystemException {
9401                    return dlFolderToDLFileEntryTypeTableMapper.getRightBaseModels(pk,
9402                            start, end, orderByComparator);
9403            }
9404    
9405            /**
9406             * Returns the number of document library file entry types associated with the document library folder.
9407             *
9408             * @param pk the primary key of the document library folder
9409             * @return the number of document library file entry types associated with the document library folder
9410             * @throws SystemException if a system exception occurred
9411             */
9412            @Override
9413            public int getDLFileEntryTypesSize(long pk) throws SystemException {
9414                    long[] pks = dlFolderToDLFileEntryTypeTableMapper.getRightPrimaryKeys(pk);
9415    
9416                    return pks.length;
9417            }
9418    
9419            /**
9420             * Returns <code>true</code> if the document library file entry type is associated with the document library folder.
9421             *
9422             * @param pk the primary key of the document library folder
9423             * @param dlFileEntryTypePK the primary key of the document library file entry type
9424             * @return <code>true</code> if the document library file entry type is associated with the document library folder; <code>false</code> otherwise
9425             * @throws SystemException if a system exception occurred
9426             */
9427            @Override
9428            public boolean containsDLFileEntryType(long pk, long dlFileEntryTypePK)
9429                    throws SystemException {
9430                    return dlFolderToDLFileEntryTypeTableMapper.containsTableMapping(pk,
9431                            dlFileEntryTypePK);
9432            }
9433    
9434            /**
9435             * Returns <code>true</code> if the document library folder has any document library file entry types associated with it.
9436             *
9437             * @param pk the primary key of the document library folder to check for associations with document library file entry types
9438             * @return <code>true</code> if the document library folder has any document library file entry types associated with it; <code>false</code> otherwise
9439             * @throws SystemException if a system exception occurred
9440             */
9441            @Override
9442            public boolean containsDLFileEntryTypes(long pk) throws SystemException {
9443                    if (getDLFileEntryTypesSize(pk) > 0) {
9444                            return true;
9445                    }
9446                    else {
9447                            return false;
9448                    }
9449            }
9450    
9451            /**
9452             * 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.
9453             *
9454             * @param pk the primary key of the document library folder
9455             * @param dlFileEntryTypePK the primary key of the document library file entry type
9456             * @throws SystemException if a system exception occurred
9457             */
9458            @Override
9459            public void addDLFileEntryType(long pk, long dlFileEntryTypePK)
9460                    throws SystemException {
9461                    dlFolderToDLFileEntryTypeTableMapper.addTableMapping(pk,
9462                            dlFileEntryTypePK);
9463            }
9464    
9465            /**
9466             * 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.
9467             *
9468             * @param pk the primary key of the document library folder
9469             * @param dlFileEntryType the document library file entry type
9470             * @throws SystemException if a system exception occurred
9471             */
9472            @Override
9473            public void addDLFileEntryType(long pk,
9474                    com.liferay.portlet.documentlibrary.model.DLFileEntryType dlFileEntryType)
9475                    throws SystemException {
9476                    dlFolderToDLFileEntryTypeTableMapper.addTableMapping(pk,
9477                            dlFileEntryType.getPrimaryKey());
9478            }
9479    
9480            /**
9481             * 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.
9482             *
9483             * @param pk the primary key of the document library folder
9484             * @param dlFileEntryTypePKs the primary keys of the document library file entry types
9485             * @throws SystemException if a system exception occurred
9486             */
9487            @Override
9488            public void addDLFileEntryTypes(long pk, long[] dlFileEntryTypePKs)
9489                    throws SystemException {
9490                    for (long dlFileEntryTypePK : dlFileEntryTypePKs) {
9491                            dlFolderToDLFileEntryTypeTableMapper.addTableMapping(pk,
9492                                    dlFileEntryTypePK);
9493                    }
9494            }
9495    
9496            /**
9497             * 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.
9498             *
9499             * @param pk the primary key of the document library folder
9500             * @param dlFileEntryTypes the document library file entry types
9501             * @throws SystemException if a system exception occurred
9502             */
9503            @Override
9504            public void addDLFileEntryTypes(long pk,
9505                    List<com.liferay.portlet.documentlibrary.model.DLFileEntryType> dlFileEntryTypes)
9506                    throws SystemException {
9507                    for (com.liferay.portlet.documentlibrary.model.DLFileEntryType dlFileEntryType : dlFileEntryTypes) {
9508                            dlFolderToDLFileEntryTypeTableMapper.addTableMapping(pk,
9509                                    dlFileEntryType.getPrimaryKey());
9510                    }
9511            }
9512    
9513            /**
9514             * 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.
9515             *
9516             * @param pk the primary key of the document library folder to clear the associated document library file entry types from
9517             * @throws SystemException if a system exception occurred
9518             */
9519            @Override
9520            public void clearDLFileEntryTypes(long pk) throws SystemException {
9521                    dlFolderToDLFileEntryTypeTableMapper.deleteLeftPrimaryKeyTableMappings(pk);
9522            }
9523    
9524            /**
9525             * 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.
9526             *
9527             * @param pk the primary key of the document library folder
9528             * @param dlFileEntryTypePK the primary key of the document library file entry type
9529             * @throws SystemException if a system exception occurred
9530             */
9531            @Override
9532            public void removeDLFileEntryType(long pk, long dlFileEntryTypePK)
9533                    throws SystemException {
9534                    dlFolderToDLFileEntryTypeTableMapper.deleteTableMapping(pk,
9535                            dlFileEntryTypePK);
9536            }
9537    
9538            /**
9539             * 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.
9540             *
9541             * @param pk the primary key of the document library folder
9542             * @param dlFileEntryType the document library file entry type
9543             * @throws SystemException if a system exception occurred
9544             */
9545            @Override
9546            public void removeDLFileEntryType(long pk,
9547                    com.liferay.portlet.documentlibrary.model.DLFileEntryType dlFileEntryType)
9548                    throws SystemException {
9549                    dlFolderToDLFileEntryTypeTableMapper.deleteTableMapping(pk,
9550                            dlFileEntryType.getPrimaryKey());
9551            }
9552    
9553            /**
9554             * 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.
9555             *
9556             * @param pk the primary key of the document library folder
9557             * @param dlFileEntryTypePKs the primary keys of the document library file entry types
9558             * @throws SystemException if a system exception occurred
9559             */
9560            @Override
9561            public void removeDLFileEntryTypes(long pk, long[] dlFileEntryTypePKs)
9562                    throws SystemException {
9563                    for (long dlFileEntryTypePK : dlFileEntryTypePKs) {
9564                            dlFolderToDLFileEntryTypeTableMapper.deleteTableMapping(pk,
9565                                    dlFileEntryTypePK);
9566                    }
9567            }
9568    
9569            /**
9570             * 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.
9571             *
9572             * @param pk the primary key of the document library folder
9573             * @param dlFileEntryTypes the document library file entry types
9574             * @throws SystemException if a system exception occurred
9575             */
9576            @Override
9577            public void removeDLFileEntryTypes(long pk,
9578                    List<com.liferay.portlet.documentlibrary.model.DLFileEntryType> dlFileEntryTypes)
9579                    throws SystemException {
9580                    for (com.liferay.portlet.documentlibrary.model.DLFileEntryType dlFileEntryType : dlFileEntryTypes) {
9581                            dlFolderToDLFileEntryTypeTableMapper.deleteTableMapping(pk,
9582                                    dlFileEntryType.getPrimaryKey());
9583                    }
9584            }
9585    
9586            /**
9587             * 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.
9588             *
9589             * @param pk the primary key of the document library folder
9590             * @param dlFileEntryTypePKs the primary keys of the document library file entry types to be associated with the document library folder
9591             * @throws SystemException if a system exception occurred
9592             */
9593            @Override
9594            public void setDLFileEntryTypes(long pk, long[] dlFileEntryTypePKs)
9595                    throws SystemException {
9596                    dlFolderToDLFileEntryTypeTableMapper.deleteLeftPrimaryKeyTableMappings(pk);
9597    
9598                    for (Long dlFileEntryTypePK : dlFileEntryTypePKs) {
9599                            dlFolderToDLFileEntryTypeTableMapper.addTableMapping(pk,
9600                                    dlFileEntryTypePK);
9601                    }
9602            }
9603    
9604            /**
9605             * 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.
9606             *
9607             * @param pk the primary key of the document library folder
9608             * @param dlFileEntryTypes the document library file entry types to be associated with the document library folder
9609             * @throws SystemException if a system exception occurred
9610             */
9611            @Override
9612            public void setDLFileEntryTypes(long pk,
9613                    List<com.liferay.portlet.documentlibrary.model.DLFileEntryType> dlFileEntryTypes)
9614                    throws SystemException {
9615                    try {
9616                            long[] dlFileEntryTypePKs = new long[dlFileEntryTypes.size()];
9617    
9618                            for (int i = 0; i < dlFileEntryTypes.size(); i++) {
9619                                    com.liferay.portlet.documentlibrary.model.DLFileEntryType dlFileEntryType =
9620                                            dlFileEntryTypes.get(i);
9621    
9622                                    dlFileEntryTypePKs[i] = dlFileEntryType.getPrimaryKey();
9623                            }
9624    
9625                            setDLFileEntryTypes(pk, dlFileEntryTypePKs);
9626                    }
9627                    catch (Exception e) {
9628                            throw processException(e);
9629                    }
9630                    finally {
9631                            FinderCacheUtil.clearCache(DLFolderModelImpl.MAPPING_TABLE_DLFILEENTRYTYPES_DLFOLDERS_NAME);
9632                    }
9633            }
9634    
9635            @Override
9636            protected Set<String> getBadColumnNames() {
9637                    return _badColumnNames;
9638            }
9639    
9640            /**
9641             * Initializes the document library folder persistence.
9642             */
9643            public void afterPropertiesSet() {
9644                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
9645                                            com.liferay.portal.util.PropsUtil.get(
9646                                                    "value.object.listener.com.liferay.portlet.documentlibrary.model.DLFolder")));
9647    
9648                    if (listenerClassNames.length > 0) {
9649                            try {
9650                                    List<ModelListener<DLFolder>> listenersList = new ArrayList<ModelListener<DLFolder>>();
9651    
9652                                    for (String listenerClassName : listenerClassNames) {
9653                                            listenersList.add((ModelListener<DLFolder>)InstanceFactory.newInstance(
9654                                                            getClassLoader(), listenerClassName));
9655                                    }
9656    
9657                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
9658                            }
9659                            catch (Exception e) {
9660                                    _log.error(e);
9661                            }
9662                    }
9663    
9664                    dlFolderToDLFileEntryTypeTableMapper = TableMapperFactory.getTableMapper("DLFileEntryTypes_DLFolders",
9665                                    "folderId", "fileEntryTypeId", this, dlFileEntryTypePersistence);
9666            }
9667    
9668            public void destroy() {
9669                    EntityCacheUtil.removeCache(DLFolderImpl.class.getName());
9670                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
9671                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
9672                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
9673            }
9674    
9675            @BeanReference(type = DLFileEntryTypePersistence.class)
9676            protected DLFileEntryTypePersistence dlFileEntryTypePersistence;
9677            protected TableMapper<DLFolder, com.liferay.portlet.documentlibrary.model.DLFileEntryType> dlFolderToDLFileEntryTypeTableMapper;
9678            private static final String _SQL_SELECT_DLFOLDER = "SELECT dlFolder FROM DLFolder dlFolder";
9679            private static final String _SQL_SELECT_DLFOLDER_WHERE = "SELECT dlFolder FROM DLFolder dlFolder WHERE ";
9680            private static final String _SQL_COUNT_DLFOLDER = "SELECT COUNT(dlFolder) FROM DLFolder dlFolder";
9681            private static final String _SQL_COUNT_DLFOLDER_WHERE = "SELECT COUNT(dlFolder) FROM DLFolder dlFolder WHERE ";
9682            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "dlFolder.folderId";
9683            private static final String _FILTER_SQL_SELECT_DLFOLDER_WHERE = "SELECT DISTINCT {dlFolder.*} FROM DLFolder dlFolder WHERE ";
9684            private static final String _FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1 =
9685                    "SELECT {DLFolder.*} FROM (SELECT DISTINCT dlFolder.folderId FROM DLFolder dlFolder WHERE ";
9686            private static final String _FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2 =
9687                    ") TEMP_TABLE INNER JOIN DLFolder ON TEMP_TABLE.folderId = DLFolder.folderId";
9688            private static final String _FILTER_SQL_COUNT_DLFOLDER_WHERE = "SELECT COUNT(DISTINCT dlFolder.folderId) AS COUNT_VALUE FROM DLFolder dlFolder WHERE ";
9689            private static final String _FILTER_ENTITY_ALIAS = "dlFolder";
9690            private static final String _FILTER_ENTITY_TABLE = "DLFolder";
9691            private static final String _ORDER_BY_ENTITY_ALIAS = "dlFolder.";
9692            private static final String _ORDER_BY_ENTITY_TABLE = "DLFolder.";
9693            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No DLFolder exists with the primary key ";
9694            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No DLFolder exists with the key {";
9695            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
9696            private static Log _log = LogFactoryUtil.getLog(DLFolderPersistenceImpl.class);
9697            private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
9698                                    "uuid", "hidden"
9699                            });
9700            private static DLFolder _nullDLFolder = new DLFolderImpl() {
9701                            @Override
9702                            public Object clone() {
9703                                    return this;
9704                            }
9705    
9706                            @Override
9707                            public CacheModel<DLFolder> toCacheModel() {
9708                                    return _nullDLFolderCacheModel;
9709                            }
9710                    };
9711    
9712            private static CacheModel<DLFolder> _nullDLFolderCacheModel = new CacheModel<DLFolder>() {
9713                            @Override
9714                            public DLFolder toEntityModel() {
9715                                    return _nullDLFolder;
9716                            }
9717                    };
9718    }