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