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_REPOSITORYIDLIST =
3022                    new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
3023                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
3024                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByRepositoryIdList",
3025                            new String[] {
3026                                    Long.class.getName(),
3027                                    
3028                            Integer.class.getName(), Integer.class.getName(),
3029                                    OrderByComparator.class.getName()
3030                            });
3031            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_REPOSITORYIDLIST =
3032                    new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
3033                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
3034                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
3035                            "findByRepositoryIdList", new String[] { Long.class.getName() },
3036                            DLFolderModelImpl.REPOSITORYID_COLUMN_BITMASK |
3037                            DLFolderModelImpl.PARENTFOLDERID_COLUMN_BITMASK |
3038                            DLFolderModelImpl.NAME_COLUMN_BITMASK);
3039            public static final FinderPath FINDER_PATH_COUNT_BY_REPOSITORYIDLIST = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
3040                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
3041                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
3042                            "countByRepositoryIdList", new String[] { Long.class.getName() });
3043    
3044            /**
3045             * Returns all the document library folders where repositoryId = &#63;.
3046             *
3047             * @param repositoryId the repository ID
3048             * @return the matching document library folders
3049             * @throws SystemException if a system exception occurred
3050             */
3051            @Override
3052            public List<DLFolder> findByRepositoryIdList(long repositoryId)
3053                    throws SystemException {
3054                    return findByRepositoryIdList(repositoryId, QueryUtil.ALL_POS,
3055                            QueryUtil.ALL_POS, null);
3056            }
3057    
3058            /**
3059             * Returns a range of all the document library folders where repositoryId = &#63;.
3060             *
3061             * <p>
3062             * 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.
3063             * </p>
3064             *
3065             * @param repositoryId the repository 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> findByRepositoryIdList(long repositoryId, int start,
3073                    int end) throws SystemException {
3074                    return findByRepositoryIdList(repositoryId, start, end, null);
3075            }
3076    
3077            /**
3078             * Returns an ordered range of all the document library folders where repositoryId = &#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 repositoryId the repository ID
3085             * @param start the lower bound of the range of document library folders
3086             * @param end the upper bound of the range of document library folders (not inclusive)
3087             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3088             * @return the ordered range of matching document library folders
3089             * @throws SystemException if a system exception occurred
3090             */
3091            @Override
3092            public List<DLFolder> findByRepositoryIdList(long repositoryId, int start,
3093                    int end, OrderByComparator orderByComparator) throws SystemException {
3094                    boolean pagination = true;
3095                    FinderPath finderPath = null;
3096                    Object[] finderArgs = null;
3097    
3098                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3099                                    (orderByComparator == null)) {
3100                            pagination = false;
3101                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_REPOSITORYIDLIST;
3102                            finderArgs = new Object[] { repositoryId };
3103                    }
3104                    else {
3105                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_REPOSITORYIDLIST;
3106                            finderArgs = new Object[] {
3107                                            repositoryId,
3108                                            
3109                                            start, end, orderByComparator
3110                                    };
3111                    }
3112    
3113                    List<DLFolder> list = (List<DLFolder>)FinderCacheUtil.getResult(finderPath,
3114                                    finderArgs, this);
3115    
3116                    if ((list != null) && !list.isEmpty()) {
3117                            for (DLFolder dlFolder : list) {
3118                                    if ((repositoryId != dlFolder.getRepositoryId())) {
3119                                            list = null;
3120    
3121                                            break;
3122                                    }
3123                            }
3124                    }
3125    
3126                    if (list == null) {
3127                            StringBundler query = null;
3128    
3129                            if (orderByComparator != null) {
3130                                    query = new StringBundler(3 +
3131                                                    (orderByComparator.getOrderByFields().length * 3));
3132                            }
3133                            else {
3134                                    query = new StringBundler(3);
3135                            }
3136    
3137                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
3138    
3139                            query.append(_FINDER_COLUMN_REPOSITORYIDLIST_REPOSITORYID_2);
3140    
3141                            if (orderByComparator != null) {
3142                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3143                                            orderByComparator);
3144                            }
3145                            else
3146                             if (pagination) {
3147                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
3148                            }
3149    
3150                            String sql = query.toString();
3151    
3152                            Session session = null;
3153    
3154                            try {
3155                                    session = openSession();
3156    
3157                                    Query q = session.createQuery(sql);
3158    
3159                                    QueryPos qPos = QueryPos.getInstance(q);
3160    
3161                                    qPos.add(repositoryId);
3162    
3163                                    if (!pagination) {
3164                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
3165                                                            start, end, false);
3166    
3167                                            Collections.sort(list);
3168    
3169                                            list = new UnmodifiableList<DLFolder>(list);
3170                                    }
3171                                    else {
3172                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
3173                                                            start, end);
3174                                    }
3175    
3176                                    cacheResult(list);
3177    
3178                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
3179                            }
3180                            catch (Exception e) {
3181                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3182    
3183                                    throw processException(e);
3184                            }
3185                            finally {
3186                                    closeSession(session);
3187                            }
3188                    }
3189    
3190                    return list;
3191            }
3192    
3193            /**
3194             * Returns the first document library folder in the ordered set where repositoryId = &#63;.
3195             *
3196             * @param repositoryId the repository ID
3197             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3198             * @return the first matching document library folder
3199             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
3200             * @throws SystemException if a system exception occurred
3201             */
3202            @Override
3203            public DLFolder findByRepositoryIdList_First(long repositoryId,
3204                    OrderByComparator orderByComparator)
3205                    throws NoSuchFolderException, SystemException {
3206                    DLFolder dlFolder = fetchByRepositoryIdList_First(repositoryId,
3207                                    orderByComparator);
3208    
3209                    if (dlFolder != null) {
3210                            return dlFolder;
3211                    }
3212    
3213                    StringBundler msg = new StringBundler(4);
3214    
3215                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3216    
3217                    msg.append("repositoryId=");
3218                    msg.append(repositoryId);
3219    
3220                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3221    
3222                    throw new NoSuchFolderException(msg.toString());
3223            }
3224    
3225            /**
3226             * Returns the first document library folder in the ordered set where repositoryId = &#63;.
3227             *
3228             * @param repositoryId the repository ID
3229             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3230             * @return the first matching document library folder, or <code>null</code> if a matching document library folder could not be found
3231             * @throws SystemException if a system exception occurred
3232             */
3233            @Override
3234            public DLFolder fetchByRepositoryIdList_First(long repositoryId,
3235                    OrderByComparator orderByComparator) throws SystemException {
3236                    List<DLFolder> list = findByRepositoryIdList(repositoryId, 0, 1,
3237                                    orderByComparator);
3238    
3239                    if (!list.isEmpty()) {
3240                            return list.get(0);
3241                    }
3242    
3243                    return null;
3244            }
3245    
3246            /**
3247             * Returns the last document library folder in the ordered set where repositoryId = &#63;.
3248             *
3249             * @param repositoryId the repository ID
3250             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3251             * @return the last matching document library folder
3252             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
3253             * @throws SystemException if a system exception occurred
3254             */
3255            @Override
3256            public DLFolder findByRepositoryIdList_Last(long repositoryId,
3257                    OrderByComparator orderByComparator)
3258                    throws NoSuchFolderException, SystemException {
3259                    DLFolder dlFolder = fetchByRepositoryIdList_Last(repositoryId,
3260                                    orderByComparator);
3261    
3262                    if (dlFolder != null) {
3263                            return dlFolder;
3264                    }
3265    
3266                    StringBundler msg = new StringBundler(4);
3267    
3268                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3269    
3270                    msg.append("repositoryId=");
3271                    msg.append(repositoryId);
3272    
3273                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3274    
3275                    throw new NoSuchFolderException(msg.toString());
3276            }
3277    
3278            /**
3279             * Returns the last document library folder in the ordered set where repositoryId = &#63;.
3280             *
3281             * @param repositoryId the repository ID
3282             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3283             * @return the last matching document library folder, or <code>null</code> if a matching document library folder could not be found
3284             * @throws SystemException if a system exception occurred
3285             */
3286            @Override
3287            public DLFolder fetchByRepositoryIdList_Last(long repositoryId,
3288                    OrderByComparator orderByComparator) throws SystemException {
3289                    int count = countByRepositoryIdList(repositoryId);
3290    
3291                    if (count == 0) {
3292                            return null;
3293                    }
3294    
3295                    List<DLFolder> list = findByRepositoryIdList(repositoryId, count - 1,
3296                                    count, orderByComparator);
3297    
3298                    if (!list.isEmpty()) {
3299                            return list.get(0);
3300                    }
3301    
3302                    return null;
3303            }
3304    
3305            /**
3306             * Returns the document library folders before and after the current document library folder in the ordered set where repositoryId = &#63;.
3307             *
3308             * @param folderId the primary key of the current document library folder
3309             * @param repositoryId the repository ID
3310             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3311             * @return the previous, current, and next document library folder
3312             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
3313             * @throws SystemException if a system exception occurred
3314             */
3315            @Override
3316            public DLFolder[] findByRepositoryIdList_PrevAndNext(long folderId,
3317                    long repositoryId, OrderByComparator orderByComparator)
3318                    throws NoSuchFolderException, SystemException {
3319                    DLFolder dlFolder = findByPrimaryKey(folderId);
3320    
3321                    Session session = null;
3322    
3323                    try {
3324                            session = openSession();
3325    
3326                            DLFolder[] array = new DLFolderImpl[3];
3327    
3328                            array[0] = getByRepositoryIdList_PrevAndNext(session, dlFolder,
3329                                            repositoryId, orderByComparator, true);
3330    
3331                            array[1] = dlFolder;
3332    
3333                            array[2] = getByRepositoryIdList_PrevAndNext(session, dlFolder,
3334                                            repositoryId, orderByComparator, false);
3335    
3336                            return array;
3337                    }
3338                    catch (Exception e) {
3339                            throw processException(e);
3340                    }
3341                    finally {
3342                            closeSession(session);
3343                    }
3344            }
3345    
3346            protected DLFolder getByRepositoryIdList_PrevAndNext(Session session,
3347                    DLFolder dlFolder, long repositoryId,
3348                    OrderByComparator orderByComparator, boolean previous) {
3349                    StringBundler query = null;
3350    
3351                    if (orderByComparator != null) {
3352                            query = new StringBundler(6 +
3353                                            (orderByComparator.getOrderByFields().length * 6));
3354                    }
3355                    else {
3356                            query = new StringBundler(3);
3357                    }
3358    
3359                    query.append(_SQL_SELECT_DLFOLDER_WHERE);
3360    
3361                    query.append(_FINDER_COLUMN_REPOSITORYIDLIST_REPOSITORYID_2);
3362    
3363                    if (orderByComparator != null) {
3364                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3365    
3366                            if (orderByConditionFields.length > 0) {
3367                                    query.append(WHERE_AND);
3368                            }
3369    
3370                            for (int i = 0; i < orderByConditionFields.length; i++) {
3371                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3372                                    query.append(orderByConditionFields[i]);
3373    
3374                                    if ((i + 1) < orderByConditionFields.length) {
3375                                            if (orderByComparator.isAscending() ^ previous) {
3376                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3377                                            }
3378                                            else {
3379                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3380                                            }
3381                                    }
3382                                    else {
3383                                            if (orderByComparator.isAscending() ^ previous) {
3384                                                    query.append(WHERE_GREATER_THAN);
3385                                            }
3386                                            else {
3387                                                    query.append(WHERE_LESSER_THAN);
3388                                            }
3389                                    }
3390                            }
3391    
3392                            query.append(ORDER_BY_CLAUSE);
3393    
3394                            String[] orderByFields = orderByComparator.getOrderByFields();
3395    
3396                            for (int i = 0; i < orderByFields.length; i++) {
3397                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3398                                    query.append(orderByFields[i]);
3399    
3400                                    if ((i + 1) < orderByFields.length) {
3401                                            if (orderByComparator.isAscending() ^ previous) {
3402                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3403                                            }
3404                                            else {
3405                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3406                                            }
3407                                    }
3408                                    else {
3409                                            if (orderByComparator.isAscending() ^ previous) {
3410                                                    query.append(ORDER_BY_ASC);
3411                                            }
3412                                            else {
3413                                                    query.append(ORDER_BY_DESC);
3414                                            }
3415                                    }
3416                            }
3417                    }
3418                    else {
3419                            query.append(DLFolderModelImpl.ORDER_BY_JPQL);
3420                    }
3421    
3422                    String sql = query.toString();
3423    
3424                    Query q = session.createQuery(sql);
3425    
3426                    q.setFirstResult(0);
3427                    q.setMaxResults(2);
3428    
3429                    QueryPos qPos = QueryPos.getInstance(q);
3430    
3431                    qPos.add(repositoryId);
3432    
3433                    if (orderByComparator != null) {
3434                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
3435    
3436                            for (Object value : values) {
3437                                    qPos.add(value);
3438                            }
3439                    }
3440    
3441                    List<DLFolder> list = q.list();
3442    
3443                    if (list.size() == 2) {
3444                            return list.get(1);
3445                    }
3446                    else {
3447                            return null;
3448                    }
3449            }
3450    
3451            /**
3452             * Removes all the document library folders where repositoryId = &#63; from the database.
3453             *
3454             * @param repositoryId the repository ID
3455             * @throws SystemException if a system exception occurred
3456             */
3457            @Override
3458            public void removeByRepositoryIdList(long repositoryId)
3459                    throws SystemException {
3460                    for (DLFolder dlFolder : findByRepositoryIdList(repositoryId,
3461                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3462                            remove(dlFolder);
3463                    }
3464            }
3465    
3466            /**
3467             * Returns the number of document library folders where repositoryId = &#63;.
3468             *
3469             * @param repositoryId the repository ID
3470             * @return the number of matching document library folders
3471             * @throws SystemException if a system exception occurred
3472             */
3473            @Override
3474            public int countByRepositoryIdList(long repositoryId)
3475                    throws SystemException {
3476                    FinderPath finderPath = FINDER_PATH_COUNT_BY_REPOSITORYIDLIST;
3477    
3478                    Object[] finderArgs = new Object[] { repositoryId };
3479    
3480                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3481                                    this);
3482    
3483                    if (count == null) {
3484                            StringBundler query = new StringBundler(2);
3485    
3486                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
3487    
3488                            query.append(_FINDER_COLUMN_REPOSITORYIDLIST_REPOSITORYID_2);
3489    
3490                            String sql = query.toString();
3491    
3492                            Session session = null;
3493    
3494                            try {
3495                                    session = openSession();
3496    
3497                                    Query q = session.createQuery(sql);
3498    
3499                                    QueryPos qPos = QueryPos.getInstance(q);
3500    
3501                                    qPos.add(repositoryId);
3502    
3503                                    count = (Long)q.uniqueResult();
3504    
3505                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
3506                            }
3507                            catch (Exception e) {
3508                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3509    
3510                                    throw processException(e);
3511                            }
3512                            finally {
3513                                    closeSession(session);
3514                            }
3515                    }
3516    
3517                    return count.intValue();
3518            }
3519    
3520            private static final String _FINDER_COLUMN_REPOSITORYIDLIST_REPOSITORYID_2 = "dlFolder.repositoryId = ?";
3521            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
3522                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
3523                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_P",
3524                            new String[] {
3525                                    Long.class.getName(), Long.class.getName(),
3526                                    
3527                            Integer.class.getName(), Integer.class.getName(),
3528                                    OrderByComparator.class.getName()
3529                            });
3530            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
3531                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
3532                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_P",
3533                            new String[] { Long.class.getName(), Long.class.getName() },
3534                            DLFolderModelImpl.GROUPID_COLUMN_BITMASK |
3535                            DLFolderModelImpl.PARENTFOLDERID_COLUMN_BITMASK |
3536                            DLFolderModelImpl.NAME_COLUMN_BITMASK);
3537            public static final FinderPath FINDER_PATH_COUNT_BY_G_P = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
3538                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
3539                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P",
3540                            new String[] { Long.class.getName(), Long.class.getName() });
3541    
3542            /**
3543             * Returns all the document library folders where groupId = &#63; and parentFolderId = &#63;.
3544             *
3545             * @param groupId the group ID
3546             * @param parentFolderId the parent folder ID
3547             * @return the matching document library folders
3548             * @throws SystemException if a system exception occurred
3549             */
3550            @Override
3551            public List<DLFolder> findByG_P(long groupId, long parentFolderId)
3552                    throws SystemException {
3553                    return findByG_P(groupId, parentFolderId, QueryUtil.ALL_POS,
3554                            QueryUtil.ALL_POS, null);
3555            }
3556    
3557            /**
3558             * Returns a range of all the document library folders where groupId = &#63; and parentFolderId = &#63;.
3559             *
3560             * <p>
3561             * 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.
3562             * </p>
3563             *
3564             * @param groupId the group ID
3565             * @param parentFolderId the parent folder ID
3566             * @param start the lower bound of the range of document library folders
3567             * @param end the upper bound of the range of document library folders (not inclusive)
3568             * @return the range of matching document library folders
3569             * @throws SystemException if a system exception occurred
3570             */
3571            @Override
3572            public List<DLFolder> findByG_P(long groupId, long parentFolderId,
3573                    int start, int end) throws SystemException {
3574                    return findByG_P(groupId, parentFolderId, start, end, null);
3575            }
3576    
3577            /**
3578             * Returns an ordered range of all the document library folders where groupId = &#63; and parentFolderId = &#63;.
3579             *
3580             * <p>
3581             * 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.
3582             * </p>
3583             *
3584             * @param groupId the group ID
3585             * @param parentFolderId the parent folder ID
3586             * @param start the lower bound of the range of document library folders
3587             * @param end the upper bound of the range of document library folders (not inclusive)
3588             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3589             * @return the ordered range of matching document library folders
3590             * @throws SystemException if a system exception occurred
3591             */
3592            @Override
3593            public List<DLFolder> findByG_P(long groupId, long parentFolderId,
3594                    int start, int end, OrderByComparator orderByComparator)
3595                    throws SystemException {
3596                    boolean pagination = true;
3597                    FinderPath finderPath = null;
3598                    Object[] finderArgs = null;
3599    
3600                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3601                                    (orderByComparator == null)) {
3602                            pagination = false;
3603                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P;
3604                            finderArgs = new Object[] { groupId, parentFolderId };
3605                    }
3606                    else {
3607                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P;
3608                            finderArgs = new Object[] {
3609                                            groupId, parentFolderId,
3610                                            
3611                                            start, end, orderByComparator
3612                                    };
3613                    }
3614    
3615                    List<DLFolder> list = (List<DLFolder>)FinderCacheUtil.getResult(finderPath,
3616                                    finderArgs, this);
3617    
3618                    if ((list != null) && !list.isEmpty()) {
3619                            for (DLFolder dlFolder : list) {
3620                                    if ((groupId != dlFolder.getGroupId()) ||
3621                                                    (parentFolderId != dlFolder.getParentFolderId())) {
3622                                            list = null;
3623    
3624                                            break;
3625                                    }
3626                            }
3627                    }
3628    
3629                    if (list == null) {
3630                            StringBundler query = null;
3631    
3632                            if (orderByComparator != null) {
3633                                    query = new StringBundler(4 +
3634                                                    (orderByComparator.getOrderByFields().length * 3));
3635                            }
3636                            else {
3637                                    query = new StringBundler(4);
3638                            }
3639    
3640                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
3641    
3642                            query.append(_FINDER_COLUMN_G_P_GROUPID_2);
3643    
3644                            query.append(_FINDER_COLUMN_G_P_PARENTFOLDERID_2);
3645    
3646                            if (orderByComparator != null) {
3647                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3648                                            orderByComparator);
3649                            }
3650                            else
3651                             if (pagination) {
3652                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
3653                            }
3654    
3655                            String sql = query.toString();
3656    
3657                            Session session = null;
3658    
3659                            try {
3660                                    session = openSession();
3661    
3662                                    Query q = session.createQuery(sql);
3663    
3664                                    QueryPos qPos = QueryPos.getInstance(q);
3665    
3666                                    qPos.add(groupId);
3667    
3668                                    qPos.add(parentFolderId);
3669    
3670                                    if (!pagination) {
3671                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
3672                                                            start, end, false);
3673    
3674                                            Collections.sort(list);
3675    
3676                                            list = new UnmodifiableList<DLFolder>(list);
3677                                    }
3678                                    else {
3679                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
3680                                                            start, end);
3681                                    }
3682    
3683                                    cacheResult(list);
3684    
3685                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
3686                            }
3687                            catch (Exception e) {
3688                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3689    
3690                                    throw processException(e);
3691                            }
3692                            finally {
3693                                    closeSession(session);
3694                            }
3695                    }
3696    
3697                    return list;
3698            }
3699    
3700            /**
3701             * Returns the first document library folder in the ordered set where groupId = &#63; and parentFolderId = &#63;.
3702             *
3703             * @param groupId the group ID
3704             * @param parentFolderId the parent folder ID
3705             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3706             * @return the first matching document library folder
3707             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
3708             * @throws SystemException if a system exception occurred
3709             */
3710            @Override
3711            public DLFolder findByG_P_First(long groupId, long parentFolderId,
3712                    OrderByComparator orderByComparator)
3713                    throws NoSuchFolderException, SystemException {
3714                    DLFolder dlFolder = fetchByG_P_First(groupId, parentFolderId,
3715                                    orderByComparator);
3716    
3717                    if (dlFolder != null) {
3718                            return dlFolder;
3719                    }
3720    
3721                    StringBundler msg = new StringBundler(6);
3722    
3723                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3724    
3725                    msg.append("groupId=");
3726                    msg.append(groupId);
3727    
3728                    msg.append(", parentFolderId=");
3729                    msg.append(parentFolderId);
3730    
3731                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3732    
3733                    throw new NoSuchFolderException(msg.toString());
3734            }
3735    
3736            /**
3737             * Returns the first document library folder in the ordered set where groupId = &#63; and parentFolderId = &#63;.
3738             *
3739             * @param groupId the group ID
3740             * @param parentFolderId the parent folder ID
3741             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3742             * @return the first matching document library folder, or <code>null</code> if a matching document library folder could not be found
3743             * @throws SystemException if a system exception occurred
3744             */
3745            @Override
3746            public DLFolder fetchByG_P_First(long groupId, long parentFolderId,
3747                    OrderByComparator orderByComparator) throws SystemException {
3748                    List<DLFolder> list = findByG_P(groupId, parentFolderId, 0, 1,
3749                                    orderByComparator);
3750    
3751                    if (!list.isEmpty()) {
3752                            return list.get(0);
3753                    }
3754    
3755                    return null;
3756            }
3757    
3758            /**
3759             * Returns the last document library folder in the ordered set where groupId = &#63; and parentFolderId = &#63;.
3760             *
3761             * @param groupId the group ID
3762             * @param parentFolderId the parent folder ID
3763             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3764             * @return the last matching document library folder
3765             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
3766             * @throws SystemException if a system exception occurred
3767             */
3768            @Override
3769            public DLFolder findByG_P_Last(long groupId, long parentFolderId,
3770                    OrderByComparator orderByComparator)
3771                    throws NoSuchFolderException, SystemException {
3772                    DLFolder dlFolder = fetchByG_P_Last(groupId, parentFolderId,
3773                                    orderByComparator);
3774    
3775                    if (dlFolder != null) {
3776                            return dlFolder;
3777                    }
3778    
3779                    StringBundler msg = new StringBundler(6);
3780    
3781                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3782    
3783                    msg.append("groupId=");
3784                    msg.append(groupId);
3785    
3786                    msg.append(", parentFolderId=");
3787                    msg.append(parentFolderId);
3788    
3789                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3790    
3791                    throw new NoSuchFolderException(msg.toString());
3792            }
3793    
3794            /**
3795             * Returns the last document library folder in the ordered set where groupId = &#63; and parentFolderId = &#63;.
3796             *
3797             * @param groupId the group ID
3798             * @param parentFolderId the parent folder ID
3799             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3800             * @return the last matching document library folder, or <code>null</code> if a matching document library folder could not be found
3801             * @throws SystemException if a system exception occurred
3802             */
3803            @Override
3804            public DLFolder fetchByG_P_Last(long groupId, long parentFolderId,
3805                    OrderByComparator orderByComparator) throws SystemException {
3806                    int count = countByG_P(groupId, parentFolderId);
3807    
3808                    if (count == 0) {
3809                            return null;
3810                    }
3811    
3812                    List<DLFolder> list = findByG_P(groupId, parentFolderId, count - 1,
3813                                    count, orderByComparator);
3814    
3815                    if (!list.isEmpty()) {
3816                            return list.get(0);
3817                    }
3818    
3819                    return null;
3820            }
3821    
3822            /**
3823             * Returns the document library folders before and after the current document library folder in the ordered set where groupId = &#63; and parentFolderId = &#63;.
3824             *
3825             * @param folderId the primary key of the current document library folder
3826             * @param groupId the group ID
3827             * @param parentFolderId the parent folder ID
3828             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3829             * @return the previous, current, and next document library folder
3830             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
3831             * @throws SystemException if a system exception occurred
3832             */
3833            @Override
3834            public DLFolder[] findByG_P_PrevAndNext(long folderId, long groupId,
3835                    long parentFolderId, OrderByComparator orderByComparator)
3836                    throws NoSuchFolderException, SystemException {
3837                    DLFolder dlFolder = findByPrimaryKey(folderId);
3838    
3839                    Session session = null;
3840    
3841                    try {
3842                            session = openSession();
3843    
3844                            DLFolder[] array = new DLFolderImpl[3];
3845    
3846                            array[0] = getByG_P_PrevAndNext(session, dlFolder, groupId,
3847                                            parentFolderId, orderByComparator, true);
3848    
3849                            array[1] = dlFolder;
3850    
3851                            array[2] = getByG_P_PrevAndNext(session, dlFolder, groupId,
3852                                            parentFolderId, orderByComparator, false);
3853    
3854                            return array;
3855                    }
3856                    catch (Exception e) {
3857                            throw processException(e);
3858                    }
3859                    finally {
3860                            closeSession(session);
3861                    }
3862            }
3863    
3864            protected DLFolder getByG_P_PrevAndNext(Session session, DLFolder dlFolder,
3865                    long groupId, long parentFolderId, OrderByComparator orderByComparator,
3866                    boolean previous) {
3867                    StringBundler query = null;
3868    
3869                    if (orderByComparator != null) {
3870                            query = new StringBundler(6 +
3871                                            (orderByComparator.getOrderByFields().length * 6));
3872                    }
3873                    else {
3874                            query = new StringBundler(3);
3875                    }
3876    
3877                    query.append(_SQL_SELECT_DLFOLDER_WHERE);
3878    
3879                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
3880    
3881                    query.append(_FINDER_COLUMN_G_P_PARENTFOLDERID_2);
3882    
3883                    if (orderByComparator != null) {
3884                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3885    
3886                            if (orderByConditionFields.length > 0) {
3887                                    query.append(WHERE_AND);
3888                            }
3889    
3890                            for (int i = 0; i < orderByConditionFields.length; i++) {
3891                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3892                                    query.append(orderByConditionFields[i]);
3893    
3894                                    if ((i + 1) < orderByConditionFields.length) {
3895                                            if (orderByComparator.isAscending() ^ previous) {
3896                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3897                                            }
3898                                            else {
3899                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3900                                            }
3901                                    }
3902                                    else {
3903                                            if (orderByComparator.isAscending() ^ previous) {
3904                                                    query.append(WHERE_GREATER_THAN);
3905                                            }
3906                                            else {
3907                                                    query.append(WHERE_LESSER_THAN);
3908                                            }
3909                                    }
3910                            }
3911    
3912                            query.append(ORDER_BY_CLAUSE);
3913    
3914                            String[] orderByFields = orderByComparator.getOrderByFields();
3915    
3916                            for (int i = 0; i < orderByFields.length; i++) {
3917                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3918                                    query.append(orderByFields[i]);
3919    
3920                                    if ((i + 1) < orderByFields.length) {
3921                                            if (orderByComparator.isAscending() ^ previous) {
3922                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3923                                            }
3924                                            else {
3925                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3926                                            }
3927                                    }
3928                                    else {
3929                                            if (orderByComparator.isAscending() ^ previous) {
3930                                                    query.append(ORDER_BY_ASC);
3931                                            }
3932                                            else {
3933                                                    query.append(ORDER_BY_DESC);
3934                                            }
3935                                    }
3936                            }
3937                    }
3938                    else {
3939                            query.append(DLFolderModelImpl.ORDER_BY_JPQL);
3940                    }
3941    
3942                    String sql = query.toString();
3943    
3944                    Query q = session.createQuery(sql);
3945    
3946                    q.setFirstResult(0);
3947                    q.setMaxResults(2);
3948    
3949                    QueryPos qPos = QueryPos.getInstance(q);
3950    
3951                    qPos.add(groupId);
3952    
3953                    qPos.add(parentFolderId);
3954    
3955                    if (orderByComparator != null) {
3956                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
3957    
3958                            for (Object value : values) {
3959                                    qPos.add(value);
3960                            }
3961                    }
3962    
3963                    List<DLFolder> list = q.list();
3964    
3965                    if (list.size() == 2) {
3966                            return list.get(1);
3967                    }
3968                    else {
3969                            return null;
3970                    }
3971            }
3972    
3973            /**
3974             * Returns all the document library folders that the user has permission to view where groupId = &#63; and parentFolderId = &#63;.
3975             *
3976             * @param groupId the group ID
3977             * @param parentFolderId the parent folder ID
3978             * @return the matching document library folders that the user has permission to view
3979             * @throws SystemException if a system exception occurred
3980             */
3981            @Override
3982            public List<DLFolder> filterFindByG_P(long groupId, long parentFolderId)
3983                    throws SystemException {
3984                    return filterFindByG_P(groupId, parentFolderId, QueryUtil.ALL_POS,
3985                            QueryUtil.ALL_POS, null);
3986            }
3987    
3988            /**
3989             * Returns a range of all the document library folders that the user has permission to view where groupId = &#63; and parentFolderId = &#63;.
3990             *
3991             * <p>
3992             * 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.
3993             * </p>
3994             *
3995             * @param groupId the group ID
3996             * @param parentFolderId the parent folder ID
3997             * @param start the lower bound of the range of document library folders
3998             * @param end the upper bound of the range of document library folders (not inclusive)
3999             * @return the range of matching document library folders that the user has permission to view
4000             * @throws SystemException if a system exception occurred
4001             */
4002            @Override
4003            public List<DLFolder> filterFindByG_P(long groupId, long parentFolderId,
4004                    int start, int end) throws SystemException {
4005                    return filterFindByG_P(groupId, parentFolderId, start, end, null);
4006            }
4007    
4008            /**
4009             * Returns an ordered range of all the document library folders that the user has permissions to view where groupId = &#63; and parentFolderId = &#63;.
4010             *
4011             * <p>
4012             * 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.
4013             * </p>
4014             *
4015             * @param groupId the group ID
4016             * @param parentFolderId the parent folder ID
4017             * @param start the lower bound of the range of document library folders
4018             * @param end the upper bound of the range of document library folders (not inclusive)
4019             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4020             * @return the ordered range of matching document library folders that the user has permission to view
4021             * @throws SystemException if a system exception occurred
4022             */
4023            @Override
4024            public List<DLFolder> filterFindByG_P(long groupId, long parentFolderId,
4025                    int start, int end, OrderByComparator orderByComparator)
4026                    throws SystemException {
4027                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4028                            return findByG_P(groupId, parentFolderId, start, end,
4029                                    orderByComparator);
4030                    }
4031    
4032                    StringBundler query = null;
4033    
4034                    if (orderByComparator != null) {
4035                            query = new StringBundler(4 +
4036                                            (orderByComparator.getOrderByFields().length * 3));
4037                    }
4038                    else {
4039                            query = new StringBundler(4);
4040                    }
4041    
4042                    if (getDB().isSupportsInlineDistinct()) {
4043                            query.append(_FILTER_SQL_SELECT_DLFOLDER_WHERE);
4044                    }
4045                    else {
4046                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1);
4047                    }
4048    
4049                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
4050    
4051                    query.append(_FINDER_COLUMN_G_P_PARENTFOLDERID_2);
4052    
4053                    if (!getDB().isSupportsInlineDistinct()) {
4054                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2);
4055                    }
4056    
4057                    if (orderByComparator != null) {
4058                            if (getDB().isSupportsInlineDistinct()) {
4059                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4060                                            orderByComparator, true);
4061                            }
4062                            else {
4063                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
4064                                            orderByComparator, true);
4065                            }
4066                    }
4067                    else {
4068                            if (getDB().isSupportsInlineDistinct()) {
4069                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
4070                            }
4071                            else {
4072                                    query.append(DLFolderModelImpl.ORDER_BY_SQL);
4073                            }
4074                    }
4075    
4076                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4077                                    DLFolder.class.getName(),
4078                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4079    
4080                    Session session = null;
4081    
4082                    try {
4083                            session = openSession();
4084    
4085                            SQLQuery q = session.createSQLQuery(sql);
4086    
4087                            if (getDB().isSupportsInlineDistinct()) {
4088                                    q.addEntity(_FILTER_ENTITY_ALIAS, DLFolderImpl.class);
4089                            }
4090                            else {
4091                                    q.addEntity(_FILTER_ENTITY_TABLE, DLFolderImpl.class);
4092                            }
4093    
4094                            QueryPos qPos = QueryPos.getInstance(q);
4095    
4096                            qPos.add(groupId);
4097    
4098                            qPos.add(parentFolderId);
4099    
4100                            return (List<DLFolder>)QueryUtil.list(q, getDialect(), start, end);
4101                    }
4102                    catch (Exception e) {
4103                            throw processException(e);
4104                    }
4105                    finally {
4106                            closeSession(session);
4107                    }
4108            }
4109    
4110            /**
4111             * 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;.
4112             *
4113             * @param folderId the primary key of the current document library folder
4114             * @param groupId the group ID
4115             * @param parentFolderId the parent folder ID
4116             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4117             * @return the previous, current, and next document library folder
4118             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
4119             * @throws SystemException if a system exception occurred
4120             */
4121            @Override
4122            public DLFolder[] filterFindByG_P_PrevAndNext(long folderId, long groupId,
4123                    long parentFolderId, OrderByComparator orderByComparator)
4124                    throws NoSuchFolderException, SystemException {
4125                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4126                            return findByG_P_PrevAndNext(folderId, groupId, parentFolderId,
4127                                    orderByComparator);
4128                    }
4129    
4130                    DLFolder dlFolder = findByPrimaryKey(folderId);
4131    
4132                    Session session = null;
4133    
4134                    try {
4135                            session = openSession();
4136    
4137                            DLFolder[] array = new DLFolderImpl[3];
4138    
4139                            array[0] = filterGetByG_P_PrevAndNext(session, dlFolder, groupId,
4140                                            parentFolderId, orderByComparator, true);
4141    
4142                            array[1] = dlFolder;
4143    
4144                            array[2] = filterGetByG_P_PrevAndNext(session, dlFolder, groupId,
4145                                            parentFolderId, orderByComparator, false);
4146    
4147                            return array;
4148                    }
4149                    catch (Exception e) {
4150                            throw processException(e);
4151                    }
4152                    finally {
4153                            closeSession(session);
4154                    }
4155            }
4156    
4157            protected DLFolder filterGetByG_P_PrevAndNext(Session session,
4158                    DLFolder dlFolder, long groupId, long parentFolderId,
4159                    OrderByComparator orderByComparator, boolean previous) {
4160                    StringBundler query = null;
4161    
4162                    if (orderByComparator != null) {
4163                            query = new StringBundler(6 +
4164                                            (orderByComparator.getOrderByFields().length * 6));
4165                    }
4166                    else {
4167                            query = new StringBundler(3);
4168                    }
4169    
4170                    if (getDB().isSupportsInlineDistinct()) {
4171                            query.append(_FILTER_SQL_SELECT_DLFOLDER_WHERE);
4172                    }
4173                    else {
4174                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1);
4175                    }
4176    
4177                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
4178    
4179                    query.append(_FINDER_COLUMN_G_P_PARENTFOLDERID_2);
4180    
4181                    if (!getDB().isSupportsInlineDistinct()) {
4182                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2);
4183                    }
4184    
4185                    if (orderByComparator != null) {
4186                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4187    
4188                            if (orderByConditionFields.length > 0) {
4189                                    query.append(WHERE_AND);
4190                            }
4191    
4192                            for (int i = 0; i < orderByConditionFields.length; i++) {
4193                                    if (getDB().isSupportsInlineDistinct()) {
4194                                            query.append(_ORDER_BY_ENTITY_ALIAS);
4195                                    }
4196                                    else {
4197                                            query.append(_ORDER_BY_ENTITY_TABLE);
4198                                    }
4199    
4200                                    query.append(orderByConditionFields[i]);
4201    
4202                                    if ((i + 1) < orderByConditionFields.length) {
4203                                            if (orderByComparator.isAscending() ^ previous) {
4204                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4205                                            }
4206                                            else {
4207                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4208                                            }
4209                                    }
4210                                    else {
4211                                            if (orderByComparator.isAscending() ^ previous) {
4212                                                    query.append(WHERE_GREATER_THAN);
4213                                            }
4214                                            else {
4215                                                    query.append(WHERE_LESSER_THAN);
4216                                            }
4217                                    }
4218                            }
4219    
4220                            query.append(ORDER_BY_CLAUSE);
4221    
4222                            String[] orderByFields = orderByComparator.getOrderByFields();
4223    
4224                            for (int i = 0; i < orderByFields.length; i++) {
4225                                    if (getDB().isSupportsInlineDistinct()) {
4226                                            query.append(_ORDER_BY_ENTITY_ALIAS);
4227                                    }
4228                                    else {
4229                                            query.append(_ORDER_BY_ENTITY_TABLE);
4230                                    }
4231    
4232                                    query.append(orderByFields[i]);
4233    
4234                                    if ((i + 1) < orderByFields.length) {
4235                                            if (orderByComparator.isAscending() ^ previous) {
4236                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4237                                            }
4238                                            else {
4239                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4240                                            }
4241                                    }
4242                                    else {
4243                                            if (orderByComparator.isAscending() ^ previous) {
4244                                                    query.append(ORDER_BY_ASC);
4245                                            }
4246                                            else {
4247                                                    query.append(ORDER_BY_DESC);
4248                                            }
4249                                    }
4250                            }
4251                    }
4252                    else {
4253                            if (getDB().isSupportsInlineDistinct()) {
4254                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
4255                            }
4256                            else {
4257                                    query.append(DLFolderModelImpl.ORDER_BY_SQL);
4258                            }
4259                    }
4260    
4261                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4262                                    DLFolder.class.getName(),
4263                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4264    
4265                    SQLQuery q = session.createSQLQuery(sql);
4266    
4267                    q.setFirstResult(0);
4268                    q.setMaxResults(2);
4269    
4270                    if (getDB().isSupportsInlineDistinct()) {
4271                            q.addEntity(_FILTER_ENTITY_ALIAS, DLFolderImpl.class);
4272                    }
4273                    else {
4274                            q.addEntity(_FILTER_ENTITY_TABLE, DLFolderImpl.class);
4275                    }
4276    
4277                    QueryPos qPos = QueryPos.getInstance(q);
4278    
4279                    qPos.add(groupId);
4280    
4281                    qPos.add(parentFolderId);
4282    
4283                    if (orderByComparator != null) {
4284                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
4285    
4286                            for (Object value : values) {
4287                                    qPos.add(value);
4288                            }
4289                    }
4290    
4291                    List<DLFolder> list = q.list();
4292    
4293                    if (list.size() == 2) {
4294                            return list.get(1);
4295                    }
4296                    else {
4297                            return null;
4298                    }
4299            }
4300    
4301            /**
4302             * Removes all the document library folders where groupId = &#63; and parentFolderId = &#63; from the database.
4303             *
4304             * @param groupId the group ID
4305             * @param parentFolderId the parent folder ID
4306             * @throws SystemException if a system exception occurred
4307             */
4308            @Override
4309            public void removeByG_P(long groupId, long parentFolderId)
4310                    throws SystemException {
4311                    for (DLFolder dlFolder : findByG_P(groupId, parentFolderId,
4312                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4313                            remove(dlFolder);
4314                    }
4315            }
4316    
4317            /**
4318             * Returns the number of document library folders where groupId = &#63; and parentFolderId = &#63;.
4319             *
4320             * @param groupId the group ID
4321             * @param parentFolderId the parent folder ID
4322             * @return the number of matching document library folders
4323             * @throws SystemException if a system exception occurred
4324             */
4325            @Override
4326            public int countByG_P(long groupId, long parentFolderId)
4327                    throws SystemException {
4328                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_P;
4329    
4330                    Object[] finderArgs = new Object[] { groupId, parentFolderId };
4331    
4332                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4333                                    this);
4334    
4335                    if (count == null) {
4336                            StringBundler query = new StringBundler(3);
4337    
4338                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
4339    
4340                            query.append(_FINDER_COLUMN_G_P_GROUPID_2);
4341    
4342                            query.append(_FINDER_COLUMN_G_P_PARENTFOLDERID_2);
4343    
4344                            String sql = query.toString();
4345    
4346                            Session session = null;
4347    
4348                            try {
4349                                    session = openSession();
4350    
4351                                    Query q = session.createQuery(sql);
4352    
4353                                    QueryPos qPos = QueryPos.getInstance(q);
4354    
4355                                    qPos.add(groupId);
4356    
4357                                    qPos.add(parentFolderId);
4358    
4359                                    count = (Long)q.uniqueResult();
4360    
4361                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
4362                            }
4363                            catch (Exception e) {
4364                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4365    
4366                                    throw processException(e);
4367                            }
4368                            finally {
4369                                    closeSession(session);
4370                            }
4371                    }
4372    
4373                    return count.intValue();
4374            }
4375    
4376            /**
4377             * Returns the number of document library folders that the user has permission to view where groupId = &#63; and parentFolderId = &#63;.
4378             *
4379             * @param groupId the group ID
4380             * @param parentFolderId the parent folder ID
4381             * @return the number of matching document library folders that the user has permission to view
4382             * @throws SystemException if a system exception occurred
4383             */
4384            @Override
4385            public int filterCountByG_P(long groupId, long parentFolderId)
4386                    throws SystemException {
4387                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4388                            return countByG_P(groupId, parentFolderId);
4389                    }
4390    
4391                    StringBundler query = new StringBundler(3);
4392    
4393                    query.append(_FILTER_SQL_COUNT_DLFOLDER_WHERE);
4394    
4395                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
4396    
4397                    query.append(_FINDER_COLUMN_G_P_PARENTFOLDERID_2);
4398    
4399                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4400                                    DLFolder.class.getName(),
4401                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4402    
4403                    Session session = null;
4404    
4405                    try {
4406                            session = openSession();
4407    
4408                            SQLQuery q = session.createSQLQuery(sql);
4409    
4410                            q.addScalar(COUNT_COLUMN_NAME,
4411                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
4412    
4413                            QueryPos qPos = QueryPos.getInstance(q);
4414    
4415                            qPos.add(groupId);
4416    
4417                            qPos.add(parentFolderId);
4418    
4419                            Long count = (Long)q.uniqueResult();
4420    
4421                            return count.intValue();
4422                    }
4423                    catch (Exception e) {
4424                            throw processException(e);
4425                    }
4426                    finally {
4427                            closeSession(session);
4428                    }
4429            }
4430    
4431            private static final String _FINDER_COLUMN_G_P_GROUPID_2 = "dlFolder.groupId = ? AND ";
4432            private static final String _FINDER_COLUMN_G_P_PARENTFOLDERID_2 = "dlFolder.parentFolderId = ?";
4433            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_NOTS = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
4434                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
4435                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_NotS",
4436                            new String[] {
4437                                    Long.class.getName(), Integer.class.getName(),
4438                                    
4439                            Integer.class.getName(), Integer.class.getName(),
4440                                    OrderByComparator.class.getName()
4441                            });
4442            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_NOTS = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
4443                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
4444                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByC_NotS",
4445                            new String[] { Long.class.getName(), Integer.class.getName() });
4446    
4447            /**
4448             * Returns all the document library folders where companyId = &#63; and status &ne; &#63;.
4449             *
4450             * @param companyId the company ID
4451             * @param status the status
4452             * @return the matching document library folders
4453             * @throws SystemException if a system exception occurred
4454             */
4455            @Override
4456            public List<DLFolder> findByC_NotS(long companyId, int status)
4457                    throws SystemException {
4458                    return findByC_NotS(companyId, status, QueryUtil.ALL_POS,
4459                            QueryUtil.ALL_POS, null);
4460            }
4461    
4462            /**
4463             * Returns a range of all the document library folders where companyId = &#63; and status &ne; &#63;.
4464             *
4465             * <p>
4466             * 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.
4467             * </p>
4468             *
4469             * @param companyId the company ID
4470             * @param status the status
4471             * @param start the lower bound of the range of document library folders
4472             * @param end the upper bound of the range of document library folders (not inclusive)
4473             * @return the range of matching document library folders
4474             * @throws SystemException if a system exception occurred
4475             */
4476            @Override
4477            public List<DLFolder> findByC_NotS(long companyId, int status, int start,
4478                    int end) throws SystemException {
4479                    return findByC_NotS(companyId, status, start, end, null);
4480            }
4481    
4482            /**
4483             * Returns an ordered range of all the document library folders where companyId = &#63; and status &ne; &#63;.
4484             *
4485             * <p>
4486             * 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.
4487             * </p>
4488             *
4489             * @param companyId the company ID
4490             * @param status the status
4491             * @param start the lower bound of the range of document library folders
4492             * @param end the upper bound of the range of document library folders (not inclusive)
4493             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4494             * @return the ordered range of matching document library folders
4495             * @throws SystemException if a system exception occurred
4496             */
4497            @Override
4498            public List<DLFolder> findByC_NotS(long companyId, int status, int start,
4499                    int end, OrderByComparator orderByComparator) throws SystemException {
4500                    boolean pagination = true;
4501                    FinderPath finderPath = null;
4502                    Object[] finderArgs = null;
4503    
4504                    finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_NOTS;
4505                    finderArgs = new Object[] {
4506                                    companyId, status,
4507                                    
4508                                    start, end, orderByComparator
4509                            };
4510    
4511                    List<DLFolder> list = (List<DLFolder>)FinderCacheUtil.getResult(finderPath,
4512                                    finderArgs, this);
4513    
4514                    if ((list != null) && !list.isEmpty()) {
4515                            for (DLFolder dlFolder : list) {
4516                                    if ((companyId != dlFolder.getCompanyId()) ||
4517                                                    (status == dlFolder.getStatus())) {
4518                                            list = null;
4519    
4520                                            break;
4521                                    }
4522                            }
4523                    }
4524    
4525                    if (list == null) {
4526                            StringBundler query = null;
4527    
4528                            if (orderByComparator != null) {
4529                                    query = new StringBundler(4 +
4530                                                    (orderByComparator.getOrderByFields().length * 3));
4531                            }
4532                            else {
4533                                    query = new StringBundler(4);
4534                            }
4535    
4536                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
4537    
4538                            query.append(_FINDER_COLUMN_C_NOTS_COMPANYID_2);
4539    
4540                            query.append(_FINDER_COLUMN_C_NOTS_STATUS_2);
4541    
4542                            if (orderByComparator != null) {
4543                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4544                                            orderByComparator);
4545                            }
4546                            else
4547                             if (pagination) {
4548                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
4549                            }
4550    
4551                            String sql = query.toString();
4552    
4553                            Session session = null;
4554    
4555                            try {
4556                                    session = openSession();
4557    
4558                                    Query q = session.createQuery(sql);
4559    
4560                                    QueryPos qPos = QueryPos.getInstance(q);
4561    
4562                                    qPos.add(companyId);
4563    
4564                                    qPos.add(status);
4565    
4566                                    if (!pagination) {
4567                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
4568                                                            start, end, false);
4569    
4570                                            Collections.sort(list);
4571    
4572                                            list = new UnmodifiableList<DLFolder>(list);
4573                                    }
4574                                    else {
4575                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
4576                                                            start, end);
4577                                    }
4578    
4579                                    cacheResult(list);
4580    
4581                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
4582                            }
4583                            catch (Exception e) {
4584                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4585    
4586                                    throw processException(e);
4587                            }
4588                            finally {
4589                                    closeSession(session);
4590                            }
4591                    }
4592    
4593                    return list;
4594            }
4595    
4596            /**
4597             * Returns the first document library folder in the ordered set where companyId = &#63; and status &ne; &#63;.
4598             *
4599             * @param companyId the company ID
4600             * @param status the status
4601             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4602             * @return the first matching document library folder
4603             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
4604             * @throws SystemException if a system exception occurred
4605             */
4606            @Override
4607            public DLFolder findByC_NotS_First(long companyId, int status,
4608                    OrderByComparator orderByComparator)
4609                    throws NoSuchFolderException, SystemException {
4610                    DLFolder dlFolder = fetchByC_NotS_First(companyId, status,
4611                                    orderByComparator);
4612    
4613                    if (dlFolder != null) {
4614                            return dlFolder;
4615                    }
4616    
4617                    StringBundler msg = new StringBundler(6);
4618    
4619                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4620    
4621                    msg.append("companyId=");
4622                    msg.append(companyId);
4623    
4624                    msg.append(", status=");
4625                    msg.append(status);
4626    
4627                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4628    
4629                    throw new NoSuchFolderException(msg.toString());
4630            }
4631    
4632            /**
4633             * Returns the first document library folder in the ordered set where companyId = &#63; and status &ne; &#63;.
4634             *
4635             * @param companyId the company ID
4636             * @param status the status
4637             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4638             * @return the first matching document library folder, or <code>null</code> if a matching document library folder could not be found
4639             * @throws SystemException if a system exception occurred
4640             */
4641            @Override
4642            public DLFolder fetchByC_NotS_First(long companyId, int status,
4643                    OrderByComparator orderByComparator) throws SystemException {
4644                    List<DLFolder> list = findByC_NotS(companyId, status, 0, 1,
4645                                    orderByComparator);
4646    
4647                    if (!list.isEmpty()) {
4648                            return list.get(0);
4649                    }
4650    
4651                    return null;
4652            }
4653    
4654            /**
4655             * Returns the last document library folder in the ordered set where companyId = &#63; and status &ne; &#63;.
4656             *
4657             * @param companyId the company ID
4658             * @param status the status
4659             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4660             * @return the last matching document library folder
4661             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
4662             * @throws SystemException if a system exception occurred
4663             */
4664            @Override
4665            public DLFolder findByC_NotS_Last(long companyId, int status,
4666                    OrderByComparator orderByComparator)
4667                    throws NoSuchFolderException, SystemException {
4668                    DLFolder dlFolder = fetchByC_NotS_Last(companyId, status,
4669                                    orderByComparator);
4670    
4671                    if (dlFolder != null) {
4672                            return dlFolder;
4673                    }
4674    
4675                    StringBundler msg = new StringBundler(6);
4676    
4677                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4678    
4679                    msg.append("companyId=");
4680                    msg.append(companyId);
4681    
4682                    msg.append(", status=");
4683                    msg.append(status);
4684    
4685                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4686    
4687                    throw new NoSuchFolderException(msg.toString());
4688            }
4689    
4690            /**
4691             * Returns the last document library folder in the ordered set where companyId = &#63; and status &ne; &#63;.
4692             *
4693             * @param companyId the company ID
4694             * @param status the status
4695             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4696             * @return the last matching document library folder, or <code>null</code> if a matching document library folder could not be found
4697             * @throws SystemException if a system exception occurred
4698             */
4699            @Override
4700            public DLFolder fetchByC_NotS_Last(long companyId, int status,
4701                    OrderByComparator orderByComparator) throws SystemException {
4702                    int count = countByC_NotS(companyId, status);
4703    
4704                    if (count == 0) {
4705                            return null;
4706                    }
4707    
4708                    List<DLFolder> list = findByC_NotS(companyId, status, count - 1, count,
4709                                    orderByComparator);
4710    
4711                    if (!list.isEmpty()) {
4712                            return list.get(0);
4713                    }
4714    
4715                    return null;
4716            }
4717    
4718            /**
4719             * Returns the document library folders before and after the current document library folder in the ordered set where companyId = &#63; and status &ne; &#63;.
4720             *
4721             * @param folderId the primary key of the current document library folder
4722             * @param companyId the company ID
4723             * @param status the status
4724             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4725             * @return the previous, current, and next document library folder
4726             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
4727             * @throws SystemException if a system exception occurred
4728             */
4729            @Override
4730            public DLFolder[] findByC_NotS_PrevAndNext(long folderId, long companyId,
4731                    int status, OrderByComparator orderByComparator)
4732                    throws NoSuchFolderException, SystemException {
4733                    DLFolder dlFolder = findByPrimaryKey(folderId);
4734    
4735                    Session session = null;
4736    
4737                    try {
4738                            session = openSession();
4739    
4740                            DLFolder[] array = new DLFolderImpl[3];
4741    
4742                            array[0] = getByC_NotS_PrevAndNext(session, dlFolder, companyId,
4743                                            status, orderByComparator, true);
4744    
4745                            array[1] = dlFolder;
4746    
4747                            array[2] = getByC_NotS_PrevAndNext(session, dlFolder, companyId,
4748                                            status, orderByComparator, false);
4749    
4750                            return array;
4751                    }
4752                    catch (Exception e) {
4753                            throw processException(e);
4754                    }
4755                    finally {
4756                            closeSession(session);
4757                    }
4758            }
4759    
4760            protected DLFolder getByC_NotS_PrevAndNext(Session session,
4761                    DLFolder dlFolder, long companyId, int status,
4762                    OrderByComparator orderByComparator, boolean previous) {
4763                    StringBundler query = null;
4764    
4765                    if (orderByComparator != null) {
4766                            query = new StringBundler(6 +
4767                                            (orderByComparator.getOrderByFields().length * 6));
4768                    }
4769                    else {
4770                            query = new StringBundler(3);
4771                    }
4772    
4773                    query.append(_SQL_SELECT_DLFOLDER_WHERE);
4774    
4775                    query.append(_FINDER_COLUMN_C_NOTS_COMPANYID_2);
4776    
4777                    query.append(_FINDER_COLUMN_C_NOTS_STATUS_2);
4778    
4779                    if (orderByComparator != null) {
4780                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4781    
4782                            if (orderByConditionFields.length > 0) {
4783                                    query.append(WHERE_AND);
4784                            }
4785    
4786                            for (int i = 0; i < orderByConditionFields.length; i++) {
4787                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4788                                    query.append(orderByConditionFields[i]);
4789    
4790                                    if ((i + 1) < orderByConditionFields.length) {
4791                                            if (orderByComparator.isAscending() ^ previous) {
4792                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4793                                            }
4794                                            else {
4795                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4796                                            }
4797                                    }
4798                                    else {
4799                                            if (orderByComparator.isAscending() ^ previous) {
4800                                                    query.append(WHERE_GREATER_THAN);
4801                                            }
4802                                            else {
4803                                                    query.append(WHERE_LESSER_THAN);
4804                                            }
4805                                    }
4806                            }
4807    
4808                            query.append(ORDER_BY_CLAUSE);
4809    
4810                            String[] orderByFields = orderByComparator.getOrderByFields();
4811    
4812                            for (int i = 0; i < orderByFields.length; i++) {
4813                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4814                                    query.append(orderByFields[i]);
4815    
4816                                    if ((i + 1) < orderByFields.length) {
4817                                            if (orderByComparator.isAscending() ^ previous) {
4818                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4819                                            }
4820                                            else {
4821                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4822                                            }
4823                                    }
4824                                    else {
4825                                            if (orderByComparator.isAscending() ^ previous) {
4826                                                    query.append(ORDER_BY_ASC);
4827                                            }
4828                                            else {
4829                                                    query.append(ORDER_BY_DESC);
4830                                            }
4831                                    }
4832                            }
4833                    }
4834                    else {
4835                            query.append(DLFolderModelImpl.ORDER_BY_JPQL);
4836                    }
4837    
4838                    String sql = query.toString();
4839    
4840                    Query q = session.createQuery(sql);
4841    
4842                    q.setFirstResult(0);
4843                    q.setMaxResults(2);
4844    
4845                    QueryPos qPos = QueryPos.getInstance(q);
4846    
4847                    qPos.add(companyId);
4848    
4849                    qPos.add(status);
4850    
4851                    if (orderByComparator != null) {
4852                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
4853    
4854                            for (Object value : values) {
4855                                    qPos.add(value);
4856                            }
4857                    }
4858    
4859                    List<DLFolder> list = q.list();
4860    
4861                    if (list.size() == 2) {
4862                            return list.get(1);
4863                    }
4864                    else {
4865                            return null;
4866                    }
4867            }
4868    
4869            /**
4870             * Removes all the document library folders where companyId = &#63; and status &ne; &#63; from the database.
4871             *
4872             * @param companyId the company ID
4873             * @param status the status
4874             * @throws SystemException if a system exception occurred
4875             */
4876            @Override
4877            public void removeByC_NotS(long companyId, int status)
4878                    throws SystemException {
4879                    for (DLFolder dlFolder : findByC_NotS(companyId, status,
4880                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4881                            remove(dlFolder);
4882                    }
4883            }
4884    
4885            /**
4886             * Returns the number of document library folders where companyId = &#63; and status &ne; &#63;.
4887             *
4888             * @param companyId the company ID
4889             * @param status the status
4890             * @return the number of matching document library folders
4891             * @throws SystemException if a system exception occurred
4892             */
4893            @Override
4894            public int countByC_NotS(long companyId, int status)
4895                    throws SystemException {
4896                    FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_NOTS;
4897    
4898                    Object[] finderArgs = new Object[] { companyId, status };
4899    
4900                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4901                                    this);
4902    
4903                    if (count == null) {
4904                            StringBundler query = new StringBundler(3);
4905    
4906                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
4907    
4908                            query.append(_FINDER_COLUMN_C_NOTS_COMPANYID_2);
4909    
4910                            query.append(_FINDER_COLUMN_C_NOTS_STATUS_2);
4911    
4912                            String sql = query.toString();
4913    
4914                            Session session = null;
4915    
4916                            try {
4917                                    session = openSession();
4918    
4919                                    Query q = session.createQuery(sql);
4920    
4921                                    QueryPos qPos = QueryPos.getInstance(q);
4922    
4923                                    qPos.add(companyId);
4924    
4925                                    qPos.add(status);
4926    
4927                                    count = (Long)q.uniqueResult();
4928    
4929                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
4930                            }
4931                            catch (Exception e) {
4932                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4933    
4934                                    throw processException(e);
4935                            }
4936                            finally {
4937                                    closeSession(session);
4938                            }
4939                    }
4940    
4941                    return count.intValue();
4942            }
4943    
4944            private static final String _FINDER_COLUMN_C_NOTS_COMPANYID_2 = "dlFolder.companyId = ? AND ";
4945            private static final String _FINDER_COLUMN_C_NOTS_STATUS_2 = "dlFolder.status != ?";
4946            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_P_N = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
4947                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
4948                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByP_N",
4949                            new String[] {
4950                                    Long.class.getName(), String.class.getName(),
4951                                    
4952                            Integer.class.getName(), Integer.class.getName(),
4953                                    OrderByComparator.class.getName()
4954                            });
4955            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_N = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
4956                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
4957                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByP_N",
4958                            new String[] { Long.class.getName(), String.class.getName() },
4959                            DLFolderModelImpl.PARENTFOLDERID_COLUMN_BITMASK |
4960                            DLFolderModelImpl.NAME_COLUMN_BITMASK);
4961            public static final FinderPath FINDER_PATH_COUNT_BY_P_N = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
4962                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
4963                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByP_N",
4964                            new String[] { Long.class.getName(), String.class.getName() });
4965    
4966            /**
4967             * Returns all the document library folders where parentFolderId = &#63; and name = &#63;.
4968             *
4969             * @param parentFolderId the parent folder ID
4970             * @param name the name
4971             * @return the matching document library folders
4972             * @throws SystemException if a system exception occurred
4973             */
4974            @Override
4975            public List<DLFolder> findByP_N(long parentFolderId, String name)
4976                    throws SystemException {
4977                    return findByP_N(parentFolderId, name, QueryUtil.ALL_POS,
4978                            QueryUtil.ALL_POS, null);
4979            }
4980    
4981            /**
4982             * Returns a range of all the document library folders where parentFolderId = &#63; and name = &#63;.
4983             *
4984             * <p>
4985             * 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.
4986             * </p>
4987             *
4988             * @param parentFolderId the parent folder ID
4989             * @param name the name
4990             * @param start the lower bound of the range of document library folders
4991             * @param end the upper bound of the range of document library folders (not inclusive)
4992             * @return the range of matching document library folders
4993             * @throws SystemException if a system exception occurred
4994             */
4995            @Override
4996            public List<DLFolder> findByP_N(long parentFolderId, String name,
4997                    int start, int end) throws SystemException {
4998                    return findByP_N(parentFolderId, name, start, end, null);
4999            }
5000    
5001            /**
5002             * Returns an ordered range of all the document library folders where parentFolderId = &#63; and name = &#63;.
5003             *
5004             * <p>
5005             * 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.
5006             * </p>
5007             *
5008             * @param parentFolderId the parent folder ID
5009             * @param name the name
5010             * @param start the lower bound of the range of document library folders
5011             * @param end the upper bound of the range of document library folders (not inclusive)
5012             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5013             * @return the ordered range of matching document library folders
5014             * @throws SystemException if a system exception occurred
5015             */
5016            @Override
5017            public List<DLFolder> findByP_N(long parentFolderId, String name,
5018                    int start, int end, OrderByComparator orderByComparator)
5019                    throws SystemException {
5020                    boolean pagination = true;
5021                    FinderPath finderPath = null;
5022                    Object[] finderArgs = null;
5023    
5024                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5025                                    (orderByComparator == null)) {
5026                            pagination = false;
5027                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_N;
5028                            finderArgs = new Object[] { parentFolderId, name };
5029                    }
5030                    else {
5031                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_P_N;
5032                            finderArgs = new Object[] {
5033                                            parentFolderId, name,
5034                                            
5035                                            start, end, orderByComparator
5036                                    };
5037                    }
5038    
5039                    List<DLFolder> list = (List<DLFolder>)FinderCacheUtil.getResult(finderPath,
5040                                    finderArgs, this);
5041    
5042                    if ((list != null) && !list.isEmpty()) {
5043                            for (DLFolder dlFolder : list) {
5044                                    if ((parentFolderId != dlFolder.getParentFolderId()) ||
5045                                                    !Validator.equals(name, dlFolder.getName())) {
5046                                            list = null;
5047    
5048                                            break;
5049                                    }
5050                            }
5051                    }
5052    
5053                    if (list == null) {
5054                            StringBundler query = null;
5055    
5056                            if (orderByComparator != null) {
5057                                    query = new StringBundler(4 +
5058                                                    (orderByComparator.getOrderByFields().length * 3));
5059                            }
5060                            else {
5061                                    query = new StringBundler(4);
5062                            }
5063    
5064                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
5065    
5066                            query.append(_FINDER_COLUMN_P_N_PARENTFOLDERID_2);
5067    
5068                            boolean bindName = false;
5069    
5070                            if (name == null) {
5071                                    query.append(_FINDER_COLUMN_P_N_NAME_1);
5072                            }
5073                            else if (name.equals(StringPool.BLANK)) {
5074                                    query.append(_FINDER_COLUMN_P_N_NAME_3);
5075                            }
5076                            else {
5077                                    bindName = true;
5078    
5079                                    query.append(_FINDER_COLUMN_P_N_NAME_2);
5080                            }
5081    
5082                            if (orderByComparator != null) {
5083                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5084                                            orderByComparator);
5085                            }
5086                            else
5087                             if (pagination) {
5088                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
5089                            }
5090    
5091                            String sql = query.toString();
5092    
5093                            Session session = null;
5094    
5095                            try {
5096                                    session = openSession();
5097    
5098                                    Query q = session.createQuery(sql);
5099    
5100                                    QueryPos qPos = QueryPos.getInstance(q);
5101    
5102                                    qPos.add(parentFolderId);
5103    
5104                                    if (bindName) {
5105                                            qPos.add(name);
5106                                    }
5107    
5108                                    if (!pagination) {
5109                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
5110                                                            start, end, false);
5111    
5112                                            Collections.sort(list);
5113    
5114                                            list = new UnmodifiableList<DLFolder>(list);
5115                                    }
5116                                    else {
5117                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
5118                                                            start, end);
5119                                    }
5120    
5121                                    cacheResult(list);
5122    
5123                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
5124                            }
5125                            catch (Exception e) {
5126                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5127    
5128                                    throw processException(e);
5129                            }
5130                            finally {
5131                                    closeSession(session);
5132                            }
5133                    }
5134    
5135                    return list;
5136            }
5137    
5138            /**
5139             * Returns the first document library folder in the ordered set where parentFolderId = &#63; and name = &#63;.
5140             *
5141             * @param parentFolderId the parent folder ID
5142             * @param name the name
5143             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5144             * @return the first matching document library folder
5145             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
5146             * @throws SystemException if a system exception occurred
5147             */
5148            @Override
5149            public DLFolder findByP_N_First(long parentFolderId, String name,
5150                    OrderByComparator orderByComparator)
5151                    throws NoSuchFolderException, SystemException {
5152                    DLFolder dlFolder = fetchByP_N_First(parentFolderId, name,
5153                                    orderByComparator);
5154    
5155                    if (dlFolder != null) {
5156                            return dlFolder;
5157                    }
5158    
5159                    StringBundler msg = new StringBundler(6);
5160    
5161                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5162    
5163                    msg.append("parentFolderId=");
5164                    msg.append(parentFolderId);
5165    
5166                    msg.append(", name=");
5167                    msg.append(name);
5168    
5169                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5170    
5171                    throw new NoSuchFolderException(msg.toString());
5172            }
5173    
5174            /**
5175             * Returns the first document library folder in the ordered set where parentFolderId = &#63; and name = &#63;.
5176             *
5177             * @param parentFolderId the parent folder ID
5178             * @param name the name
5179             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5180             * @return the first matching document library folder, or <code>null</code> if a matching document library folder could not be found
5181             * @throws SystemException if a system exception occurred
5182             */
5183            @Override
5184            public DLFolder fetchByP_N_First(long parentFolderId, String name,
5185                    OrderByComparator orderByComparator) throws SystemException {
5186                    List<DLFolder> list = findByP_N(parentFolderId, name, 0, 1,
5187                                    orderByComparator);
5188    
5189                    if (!list.isEmpty()) {
5190                            return list.get(0);
5191                    }
5192    
5193                    return null;
5194            }
5195    
5196            /**
5197             * Returns the last document library folder in the ordered set where parentFolderId = &#63; and name = &#63;.
5198             *
5199             * @param parentFolderId the parent folder ID
5200             * @param name the name
5201             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5202             * @return the last matching document library folder
5203             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
5204             * @throws SystemException if a system exception occurred
5205             */
5206            @Override
5207            public DLFolder findByP_N_Last(long parentFolderId, String name,
5208                    OrderByComparator orderByComparator)
5209                    throws NoSuchFolderException, SystemException {
5210                    DLFolder dlFolder = fetchByP_N_Last(parentFolderId, name,
5211                                    orderByComparator);
5212    
5213                    if (dlFolder != null) {
5214                            return dlFolder;
5215                    }
5216    
5217                    StringBundler msg = new StringBundler(6);
5218    
5219                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5220    
5221                    msg.append("parentFolderId=");
5222                    msg.append(parentFolderId);
5223    
5224                    msg.append(", name=");
5225                    msg.append(name);
5226    
5227                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5228    
5229                    throw new NoSuchFolderException(msg.toString());
5230            }
5231    
5232            /**
5233             * Returns the last document library folder in the ordered set where parentFolderId = &#63; and name = &#63;.
5234             *
5235             * @param parentFolderId the parent folder ID
5236             * @param name the name
5237             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5238             * @return the last matching document library folder, or <code>null</code> if a matching document library folder could not be found
5239             * @throws SystemException if a system exception occurred
5240             */
5241            @Override
5242            public DLFolder fetchByP_N_Last(long parentFolderId, String name,
5243                    OrderByComparator orderByComparator) throws SystemException {
5244                    int count = countByP_N(parentFolderId, name);
5245    
5246                    if (count == 0) {
5247                            return null;
5248                    }
5249    
5250                    List<DLFolder> list = findByP_N(parentFolderId, name, count - 1, count,
5251                                    orderByComparator);
5252    
5253                    if (!list.isEmpty()) {
5254                            return list.get(0);
5255                    }
5256    
5257                    return null;
5258            }
5259    
5260            /**
5261             * Returns the document library folders before and after the current document library folder in the ordered set where parentFolderId = &#63; and name = &#63;.
5262             *
5263             * @param folderId the primary key of the current document library folder
5264             * @param parentFolderId the parent folder ID
5265             * @param name the name
5266             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5267             * @return the previous, current, and next document library folder
5268             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
5269             * @throws SystemException if a system exception occurred
5270             */
5271            @Override
5272            public DLFolder[] findByP_N_PrevAndNext(long folderId, long parentFolderId,
5273                    String name, OrderByComparator orderByComparator)
5274                    throws NoSuchFolderException, SystemException {
5275                    DLFolder dlFolder = findByPrimaryKey(folderId);
5276    
5277                    Session session = null;
5278    
5279                    try {
5280                            session = openSession();
5281    
5282                            DLFolder[] array = new DLFolderImpl[3];
5283    
5284                            array[0] = getByP_N_PrevAndNext(session, dlFolder, parentFolderId,
5285                                            name, orderByComparator, true);
5286    
5287                            array[1] = dlFolder;
5288    
5289                            array[2] = getByP_N_PrevAndNext(session, dlFolder, parentFolderId,
5290                                            name, orderByComparator, false);
5291    
5292                            return array;
5293                    }
5294                    catch (Exception e) {
5295                            throw processException(e);
5296                    }
5297                    finally {
5298                            closeSession(session);
5299                    }
5300            }
5301    
5302            protected DLFolder getByP_N_PrevAndNext(Session session, DLFolder dlFolder,
5303                    long parentFolderId, String name, OrderByComparator orderByComparator,
5304                    boolean previous) {
5305                    StringBundler query = null;
5306    
5307                    if (orderByComparator != null) {
5308                            query = new StringBundler(6 +
5309                                            (orderByComparator.getOrderByFields().length * 6));
5310                    }
5311                    else {
5312                            query = new StringBundler(3);
5313                    }
5314    
5315                    query.append(_SQL_SELECT_DLFOLDER_WHERE);
5316    
5317                    query.append(_FINDER_COLUMN_P_N_PARENTFOLDERID_2);
5318    
5319                    boolean bindName = false;
5320    
5321                    if (name == null) {
5322                            query.append(_FINDER_COLUMN_P_N_NAME_1);
5323                    }
5324                    else if (name.equals(StringPool.BLANK)) {
5325                            query.append(_FINDER_COLUMN_P_N_NAME_3);
5326                    }
5327                    else {
5328                            bindName = true;
5329    
5330                            query.append(_FINDER_COLUMN_P_N_NAME_2);
5331                    }
5332    
5333                    if (orderByComparator != null) {
5334                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5335    
5336                            if (orderByConditionFields.length > 0) {
5337                                    query.append(WHERE_AND);
5338                            }
5339    
5340                            for (int i = 0; i < orderByConditionFields.length; i++) {
5341                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5342                                    query.append(orderByConditionFields[i]);
5343    
5344                                    if ((i + 1) < orderByConditionFields.length) {
5345                                            if (orderByComparator.isAscending() ^ previous) {
5346                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5347                                            }
5348                                            else {
5349                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5350                                            }
5351                                    }
5352                                    else {
5353                                            if (orderByComparator.isAscending() ^ previous) {
5354                                                    query.append(WHERE_GREATER_THAN);
5355                                            }
5356                                            else {
5357                                                    query.append(WHERE_LESSER_THAN);
5358                                            }
5359                                    }
5360                            }
5361    
5362                            query.append(ORDER_BY_CLAUSE);
5363    
5364                            String[] orderByFields = orderByComparator.getOrderByFields();
5365    
5366                            for (int i = 0; i < orderByFields.length; i++) {
5367                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5368                                    query.append(orderByFields[i]);
5369    
5370                                    if ((i + 1) < orderByFields.length) {
5371                                            if (orderByComparator.isAscending() ^ previous) {
5372                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5373                                            }
5374                                            else {
5375                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5376                                            }
5377                                    }
5378                                    else {
5379                                            if (orderByComparator.isAscending() ^ previous) {
5380                                                    query.append(ORDER_BY_ASC);
5381                                            }
5382                                            else {
5383                                                    query.append(ORDER_BY_DESC);
5384                                            }
5385                                    }
5386                            }
5387                    }
5388                    else {
5389                            query.append(DLFolderModelImpl.ORDER_BY_JPQL);
5390                    }
5391    
5392                    String sql = query.toString();
5393    
5394                    Query q = session.createQuery(sql);
5395    
5396                    q.setFirstResult(0);
5397                    q.setMaxResults(2);
5398    
5399                    QueryPos qPos = QueryPos.getInstance(q);
5400    
5401                    qPos.add(parentFolderId);
5402    
5403                    if (bindName) {
5404                            qPos.add(name);
5405                    }
5406    
5407                    if (orderByComparator != null) {
5408                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
5409    
5410                            for (Object value : values) {
5411                                    qPos.add(value);
5412                            }
5413                    }
5414    
5415                    List<DLFolder> list = q.list();
5416    
5417                    if (list.size() == 2) {
5418                            return list.get(1);
5419                    }
5420                    else {
5421                            return null;
5422                    }
5423            }
5424    
5425            /**
5426             * Removes all the document library folders where parentFolderId = &#63; and name = &#63; from the database.
5427             *
5428             * @param parentFolderId the parent folder ID
5429             * @param name the name
5430             * @throws SystemException if a system exception occurred
5431             */
5432            @Override
5433            public void removeByP_N(long parentFolderId, String name)
5434                    throws SystemException {
5435                    for (DLFolder dlFolder : findByP_N(parentFolderId, name,
5436                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
5437                            remove(dlFolder);
5438                    }
5439            }
5440    
5441            /**
5442             * Returns the number of document library folders where parentFolderId = &#63; and name = &#63;.
5443             *
5444             * @param parentFolderId the parent folder ID
5445             * @param name the name
5446             * @return the number of matching document library folders
5447             * @throws SystemException if a system exception occurred
5448             */
5449            @Override
5450            public int countByP_N(long parentFolderId, String name)
5451                    throws SystemException {
5452                    FinderPath finderPath = FINDER_PATH_COUNT_BY_P_N;
5453    
5454                    Object[] finderArgs = new Object[] { parentFolderId, name };
5455    
5456                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5457                                    this);
5458    
5459                    if (count == null) {
5460                            StringBundler query = new StringBundler(3);
5461    
5462                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
5463    
5464                            query.append(_FINDER_COLUMN_P_N_PARENTFOLDERID_2);
5465    
5466                            boolean bindName = false;
5467    
5468                            if (name == null) {
5469                                    query.append(_FINDER_COLUMN_P_N_NAME_1);
5470                            }
5471                            else if (name.equals(StringPool.BLANK)) {
5472                                    query.append(_FINDER_COLUMN_P_N_NAME_3);
5473                            }
5474                            else {
5475                                    bindName = true;
5476    
5477                                    query.append(_FINDER_COLUMN_P_N_NAME_2);
5478                            }
5479    
5480                            String sql = query.toString();
5481    
5482                            Session session = null;
5483    
5484                            try {
5485                                    session = openSession();
5486    
5487                                    Query q = session.createQuery(sql);
5488    
5489                                    QueryPos qPos = QueryPos.getInstance(q);
5490    
5491                                    qPos.add(parentFolderId);
5492    
5493                                    if (bindName) {
5494                                            qPos.add(name);
5495                                    }
5496    
5497                                    count = (Long)q.uniqueResult();
5498    
5499                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
5500                            }
5501                            catch (Exception e) {
5502                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5503    
5504                                    throw processException(e);
5505                            }
5506                            finally {
5507                                    closeSession(session);
5508                            }
5509                    }
5510    
5511                    return count.intValue();
5512            }
5513    
5514            private static final String _FINDER_COLUMN_P_N_PARENTFOLDERID_2 = "dlFolder.parentFolderId = ? AND ";
5515            private static final String _FINDER_COLUMN_P_N_NAME_1 = "dlFolder.name IS NULL";
5516            private static final String _FINDER_COLUMN_P_N_NAME_2 = "dlFolder.name = ?";
5517            private static final String _FINDER_COLUMN_P_N_NAME_3 = "(dlFolder.name IS NULL OR dlFolder.name = '')";
5518            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_F_C_P_NOTS =
5519                    new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
5520                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
5521                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByF_C_P_NotS",
5522                            new String[] {
5523                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
5524                                    Integer.class.getName(),
5525                                    
5526                            Integer.class.getName(), Integer.class.getName(),
5527                                    OrderByComparator.class.getName()
5528                            });
5529            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_F_C_P_NOTS =
5530                    new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
5531                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
5532                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByF_C_P_NotS",
5533                            new String[] {
5534                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
5535                                    Integer.class.getName()
5536                            });
5537    
5538            /**
5539             * Returns all the document library folders where folderId &gt; &#63; and companyId = &#63; and parentFolderId = &#63; and status &ne; &#63;.
5540             *
5541             * @param folderId the folder ID
5542             * @param companyId the company ID
5543             * @param parentFolderId the parent folder ID
5544             * @param status the status
5545             * @return the matching document library folders
5546             * @throws SystemException if a system exception occurred
5547             */
5548            @Override
5549            public List<DLFolder> findByF_C_P_NotS(long folderId, long companyId,
5550                    long parentFolderId, int status) throws SystemException {
5551                    return findByF_C_P_NotS(folderId, companyId, parentFolderId, status,
5552                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
5553            }
5554    
5555            /**
5556             * Returns a range of all the document library folders where folderId &gt; &#63; and companyId = &#63; and parentFolderId = &#63; and status &ne; &#63;.
5557             *
5558             * <p>
5559             * 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.
5560             * </p>
5561             *
5562             * @param folderId the folder ID
5563             * @param companyId the company ID
5564             * @param parentFolderId the parent folder ID
5565             * @param status the status
5566             * @param start the lower bound of the range of document library folders
5567             * @param end the upper bound of the range of document library folders (not inclusive)
5568             * @return the range of matching document library folders
5569             * @throws SystemException if a system exception occurred
5570             */
5571            @Override
5572            public List<DLFolder> findByF_C_P_NotS(long folderId, long companyId,
5573                    long parentFolderId, int status, int start, int end)
5574                    throws SystemException {
5575                    return findByF_C_P_NotS(folderId, companyId, parentFolderId, status,
5576                            start, end, null);
5577            }
5578    
5579            /**
5580             * Returns an ordered range of all the document library folders where folderId &gt; &#63; and companyId = &#63; and parentFolderId = &#63; and status &ne; &#63;.
5581             *
5582             * <p>
5583             * 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.
5584             * </p>
5585             *
5586             * @param folderId the folder ID
5587             * @param companyId the company ID
5588             * @param parentFolderId the parent folder ID
5589             * @param status the status
5590             * @param start the lower bound of the range of document library folders
5591             * @param end the upper bound of the range of document library folders (not inclusive)
5592             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5593             * @return the ordered range of matching document library folders
5594             * @throws SystemException if a system exception occurred
5595             */
5596            @Override
5597            public List<DLFolder> findByF_C_P_NotS(long folderId, long companyId,
5598                    long parentFolderId, int status, int start, int end,
5599                    OrderByComparator orderByComparator) throws SystemException {
5600                    boolean pagination = true;
5601                    FinderPath finderPath = null;
5602                    Object[] finderArgs = null;
5603    
5604                    finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_F_C_P_NOTS;
5605                    finderArgs = new Object[] {
5606                                    folderId, companyId, parentFolderId, status,
5607                                    
5608                                    start, end, orderByComparator
5609                            };
5610    
5611                    List<DLFolder> list = (List<DLFolder>)FinderCacheUtil.getResult(finderPath,
5612                                    finderArgs, this);
5613    
5614                    if ((list != null) && !list.isEmpty()) {
5615                            for (DLFolder dlFolder : list) {
5616                                    if ((folderId >= dlFolder.getFolderId()) ||
5617                                                    (companyId != dlFolder.getCompanyId()) ||
5618                                                    (parentFolderId != dlFolder.getParentFolderId()) ||
5619                                                    (status == dlFolder.getStatus())) {
5620                                            list = null;
5621    
5622                                            break;
5623                                    }
5624                            }
5625                    }
5626    
5627                    if (list == null) {
5628                            StringBundler query = null;
5629    
5630                            if (orderByComparator != null) {
5631                                    query = new StringBundler(6 +
5632                                                    (orderByComparator.getOrderByFields().length * 3));
5633                            }
5634                            else {
5635                                    query = new StringBundler(6);
5636                            }
5637    
5638                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
5639    
5640                            query.append(_FINDER_COLUMN_F_C_P_NOTS_FOLDERID_2);
5641    
5642                            query.append(_FINDER_COLUMN_F_C_P_NOTS_COMPANYID_2);
5643    
5644                            query.append(_FINDER_COLUMN_F_C_P_NOTS_PARENTFOLDERID_2);
5645    
5646                            query.append(_FINDER_COLUMN_F_C_P_NOTS_STATUS_2);
5647    
5648                            if (orderByComparator != null) {
5649                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5650                                            orderByComparator);
5651                            }
5652                            else
5653                             if (pagination) {
5654                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
5655                            }
5656    
5657                            String sql = query.toString();
5658    
5659                            Session session = null;
5660    
5661                            try {
5662                                    session = openSession();
5663    
5664                                    Query q = session.createQuery(sql);
5665    
5666                                    QueryPos qPos = QueryPos.getInstance(q);
5667    
5668                                    qPos.add(folderId);
5669    
5670                                    qPos.add(companyId);
5671    
5672                                    qPos.add(parentFolderId);
5673    
5674                                    qPos.add(status);
5675    
5676                                    if (!pagination) {
5677                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
5678                                                            start, end, false);
5679    
5680                                            Collections.sort(list);
5681    
5682                                            list = new UnmodifiableList<DLFolder>(list);
5683                                    }
5684                                    else {
5685                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
5686                                                            start, end);
5687                                    }
5688    
5689                                    cacheResult(list);
5690    
5691                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
5692                            }
5693                            catch (Exception e) {
5694                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5695    
5696                                    throw processException(e);
5697                            }
5698                            finally {
5699                                    closeSession(session);
5700                            }
5701                    }
5702    
5703                    return list;
5704            }
5705    
5706            /**
5707             * Returns the first document library folder in the ordered set where folderId &gt; &#63; and companyId = &#63; and parentFolderId = &#63; and status &ne; &#63;.
5708             *
5709             * @param folderId the folder ID
5710             * @param companyId the company ID
5711             * @param parentFolderId the parent folder ID
5712             * @param status the status
5713             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5714             * @return the first matching document library folder
5715             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
5716             * @throws SystemException if a system exception occurred
5717             */
5718            @Override
5719            public DLFolder findByF_C_P_NotS_First(long folderId, long companyId,
5720                    long parentFolderId, int status, OrderByComparator orderByComparator)
5721                    throws NoSuchFolderException, SystemException {
5722                    DLFolder dlFolder = fetchByF_C_P_NotS_First(folderId, companyId,
5723                                    parentFolderId, status, orderByComparator);
5724    
5725                    if (dlFolder != null) {
5726                            return dlFolder;
5727                    }
5728    
5729                    StringBundler msg = new StringBundler(10);
5730    
5731                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5732    
5733                    msg.append("folderId=");
5734                    msg.append(folderId);
5735    
5736                    msg.append(", companyId=");
5737                    msg.append(companyId);
5738    
5739                    msg.append(", parentFolderId=");
5740                    msg.append(parentFolderId);
5741    
5742                    msg.append(", status=");
5743                    msg.append(status);
5744    
5745                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5746    
5747                    throw new NoSuchFolderException(msg.toString());
5748            }
5749    
5750            /**
5751             * Returns the first document library folder in the ordered set where folderId &gt; &#63; and companyId = &#63; and parentFolderId = &#63; and status &ne; &#63;.
5752             *
5753             * @param folderId the folder ID
5754             * @param companyId the company ID
5755             * @param parentFolderId the parent folder ID
5756             * @param status the status
5757             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5758             * @return the first matching document library folder, or <code>null</code> if a matching document library folder could not be found
5759             * @throws SystemException if a system exception occurred
5760             */
5761            @Override
5762            public DLFolder fetchByF_C_P_NotS_First(long folderId, long companyId,
5763                    long parentFolderId, int status, OrderByComparator orderByComparator)
5764                    throws SystemException {
5765                    List<DLFolder> list = findByF_C_P_NotS(folderId, companyId,
5766                                    parentFolderId, status, 0, 1, orderByComparator);
5767    
5768                    if (!list.isEmpty()) {
5769                            return list.get(0);
5770                    }
5771    
5772                    return null;
5773            }
5774    
5775            /**
5776             * Returns the last document library folder in the ordered set where folderId &gt; &#63; and companyId = &#63; and parentFolderId = &#63; and status &ne; &#63;.
5777             *
5778             * @param folderId the folder ID
5779             * @param companyId the company ID
5780             * @param parentFolderId the parent folder ID
5781             * @param status the status
5782             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5783             * @return the last matching document library folder
5784             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
5785             * @throws SystemException if a system exception occurred
5786             */
5787            @Override
5788            public DLFolder findByF_C_P_NotS_Last(long folderId, long companyId,
5789                    long parentFolderId, int status, OrderByComparator orderByComparator)
5790                    throws NoSuchFolderException, SystemException {
5791                    DLFolder dlFolder = fetchByF_C_P_NotS_Last(folderId, companyId,
5792                                    parentFolderId, status, orderByComparator);
5793    
5794                    if (dlFolder != null) {
5795                            return dlFolder;
5796                    }
5797    
5798                    StringBundler msg = new StringBundler(10);
5799    
5800                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5801    
5802                    msg.append("folderId=");
5803                    msg.append(folderId);
5804    
5805                    msg.append(", companyId=");
5806                    msg.append(companyId);
5807    
5808                    msg.append(", parentFolderId=");
5809                    msg.append(parentFolderId);
5810    
5811                    msg.append(", status=");
5812                    msg.append(status);
5813    
5814                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5815    
5816                    throw new NoSuchFolderException(msg.toString());
5817            }
5818    
5819            /**
5820             * Returns the last document library folder in the ordered set where folderId &gt; &#63; and companyId = &#63; and parentFolderId = &#63; and status &ne; &#63;.
5821             *
5822             * @param folderId the folder ID
5823             * @param companyId the company ID
5824             * @param parentFolderId the parent folder ID
5825             * @param status the status
5826             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5827             * @return the last matching document library folder, or <code>null</code> if a matching document library folder could not be found
5828             * @throws SystemException if a system exception occurred
5829             */
5830            @Override
5831            public DLFolder fetchByF_C_P_NotS_Last(long folderId, long companyId,
5832                    long parentFolderId, int status, OrderByComparator orderByComparator)
5833                    throws SystemException {
5834                    int count = countByF_C_P_NotS(folderId, companyId, parentFolderId,
5835                                    status);
5836    
5837                    if (count == 0) {
5838                            return null;
5839                    }
5840    
5841                    List<DLFolder> list = findByF_C_P_NotS(folderId, companyId,
5842                                    parentFolderId, status, count - 1, count, orderByComparator);
5843    
5844                    if (!list.isEmpty()) {
5845                            return list.get(0);
5846                    }
5847    
5848                    return null;
5849            }
5850    
5851            /**
5852             * Removes all the document library folders where folderId &gt; &#63; and companyId = &#63; and parentFolderId = &#63; and status &ne; &#63; from the database.
5853             *
5854             * @param folderId the folder ID
5855             * @param companyId the company ID
5856             * @param parentFolderId the parent folder ID
5857             * @param status the status
5858             * @throws SystemException if a system exception occurred
5859             */
5860            @Override
5861            public void removeByF_C_P_NotS(long folderId, long companyId,
5862                    long parentFolderId, int status) throws SystemException {
5863                    for (DLFolder dlFolder : findByF_C_P_NotS(folderId, companyId,
5864                                    parentFolderId, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
5865                                    null)) {
5866                            remove(dlFolder);
5867                    }
5868            }
5869    
5870            /**
5871             * Returns the number of document library folders where folderId &gt; &#63; and companyId = &#63; and parentFolderId = &#63; and status &ne; &#63;.
5872             *
5873             * @param folderId the folder ID
5874             * @param companyId the company ID
5875             * @param parentFolderId the parent folder ID
5876             * @param status the status
5877             * @return the number of matching document library folders
5878             * @throws SystemException if a system exception occurred
5879             */
5880            @Override
5881            public int countByF_C_P_NotS(long folderId, long companyId,
5882                    long parentFolderId, int status) throws SystemException {
5883                    FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_F_C_P_NOTS;
5884    
5885                    Object[] finderArgs = new Object[] {
5886                                    folderId, companyId, parentFolderId, status
5887                            };
5888    
5889                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5890                                    this);
5891    
5892                    if (count == null) {
5893                            StringBundler query = new StringBundler(5);
5894    
5895                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
5896    
5897                            query.append(_FINDER_COLUMN_F_C_P_NOTS_FOLDERID_2);
5898    
5899                            query.append(_FINDER_COLUMN_F_C_P_NOTS_COMPANYID_2);
5900    
5901                            query.append(_FINDER_COLUMN_F_C_P_NOTS_PARENTFOLDERID_2);
5902    
5903                            query.append(_FINDER_COLUMN_F_C_P_NOTS_STATUS_2);
5904    
5905                            String sql = query.toString();
5906    
5907                            Session session = null;
5908    
5909                            try {
5910                                    session = openSession();
5911    
5912                                    Query q = session.createQuery(sql);
5913    
5914                                    QueryPos qPos = QueryPos.getInstance(q);
5915    
5916                                    qPos.add(folderId);
5917    
5918                                    qPos.add(companyId);
5919    
5920                                    qPos.add(parentFolderId);
5921    
5922                                    qPos.add(status);
5923    
5924                                    count = (Long)q.uniqueResult();
5925    
5926                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
5927                            }
5928                            catch (Exception e) {
5929                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5930    
5931                                    throw processException(e);
5932                            }
5933                            finally {
5934                                    closeSession(session);
5935                            }
5936                    }
5937    
5938                    return count.intValue();
5939            }
5940    
5941            private static final String _FINDER_COLUMN_F_C_P_NOTS_FOLDERID_2 = "dlFolder.folderId > ? AND ";
5942            private static final String _FINDER_COLUMN_F_C_P_NOTS_COMPANYID_2 = "dlFolder.companyId = ? AND ";
5943            private static final String _FINDER_COLUMN_F_C_P_NOTS_PARENTFOLDERID_2 = "dlFolder.parentFolderId = ? AND ";
5944            private static final String _FINDER_COLUMN_F_C_P_NOTS_STATUS_2 = "dlFolder.status != ?";
5945            public static final FinderPath FINDER_PATH_FETCH_BY_G_P_N = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
5946                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
5947                            FINDER_CLASS_NAME_ENTITY, "fetchByG_P_N",
5948                            new String[] {
5949                                    Long.class.getName(), Long.class.getName(),
5950                                    String.class.getName()
5951                            },
5952                            DLFolderModelImpl.GROUPID_COLUMN_BITMASK |
5953                            DLFolderModelImpl.PARENTFOLDERID_COLUMN_BITMASK |
5954                            DLFolderModelImpl.NAME_COLUMN_BITMASK);
5955            public static final FinderPath FINDER_PATH_COUNT_BY_G_P_N = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
5956                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
5957                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P_N",
5958                            new String[] {
5959                                    Long.class.getName(), Long.class.getName(),
5960                                    String.class.getName()
5961                            });
5962    
5963            /**
5964             * 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.
5965             *
5966             * @param groupId the group ID
5967             * @param parentFolderId the parent folder ID
5968             * @param name the name
5969             * @return the matching document library folder
5970             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
5971             * @throws SystemException if a system exception occurred
5972             */
5973            @Override
5974            public DLFolder findByG_P_N(long groupId, long parentFolderId, String name)
5975                    throws NoSuchFolderException, SystemException {
5976                    DLFolder dlFolder = fetchByG_P_N(groupId, parentFolderId, name);
5977    
5978                    if (dlFolder == null) {
5979                            StringBundler msg = new StringBundler(8);
5980    
5981                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5982    
5983                            msg.append("groupId=");
5984                            msg.append(groupId);
5985    
5986                            msg.append(", parentFolderId=");
5987                            msg.append(parentFolderId);
5988    
5989                            msg.append(", name=");
5990                            msg.append(name);
5991    
5992                            msg.append(StringPool.CLOSE_CURLY_BRACE);
5993    
5994                            if (_log.isWarnEnabled()) {
5995                                    _log.warn(msg.toString());
5996                            }
5997    
5998                            throw new NoSuchFolderException(msg.toString());
5999                    }
6000    
6001                    return dlFolder;
6002            }
6003    
6004            /**
6005             * 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.
6006             *
6007             * @param groupId the group ID
6008             * @param parentFolderId the parent folder ID
6009             * @param name the name
6010             * @return the matching document library folder, or <code>null</code> if a matching document library folder could not be found
6011             * @throws SystemException if a system exception occurred
6012             */
6013            @Override
6014            public DLFolder fetchByG_P_N(long groupId, long parentFolderId, String name)
6015                    throws SystemException {
6016                    return fetchByG_P_N(groupId, parentFolderId, name, true);
6017            }
6018    
6019            /**
6020             * 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.
6021             *
6022             * @param groupId the group ID
6023             * @param parentFolderId the parent folder ID
6024             * @param name the name
6025             * @param retrieveFromCache whether to use the finder cache
6026             * @return the matching document library folder, or <code>null</code> if a matching document library folder could not be found
6027             * @throws SystemException if a system exception occurred
6028             */
6029            @Override
6030            public DLFolder fetchByG_P_N(long groupId, long parentFolderId,
6031                    String name, boolean retrieveFromCache) throws SystemException {
6032                    Object[] finderArgs = new Object[] { groupId, parentFolderId, name };
6033    
6034                    Object result = null;
6035    
6036                    if (retrieveFromCache) {
6037                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_P_N,
6038                                            finderArgs, this);
6039                    }
6040    
6041                    if (result instanceof DLFolder) {
6042                            DLFolder dlFolder = (DLFolder)result;
6043    
6044                            if ((groupId != dlFolder.getGroupId()) ||
6045                                            (parentFolderId != dlFolder.getParentFolderId()) ||
6046                                            !Validator.equals(name, dlFolder.getName())) {
6047                                    result = null;
6048                            }
6049                    }
6050    
6051                    if (result == null) {
6052                            StringBundler query = new StringBundler(5);
6053    
6054                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
6055    
6056                            query.append(_FINDER_COLUMN_G_P_N_GROUPID_2);
6057    
6058                            query.append(_FINDER_COLUMN_G_P_N_PARENTFOLDERID_2);
6059    
6060                            boolean bindName = false;
6061    
6062                            if (name == null) {
6063                                    query.append(_FINDER_COLUMN_G_P_N_NAME_1);
6064                            }
6065                            else if (name.equals(StringPool.BLANK)) {
6066                                    query.append(_FINDER_COLUMN_G_P_N_NAME_3);
6067                            }
6068                            else {
6069                                    bindName = true;
6070    
6071                                    query.append(_FINDER_COLUMN_G_P_N_NAME_2);
6072                            }
6073    
6074                            String sql = query.toString();
6075    
6076                            Session session = null;
6077    
6078                            try {
6079                                    session = openSession();
6080    
6081                                    Query q = session.createQuery(sql);
6082    
6083                                    QueryPos qPos = QueryPos.getInstance(q);
6084    
6085                                    qPos.add(groupId);
6086    
6087                                    qPos.add(parentFolderId);
6088    
6089                                    if (bindName) {
6090                                            qPos.add(name);
6091                                    }
6092    
6093                                    List<DLFolder> list = q.list();
6094    
6095                                    if (list.isEmpty()) {
6096                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_N,
6097                                                    finderArgs, list);
6098                                    }
6099                                    else {
6100                                            DLFolder dlFolder = list.get(0);
6101    
6102                                            result = dlFolder;
6103    
6104                                            cacheResult(dlFolder);
6105    
6106                                            if ((dlFolder.getGroupId() != groupId) ||
6107                                                            (dlFolder.getParentFolderId() != parentFolderId) ||
6108                                                            (dlFolder.getName() == null) ||
6109                                                            !dlFolder.getName().equals(name)) {
6110                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_N,
6111                                                            finderArgs, dlFolder);
6112                                            }
6113                                    }
6114                            }
6115                            catch (Exception e) {
6116                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P_N,
6117                                            finderArgs);
6118    
6119                                    throw processException(e);
6120                            }
6121                            finally {
6122                                    closeSession(session);
6123                            }
6124                    }
6125    
6126                    if (result instanceof List<?>) {
6127                            return null;
6128                    }
6129                    else {
6130                            return (DLFolder)result;
6131                    }
6132            }
6133    
6134            /**
6135             * Removes the document library folder where groupId = &#63; and parentFolderId = &#63; and name = &#63; from the database.
6136             *
6137             * @param groupId the group ID
6138             * @param parentFolderId the parent folder ID
6139             * @param name the name
6140             * @return the document library folder that was removed
6141             * @throws SystemException if a system exception occurred
6142             */
6143            @Override
6144            public DLFolder removeByG_P_N(long groupId, long parentFolderId, String name)
6145                    throws NoSuchFolderException, SystemException {
6146                    DLFolder dlFolder = findByG_P_N(groupId, parentFolderId, name);
6147    
6148                    return remove(dlFolder);
6149            }
6150    
6151            /**
6152             * Returns the number of document library folders where groupId = &#63; and parentFolderId = &#63; and name = &#63;.
6153             *
6154             * @param groupId the group ID
6155             * @param parentFolderId the parent folder ID
6156             * @param name the name
6157             * @return the number of matching document library folders
6158             * @throws SystemException if a system exception occurred
6159             */
6160            @Override
6161            public int countByG_P_N(long groupId, long parentFolderId, String name)
6162                    throws SystemException {
6163                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_P_N;
6164    
6165                    Object[] finderArgs = new Object[] { groupId, parentFolderId, name };
6166    
6167                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
6168                                    this);
6169    
6170                    if (count == null) {
6171                            StringBundler query = new StringBundler(4);
6172    
6173                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
6174    
6175                            query.append(_FINDER_COLUMN_G_P_N_GROUPID_2);
6176    
6177                            query.append(_FINDER_COLUMN_G_P_N_PARENTFOLDERID_2);
6178    
6179                            boolean bindName = false;
6180    
6181                            if (name == null) {
6182                                    query.append(_FINDER_COLUMN_G_P_N_NAME_1);
6183                            }
6184                            else if (name.equals(StringPool.BLANK)) {
6185                                    query.append(_FINDER_COLUMN_G_P_N_NAME_3);
6186                            }
6187                            else {
6188                                    bindName = true;
6189    
6190                                    query.append(_FINDER_COLUMN_G_P_N_NAME_2);
6191                            }
6192    
6193                            String sql = query.toString();
6194    
6195                            Session session = null;
6196    
6197                            try {
6198                                    session = openSession();
6199    
6200                                    Query q = session.createQuery(sql);
6201    
6202                                    QueryPos qPos = QueryPos.getInstance(q);
6203    
6204                                    qPos.add(groupId);
6205    
6206                                    qPos.add(parentFolderId);
6207    
6208                                    if (bindName) {
6209                                            qPos.add(name);
6210                                    }
6211    
6212                                    count = (Long)q.uniqueResult();
6213    
6214                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
6215                            }
6216                            catch (Exception e) {
6217                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6218    
6219                                    throw processException(e);
6220                            }
6221                            finally {
6222                                    closeSession(session);
6223                            }
6224                    }
6225    
6226                    return count.intValue();
6227            }
6228    
6229            private static final String _FINDER_COLUMN_G_P_N_GROUPID_2 = "dlFolder.groupId = ? AND ";
6230            private static final String _FINDER_COLUMN_G_P_N_PARENTFOLDERID_2 = "dlFolder.parentFolderId = ? AND ";
6231            private static final String _FINDER_COLUMN_G_P_N_NAME_1 = "dlFolder.name IS NULL";
6232            private static final String _FINDER_COLUMN_G_P_N_NAME_2 = "dlFolder.name = ?";
6233            private static final String _FINDER_COLUMN_G_P_N_NAME_3 = "(dlFolder.name IS NULL OR dlFolder.name = '')";
6234            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_M_P_H = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
6235                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
6236                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_M_P_H",
6237                            new String[] {
6238                                    Long.class.getName(), Boolean.class.getName(),
6239                                    Long.class.getName(), Boolean.class.getName(),
6240                                    
6241                            Integer.class.getName(), Integer.class.getName(),
6242                                    OrderByComparator.class.getName()
6243                            });
6244            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P_H =
6245                    new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
6246                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
6247                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_M_P_H",
6248                            new String[] {
6249                                    Long.class.getName(), Boolean.class.getName(),
6250                                    Long.class.getName(), Boolean.class.getName()
6251                            },
6252                            DLFolderModelImpl.GROUPID_COLUMN_BITMASK |
6253                            DLFolderModelImpl.MOUNTPOINT_COLUMN_BITMASK |
6254                            DLFolderModelImpl.PARENTFOLDERID_COLUMN_BITMASK |
6255                            DLFolderModelImpl.HIDDEN_COLUMN_BITMASK |
6256                            DLFolderModelImpl.NAME_COLUMN_BITMASK);
6257            public static final FinderPath FINDER_PATH_COUNT_BY_G_M_P_H = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
6258                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
6259                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_M_P_H",
6260                            new String[] {
6261                                    Long.class.getName(), Boolean.class.getName(),
6262                                    Long.class.getName(), Boolean.class.getName()
6263                            });
6264    
6265            /**
6266             * Returns all the document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63;.
6267             *
6268             * @param groupId the group ID
6269             * @param mountPoint the mount point
6270             * @param parentFolderId the parent folder ID
6271             * @param hidden the hidden
6272             * @return the matching document library folders
6273             * @throws SystemException if a system exception occurred
6274             */
6275            @Override
6276            public List<DLFolder> findByG_M_P_H(long groupId, boolean mountPoint,
6277                    long parentFolderId, boolean hidden) throws SystemException {
6278                    return findByG_M_P_H(groupId, mountPoint, parentFolderId, hidden,
6279                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
6280            }
6281    
6282            /**
6283             * Returns a range of all the document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63;.
6284             *
6285             * <p>
6286             * 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.
6287             * </p>
6288             *
6289             * @param groupId the group ID
6290             * @param mountPoint the mount point
6291             * @param parentFolderId the parent folder ID
6292             * @param hidden the hidden
6293             * @param start the lower bound of the range of document library folders
6294             * @param end the upper bound of the range of document library folders (not inclusive)
6295             * @return the range of matching document library folders
6296             * @throws SystemException if a system exception occurred
6297             */
6298            @Override
6299            public List<DLFolder> findByG_M_P_H(long groupId, boolean mountPoint,
6300                    long parentFolderId, boolean hidden, int start, int end)
6301                    throws SystemException {
6302                    return findByG_M_P_H(groupId, mountPoint, parentFolderId, hidden,
6303                            start, end, null);
6304            }
6305    
6306            /**
6307             * Returns an ordered range of all the document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63;.
6308             *
6309             * <p>
6310             * 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.
6311             * </p>
6312             *
6313             * @param groupId the group ID
6314             * @param mountPoint the mount point
6315             * @param parentFolderId the parent folder ID
6316             * @param hidden the hidden
6317             * @param start the lower bound of the range of document library folders
6318             * @param end the upper bound of the range of document library folders (not inclusive)
6319             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6320             * @return the ordered range of matching document library folders
6321             * @throws SystemException if a system exception occurred
6322             */
6323            @Override
6324            public List<DLFolder> findByG_M_P_H(long groupId, boolean mountPoint,
6325                    long parentFolderId, boolean hidden, int start, int end,
6326                    OrderByComparator orderByComparator) throws SystemException {
6327                    boolean pagination = true;
6328                    FinderPath finderPath = null;
6329                    Object[] finderArgs = null;
6330    
6331                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6332                                    (orderByComparator == null)) {
6333                            pagination = false;
6334                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P_H;
6335                            finderArgs = new Object[] {
6336                                            groupId, mountPoint, parentFolderId, hidden
6337                                    };
6338                    }
6339                    else {
6340                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_M_P_H;
6341                            finderArgs = new Object[] {
6342                                            groupId, mountPoint, parentFolderId, hidden,
6343                                            
6344                                            start, end, orderByComparator
6345                                    };
6346                    }
6347    
6348                    List<DLFolder> list = (List<DLFolder>)FinderCacheUtil.getResult(finderPath,
6349                                    finderArgs, this);
6350    
6351                    if ((list != null) && !list.isEmpty()) {
6352                            for (DLFolder dlFolder : list) {
6353                                    if ((groupId != dlFolder.getGroupId()) ||
6354                                                    (mountPoint != dlFolder.getMountPoint()) ||
6355                                                    (parentFolderId != dlFolder.getParentFolderId()) ||
6356                                                    (hidden != dlFolder.getHidden())) {
6357                                            list = null;
6358    
6359                                            break;
6360                                    }
6361                            }
6362                    }
6363    
6364                    if (list == null) {
6365                            StringBundler query = null;
6366    
6367                            if (orderByComparator != null) {
6368                                    query = new StringBundler(6 +
6369                                                    (orderByComparator.getOrderByFields().length * 3));
6370                            }
6371                            else {
6372                                    query = new StringBundler(6);
6373                            }
6374    
6375                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
6376    
6377                            query.append(_FINDER_COLUMN_G_M_P_H_GROUPID_2);
6378    
6379                            query.append(_FINDER_COLUMN_G_M_P_H_MOUNTPOINT_2);
6380    
6381                            query.append(_FINDER_COLUMN_G_M_P_H_PARENTFOLDERID_2);
6382    
6383                            query.append(_FINDER_COLUMN_G_M_P_H_HIDDEN_2);
6384    
6385                            if (orderByComparator != null) {
6386                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6387                                            orderByComparator);
6388                            }
6389                            else
6390                             if (pagination) {
6391                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
6392                            }
6393    
6394                            String sql = query.toString();
6395    
6396                            Session session = null;
6397    
6398                            try {
6399                                    session = openSession();
6400    
6401                                    Query q = session.createQuery(sql);
6402    
6403                                    QueryPos qPos = QueryPos.getInstance(q);
6404    
6405                                    qPos.add(groupId);
6406    
6407                                    qPos.add(mountPoint);
6408    
6409                                    qPos.add(parentFolderId);
6410    
6411                                    qPos.add(hidden);
6412    
6413                                    if (!pagination) {
6414                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
6415                                                            start, end, false);
6416    
6417                                            Collections.sort(list);
6418    
6419                                            list = new UnmodifiableList<DLFolder>(list);
6420                                    }
6421                                    else {
6422                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
6423                                                            start, end);
6424                                    }
6425    
6426                                    cacheResult(list);
6427    
6428                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
6429                            }
6430                            catch (Exception e) {
6431                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6432    
6433                                    throw processException(e);
6434                            }
6435                            finally {
6436                                    closeSession(session);
6437                            }
6438                    }
6439    
6440                    return list;
6441            }
6442    
6443            /**
6444             * Returns the first document library folder in the ordered set where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63;.
6445             *
6446             * @param groupId the group ID
6447             * @param mountPoint the mount point
6448             * @param parentFolderId the parent folder ID
6449             * @param hidden the hidden
6450             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6451             * @return the first matching document library folder
6452             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
6453             * @throws SystemException if a system exception occurred
6454             */
6455            @Override
6456            public DLFolder findByG_M_P_H_First(long groupId, boolean mountPoint,
6457                    long parentFolderId, boolean hidden, OrderByComparator orderByComparator)
6458                    throws NoSuchFolderException, SystemException {
6459                    DLFolder dlFolder = fetchByG_M_P_H_First(groupId, mountPoint,
6460                                    parentFolderId, hidden, orderByComparator);
6461    
6462                    if (dlFolder != null) {
6463                            return dlFolder;
6464                    }
6465    
6466                    StringBundler msg = new StringBundler(10);
6467    
6468                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6469    
6470                    msg.append("groupId=");
6471                    msg.append(groupId);
6472    
6473                    msg.append(", mountPoint=");
6474                    msg.append(mountPoint);
6475    
6476                    msg.append(", parentFolderId=");
6477                    msg.append(parentFolderId);
6478    
6479                    msg.append(", hidden=");
6480                    msg.append(hidden);
6481    
6482                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6483    
6484                    throw new NoSuchFolderException(msg.toString());
6485            }
6486    
6487            /**
6488             * Returns the first document library folder in the ordered set where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63;.
6489             *
6490             * @param groupId the group ID
6491             * @param mountPoint the mount point
6492             * @param parentFolderId the parent folder ID
6493             * @param hidden the hidden
6494             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6495             * @return the first matching document library folder, or <code>null</code> if a matching document library folder could not be found
6496             * @throws SystemException if a system exception occurred
6497             */
6498            @Override
6499            public DLFolder fetchByG_M_P_H_First(long groupId, boolean mountPoint,
6500                    long parentFolderId, boolean hidden, OrderByComparator orderByComparator)
6501                    throws SystemException {
6502                    List<DLFolder> list = findByG_M_P_H(groupId, mountPoint,
6503                                    parentFolderId, hidden, 0, 1, orderByComparator);
6504    
6505                    if (!list.isEmpty()) {
6506                            return list.get(0);
6507                    }
6508    
6509                    return null;
6510            }
6511    
6512            /**
6513             * Returns the last document library folder in the ordered set where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63;.
6514             *
6515             * @param groupId the group ID
6516             * @param mountPoint the mount point
6517             * @param parentFolderId the parent folder ID
6518             * @param hidden the hidden
6519             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6520             * @return the last matching document library folder
6521             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
6522             * @throws SystemException if a system exception occurred
6523             */
6524            @Override
6525            public DLFolder findByG_M_P_H_Last(long groupId, boolean mountPoint,
6526                    long parentFolderId, boolean hidden, OrderByComparator orderByComparator)
6527                    throws NoSuchFolderException, SystemException {
6528                    DLFolder dlFolder = fetchByG_M_P_H_Last(groupId, mountPoint,
6529                                    parentFolderId, hidden, orderByComparator);
6530    
6531                    if (dlFolder != null) {
6532                            return dlFolder;
6533                    }
6534    
6535                    StringBundler msg = new StringBundler(10);
6536    
6537                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6538    
6539                    msg.append("groupId=");
6540                    msg.append(groupId);
6541    
6542                    msg.append(", mountPoint=");
6543                    msg.append(mountPoint);
6544    
6545                    msg.append(", parentFolderId=");
6546                    msg.append(parentFolderId);
6547    
6548                    msg.append(", hidden=");
6549                    msg.append(hidden);
6550    
6551                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6552    
6553                    throw new NoSuchFolderException(msg.toString());
6554            }
6555    
6556            /**
6557             * Returns the last document library folder in the ordered set where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63;.
6558             *
6559             * @param groupId the group ID
6560             * @param mountPoint the mount point
6561             * @param parentFolderId the parent folder ID
6562             * @param hidden the hidden
6563             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6564             * @return the last matching document library folder, or <code>null</code> if a matching document library folder could not be found
6565             * @throws SystemException if a system exception occurred
6566             */
6567            @Override
6568            public DLFolder fetchByG_M_P_H_Last(long groupId, boolean mountPoint,
6569                    long parentFolderId, boolean hidden, OrderByComparator orderByComparator)
6570                    throws SystemException {
6571                    int count = countByG_M_P_H(groupId, mountPoint, parentFolderId, hidden);
6572    
6573                    if (count == 0) {
6574                            return null;
6575                    }
6576    
6577                    List<DLFolder> list = findByG_M_P_H(groupId, mountPoint,
6578                                    parentFolderId, hidden, count - 1, count, orderByComparator);
6579    
6580                    if (!list.isEmpty()) {
6581                            return list.get(0);
6582                    }
6583    
6584                    return null;
6585            }
6586    
6587            /**
6588             * 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;.
6589             *
6590             * @param folderId the primary key of the current document library folder
6591             * @param groupId the group ID
6592             * @param mountPoint the mount point
6593             * @param parentFolderId the parent folder ID
6594             * @param hidden the hidden
6595             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6596             * @return the previous, current, and next document library folder
6597             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
6598             * @throws SystemException if a system exception occurred
6599             */
6600            @Override
6601            public DLFolder[] findByG_M_P_H_PrevAndNext(long folderId, long groupId,
6602                    boolean mountPoint, long parentFolderId, boolean hidden,
6603                    OrderByComparator orderByComparator)
6604                    throws NoSuchFolderException, SystemException {
6605                    DLFolder dlFolder = findByPrimaryKey(folderId);
6606    
6607                    Session session = null;
6608    
6609                    try {
6610                            session = openSession();
6611    
6612                            DLFolder[] array = new DLFolderImpl[3];
6613    
6614                            array[0] = getByG_M_P_H_PrevAndNext(session, dlFolder, groupId,
6615                                            mountPoint, parentFolderId, hidden, orderByComparator, true);
6616    
6617                            array[1] = dlFolder;
6618    
6619                            array[2] = getByG_M_P_H_PrevAndNext(session, dlFolder, groupId,
6620                                            mountPoint, parentFolderId, hidden, orderByComparator, false);
6621    
6622                            return array;
6623                    }
6624                    catch (Exception e) {
6625                            throw processException(e);
6626                    }
6627                    finally {
6628                            closeSession(session);
6629                    }
6630            }
6631    
6632            protected DLFolder getByG_M_P_H_PrevAndNext(Session session,
6633                    DLFolder dlFolder, long groupId, boolean mountPoint,
6634                    long parentFolderId, boolean hidden,
6635                    OrderByComparator orderByComparator, boolean previous) {
6636                    StringBundler query = null;
6637    
6638                    if (orderByComparator != null) {
6639                            query = new StringBundler(6 +
6640                                            (orderByComparator.getOrderByFields().length * 6));
6641                    }
6642                    else {
6643                            query = new StringBundler(3);
6644                    }
6645    
6646                    query.append(_SQL_SELECT_DLFOLDER_WHERE);
6647    
6648                    query.append(_FINDER_COLUMN_G_M_P_H_GROUPID_2);
6649    
6650                    query.append(_FINDER_COLUMN_G_M_P_H_MOUNTPOINT_2);
6651    
6652                    query.append(_FINDER_COLUMN_G_M_P_H_PARENTFOLDERID_2);
6653    
6654                    query.append(_FINDER_COLUMN_G_M_P_H_HIDDEN_2);
6655    
6656                    if (orderByComparator != null) {
6657                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6658    
6659                            if (orderByConditionFields.length > 0) {
6660                                    query.append(WHERE_AND);
6661                            }
6662    
6663                            for (int i = 0; i < orderByConditionFields.length; i++) {
6664                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6665                                    query.append(orderByConditionFields[i]);
6666    
6667                                    if ((i + 1) < orderByConditionFields.length) {
6668                                            if (orderByComparator.isAscending() ^ previous) {
6669                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6670                                            }
6671                                            else {
6672                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6673                                            }
6674                                    }
6675                                    else {
6676                                            if (orderByComparator.isAscending() ^ previous) {
6677                                                    query.append(WHERE_GREATER_THAN);
6678                                            }
6679                                            else {
6680                                                    query.append(WHERE_LESSER_THAN);
6681                                            }
6682                                    }
6683                            }
6684    
6685                            query.append(ORDER_BY_CLAUSE);
6686    
6687                            String[] orderByFields = orderByComparator.getOrderByFields();
6688    
6689                            for (int i = 0; i < orderByFields.length; i++) {
6690                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6691                                    query.append(orderByFields[i]);
6692    
6693                                    if ((i + 1) < orderByFields.length) {
6694                                            if (orderByComparator.isAscending() ^ previous) {
6695                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6696                                            }
6697                                            else {
6698                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6699                                            }
6700                                    }
6701                                    else {
6702                                            if (orderByComparator.isAscending() ^ previous) {
6703                                                    query.append(ORDER_BY_ASC);
6704                                            }
6705                                            else {
6706                                                    query.append(ORDER_BY_DESC);
6707                                            }
6708                                    }
6709                            }
6710                    }
6711                    else {
6712                            query.append(DLFolderModelImpl.ORDER_BY_JPQL);
6713                    }
6714    
6715                    String sql = query.toString();
6716    
6717                    Query q = session.createQuery(sql);
6718    
6719                    q.setFirstResult(0);
6720                    q.setMaxResults(2);
6721    
6722                    QueryPos qPos = QueryPos.getInstance(q);
6723    
6724                    qPos.add(groupId);
6725    
6726                    qPos.add(mountPoint);
6727    
6728                    qPos.add(parentFolderId);
6729    
6730                    qPos.add(hidden);
6731    
6732                    if (orderByComparator != null) {
6733                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
6734    
6735                            for (Object value : values) {
6736                                    qPos.add(value);
6737                            }
6738                    }
6739    
6740                    List<DLFolder> list = q.list();
6741    
6742                    if (list.size() == 2) {
6743                            return list.get(1);
6744                    }
6745                    else {
6746                            return null;
6747                    }
6748            }
6749    
6750            /**
6751             * 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;.
6752             *
6753             * @param groupId the group ID
6754             * @param mountPoint the mount point
6755             * @param parentFolderId the parent folder ID
6756             * @param hidden the hidden
6757             * @return the matching document library folders that the user has permission to view
6758             * @throws SystemException if a system exception occurred
6759             */
6760            @Override
6761            public List<DLFolder> filterFindByG_M_P_H(long groupId, boolean mountPoint,
6762                    long parentFolderId, boolean hidden) throws SystemException {
6763                    return filterFindByG_M_P_H(groupId, mountPoint, parentFolderId, hidden,
6764                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
6765            }
6766    
6767            /**
6768             * 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;.
6769             *
6770             * <p>
6771             * 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.
6772             * </p>
6773             *
6774             * @param groupId the group ID
6775             * @param mountPoint the mount point
6776             * @param parentFolderId the parent folder ID
6777             * @param hidden the hidden
6778             * @param start the lower bound of the range of document library folders
6779             * @param end the upper bound of the range of document library folders (not inclusive)
6780             * @return the range of matching document library folders that the user has permission to view
6781             * @throws SystemException if a system exception occurred
6782             */
6783            @Override
6784            public List<DLFolder> filterFindByG_M_P_H(long groupId, boolean mountPoint,
6785                    long parentFolderId, boolean hidden, int start, int end)
6786                    throws SystemException {
6787                    return filterFindByG_M_P_H(groupId, mountPoint, parentFolderId, hidden,
6788                            start, end, null);
6789            }
6790    
6791            /**
6792             * 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;.
6793             *
6794             * <p>
6795             * 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.
6796             * </p>
6797             *
6798             * @param groupId the group ID
6799             * @param mountPoint the mount point
6800             * @param parentFolderId the parent folder ID
6801             * @param hidden the hidden
6802             * @param start the lower bound of the range of document library folders
6803             * @param end the upper bound of the range of document library folders (not inclusive)
6804             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6805             * @return the ordered range of matching document library folders that the user has permission to view
6806             * @throws SystemException if a system exception occurred
6807             */
6808            @Override
6809            public List<DLFolder> filterFindByG_M_P_H(long groupId, boolean mountPoint,
6810                    long parentFolderId, boolean hidden, int start, int end,
6811                    OrderByComparator orderByComparator) throws SystemException {
6812                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6813                            return findByG_M_P_H(groupId, mountPoint, parentFolderId, hidden,
6814                                    start, end, orderByComparator);
6815                    }
6816    
6817                    StringBundler query = null;
6818    
6819                    if (orderByComparator != null) {
6820                            query = new StringBundler(6 +
6821                                            (orderByComparator.getOrderByFields().length * 3));
6822                    }
6823                    else {
6824                            query = new StringBundler(6);
6825                    }
6826    
6827                    if (getDB().isSupportsInlineDistinct()) {
6828                            query.append(_FILTER_SQL_SELECT_DLFOLDER_WHERE);
6829                    }
6830                    else {
6831                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1);
6832                    }
6833    
6834                    query.append(_FINDER_COLUMN_G_M_P_H_GROUPID_2);
6835    
6836                    query.append(_FINDER_COLUMN_G_M_P_H_MOUNTPOINT_2);
6837    
6838                    query.append(_FINDER_COLUMN_G_M_P_H_PARENTFOLDERID_2);
6839    
6840                    query.append(_FINDER_COLUMN_G_M_P_H_HIDDEN_2_SQL);
6841    
6842                    if (!getDB().isSupportsInlineDistinct()) {
6843                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2);
6844                    }
6845    
6846                    if (orderByComparator != null) {
6847                            if (getDB().isSupportsInlineDistinct()) {
6848                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6849                                            orderByComparator, true);
6850                            }
6851                            else {
6852                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
6853                                            orderByComparator, true);
6854                            }
6855                    }
6856                    else {
6857                            if (getDB().isSupportsInlineDistinct()) {
6858                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
6859                            }
6860                            else {
6861                                    query.append(DLFolderModelImpl.ORDER_BY_SQL);
6862                            }
6863                    }
6864    
6865                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6866                                    DLFolder.class.getName(),
6867                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6868    
6869                    Session session = null;
6870    
6871                    try {
6872                            session = openSession();
6873    
6874                            SQLQuery q = session.createSQLQuery(sql);
6875    
6876                            if (getDB().isSupportsInlineDistinct()) {
6877                                    q.addEntity(_FILTER_ENTITY_ALIAS, DLFolderImpl.class);
6878                            }
6879                            else {
6880                                    q.addEntity(_FILTER_ENTITY_TABLE, DLFolderImpl.class);
6881                            }
6882    
6883                            QueryPos qPos = QueryPos.getInstance(q);
6884    
6885                            qPos.add(groupId);
6886    
6887                            qPos.add(mountPoint);
6888    
6889                            qPos.add(parentFolderId);
6890    
6891                            qPos.add(hidden);
6892    
6893                            return (List<DLFolder>)QueryUtil.list(q, getDialect(), start, end);
6894                    }
6895                    catch (Exception e) {
6896                            throw processException(e);
6897                    }
6898                    finally {
6899                            closeSession(session);
6900                    }
6901            }
6902    
6903            /**
6904             * 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;.
6905             *
6906             * @param folderId the primary key of the current document library folder
6907             * @param groupId the group ID
6908             * @param mountPoint the mount point
6909             * @param parentFolderId the parent folder ID
6910             * @param hidden the hidden
6911             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6912             * @return the previous, current, and next document library folder
6913             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
6914             * @throws SystemException if a system exception occurred
6915             */
6916            @Override
6917            public DLFolder[] filterFindByG_M_P_H_PrevAndNext(long folderId,
6918                    long groupId, boolean mountPoint, long parentFolderId, boolean hidden,
6919                    OrderByComparator orderByComparator)
6920                    throws NoSuchFolderException, SystemException {
6921                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6922                            return findByG_M_P_H_PrevAndNext(folderId, groupId, mountPoint,
6923                                    parentFolderId, hidden, orderByComparator);
6924                    }
6925    
6926                    DLFolder dlFolder = findByPrimaryKey(folderId);
6927    
6928                    Session session = null;
6929    
6930                    try {
6931                            session = openSession();
6932    
6933                            DLFolder[] array = new DLFolderImpl[3];
6934    
6935                            array[0] = filterGetByG_M_P_H_PrevAndNext(session, dlFolder,
6936                                            groupId, mountPoint, parentFolderId, hidden,
6937                                            orderByComparator, true);
6938    
6939                            array[1] = dlFolder;
6940    
6941                            array[2] = filterGetByG_M_P_H_PrevAndNext(session, dlFolder,
6942                                            groupId, mountPoint, parentFolderId, hidden,
6943                                            orderByComparator, false);
6944    
6945                            return array;
6946                    }
6947                    catch (Exception e) {
6948                            throw processException(e);
6949                    }
6950                    finally {
6951                            closeSession(session);
6952                    }
6953            }
6954    
6955            protected DLFolder filterGetByG_M_P_H_PrevAndNext(Session session,
6956                    DLFolder dlFolder, long groupId, boolean mountPoint,
6957                    long parentFolderId, boolean hidden,
6958                    OrderByComparator orderByComparator, boolean previous) {
6959                    StringBundler query = null;
6960    
6961                    if (orderByComparator != null) {
6962                            query = new StringBundler(6 +
6963                                            (orderByComparator.getOrderByFields().length * 6));
6964                    }
6965                    else {
6966                            query = new StringBundler(3);
6967                    }
6968    
6969                    if (getDB().isSupportsInlineDistinct()) {
6970                            query.append(_FILTER_SQL_SELECT_DLFOLDER_WHERE);
6971                    }
6972                    else {
6973                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1);
6974                    }
6975    
6976                    query.append(_FINDER_COLUMN_G_M_P_H_GROUPID_2);
6977    
6978                    query.append(_FINDER_COLUMN_G_M_P_H_MOUNTPOINT_2);
6979    
6980                    query.append(_FINDER_COLUMN_G_M_P_H_PARENTFOLDERID_2);
6981    
6982                    query.append(_FINDER_COLUMN_G_M_P_H_HIDDEN_2_SQL);
6983    
6984                    if (!getDB().isSupportsInlineDistinct()) {
6985                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2);
6986                    }
6987    
6988                    if (orderByComparator != null) {
6989                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6990    
6991                            if (orderByConditionFields.length > 0) {
6992                                    query.append(WHERE_AND);
6993                            }
6994    
6995                            for (int i = 0; i < orderByConditionFields.length; i++) {
6996                                    if (getDB().isSupportsInlineDistinct()) {
6997                                            query.append(_ORDER_BY_ENTITY_ALIAS);
6998                                    }
6999                                    else {
7000                                            query.append(_ORDER_BY_ENTITY_TABLE);
7001                                    }
7002    
7003                                    query.append(orderByConditionFields[i]);
7004    
7005                                    if ((i + 1) < orderByConditionFields.length) {
7006                                            if (orderByComparator.isAscending() ^ previous) {
7007                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
7008                                            }
7009                                            else {
7010                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
7011                                            }
7012                                    }
7013                                    else {
7014                                            if (orderByComparator.isAscending() ^ previous) {
7015                                                    query.append(WHERE_GREATER_THAN);
7016                                            }
7017                                            else {
7018                                                    query.append(WHERE_LESSER_THAN);
7019                                            }
7020                                    }
7021                            }
7022    
7023                            query.append(ORDER_BY_CLAUSE);
7024    
7025                            String[] orderByFields = orderByComparator.getOrderByFields();
7026    
7027                            for (int i = 0; i < orderByFields.length; i++) {
7028                                    if (getDB().isSupportsInlineDistinct()) {
7029                                            query.append(_ORDER_BY_ENTITY_ALIAS);
7030                                    }
7031                                    else {
7032                                            query.append(_ORDER_BY_ENTITY_TABLE);
7033                                    }
7034    
7035                                    query.append(orderByFields[i]);
7036    
7037                                    if ((i + 1) < orderByFields.length) {
7038                                            if (orderByComparator.isAscending() ^ previous) {
7039                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
7040                                            }
7041                                            else {
7042                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
7043                                            }
7044                                    }
7045                                    else {
7046                                            if (orderByComparator.isAscending() ^ previous) {
7047                                                    query.append(ORDER_BY_ASC);
7048                                            }
7049                                            else {
7050                                                    query.append(ORDER_BY_DESC);
7051                                            }
7052                                    }
7053                            }
7054                    }
7055                    else {
7056                            if (getDB().isSupportsInlineDistinct()) {
7057                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
7058                            }
7059                            else {
7060                                    query.append(DLFolderModelImpl.ORDER_BY_SQL);
7061                            }
7062                    }
7063    
7064                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7065                                    DLFolder.class.getName(),
7066                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7067    
7068                    SQLQuery q = session.createSQLQuery(sql);
7069    
7070                    q.setFirstResult(0);
7071                    q.setMaxResults(2);
7072    
7073                    if (getDB().isSupportsInlineDistinct()) {
7074                            q.addEntity(_FILTER_ENTITY_ALIAS, DLFolderImpl.class);
7075                    }
7076                    else {
7077                            q.addEntity(_FILTER_ENTITY_TABLE, DLFolderImpl.class);
7078                    }
7079    
7080                    QueryPos qPos = QueryPos.getInstance(q);
7081    
7082                    qPos.add(groupId);
7083    
7084                    qPos.add(mountPoint);
7085    
7086                    qPos.add(parentFolderId);
7087    
7088                    qPos.add(hidden);
7089    
7090                    if (orderByComparator != null) {
7091                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
7092    
7093                            for (Object value : values) {
7094                                    qPos.add(value);
7095                            }
7096                    }
7097    
7098                    List<DLFolder> list = q.list();
7099    
7100                    if (list.size() == 2) {
7101                            return list.get(1);
7102                    }
7103                    else {
7104                            return null;
7105                    }
7106            }
7107    
7108            /**
7109             * Removes all the document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63; from the database.
7110             *
7111             * @param groupId the group ID
7112             * @param mountPoint the mount point
7113             * @param parentFolderId the parent folder ID
7114             * @param hidden the hidden
7115             * @throws SystemException if a system exception occurred
7116             */
7117            @Override
7118            public void removeByG_M_P_H(long groupId, boolean mountPoint,
7119                    long parentFolderId, boolean hidden) throws SystemException {
7120                    for (DLFolder dlFolder : findByG_M_P_H(groupId, mountPoint,
7121                                    parentFolderId, hidden, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
7122                                    null)) {
7123                            remove(dlFolder);
7124                    }
7125            }
7126    
7127            /**
7128             * Returns the number of document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63;.
7129             *
7130             * @param groupId the group ID
7131             * @param mountPoint the mount point
7132             * @param parentFolderId the parent folder ID
7133             * @param hidden the hidden
7134             * @return the number of matching document library folders
7135             * @throws SystemException if a system exception occurred
7136             */
7137            @Override
7138            public int countByG_M_P_H(long groupId, boolean mountPoint,
7139                    long parentFolderId, boolean hidden) throws SystemException {
7140                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_M_P_H;
7141    
7142                    Object[] finderArgs = new Object[] {
7143                                    groupId, mountPoint, parentFolderId, hidden
7144                            };
7145    
7146                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
7147                                    this);
7148    
7149                    if (count == null) {
7150                            StringBundler query = new StringBundler(5);
7151    
7152                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
7153    
7154                            query.append(_FINDER_COLUMN_G_M_P_H_GROUPID_2);
7155    
7156                            query.append(_FINDER_COLUMN_G_M_P_H_MOUNTPOINT_2);
7157    
7158                            query.append(_FINDER_COLUMN_G_M_P_H_PARENTFOLDERID_2);
7159    
7160                            query.append(_FINDER_COLUMN_G_M_P_H_HIDDEN_2);
7161    
7162                            String sql = query.toString();
7163    
7164                            Session session = null;
7165    
7166                            try {
7167                                    session = openSession();
7168    
7169                                    Query q = session.createQuery(sql);
7170    
7171                                    QueryPos qPos = QueryPos.getInstance(q);
7172    
7173                                    qPos.add(groupId);
7174    
7175                                    qPos.add(mountPoint);
7176    
7177                                    qPos.add(parentFolderId);
7178    
7179                                    qPos.add(hidden);
7180    
7181                                    count = (Long)q.uniqueResult();
7182    
7183                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
7184                            }
7185                            catch (Exception e) {
7186                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
7187    
7188                                    throw processException(e);
7189                            }
7190                            finally {
7191                                    closeSession(session);
7192                            }
7193                    }
7194    
7195                    return count.intValue();
7196            }
7197    
7198            /**
7199             * 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;.
7200             *
7201             * @param groupId the group ID
7202             * @param mountPoint the mount point
7203             * @param parentFolderId the parent folder ID
7204             * @param hidden the hidden
7205             * @return the number of matching document library folders that the user has permission to view
7206             * @throws SystemException if a system exception occurred
7207             */
7208            @Override
7209            public int filterCountByG_M_P_H(long groupId, boolean mountPoint,
7210                    long parentFolderId, boolean hidden) throws SystemException {
7211                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7212                            return countByG_M_P_H(groupId, mountPoint, parentFolderId, hidden);
7213                    }
7214    
7215                    StringBundler query = new StringBundler(5);
7216    
7217                    query.append(_FILTER_SQL_COUNT_DLFOLDER_WHERE);
7218    
7219                    query.append(_FINDER_COLUMN_G_M_P_H_GROUPID_2);
7220    
7221                    query.append(_FINDER_COLUMN_G_M_P_H_MOUNTPOINT_2);
7222    
7223                    query.append(_FINDER_COLUMN_G_M_P_H_PARENTFOLDERID_2);
7224    
7225                    query.append(_FINDER_COLUMN_G_M_P_H_HIDDEN_2_SQL);
7226    
7227                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7228                                    DLFolder.class.getName(),
7229                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7230    
7231                    Session session = null;
7232    
7233                    try {
7234                            session = openSession();
7235    
7236                            SQLQuery q = session.createSQLQuery(sql);
7237    
7238                            q.addScalar(COUNT_COLUMN_NAME,
7239                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
7240    
7241                            QueryPos qPos = QueryPos.getInstance(q);
7242    
7243                            qPos.add(groupId);
7244    
7245                            qPos.add(mountPoint);
7246    
7247                            qPos.add(parentFolderId);
7248    
7249                            qPos.add(hidden);
7250    
7251                            Long count = (Long)q.uniqueResult();
7252    
7253                            return count.intValue();
7254                    }
7255                    catch (Exception e) {
7256                            throw processException(e);
7257                    }
7258                    finally {
7259                            closeSession(session);
7260                    }
7261            }
7262    
7263            private static final String _FINDER_COLUMN_G_M_P_H_GROUPID_2 = "dlFolder.groupId = ? AND ";
7264            private static final String _FINDER_COLUMN_G_M_P_H_MOUNTPOINT_2 = "dlFolder.mountPoint = ? AND ";
7265            private static final String _FINDER_COLUMN_G_M_P_H_PARENTFOLDERID_2 = "dlFolder.parentFolderId = ? AND ";
7266            private static final String _FINDER_COLUMN_G_M_P_H_HIDDEN_2 = "dlFolder.hidden = ?";
7267            private static final String _FINDER_COLUMN_G_M_P_H_HIDDEN_2_SQL = "dlFolder.hidden_ = ?";
7268            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_H_S = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
7269                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
7270                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_P_H_S",
7271                            new String[] {
7272                                    Long.class.getName(), Long.class.getName(),
7273                                    Boolean.class.getName(), Integer.class.getName(),
7274                                    
7275                            Integer.class.getName(), Integer.class.getName(),
7276                                    OrderByComparator.class.getName()
7277                            });
7278            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_H_S =
7279                    new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
7280                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
7281                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_P_H_S",
7282                            new String[] {
7283                                    Long.class.getName(), Long.class.getName(),
7284                                    Boolean.class.getName(), Integer.class.getName()
7285                            },
7286                            DLFolderModelImpl.GROUPID_COLUMN_BITMASK |
7287                            DLFolderModelImpl.PARENTFOLDERID_COLUMN_BITMASK |
7288                            DLFolderModelImpl.HIDDEN_COLUMN_BITMASK |
7289                            DLFolderModelImpl.STATUS_COLUMN_BITMASK |
7290                            DLFolderModelImpl.NAME_COLUMN_BITMASK);
7291            public static final FinderPath FINDER_PATH_COUNT_BY_G_P_H_S = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
7292                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
7293                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P_H_S",
7294                            new String[] {
7295                                    Long.class.getName(), Long.class.getName(),
7296                                    Boolean.class.getName(), Integer.class.getName()
7297                            });
7298    
7299            /**
7300             * Returns all the document library folders where groupId = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
7301             *
7302             * @param groupId the group ID
7303             * @param parentFolderId the parent folder ID
7304             * @param hidden the hidden
7305             * @param status the status
7306             * @return the matching document library folders
7307             * @throws SystemException if a system exception occurred
7308             */
7309            @Override
7310            public List<DLFolder> findByG_P_H_S(long groupId, long parentFolderId,
7311                    boolean hidden, int status) throws SystemException {
7312                    return findByG_P_H_S(groupId, parentFolderId, hidden, status,
7313                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
7314            }
7315    
7316            /**
7317             * Returns a range of all the document library folders where groupId = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
7318             *
7319             * <p>
7320             * 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.
7321             * </p>
7322             *
7323             * @param groupId the group ID
7324             * @param parentFolderId the parent folder ID
7325             * @param hidden the hidden
7326             * @param status the status
7327             * @param start the lower bound of the range of document library folders
7328             * @param end the upper bound of the range of document library folders (not inclusive)
7329             * @return the range of matching document library folders
7330             * @throws SystemException if a system exception occurred
7331             */
7332            @Override
7333            public List<DLFolder> findByG_P_H_S(long groupId, long parentFolderId,
7334                    boolean hidden, int status, int start, int end)
7335                    throws SystemException {
7336                    return findByG_P_H_S(groupId, parentFolderId, hidden, status, start,
7337                            end, null);
7338            }
7339    
7340            /**
7341             * Returns an ordered range of all the document library folders where groupId = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
7342             *
7343             * <p>
7344             * 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.
7345             * </p>
7346             *
7347             * @param groupId the group ID
7348             * @param parentFolderId the parent folder ID
7349             * @param hidden the hidden
7350             * @param status the status
7351             * @param start the lower bound of the range of document library folders
7352             * @param end the upper bound of the range of document library folders (not inclusive)
7353             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7354             * @return the ordered range of matching document library folders
7355             * @throws SystemException if a system exception occurred
7356             */
7357            @Override
7358            public List<DLFolder> findByG_P_H_S(long groupId, long parentFolderId,
7359                    boolean hidden, int status, int start, int end,
7360                    OrderByComparator orderByComparator) throws SystemException {
7361                    boolean pagination = true;
7362                    FinderPath finderPath = null;
7363                    Object[] finderArgs = null;
7364    
7365                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7366                                    (orderByComparator == null)) {
7367                            pagination = false;
7368                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_H_S;
7369                            finderArgs = new Object[] { groupId, parentFolderId, hidden, status };
7370                    }
7371                    else {
7372                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_H_S;
7373                            finderArgs = new Object[] {
7374                                            groupId, parentFolderId, hidden, status,
7375                                            
7376                                            start, end, orderByComparator
7377                                    };
7378                    }
7379    
7380                    List<DLFolder> list = (List<DLFolder>)FinderCacheUtil.getResult(finderPath,
7381                                    finderArgs, this);
7382    
7383                    if ((list != null) && !list.isEmpty()) {
7384                            for (DLFolder dlFolder : list) {
7385                                    if ((groupId != dlFolder.getGroupId()) ||
7386                                                    (parentFolderId != dlFolder.getParentFolderId()) ||
7387                                                    (hidden != dlFolder.getHidden()) ||
7388                                                    (status != dlFolder.getStatus())) {
7389                                            list = null;
7390    
7391                                            break;
7392                                    }
7393                            }
7394                    }
7395    
7396                    if (list == null) {
7397                            StringBundler query = null;
7398    
7399                            if (orderByComparator != null) {
7400                                    query = new StringBundler(6 +
7401                                                    (orderByComparator.getOrderByFields().length * 3));
7402                            }
7403                            else {
7404                                    query = new StringBundler(6);
7405                            }
7406    
7407                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
7408    
7409                            query.append(_FINDER_COLUMN_G_P_H_S_GROUPID_2);
7410    
7411                            query.append(_FINDER_COLUMN_G_P_H_S_PARENTFOLDERID_2);
7412    
7413                            query.append(_FINDER_COLUMN_G_P_H_S_HIDDEN_2);
7414    
7415                            query.append(_FINDER_COLUMN_G_P_H_S_STATUS_2);
7416    
7417                            if (orderByComparator != null) {
7418                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7419                                            orderByComparator);
7420                            }
7421                            else
7422                             if (pagination) {
7423                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
7424                            }
7425    
7426                            String sql = query.toString();
7427    
7428                            Session session = null;
7429    
7430                            try {
7431                                    session = openSession();
7432    
7433                                    Query q = session.createQuery(sql);
7434    
7435                                    QueryPos qPos = QueryPos.getInstance(q);
7436    
7437                                    qPos.add(groupId);
7438    
7439                                    qPos.add(parentFolderId);
7440    
7441                                    qPos.add(hidden);
7442    
7443                                    qPos.add(status);
7444    
7445                                    if (!pagination) {
7446                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
7447                                                            start, end, false);
7448    
7449                                            Collections.sort(list);
7450    
7451                                            list = new UnmodifiableList<DLFolder>(list);
7452                                    }
7453                                    else {
7454                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
7455                                                            start, end);
7456                                    }
7457    
7458                                    cacheResult(list);
7459    
7460                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
7461                            }
7462                            catch (Exception e) {
7463                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
7464    
7465                                    throw processException(e);
7466                            }
7467                            finally {
7468                                    closeSession(session);
7469                            }
7470                    }
7471    
7472                    return list;
7473            }
7474    
7475            /**
7476             * Returns the first document library folder in the ordered set where groupId = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
7477             *
7478             * @param groupId the group ID
7479             * @param parentFolderId the parent folder ID
7480             * @param hidden the hidden
7481             * @param status the status
7482             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7483             * @return the first matching document library folder
7484             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
7485             * @throws SystemException if a system exception occurred
7486             */
7487            @Override
7488            public DLFolder findByG_P_H_S_First(long groupId, long parentFolderId,
7489                    boolean hidden, int status, OrderByComparator orderByComparator)
7490                    throws NoSuchFolderException, SystemException {
7491                    DLFolder dlFolder = fetchByG_P_H_S_First(groupId, parentFolderId,
7492                                    hidden, status, orderByComparator);
7493    
7494                    if (dlFolder != null) {
7495                            return dlFolder;
7496                    }
7497    
7498                    StringBundler msg = new StringBundler(10);
7499    
7500                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7501    
7502                    msg.append("groupId=");
7503                    msg.append(groupId);
7504    
7505                    msg.append(", parentFolderId=");
7506                    msg.append(parentFolderId);
7507    
7508                    msg.append(", hidden=");
7509                    msg.append(hidden);
7510    
7511                    msg.append(", status=");
7512                    msg.append(status);
7513    
7514                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7515    
7516                    throw new NoSuchFolderException(msg.toString());
7517            }
7518    
7519            /**
7520             * Returns the first document library folder in the ordered set where groupId = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
7521             *
7522             * @param groupId the group ID
7523             * @param parentFolderId the parent folder ID
7524             * @param hidden the hidden
7525             * @param status the status
7526             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7527             * @return the first matching document library folder, or <code>null</code> if a matching document library folder could not be found
7528             * @throws SystemException if a system exception occurred
7529             */
7530            @Override
7531            public DLFolder fetchByG_P_H_S_First(long groupId, long parentFolderId,
7532                    boolean hidden, int status, OrderByComparator orderByComparator)
7533                    throws SystemException {
7534                    List<DLFolder> list = findByG_P_H_S(groupId, parentFolderId, hidden,
7535                                    status, 0, 1, orderByComparator);
7536    
7537                    if (!list.isEmpty()) {
7538                            return list.get(0);
7539                    }
7540    
7541                    return null;
7542            }
7543    
7544            /**
7545             * Returns the last document library folder in the ordered set where groupId = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
7546             *
7547             * @param groupId the group ID
7548             * @param parentFolderId the parent folder ID
7549             * @param hidden the hidden
7550             * @param status the status
7551             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7552             * @return the last matching document library folder
7553             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
7554             * @throws SystemException if a system exception occurred
7555             */
7556            @Override
7557            public DLFolder findByG_P_H_S_Last(long groupId, long parentFolderId,
7558                    boolean hidden, int status, OrderByComparator orderByComparator)
7559                    throws NoSuchFolderException, SystemException {
7560                    DLFolder dlFolder = fetchByG_P_H_S_Last(groupId, parentFolderId,
7561                                    hidden, status, orderByComparator);
7562    
7563                    if (dlFolder != null) {
7564                            return dlFolder;
7565                    }
7566    
7567                    StringBundler msg = new StringBundler(10);
7568    
7569                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7570    
7571                    msg.append("groupId=");
7572                    msg.append(groupId);
7573    
7574                    msg.append(", parentFolderId=");
7575                    msg.append(parentFolderId);
7576    
7577                    msg.append(", hidden=");
7578                    msg.append(hidden);
7579    
7580                    msg.append(", status=");
7581                    msg.append(status);
7582    
7583                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7584    
7585                    throw new NoSuchFolderException(msg.toString());
7586            }
7587    
7588            /**
7589             * Returns the last document library folder in the ordered set where groupId = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
7590             *
7591             * @param groupId the group ID
7592             * @param parentFolderId the parent folder ID
7593             * @param hidden the hidden
7594             * @param status the status
7595             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7596             * @return the last matching document library folder, or <code>null</code> if a matching document library folder could not be found
7597             * @throws SystemException if a system exception occurred
7598             */
7599            @Override
7600            public DLFolder fetchByG_P_H_S_Last(long groupId, long parentFolderId,
7601                    boolean hidden, int status, OrderByComparator orderByComparator)
7602                    throws SystemException {
7603                    int count = countByG_P_H_S(groupId, parentFolderId, hidden, status);
7604    
7605                    if (count == 0) {
7606                            return null;
7607                    }
7608    
7609                    List<DLFolder> list = findByG_P_H_S(groupId, parentFolderId, hidden,
7610                                    status, count - 1, count, orderByComparator);
7611    
7612                    if (!list.isEmpty()) {
7613                            return list.get(0);
7614                    }
7615    
7616                    return null;
7617            }
7618    
7619            /**
7620             * 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;.
7621             *
7622             * @param folderId the primary key of the current document library folder
7623             * @param groupId the group ID
7624             * @param parentFolderId the parent folder ID
7625             * @param hidden the hidden
7626             * @param status the status
7627             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7628             * @return the previous, current, and next document library folder
7629             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
7630             * @throws SystemException if a system exception occurred
7631             */
7632            @Override
7633            public DLFolder[] findByG_P_H_S_PrevAndNext(long folderId, long groupId,
7634                    long parentFolderId, boolean hidden, int status,
7635                    OrderByComparator orderByComparator)
7636                    throws NoSuchFolderException, SystemException {
7637                    DLFolder dlFolder = findByPrimaryKey(folderId);
7638    
7639                    Session session = null;
7640    
7641                    try {
7642                            session = openSession();
7643    
7644                            DLFolder[] array = new DLFolderImpl[3];
7645    
7646                            array[0] = getByG_P_H_S_PrevAndNext(session, dlFolder, groupId,
7647                                            parentFolderId, hidden, status, orderByComparator, true);
7648    
7649                            array[1] = dlFolder;
7650    
7651                            array[2] = getByG_P_H_S_PrevAndNext(session, dlFolder, groupId,
7652                                            parentFolderId, hidden, status, orderByComparator, false);
7653    
7654                            return array;
7655                    }
7656                    catch (Exception e) {
7657                            throw processException(e);
7658                    }
7659                    finally {
7660                            closeSession(session);
7661                    }
7662            }
7663    
7664            protected DLFolder getByG_P_H_S_PrevAndNext(Session session,
7665                    DLFolder dlFolder, long groupId, long parentFolderId, boolean hidden,
7666                    int status, OrderByComparator orderByComparator, boolean previous) {
7667                    StringBundler query = null;
7668    
7669                    if (orderByComparator != null) {
7670                            query = new StringBundler(6 +
7671                                            (orderByComparator.getOrderByFields().length * 6));
7672                    }
7673                    else {
7674                            query = new StringBundler(3);
7675                    }
7676    
7677                    query.append(_SQL_SELECT_DLFOLDER_WHERE);
7678    
7679                    query.append(_FINDER_COLUMN_G_P_H_S_GROUPID_2);
7680    
7681                    query.append(_FINDER_COLUMN_G_P_H_S_PARENTFOLDERID_2);
7682    
7683                    query.append(_FINDER_COLUMN_G_P_H_S_HIDDEN_2);
7684    
7685                    query.append(_FINDER_COLUMN_G_P_H_S_STATUS_2);
7686    
7687                    if (orderByComparator != null) {
7688                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7689    
7690                            if (orderByConditionFields.length > 0) {
7691                                    query.append(WHERE_AND);
7692                            }
7693    
7694                            for (int i = 0; i < orderByConditionFields.length; i++) {
7695                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7696                                    query.append(orderByConditionFields[i]);
7697    
7698                                    if ((i + 1) < orderByConditionFields.length) {
7699                                            if (orderByComparator.isAscending() ^ previous) {
7700                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
7701                                            }
7702                                            else {
7703                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
7704                                            }
7705                                    }
7706                                    else {
7707                                            if (orderByComparator.isAscending() ^ previous) {
7708                                                    query.append(WHERE_GREATER_THAN);
7709                                            }
7710                                            else {
7711                                                    query.append(WHERE_LESSER_THAN);
7712                                            }
7713                                    }
7714                            }
7715    
7716                            query.append(ORDER_BY_CLAUSE);
7717    
7718                            String[] orderByFields = orderByComparator.getOrderByFields();
7719    
7720                            for (int i = 0; i < orderByFields.length; i++) {
7721                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7722                                    query.append(orderByFields[i]);
7723    
7724                                    if ((i + 1) < orderByFields.length) {
7725                                            if (orderByComparator.isAscending() ^ previous) {
7726                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
7727                                            }
7728                                            else {
7729                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
7730                                            }
7731                                    }
7732                                    else {
7733                                            if (orderByComparator.isAscending() ^ previous) {
7734                                                    query.append(ORDER_BY_ASC);
7735                                            }
7736                                            else {
7737                                                    query.append(ORDER_BY_DESC);
7738                                            }
7739                                    }
7740                            }
7741                    }
7742                    else {
7743                            query.append(DLFolderModelImpl.ORDER_BY_JPQL);
7744                    }
7745    
7746                    String sql = query.toString();
7747    
7748                    Query q = session.createQuery(sql);
7749    
7750                    q.setFirstResult(0);
7751                    q.setMaxResults(2);
7752    
7753                    QueryPos qPos = QueryPos.getInstance(q);
7754    
7755                    qPos.add(groupId);
7756    
7757                    qPos.add(parentFolderId);
7758    
7759                    qPos.add(hidden);
7760    
7761                    qPos.add(status);
7762    
7763                    if (orderByComparator != null) {
7764                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
7765    
7766                            for (Object value : values) {
7767                                    qPos.add(value);
7768                            }
7769                    }
7770    
7771                    List<DLFolder> list = q.list();
7772    
7773                    if (list.size() == 2) {
7774                            return list.get(1);
7775                    }
7776                    else {
7777                            return null;
7778                    }
7779            }
7780    
7781            /**
7782             * 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;.
7783             *
7784             * @param groupId the group ID
7785             * @param parentFolderId the parent folder ID
7786             * @param hidden the hidden
7787             * @param status the status
7788             * @return the matching document library folders that the user has permission to view
7789             * @throws SystemException if a system exception occurred
7790             */
7791            @Override
7792            public List<DLFolder> filterFindByG_P_H_S(long groupId,
7793                    long parentFolderId, boolean hidden, int status)
7794                    throws SystemException {
7795                    return filterFindByG_P_H_S(groupId, parentFolderId, hidden, status,
7796                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
7797            }
7798    
7799            /**
7800             * 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;.
7801             *
7802             * <p>
7803             * 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.
7804             * </p>
7805             *
7806             * @param groupId the group ID
7807             * @param parentFolderId the parent folder ID
7808             * @param hidden the hidden
7809             * @param status the status
7810             * @param start the lower bound of the range of document library folders
7811             * @param end the upper bound of the range of document library folders (not inclusive)
7812             * @return the range of matching document library folders that the user has permission to view
7813             * @throws SystemException if a system exception occurred
7814             */
7815            @Override
7816            public List<DLFolder> filterFindByG_P_H_S(long groupId,
7817                    long parentFolderId, boolean hidden, int status, int start, int end)
7818                    throws SystemException {
7819                    return filterFindByG_P_H_S(groupId, parentFolderId, hidden, status,
7820                            start, end, null);
7821            }
7822    
7823            /**
7824             * 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;.
7825             *
7826             * <p>
7827             * 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.
7828             * </p>
7829             *
7830             * @param groupId the group ID
7831             * @param parentFolderId the parent folder ID
7832             * @param hidden the hidden
7833             * @param status the status
7834             * @param start the lower bound of the range of document library folders
7835             * @param end the upper bound of the range of document library folders (not inclusive)
7836             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7837             * @return the ordered range of matching document library folders that the user has permission to view
7838             * @throws SystemException if a system exception occurred
7839             */
7840            @Override
7841            public List<DLFolder> filterFindByG_P_H_S(long groupId,
7842                    long parentFolderId, boolean hidden, int status, int start, int end,
7843                    OrderByComparator orderByComparator) throws SystemException {
7844                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7845                            return findByG_P_H_S(groupId, parentFolderId, hidden, status,
7846                                    start, end, orderByComparator);
7847                    }
7848    
7849                    StringBundler query = null;
7850    
7851                    if (orderByComparator != null) {
7852                            query = new StringBundler(6 +
7853                                            (orderByComparator.getOrderByFields().length * 3));
7854                    }
7855                    else {
7856                            query = new StringBundler(6);
7857                    }
7858    
7859                    if (getDB().isSupportsInlineDistinct()) {
7860                            query.append(_FILTER_SQL_SELECT_DLFOLDER_WHERE);
7861                    }
7862                    else {
7863                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1);
7864                    }
7865    
7866                    query.append(_FINDER_COLUMN_G_P_H_S_GROUPID_2);
7867    
7868                    query.append(_FINDER_COLUMN_G_P_H_S_PARENTFOLDERID_2);
7869    
7870                    query.append(_FINDER_COLUMN_G_P_H_S_HIDDEN_2_SQL);
7871    
7872                    query.append(_FINDER_COLUMN_G_P_H_S_STATUS_2);
7873    
7874                    if (!getDB().isSupportsInlineDistinct()) {
7875                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2);
7876                    }
7877    
7878                    if (orderByComparator != null) {
7879                            if (getDB().isSupportsInlineDistinct()) {
7880                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7881                                            orderByComparator, true);
7882                            }
7883                            else {
7884                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
7885                                            orderByComparator, true);
7886                            }
7887                    }
7888                    else {
7889                            if (getDB().isSupportsInlineDistinct()) {
7890                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
7891                            }
7892                            else {
7893                                    query.append(DLFolderModelImpl.ORDER_BY_SQL);
7894                            }
7895                    }
7896    
7897                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7898                                    DLFolder.class.getName(),
7899                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7900    
7901                    Session session = null;
7902    
7903                    try {
7904                            session = openSession();
7905    
7906                            SQLQuery q = session.createSQLQuery(sql);
7907    
7908                            if (getDB().isSupportsInlineDistinct()) {
7909                                    q.addEntity(_FILTER_ENTITY_ALIAS, DLFolderImpl.class);
7910                            }
7911                            else {
7912                                    q.addEntity(_FILTER_ENTITY_TABLE, DLFolderImpl.class);
7913                            }
7914    
7915                            QueryPos qPos = QueryPos.getInstance(q);
7916    
7917                            qPos.add(groupId);
7918    
7919                            qPos.add(parentFolderId);
7920    
7921                            qPos.add(hidden);
7922    
7923                            qPos.add(status);
7924    
7925                            return (List<DLFolder>)QueryUtil.list(q, getDialect(), start, end);
7926                    }
7927                    catch (Exception e) {
7928                            throw processException(e);
7929                    }
7930                    finally {
7931                            closeSession(session);
7932                    }
7933            }
7934    
7935            /**
7936             * 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;.
7937             *
7938             * @param folderId the primary key of the current document library folder
7939             * @param groupId the group ID
7940             * @param parentFolderId the parent folder ID
7941             * @param hidden the hidden
7942             * @param status the status
7943             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7944             * @return the previous, current, and next document library folder
7945             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
7946             * @throws SystemException if a system exception occurred
7947             */
7948            @Override
7949            public DLFolder[] filterFindByG_P_H_S_PrevAndNext(long folderId,
7950                    long groupId, long parentFolderId, boolean hidden, int status,
7951                    OrderByComparator orderByComparator)
7952                    throws NoSuchFolderException, SystemException {
7953                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7954                            return findByG_P_H_S_PrevAndNext(folderId, groupId, parentFolderId,
7955                                    hidden, status, orderByComparator);
7956                    }
7957    
7958                    DLFolder dlFolder = findByPrimaryKey(folderId);
7959    
7960                    Session session = null;
7961    
7962                    try {
7963                            session = openSession();
7964    
7965                            DLFolder[] array = new DLFolderImpl[3];
7966    
7967                            array[0] = filterGetByG_P_H_S_PrevAndNext(session, dlFolder,
7968                                            groupId, parentFolderId, hidden, status, orderByComparator,
7969                                            true);
7970    
7971                            array[1] = dlFolder;
7972    
7973                            array[2] = filterGetByG_P_H_S_PrevAndNext(session, dlFolder,
7974                                            groupId, parentFolderId, hidden, status, orderByComparator,
7975                                            false);
7976    
7977                            return array;
7978                    }
7979                    catch (Exception e) {
7980                            throw processException(e);
7981                    }
7982                    finally {
7983                            closeSession(session);
7984                    }
7985            }
7986    
7987            protected DLFolder filterGetByG_P_H_S_PrevAndNext(Session session,
7988                    DLFolder dlFolder, long groupId, long parentFolderId, boolean hidden,
7989                    int status, OrderByComparator orderByComparator, boolean previous) {
7990                    StringBundler query = null;
7991    
7992                    if (orderByComparator != null) {
7993                            query = new StringBundler(6 +
7994                                            (orderByComparator.getOrderByFields().length * 6));
7995                    }
7996                    else {
7997                            query = new StringBundler(3);
7998                    }
7999    
8000                    if (getDB().isSupportsInlineDistinct()) {
8001                            query.append(_FILTER_SQL_SELECT_DLFOLDER_WHERE);
8002                    }
8003                    else {
8004                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1);
8005                    }
8006    
8007                    query.append(_FINDER_COLUMN_G_P_H_S_GROUPID_2);
8008    
8009                    query.append(_FINDER_COLUMN_G_P_H_S_PARENTFOLDERID_2);
8010    
8011                    query.append(_FINDER_COLUMN_G_P_H_S_HIDDEN_2_SQL);
8012    
8013                    query.append(_FINDER_COLUMN_G_P_H_S_STATUS_2);
8014    
8015                    if (!getDB().isSupportsInlineDistinct()) {
8016                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2);
8017                    }
8018    
8019                    if (orderByComparator != null) {
8020                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
8021    
8022                            if (orderByConditionFields.length > 0) {
8023                                    query.append(WHERE_AND);
8024                            }
8025    
8026                            for (int i = 0; i < orderByConditionFields.length; i++) {
8027                                    if (getDB().isSupportsInlineDistinct()) {
8028                                            query.append(_ORDER_BY_ENTITY_ALIAS);
8029                                    }
8030                                    else {
8031                                            query.append(_ORDER_BY_ENTITY_TABLE);
8032                                    }
8033    
8034                                    query.append(orderByConditionFields[i]);
8035    
8036                                    if ((i + 1) < orderByConditionFields.length) {
8037                                            if (orderByComparator.isAscending() ^ previous) {
8038                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
8039                                            }
8040                                            else {
8041                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
8042                                            }
8043                                    }
8044                                    else {
8045                                            if (orderByComparator.isAscending() ^ previous) {
8046                                                    query.append(WHERE_GREATER_THAN);
8047                                            }
8048                                            else {
8049                                                    query.append(WHERE_LESSER_THAN);
8050                                            }
8051                                    }
8052                            }
8053    
8054                            query.append(ORDER_BY_CLAUSE);
8055    
8056                            String[] orderByFields = orderByComparator.getOrderByFields();
8057    
8058                            for (int i = 0; i < orderByFields.length; i++) {
8059                                    if (getDB().isSupportsInlineDistinct()) {
8060                                            query.append(_ORDER_BY_ENTITY_ALIAS);
8061                                    }
8062                                    else {
8063                                            query.append(_ORDER_BY_ENTITY_TABLE);
8064                                    }
8065    
8066                                    query.append(orderByFields[i]);
8067    
8068                                    if ((i + 1) < orderByFields.length) {
8069                                            if (orderByComparator.isAscending() ^ previous) {
8070                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
8071                                            }
8072                                            else {
8073                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
8074                                            }
8075                                    }
8076                                    else {
8077                                            if (orderByComparator.isAscending() ^ previous) {
8078                                                    query.append(ORDER_BY_ASC);
8079                                            }
8080                                            else {
8081                                                    query.append(ORDER_BY_DESC);
8082                                            }
8083                                    }
8084                            }
8085                    }
8086                    else {
8087                            if (getDB().isSupportsInlineDistinct()) {
8088                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
8089                            }
8090                            else {
8091                                    query.append(DLFolderModelImpl.ORDER_BY_SQL);
8092                            }
8093                    }
8094    
8095                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8096                                    DLFolder.class.getName(),
8097                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8098    
8099                    SQLQuery q = session.createSQLQuery(sql);
8100    
8101                    q.setFirstResult(0);
8102                    q.setMaxResults(2);
8103    
8104                    if (getDB().isSupportsInlineDistinct()) {
8105                            q.addEntity(_FILTER_ENTITY_ALIAS, DLFolderImpl.class);
8106                    }
8107                    else {
8108                            q.addEntity(_FILTER_ENTITY_TABLE, DLFolderImpl.class);
8109                    }
8110    
8111                    QueryPos qPos = QueryPos.getInstance(q);
8112    
8113                    qPos.add(groupId);
8114    
8115                    qPos.add(parentFolderId);
8116    
8117                    qPos.add(hidden);
8118    
8119                    qPos.add(status);
8120    
8121                    if (orderByComparator != null) {
8122                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
8123    
8124                            for (Object value : values) {
8125                                    qPos.add(value);
8126                            }
8127                    }
8128    
8129                    List<DLFolder> list = q.list();
8130    
8131                    if (list.size() == 2) {
8132                            return list.get(1);
8133                    }
8134                    else {
8135                            return null;
8136                    }
8137            }
8138    
8139            /**
8140             * Removes all the document library folders where groupId = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63; from the database.
8141             *
8142             * @param groupId the group ID
8143             * @param parentFolderId the parent folder ID
8144             * @param hidden the hidden
8145             * @param status the status
8146             * @throws SystemException if a system exception occurred
8147             */
8148            @Override
8149            public void removeByG_P_H_S(long groupId, long parentFolderId,
8150                    boolean hidden, int status) throws SystemException {
8151                    for (DLFolder dlFolder : findByG_P_H_S(groupId, parentFolderId, hidden,
8152                                    status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
8153                            remove(dlFolder);
8154                    }
8155            }
8156    
8157            /**
8158             * Returns the number of document library folders where groupId = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
8159             *
8160             * @param groupId the group ID
8161             * @param parentFolderId the parent folder ID
8162             * @param hidden the hidden
8163             * @param status the status
8164             * @return the number of matching document library folders
8165             * @throws SystemException if a system exception occurred
8166             */
8167            @Override
8168            public int countByG_P_H_S(long groupId, long parentFolderId,
8169                    boolean hidden, int status) throws SystemException {
8170                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_P_H_S;
8171    
8172                    Object[] finderArgs = new Object[] {
8173                                    groupId, parentFolderId, hidden, status
8174                            };
8175    
8176                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
8177                                    this);
8178    
8179                    if (count == null) {
8180                            StringBundler query = new StringBundler(5);
8181    
8182                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
8183    
8184                            query.append(_FINDER_COLUMN_G_P_H_S_GROUPID_2);
8185    
8186                            query.append(_FINDER_COLUMN_G_P_H_S_PARENTFOLDERID_2);
8187    
8188                            query.append(_FINDER_COLUMN_G_P_H_S_HIDDEN_2);
8189    
8190                            query.append(_FINDER_COLUMN_G_P_H_S_STATUS_2);
8191    
8192                            String sql = query.toString();
8193    
8194                            Session session = null;
8195    
8196                            try {
8197                                    session = openSession();
8198    
8199                                    Query q = session.createQuery(sql);
8200    
8201                                    QueryPos qPos = QueryPos.getInstance(q);
8202    
8203                                    qPos.add(groupId);
8204    
8205                                    qPos.add(parentFolderId);
8206    
8207                                    qPos.add(hidden);
8208    
8209                                    qPos.add(status);
8210    
8211                                    count = (Long)q.uniqueResult();
8212    
8213                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
8214                            }
8215                            catch (Exception e) {
8216                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
8217    
8218                                    throw processException(e);
8219                            }
8220                            finally {
8221                                    closeSession(session);
8222                            }
8223                    }
8224    
8225                    return count.intValue();
8226            }
8227    
8228            /**
8229             * 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;.
8230             *
8231             * @param groupId the group ID
8232             * @param parentFolderId the parent folder ID
8233             * @param hidden the hidden
8234             * @param status the status
8235             * @return the number of matching document library folders that the user has permission to view
8236             * @throws SystemException if a system exception occurred
8237             */
8238            @Override
8239            public int filterCountByG_P_H_S(long groupId, long parentFolderId,
8240                    boolean hidden, int status) throws SystemException {
8241                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8242                            return countByG_P_H_S(groupId, parentFolderId, hidden, status);
8243                    }
8244    
8245                    StringBundler query = new StringBundler(5);
8246    
8247                    query.append(_FILTER_SQL_COUNT_DLFOLDER_WHERE);
8248    
8249                    query.append(_FINDER_COLUMN_G_P_H_S_GROUPID_2);
8250    
8251                    query.append(_FINDER_COLUMN_G_P_H_S_PARENTFOLDERID_2);
8252    
8253                    query.append(_FINDER_COLUMN_G_P_H_S_HIDDEN_2_SQL);
8254    
8255                    query.append(_FINDER_COLUMN_G_P_H_S_STATUS_2);
8256    
8257                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8258                                    DLFolder.class.getName(),
8259                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8260    
8261                    Session session = null;
8262    
8263                    try {
8264                            session = openSession();
8265    
8266                            SQLQuery q = session.createSQLQuery(sql);
8267    
8268                            q.addScalar(COUNT_COLUMN_NAME,
8269                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
8270    
8271                            QueryPos qPos = QueryPos.getInstance(q);
8272    
8273                            qPos.add(groupId);
8274    
8275                            qPos.add(parentFolderId);
8276    
8277                            qPos.add(hidden);
8278    
8279                            qPos.add(status);
8280    
8281                            Long count = (Long)q.uniqueResult();
8282    
8283                            return count.intValue();
8284                    }
8285                    catch (Exception e) {
8286                            throw processException(e);
8287                    }
8288                    finally {
8289                            closeSession(session);
8290                    }
8291            }
8292    
8293            private static final String _FINDER_COLUMN_G_P_H_S_GROUPID_2 = "dlFolder.groupId = ? AND ";
8294            private static final String _FINDER_COLUMN_G_P_H_S_PARENTFOLDERID_2 = "dlFolder.parentFolderId = ? AND ";
8295            private static final String _FINDER_COLUMN_G_P_H_S_HIDDEN_2 = "dlFolder.hidden = ? AND ";
8296            private static final String _FINDER_COLUMN_G_P_H_S_HIDDEN_2_SQL = "dlFolder.hidden_ = ? AND ";
8297            private static final String _FINDER_COLUMN_G_P_H_S_STATUS_2 = "dlFolder.status = ?";
8298            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_M_P_H_S =
8299                    new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
8300                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
8301                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_M_P_H_S",
8302                            new String[] {
8303                                    Long.class.getName(), Boolean.class.getName(),
8304                                    Long.class.getName(), Boolean.class.getName(),
8305                                    Integer.class.getName(),
8306                                    
8307                            Integer.class.getName(), Integer.class.getName(),
8308                                    OrderByComparator.class.getName()
8309                            });
8310            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P_H_S =
8311                    new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
8312                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
8313                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_M_P_H_S",
8314                            new String[] {
8315                                    Long.class.getName(), Boolean.class.getName(),
8316                                    Long.class.getName(), Boolean.class.getName(),
8317                                    Integer.class.getName()
8318                            },
8319                            DLFolderModelImpl.GROUPID_COLUMN_BITMASK |
8320                            DLFolderModelImpl.MOUNTPOINT_COLUMN_BITMASK |
8321                            DLFolderModelImpl.PARENTFOLDERID_COLUMN_BITMASK |
8322                            DLFolderModelImpl.HIDDEN_COLUMN_BITMASK |
8323                            DLFolderModelImpl.STATUS_COLUMN_BITMASK |
8324                            DLFolderModelImpl.NAME_COLUMN_BITMASK);
8325            public static final FinderPath FINDER_PATH_COUNT_BY_G_M_P_H_S = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
8326                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
8327                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_M_P_H_S",
8328                            new String[] {
8329                                    Long.class.getName(), Boolean.class.getName(),
8330                                    Long.class.getName(), Boolean.class.getName(),
8331                                    Integer.class.getName()
8332                            });
8333    
8334            /**
8335             * Returns all the document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
8336             *
8337             * @param groupId the group ID
8338             * @param mountPoint the mount point
8339             * @param parentFolderId the parent folder ID
8340             * @param hidden the hidden
8341             * @param status the status
8342             * @return the matching document library folders
8343             * @throws SystemException if a system exception occurred
8344             */
8345            @Override
8346            public List<DLFolder> findByG_M_P_H_S(long groupId, boolean mountPoint,
8347                    long parentFolderId, boolean hidden, int status)
8348                    throws SystemException {
8349                    return findByG_M_P_H_S(groupId, mountPoint, parentFolderId, hidden,
8350                            status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
8351            }
8352    
8353            /**
8354             * Returns a range of all the document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
8355             *
8356             * <p>
8357             * 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.
8358             * </p>
8359             *
8360             * @param groupId the group ID
8361             * @param mountPoint the mount point
8362             * @param parentFolderId the parent folder ID
8363             * @param hidden the hidden
8364             * @param status the status
8365             * @param start the lower bound of the range of document library folders
8366             * @param end the upper bound of the range of document library folders (not inclusive)
8367             * @return the range of matching document library folders
8368             * @throws SystemException if a system exception occurred
8369             */
8370            @Override
8371            public List<DLFolder> findByG_M_P_H_S(long groupId, boolean mountPoint,
8372                    long parentFolderId, boolean hidden, int status, int start, int end)
8373                    throws SystemException {
8374                    return findByG_M_P_H_S(groupId, mountPoint, parentFolderId, hidden,
8375                            status, start, end, null);
8376            }
8377    
8378            /**
8379             * 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;.
8380             *
8381             * <p>
8382             * 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.
8383             * </p>
8384             *
8385             * @param groupId the group ID
8386             * @param mountPoint the mount point
8387             * @param parentFolderId the parent folder ID
8388             * @param hidden the hidden
8389             * @param status the status
8390             * @param start the lower bound of the range of document library folders
8391             * @param end the upper bound of the range of document library folders (not inclusive)
8392             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8393             * @return the ordered range of matching document library folders
8394             * @throws SystemException if a system exception occurred
8395             */
8396            @Override
8397            public List<DLFolder> findByG_M_P_H_S(long groupId, boolean mountPoint,
8398                    long parentFolderId, boolean hidden, int status, int start, int end,
8399                    OrderByComparator orderByComparator) throws SystemException {
8400                    boolean pagination = true;
8401                    FinderPath finderPath = null;
8402                    Object[] finderArgs = null;
8403    
8404                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8405                                    (orderByComparator == null)) {
8406                            pagination = false;
8407                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P_H_S;
8408                            finderArgs = new Object[] {
8409                                            groupId, mountPoint, parentFolderId, hidden, status
8410                                    };
8411                    }
8412                    else {
8413                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_M_P_H_S;
8414                            finderArgs = new Object[] {
8415                                            groupId, mountPoint, parentFolderId, hidden, status,
8416                                            
8417                                            start, end, orderByComparator
8418                                    };
8419                    }
8420    
8421                    List<DLFolder> list = (List<DLFolder>)FinderCacheUtil.getResult(finderPath,
8422                                    finderArgs, this);
8423    
8424                    if ((list != null) && !list.isEmpty()) {
8425                            for (DLFolder dlFolder : list) {
8426                                    if ((groupId != dlFolder.getGroupId()) ||
8427                                                    (mountPoint != dlFolder.getMountPoint()) ||
8428                                                    (parentFolderId != dlFolder.getParentFolderId()) ||
8429                                                    (hidden != dlFolder.getHidden()) ||
8430                                                    (status != dlFolder.getStatus())) {
8431                                            list = null;
8432    
8433                                            break;
8434                                    }
8435                            }
8436                    }
8437    
8438                    if (list == null) {
8439                            StringBundler query = null;
8440    
8441                            if (orderByComparator != null) {
8442                                    query = new StringBundler(7 +
8443                                                    (orderByComparator.getOrderByFields().length * 3));
8444                            }
8445                            else {
8446                                    query = new StringBundler(7);
8447                            }
8448    
8449                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
8450    
8451                            query.append(_FINDER_COLUMN_G_M_P_H_S_GROUPID_2);
8452    
8453                            query.append(_FINDER_COLUMN_G_M_P_H_S_MOUNTPOINT_2);
8454    
8455                            query.append(_FINDER_COLUMN_G_M_P_H_S_PARENTFOLDERID_2);
8456    
8457                            query.append(_FINDER_COLUMN_G_M_P_H_S_HIDDEN_2);
8458    
8459                            query.append(_FINDER_COLUMN_G_M_P_H_S_STATUS_2);
8460    
8461                            if (orderByComparator != null) {
8462                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8463                                            orderByComparator);
8464                            }
8465                            else
8466                             if (pagination) {
8467                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
8468                            }
8469    
8470                            String sql = query.toString();
8471    
8472                            Session session = null;
8473    
8474                            try {
8475                                    session = openSession();
8476    
8477                                    Query q = session.createQuery(sql);
8478    
8479                                    QueryPos qPos = QueryPos.getInstance(q);
8480    
8481                                    qPos.add(groupId);
8482    
8483                                    qPos.add(mountPoint);
8484    
8485                                    qPos.add(parentFolderId);
8486    
8487                                    qPos.add(hidden);
8488    
8489                                    qPos.add(status);
8490    
8491                                    if (!pagination) {
8492                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
8493                                                            start, end, false);
8494    
8495                                            Collections.sort(list);
8496    
8497                                            list = new UnmodifiableList<DLFolder>(list);
8498                                    }
8499                                    else {
8500                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
8501                                                            start, end);
8502                                    }
8503    
8504                                    cacheResult(list);
8505    
8506                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
8507                            }
8508                            catch (Exception e) {
8509                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
8510    
8511                                    throw processException(e);
8512                            }
8513                            finally {
8514                                    closeSession(session);
8515                            }
8516                    }
8517    
8518                    return list;
8519            }
8520    
8521            /**
8522             * 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;.
8523             *
8524             * @param groupId the group ID
8525             * @param mountPoint the mount point
8526             * @param parentFolderId the parent folder ID
8527             * @param hidden the hidden
8528             * @param status the status
8529             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8530             * @return the first matching document library folder
8531             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
8532             * @throws SystemException if a system exception occurred
8533             */
8534            @Override
8535            public DLFolder findByG_M_P_H_S_First(long groupId, boolean mountPoint,
8536                    long parentFolderId, boolean hidden, int status,
8537                    OrderByComparator orderByComparator)
8538                    throws NoSuchFolderException, SystemException {
8539                    DLFolder dlFolder = fetchByG_M_P_H_S_First(groupId, mountPoint,
8540                                    parentFolderId, hidden, status, orderByComparator);
8541    
8542                    if (dlFolder != null) {
8543                            return dlFolder;
8544                    }
8545    
8546                    StringBundler msg = new StringBundler(12);
8547    
8548                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8549    
8550                    msg.append("groupId=");
8551                    msg.append(groupId);
8552    
8553                    msg.append(", mountPoint=");
8554                    msg.append(mountPoint);
8555    
8556                    msg.append(", parentFolderId=");
8557                    msg.append(parentFolderId);
8558    
8559                    msg.append(", hidden=");
8560                    msg.append(hidden);
8561    
8562                    msg.append(", status=");
8563                    msg.append(status);
8564    
8565                    msg.append(StringPool.CLOSE_CURLY_BRACE);
8566    
8567                    throw new NoSuchFolderException(msg.toString());
8568            }
8569    
8570            /**
8571             * 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;.
8572             *
8573             * @param groupId the group ID
8574             * @param mountPoint the mount point
8575             * @param parentFolderId the parent folder ID
8576             * @param hidden the hidden
8577             * @param status the status
8578             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8579             * @return the first matching document library folder, or <code>null</code> if a matching document library folder could not be found
8580             * @throws SystemException if a system exception occurred
8581             */
8582            @Override
8583            public DLFolder fetchByG_M_P_H_S_First(long groupId, boolean mountPoint,
8584                    long parentFolderId, boolean hidden, int status,
8585                    OrderByComparator orderByComparator) throws SystemException {
8586                    List<DLFolder> list = findByG_M_P_H_S(groupId, mountPoint,
8587                                    parentFolderId, hidden, status, 0, 1, orderByComparator);
8588    
8589                    if (!list.isEmpty()) {
8590                            return list.get(0);
8591                    }
8592    
8593                    return null;
8594            }
8595    
8596            /**
8597             * 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;.
8598             *
8599             * @param groupId the group ID
8600             * @param mountPoint the mount point
8601             * @param parentFolderId the parent folder ID
8602             * @param hidden the hidden
8603             * @param status the status
8604             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8605             * @return the last matching document library folder
8606             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
8607             * @throws SystemException if a system exception occurred
8608             */
8609            @Override
8610            public DLFolder findByG_M_P_H_S_Last(long groupId, boolean mountPoint,
8611                    long parentFolderId, boolean hidden, int status,
8612                    OrderByComparator orderByComparator)
8613                    throws NoSuchFolderException, SystemException {
8614                    DLFolder dlFolder = fetchByG_M_P_H_S_Last(groupId, mountPoint,
8615                                    parentFolderId, hidden, status, orderByComparator);
8616    
8617                    if (dlFolder != null) {
8618                            return dlFolder;
8619                    }
8620    
8621                    StringBundler msg = new StringBundler(12);
8622    
8623                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8624    
8625                    msg.append("groupId=");
8626                    msg.append(groupId);
8627    
8628                    msg.append(", mountPoint=");
8629                    msg.append(mountPoint);
8630    
8631                    msg.append(", parentFolderId=");
8632                    msg.append(parentFolderId);
8633    
8634                    msg.append(", hidden=");
8635                    msg.append(hidden);
8636    
8637                    msg.append(", status=");
8638                    msg.append(status);
8639    
8640                    msg.append(StringPool.CLOSE_CURLY_BRACE);
8641    
8642                    throw new NoSuchFolderException(msg.toString());
8643            }
8644    
8645            /**
8646             * 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;.
8647             *
8648             * @param groupId the group ID
8649             * @param mountPoint the mount point
8650             * @param parentFolderId the parent folder ID
8651             * @param hidden the hidden
8652             * @param status the status
8653             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8654             * @return the last matching document library folder, or <code>null</code> if a matching document library folder could not be found
8655             * @throws SystemException if a system exception occurred
8656             */
8657            @Override
8658            public DLFolder fetchByG_M_P_H_S_Last(long groupId, boolean mountPoint,
8659                    long parentFolderId, boolean hidden, int status,
8660                    OrderByComparator orderByComparator) throws SystemException {
8661                    int count = countByG_M_P_H_S(groupId, mountPoint, parentFolderId,
8662                                    hidden, status);
8663    
8664                    if (count == 0) {
8665                            return null;
8666                    }
8667    
8668                    List<DLFolder> list = findByG_M_P_H_S(groupId, mountPoint,
8669                                    parentFolderId, hidden, status, count - 1, count,
8670                                    orderByComparator);
8671    
8672                    if (!list.isEmpty()) {
8673                            return list.get(0);
8674                    }
8675    
8676                    return null;
8677            }
8678    
8679            /**
8680             * 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;.
8681             *
8682             * @param folderId the primary key of the current document library folder
8683             * @param groupId the group ID
8684             * @param mountPoint the mount point
8685             * @param parentFolderId the parent folder ID
8686             * @param hidden the hidden
8687             * @param status the status
8688             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8689             * @return the previous, current, and next document library folder
8690             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
8691             * @throws SystemException if a system exception occurred
8692             */
8693            @Override
8694            public DLFolder[] findByG_M_P_H_S_PrevAndNext(long folderId, long groupId,
8695                    boolean mountPoint, long parentFolderId, boolean hidden, int status,
8696                    OrderByComparator orderByComparator)
8697                    throws NoSuchFolderException, SystemException {
8698                    DLFolder dlFolder = findByPrimaryKey(folderId);
8699    
8700                    Session session = null;
8701    
8702                    try {
8703                            session = openSession();
8704    
8705                            DLFolder[] array = new DLFolderImpl[3];
8706    
8707                            array[0] = getByG_M_P_H_S_PrevAndNext(session, dlFolder, groupId,
8708                                            mountPoint, parentFolderId, hidden, status,
8709                                            orderByComparator, true);
8710    
8711                            array[1] = dlFolder;
8712    
8713                            array[2] = getByG_M_P_H_S_PrevAndNext(session, dlFolder, groupId,
8714                                            mountPoint, parentFolderId, hidden, status,
8715                                            orderByComparator, false);
8716    
8717                            return array;
8718                    }
8719                    catch (Exception e) {
8720                            throw processException(e);
8721                    }
8722                    finally {
8723                            closeSession(session);
8724                    }
8725            }
8726    
8727            protected DLFolder getByG_M_P_H_S_PrevAndNext(Session session,
8728                    DLFolder dlFolder, long groupId, boolean mountPoint,
8729                    long parentFolderId, boolean hidden, int status,
8730                    OrderByComparator orderByComparator, boolean previous) {
8731                    StringBundler query = null;
8732    
8733                    if (orderByComparator != null) {
8734                            query = new StringBundler(6 +
8735                                            (orderByComparator.getOrderByFields().length * 6));
8736                    }
8737                    else {
8738                            query = new StringBundler(3);
8739                    }
8740    
8741                    query.append(_SQL_SELECT_DLFOLDER_WHERE);
8742    
8743                    query.append(_FINDER_COLUMN_G_M_P_H_S_GROUPID_2);
8744    
8745                    query.append(_FINDER_COLUMN_G_M_P_H_S_MOUNTPOINT_2);
8746    
8747                    query.append(_FINDER_COLUMN_G_M_P_H_S_PARENTFOLDERID_2);
8748    
8749                    query.append(_FINDER_COLUMN_G_M_P_H_S_HIDDEN_2);
8750    
8751                    query.append(_FINDER_COLUMN_G_M_P_H_S_STATUS_2);
8752    
8753                    if (orderByComparator != null) {
8754                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
8755    
8756                            if (orderByConditionFields.length > 0) {
8757                                    query.append(WHERE_AND);
8758                            }
8759    
8760                            for (int i = 0; i < orderByConditionFields.length; i++) {
8761                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8762                                    query.append(orderByConditionFields[i]);
8763    
8764                                    if ((i + 1) < orderByConditionFields.length) {
8765                                            if (orderByComparator.isAscending() ^ previous) {
8766                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
8767                                            }
8768                                            else {
8769                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
8770                                            }
8771                                    }
8772                                    else {
8773                                            if (orderByComparator.isAscending() ^ previous) {
8774                                                    query.append(WHERE_GREATER_THAN);
8775                                            }
8776                                            else {
8777                                                    query.append(WHERE_LESSER_THAN);
8778                                            }
8779                                    }
8780                            }
8781    
8782                            query.append(ORDER_BY_CLAUSE);
8783    
8784                            String[] orderByFields = orderByComparator.getOrderByFields();
8785    
8786                            for (int i = 0; i < orderByFields.length; i++) {
8787                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8788                                    query.append(orderByFields[i]);
8789    
8790                                    if ((i + 1) < orderByFields.length) {
8791                                            if (orderByComparator.isAscending() ^ previous) {
8792                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
8793                                            }
8794                                            else {
8795                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
8796                                            }
8797                                    }
8798                                    else {
8799                                            if (orderByComparator.isAscending() ^ previous) {
8800                                                    query.append(ORDER_BY_ASC);
8801                                            }
8802                                            else {
8803                                                    query.append(ORDER_BY_DESC);
8804                                            }
8805                                    }
8806                            }
8807                    }
8808                    else {
8809                            query.append(DLFolderModelImpl.ORDER_BY_JPQL);
8810                    }
8811    
8812                    String sql = query.toString();
8813    
8814                    Query q = session.createQuery(sql);
8815    
8816                    q.setFirstResult(0);
8817                    q.setMaxResults(2);
8818    
8819                    QueryPos qPos = QueryPos.getInstance(q);
8820    
8821                    qPos.add(groupId);
8822    
8823                    qPos.add(mountPoint);
8824    
8825                    qPos.add(parentFolderId);
8826    
8827                    qPos.add(hidden);
8828    
8829                    qPos.add(status);
8830    
8831                    if (orderByComparator != null) {
8832                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
8833    
8834                            for (Object value : values) {
8835                                    qPos.add(value);
8836                            }
8837                    }
8838    
8839                    List<DLFolder> list = q.list();
8840    
8841                    if (list.size() == 2) {
8842                            return list.get(1);
8843                    }
8844                    else {
8845                            return null;
8846                    }
8847            }
8848    
8849            /**
8850             * 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;.
8851             *
8852             * @param groupId the group ID
8853             * @param mountPoint the mount point
8854             * @param parentFolderId the parent folder ID
8855             * @param hidden the hidden
8856             * @param status the status
8857             * @return the matching document library folders that the user has permission to view
8858             * @throws SystemException if a system exception occurred
8859             */
8860            @Override
8861            public List<DLFolder> filterFindByG_M_P_H_S(long groupId,
8862                    boolean mountPoint, long parentFolderId, boolean hidden, int status)
8863                    throws SystemException {
8864                    return filterFindByG_M_P_H_S(groupId, mountPoint, parentFolderId,
8865                            hidden, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
8866            }
8867    
8868            /**
8869             * 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;.
8870             *
8871             * <p>
8872             * 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.
8873             * </p>
8874             *
8875             * @param groupId the group ID
8876             * @param mountPoint the mount point
8877             * @param parentFolderId the parent folder ID
8878             * @param hidden the hidden
8879             * @param status the status
8880             * @param start the lower bound of the range of document library folders
8881             * @param end the upper bound of the range of document library folders (not inclusive)
8882             * @return the range of matching document library folders that the user has permission to view
8883             * @throws SystemException if a system exception occurred
8884             */
8885            @Override
8886            public List<DLFolder> filterFindByG_M_P_H_S(long groupId,
8887                    boolean mountPoint, long parentFolderId, boolean hidden, int status,
8888                    int start, int end) throws SystemException {
8889                    return filterFindByG_M_P_H_S(groupId, mountPoint, parentFolderId,
8890                            hidden, status, start, end, null);
8891            }
8892    
8893            /**
8894             * 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;.
8895             *
8896             * <p>
8897             * 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.
8898             * </p>
8899             *
8900             * @param groupId the group ID
8901             * @param mountPoint the mount point
8902             * @param parentFolderId the parent folder ID
8903             * @param hidden the hidden
8904             * @param status the status
8905             * @param start the lower bound of the range of document library folders
8906             * @param end the upper bound of the range of document library folders (not inclusive)
8907             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8908             * @return the ordered range of matching document library folders that the user has permission to view
8909             * @throws SystemException if a system exception occurred
8910             */
8911            @Override
8912            public List<DLFolder> filterFindByG_M_P_H_S(long groupId,
8913                    boolean mountPoint, long parentFolderId, boolean hidden, int status,
8914                    int start, int end, OrderByComparator orderByComparator)
8915                    throws SystemException {
8916                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8917                            return findByG_M_P_H_S(groupId, mountPoint, parentFolderId, hidden,
8918                                    status, start, end, orderByComparator);
8919                    }
8920    
8921                    StringBundler query = null;
8922    
8923                    if (orderByComparator != null) {
8924                            query = new StringBundler(7 +
8925                                            (orderByComparator.getOrderByFields().length * 3));
8926                    }
8927                    else {
8928                            query = new StringBundler(7);
8929                    }
8930    
8931                    if (getDB().isSupportsInlineDistinct()) {
8932                            query.append(_FILTER_SQL_SELECT_DLFOLDER_WHERE);
8933                    }
8934                    else {
8935                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1);
8936                    }
8937    
8938                    query.append(_FINDER_COLUMN_G_M_P_H_S_GROUPID_2);
8939    
8940                    query.append(_FINDER_COLUMN_G_M_P_H_S_MOUNTPOINT_2);
8941    
8942                    query.append(_FINDER_COLUMN_G_M_P_H_S_PARENTFOLDERID_2);
8943    
8944                    query.append(_FINDER_COLUMN_G_M_P_H_S_HIDDEN_2_SQL);
8945    
8946                    query.append(_FINDER_COLUMN_G_M_P_H_S_STATUS_2);
8947    
8948                    if (!getDB().isSupportsInlineDistinct()) {
8949                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2);
8950                    }
8951    
8952                    if (orderByComparator != null) {
8953                            if (getDB().isSupportsInlineDistinct()) {
8954                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8955                                            orderByComparator, true);
8956                            }
8957                            else {
8958                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
8959                                            orderByComparator, true);
8960                            }
8961                    }
8962                    else {
8963                            if (getDB().isSupportsInlineDistinct()) {
8964                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
8965                            }
8966                            else {
8967                                    query.append(DLFolderModelImpl.ORDER_BY_SQL);
8968                            }
8969                    }
8970    
8971                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8972                                    DLFolder.class.getName(),
8973                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8974    
8975                    Session session = null;
8976    
8977                    try {
8978                            session = openSession();
8979    
8980                            SQLQuery q = session.createSQLQuery(sql);
8981    
8982                            if (getDB().isSupportsInlineDistinct()) {
8983                                    q.addEntity(_FILTER_ENTITY_ALIAS, DLFolderImpl.class);
8984                            }
8985                            else {
8986                                    q.addEntity(_FILTER_ENTITY_TABLE, DLFolderImpl.class);
8987                            }
8988    
8989                            QueryPos qPos = QueryPos.getInstance(q);
8990    
8991                            qPos.add(groupId);
8992    
8993                            qPos.add(mountPoint);
8994    
8995                            qPos.add(parentFolderId);
8996    
8997                            qPos.add(hidden);
8998    
8999                            qPos.add(status);
9000    
9001                            return (List<DLFolder>)QueryUtil.list(q, getDialect(), start, end);
9002                    }
9003                    catch (Exception e) {
9004                            throw processException(e);
9005                    }
9006                    finally {
9007                            closeSession(session);
9008                    }
9009            }
9010    
9011            /**
9012             * 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;.
9013             *
9014             * @param folderId the primary key of the current document library folder
9015             * @param groupId the group ID
9016             * @param mountPoint the mount point
9017             * @param parentFolderId the parent folder ID
9018             * @param hidden the hidden
9019             * @param status the status
9020             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9021             * @return the previous, current, and next document library folder
9022             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
9023             * @throws SystemException if a system exception occurred
9024             */
9025            @Override
9026            public DLFolder[] filterFindByG_M_P_H_S_PrevAndNext(long folderId,
9027                    long groupId, boolean mountPoint, long parentFolderId, boolean hidden,
9028                    int status, OrderByComparator orderByComparator)
9029                    throws NoSuchFolderException, SystemException {
9030                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
9031                            return findByG_M_P_H_S_PrevAndNext(folderId, groupId, mountPoint,
9032                                    parentFolderId, hidden, status, orderByComparator);
9033                    }
9034    
9035                    DLFolder dlFolder = findByPrimaryKey(folderId);
9036    
9037                    Session session = null;
9038    
9039                    try {
9040                            session = openSession();
9041    
9042                            DLFolder[] array = new DLFolderImpl[3];
9043    
9044                            array[0] = filterGetByG_M_P_H_S_PrevAndNext(session, dlFolder,
9045                                            groupId, mountPoint, parentFolderId, hidden, status,
9046                                            orderByComparator, true);
9047    
9048                            array[1] = dlFolder;
9049    
9050                            array[2] = filterGetByG_M_P_H_S_PrevAndNext(session, dlFolder,
9051                                            groupId, mountPoint, parentFolderId, hidden, status,
9052                                            orderByComparator, false);
9053    
9054                            return array;
9055                    }
9056                    catch (Exception e) {
9057                            throw processException(e);
9058                    }
9059                    finally {
9060                            closeSession(session);
9061                    }
9062            }
9063    
9064            protected DLFolder filterGetByG_M_P_H_S_PrevAndNext(Session session,
9065                    DLFolder dlFolder, long groupId, boolean mountPoint,
9066                    long parentFolderId, boolean hidden, int status,
9067                    OrderByComparator orderByComparator, boolean previous) {
9068                    StringBundler query = null;
9069    
9070                    if (orderByComparator != null) {
9071                            query = new StringBundler(6 +
9072                                            (orderByComparator.getOrderByFields().length * 6));
9073                    }
9074                    else {
9075                            query = new StringBundler(3);
9076                    }
9077    
9078                    if (getDB().isSupportsInlineDistinct()) {
9079                            query.append(_FILTER_SQL_SELECT_DLFOLDER_WHERE);
9080                    }
9081                    else {
9082                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1);
9083                    }
9084    
9085                    query.append(_FINDER_COLUMN_G_M_P_H_S_GROUPID_2);
9086    
9087                    query.append(_FINDER_COLUMN_G_M_P_H_S_MOUNTPOINT_2);
9088    
9089                    query.append(_FINDER_COLUMN_G_M_P_H_S_PARENTFOLDERID_2);
9090    
9091                    query.append(_FINDER_COLUMN_G_M_P_H_S_HIDDEN_2_SQL);
9092    
9093                    query.append(_FINDER_COLUMN_G_M_P_H_S_STATUS_2);
9094    
9095                    if (!getDB().isSupportsInlineDistinct()) {
9096                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2);
9097                    }
9098    
9099                    if (orderByComparator != null) {
9100                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
9101    
9102                            if (orderByConditionFields.length > 0) {
9103                                    query.append(WHERE_AND);
9104                            }
9105    
9106                            for (int i = 0; i < orderByConditionFields.length; i++) {
9107                                    if (getDB().isSupportsInlineDistinct()) {
9108                                            query.append(_ORDER_BY_ENTITY_ALIAS);
9109                                    }
9110                                    else {
9111                                            query.append(_ORDER_BY_ENTITY_TABLE);
9112                                    }
9113    
9114                                    query.append(orderByConditionFields[i]);
9115    
9116                                    if ((i + 1) < orderByConditionFields.length) {
9117                                            if (orderByComparator.isAscending() ^ previous) {
9118                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
9119                                            }
9120                                            else {
9121                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
9122                                            }
9123                                    }
9124                                    else {
9125                                            if (orderByComparator.isAscending() ^ previous) {
9126                                                    query.append(WHERE_GREATER_THAN);
9127                                            }
9128                                            else {
9129                                                    query.append(WHERE_LESSER_THAN);
9130                                            }
9131                                    }
9132                            }
9133    
9134                            query.append(ORDER_BY_CLAUSE);
9135    
9136                            String[] orderByFields = orderByComparator.getOrderByFields();
9137    
9138                            for (int i = 0; i < orderByFields.length; i++) {
9139                                    if (getDB().isSupportsInlineDistinct()) {
9140                                            query.append(_ORDER_BY_ENTITY_ALIAS);
9141                                    }
9142                                    else {
9143                                            query.append(_ORDER_BY_ENTITY_TABLE);
9144                                    }
9145    
9146                                    query.append(orderByFields[i]);
9147    
9148                                    if ((i + 1) < orderByFields.length) {
9149                                            if (orderByComparator.isAscending() ^ previous) {
9150                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
9151                                            }
9152                                            else {
9153                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
9154                                            }
9155                                    }
9156                                    else {
9157                                            if (orderByComparator.isAscending() ^ previous) {
9158                                                    query.append(ORDER_BY_ASC);
9159                                            }
9160                                            else {
9161                                                    query.append(ORDER_BY_DESC);
9162                                            }
9163                                    }
9164                            }
9165                    }
9166                    else {
9167                            if (getDB().isSupportsInlineDistinct()) {
9168                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
9169                            }
9170                            else {
9171                                    query.append(DLFolderModelImpl.ORDER_BY_SQL);
9172                            }
9173                    }
9174    
9175                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
9176                                    DLFolder.class.getName(),
9177                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
9178    
9179                    SQLQuery q = session.createSQLQuery(sql);
9180    
9181                    q.setFirstResult(0);
9182                    q.setMaxResults(2);
9183    
9184                    if (getDB().isSupportsInlineDistinct()) {
9185                            q.addEntity(_FILTER_ENTITY_ALIAS, DLFolderImpl.class);
9186                    }
9187                    else {
9188                            q.addEntity(_FILTER_ENTITY_TABLE, DLFolderImpl.class);
9189                    }
9190    
9191                    QueryPos qPos = QueryPos.getInstance(q);
9192    
9193                    qPos.add(groupId);
9194    
9195                    qPos.add(mountPoint);
9196    
9197                    qPos.add(parentFolderId);
9198    
9199                    qPos.add(hidden);
9200    
9201                    qPos.add(status);
9202    
9203                    if (orderByComparator != null) {
9204                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
9205    
9206                            for (Object value : values) {
9207                                    qPos.add(value);
9208                            }
9209                    }
9210    
9211                    List<DLFolder> list = q.list();
9212    
9213                    if (list.size() == 2) {
9214                            return list.get(1);
9215                    }
9216                    else {
9217                            return null;
9218                    }
9219            }
9220    
9221            /**
9222             * Removes all the document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63; from the database.
9223             *
9224             * @param groupId the group ID
9225             * @param mountPoint the mount point
9226             * @param parentFolderId the parent folder ID
9227             * @param hidden the hidden
9228             * @param status the status
9229             * @throws SystemException if a system exception occurred
9230             */
9231            @Override
9232            public void removeByG_M_P_H_S(long groupId, boolean mountPoint,
9233                    long parentFolderId, boolean hidden, int status)
9234                    throws SystemException {
9235                    for (DLFolder dlFolder : findByG_M_P_H_S(groupId, mountPoint,
9236                                    parentFolderId, hidden, status, QueryUtil.ALL_POS,
9237                                    QueryUtil.ALL_POS, null)) {
9238                            remove(dlFolder);
9239                    }
9240            }
9241    
9242            /**
9243             * Returns the number of document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
9244             *
9245             * @param groupId the group ID
9246             * @param mountPoint the mount point
9247             * @param parentFolderId the parent folder ID
9248             * @param hidden the hidden
9249             * @param status the status
9250             * @return the number of matching document library folders
9251             * @throws SystemException if a system exception occurred
9252             */
9253            @Override
9254            public int countByG_M_P_H_S(long groupId, boolean mountPoint,
9255                    long parentFolderId, boolean hidden, int status)
9256                    throws SystemException {
9257                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_M_P_H_S;
9258    
9259                    Object[] finderArgs = new Object[] {
9260                                    groupId, mountPoint, parentFolderId, hidden, status
9261                            };
9262    
9263                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
9264                                    this);
9265    
9266                    if (count == null) {
9267                            StringBundler query = new StringBundler(6);
9268    
9269                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
9270    
9271                            query.append(_FINDER_COLUMN_G_M_P_H_S_GROUPID_2);
9272    
9273                            query.append(_FINDER_COLUMN_G_M_P_H_S_MOUNTPOINT_2);
9274    
9275                            query.append(_FINDER_COLUMN_G_M_P_H_S_PARENTFOLDERID_2);
9276    
9277                            query.append(_FINDER_COLUMN_G_M_P_H_S_HIDDEN_2);
9278    
9279                            query.append(_FINDER_COLUMN_G_M_P_H_S_STATUS_2);
9280    
9281                            String sql = query.toString();
9282    
9283                            Session session = null;
9284    
9285                            try {
9286                                    session = openSession();
9287    
9288                                    Query q = session.createQuery(sql);
9289    
9290                                    QueryPos qPos = QueryPos.getInstance(q);
9291    
9292                                    qPos.add(groupId);
9293    
9294                                    qPos.add(mountPoint);
9295    
9296                                    qPos.add(parentFolderId);
9297    
9298                                    qPos.add(hidden);
9299    
9300                                    qPos.add(status);
9301    
9302                                    count = (Long)q.uniqueResult();
9303    
9304                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
9305                            }
9306                            catch (Exception e) {
9307                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
9308    
9309                                    throw processException(e);
9310                            }
9311                            finally {
9312                                    closeSession(session);
9313                            }
9314                    }
9315    
9316                    return count.intValue();
9317            }
9318    
9319            /**
9320             * 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;.
9321             *
9322             * @param groupId the group ID
9323             * @param mountPoint the mount point
9324             * @param parentFolderId the parent folder ID
9325             * @param hidden the hidden
9326             * @param status the status
9327             * @return the number of matching document library folders that the user has permission to view
9328             * @throws SystemException if a system exception occurred
9329             */
9330            @Override
9331            public int filterCountByG_M_P_H_S(long groupId, boolean mountPoint,
9332                    long parentFolderId, boolean hidden, int status)
9333                    throws SystemException {
9334                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
9335                            return countByG_M_P_H_S(groupId, mountPoint, parentFolderId,
9336                                    hidden, status);
9337                    }
9338    
9339                    StringBundler query = new StringBundler(6);
9340    
9341                    query.append(_FILTER_SQL_COUNT_DLFOLDER_WHERE);
9342    
9343                    query.append(_FINDER_COLUMN_G_M_P_H_S_GROUPID_2);
9344    
9345                    query.append(_FINDER_COLUMN_G_M_P_H_S_MOUNTPOINT_2);
9346    
9347                    query.append(_FINDER_COLUMN_G_M_P_H_S_PARENTFOLDERID_2);
9348    
9349                    query.append(_FINDER_COLUMN_G_M_P_H_S_HIDDEN_2_SQL);
9350    
9351                    query.append(_FINDER_COLUMN_G_M_P_H_S_STATUS_2);
9352    
9353                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
9354                                    DLFolder.class.getName(),
9355                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
9356    
9357                    Session session = null;
9358    
9359                    try {
9360                            session = openSession();
9361    
9362                            SQLQuery q = session.createSQLQuery(sql);
9363    
9364                            q.addScalar(COUNT_COLUMN_NAME,
9365                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
9366    
9367                            QueryPos qPos = QueryPos.getInstance(q);
9368    
9369                            qPos.add(groupId);
9370    
9371                            qPos.add(mountPoint);
9372    
9373                            qPos.add(parentFolderId);
9374    
9375                            qPos.add(hidden);
9376    
9377                            qPos.add(status);
9378    
9379                            Long count = (Long)q.uniqueResult();
9380    
9381                            return count.intValue();
9382                    }
9383                    catch (Exception e) {
9384                            throw processException(e);
9385                    }
9386                    finally {
9387                            closeSession(session);
9388                    }
9389            }
9390    
9391            private static final String _FINDER_COLUMN_G_M_P_H_S_GROUPID_2 = "dlFolder.groupId = ? AND ";
9392            private static final String _FINDER_COLUMN_G_M_P_H_S_MOUNTPOINT_2 = "dlFolder.mountPoint = ? AND ";
9393            private static final String _FINDER_COLUMN_G_M_P_H_S_PARENTFOLDERID_2 = "dlFolder.parentFolderId = ? AND ";
9394            private static final String _FINDER_COLUMN_G_M_P_H_S_HIDDEN_2 = "dlFolder.hidden = ? AND ";
9395            private static final String _FINDER_COLUMN_G_M_P_H_S_HIDDEN_2_SQL = "dlFolder.hidden_ = ? AND ";
9396            private static final String _FINDER_COLUMN_G_M_P_H_S_STATUS_2 = "dlFolder.status = ?";
9397    
9398            public DLFolderPersistenceImpl() {
9399                    setModelClass(DLFolder.class);
9400            }
9401    
9402            /**
9403             * Caches the document library folder in the entity cache if it is enabled.
9404             *
9405             * @param dlFolder the document library folder
9406             */
9407            @Override
9408            public void cacheResult(DLFolder dlFolder) {
9409                    EntityCacheUtil.putResult(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
9410                            DLFolderImpl.class, dlFolder.getPrimaryKey(), dlFolder);
9411    
9412                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
9413                            new Object[] { dlFolder.getUuid(), dlFolder.getGroupId() }, dlFolder);
9414    
9415                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_REPOSITORYID,
9416                            new Object[] { dlFolder.getRepositoryId() }, dlFolder);
9417    
9418                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_N,
9419                            new Object[] {
9420                                    dlFolder.getGroupId(), dlFolder.getParentFolderId(),
9421                                    dlFolder.getName()
9422                            }, dlFolder);
9423    
9424                    dlFolder.resetOriginalValues();
9425            }
9426    
9427            /**
9428             * Caches the document library folders in the entity cache if it is enabled.
9429             *
9430             * @param dlFolders the document library folders
9431             */
9432            @Override
9433            public void cacheResult(List<DLFolder> dlFolders) {
9434                    for (DLFolder dlFolder : dlFolders) {
9435                            if (EntityCacheUtil.getResult(
9436                                                    DLFolderModelImpl.ENTITY_CACHE_ENABLED,
9437                                                    DLFolderImpl.class, dlFolder.getPrimaryKey()) == null) {
9438                                    cacheResult(dlFolder);
9439                            }
9440                            else {
9441                                    dlFolder.resetOriginalValues();
9442                            }
9443                    }
9444            }
9445    
9446            /**
9447             * Clears the cache for all document library folders.
9448             *
9449             * <p>
9450             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
9451             * </p>
9452             */
9453            @Override
9454            public void clearCache() {
9455                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
9456                            CacheRegistryUtil.clear(DLFolderImpl.class.getName());
9457                    }
9458    
9459                    EntityCacheUtil.clearCache(DLFolderImpl.class.getName());
9460    
9461                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
9462                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
9463                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
9464            }
9465    
9466            /**
9467             * Clears the cache for the document library folder.
9468             *
9469             * <p>
9470             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
9471             * </p>
9472             */
9473            @Override
9474            public void clearCache(DLFolder dlFolder) {
9475                    EntityCacheUtil.removeResult(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
9476                            DLFolderImpl.class, dlFolder.getPrimaryKey());
9477    
9478                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
9479                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
9480    
9481                    clearUniqueFindersCache(dlFolder);
9482            }
9483    
9484            @Override
9485            public void clearCache(List<DLFolder> dlFolders) {
9486                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
9487                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
9488    
9489                    for (DLFolder dlFolder : dlFolders) {
9490                            EntityCacheUtil.removeResult(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
9491                                    DLFolderImpl.class, dlFolder.getPrimaryKey());
9492    
9493                            clearUniqueFindersCache(dlFolder);
9494                    }
9495            }
9496    
9497            protected void cacheUniqueFindersCache(DLFolder dlFolder) {
9498                    if (dlFolder.isNew()) {
9499                            Object[] args = new Object[] {
9500                                            dlFolder.getUuid(), dlFolder.getGroupId()
9501                                    };
9502    
9503                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
9504                                    Long.valueOf(1));
9505                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
9506                                    dlFolder);
9507    
9508                            args = new Object[] { dlFolder.getRepositoryId() };
9509    
9510                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_REPOSITORYID, args,
9511                                    Long.valueOf(1));
9512                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_REPOSITORYID, args,
9513                                    dlFolder);
9514    
9515                            args = new Object[] {
9516                                            dlFolder.getGroupId(), dlFolder.getParentFolderId(),
9517                                            dlFolder.getName()
9518                                    };
9519    
9520                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_P_N, args,
9521                                    Long.valueOf(1));
9522                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_N, args, dlFolder);
9523                    }
9524                    else {
9525                            DLFolderModelImpl dlFolderModelImpl = (DLFolderModelImpl)dlFolder;
9526    
9527                            if ((dlFolderModelImpl.getColumnBitmask() &
9528                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
9529                                    Object[] args = new Object[] {
9530                                                    dlFolder.getUuid(), dlFolder.getGroupId()
9531                                            };
9532    
9533                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
9534                                            Long.valueOf(1));
9535                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
9536                                            dlFolder);
9537                            }
9538    
9539                            if ((dlFolderModelImpl.getColumnBitmask() &
9540                                            FINDER_PATH_FETCH_BY_REPOSITORYID.getColumnBitmask()) != 0) {
9541                                    Object[] args = new Object[] { dlFolder.getRepositoryId() };
9542    
9543                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_REPOSITORYID,
9544                                            args, Long.valueOf(1));
9545                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_REPOSITORYID,
9546                                            args, dlFolder);
9547                            }
9548    
9549                            if ((dlFolderModelImpl.getColumnBitmask() &
9550                                            FINDER_PATH_FETCH_BY_G_P_N.getColumnBitmask()) != 0) {
9551                                    Object[] args = new Object[] {
9552                                                    dlFolder.getGroupId(), dlFolder.getParentFolderId(),
9553                                                    dlFolder.getName()
9554                                            };
9555    
9556                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_P_N, args,
9557                                            Long.valueOf(1));
9558                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_N, args,
9559                                            dlFolder);
9560                            }
9561                    }
9562            }
9563    
9564            protected void clearUniqueFindersCache(DLFolder dlFolder) {
9565                    DLFolderModelImpl dlFolderModelImpl = (DLFolderModelImpl)dlFolder;
9566    
9567                    Object[] args = new Object[] { dlFolder.getUuid(), dlFolder.getGroupId() };
9568    
9569                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
9570                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
9571    
9572                    if ((dlFolderModelImpl.getColumnBitmask() &
9573                                    FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
9574                            args = new Object[] {
9575                                            dlFolderModelImpl.getOriginalUuid(),
9576                                            dlFolderModelImpl.getOriginalGroupId()
9577                                    };
9578    
9579                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
9580                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
9581                    }
9582    
9583                    args = new Object[] { dlFolder.getRepositoryId() };
9584    
9585                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_REPOSITORYID, args);
9586                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_REPOSITORYID, args);
9587    
9588                    if ((dlFolderModelImpl.getColumnBitmask() &
9589                                    FINDER_PATH_FETCH_BY_REPOSITORYID.getColumnBitmask()) != 0) {
9590                            args = new Object[] { dlFolderModelImpl.getOriginalRepositoryId() };
9591    
9592                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_REPOSITORYID, args);
9593                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_REPOSITORYID, args);
9594                    }
9595    
9596                    args = new Object[] {
9597                                    dlFolder.getGroupId(), dlFolder.getParentFolderId(),
9598                                    dlFolder.getName()
9599                            };
9600    
9601                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_N, args);
9602                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P_N, args);
9603    
9604                    if ((dlFolderModelImpl.getColumnBitmask() &
9605                                    FINDER_PATH_FETCH_BY_G_P_N.getColumnBitmask()) != 0) {
9606                            args = new Object[] {
9607                                            dlFolderModelImpl.getOriginalGroupId(),
9608                                            dlFolderModelImpl.getOriginalParentFolderId(),
9609                                            dlFolderModelImpl.getOriginalName()
9610                                    };
9611    
9612                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_N, args);
9613                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P_N, args);
9614                    }
9615            }
9616    
9617            /**
9618             * Creates a new document library folder with the primary key. Does not add the document library folder to the database.
9619             *
9620             * @param folderId the primary key for the new document library folder
9621             * @return the new document library folder
9622             */
9623            @Override
9624            public DLFolder create(long folderId) {
9625                    DLFolder dlFolder = new DLFolderImpl();
9626    
9627                    dlFolder.setNew(true);
9628                    dlFolder.setPrimaryKey(folderId);
9629    
9630                    String uuid = PortalUUIDUtil.generate();
9631    
9632                    dlFolder.setUuid(uuid);
9633    
9634                    return dlFolder;
9635            }
9636    
9637            /**
9638             * Removes the document library folder with the primary key from the database. Also notifies the appropriate model listeners.
9639             *
9640             * @param folderId the primary key of the document library folder
9641             * @return the document library folder that was removed
9642             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
9643             * @throws SystemException if a system exception occurred
9644             */
9645            @Override
9646            public DLFolder remove(long folderId)
9647                    throws NoSuchFolderException, SystemException {
9648                    return remove((Serializable)folderId);
9649            }
9650    
9651            /**
9652             * Removes the document library folder with the primary key from the database. Also notifies the appropriate model listeners.
9653             *
9654             * @param primaryKey the primary key of the document library folder
9655             * @return the document library folder that was removed
9656             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
9657             * @throws SystemException if a system exception occurred
9658             */
9659            @Override
9660            public DLFolder remove(Serializable primaryKey)
9661                    throws NoSuchFolderException, SystemException {
9662                    Session session = null;
9663    
9664                    try {
9665                            session = openSession();
9666    
9667                            DLFolder dlFolder = (DLFolder)session.get(DLFolderImpl.class,
9668                                            primaryKey);
9669    
9670                            if (dlFolder == null) {
9671                                    if (_log.isWarnEnabled()) {
9672                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
9673                                    }
9674    
9675                                    throw new NoSuchFolderException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
9676                                            primaryKey);
9677                            }
9678    
9679                            return remove(dlFolder);
9680                    }
9681                    catch (NoSuchFolderException nsee) {
9682                            throw nsee;
9683                    }
9684                    catch (Exception e) {
9685                            throw processException(e);
9686                    }
9687                    finally {
9688                            closeSession(session);
9689                    }
9690            }
9691    
9692            @Override
9693            protected DLFolder removeImpl(DLFolder dlFolder) throws SystemException {
9694                    dlFolder = toUnwrappedModel(dlFolder);
9695    
9696                    dlFolderToDLFileEntryTypeTableMapper.deleteLeftPrimaryKeyTableMappings(dlFolder.getPrimaryKey());
9697    
9698                    Session session = null;
9699    
9700                    try {
9701                            session = openSession();
9702    
9703                            if (!session.contains(dlFolder)) {
9704                                    dlFolder = (DLFolder)session.get(DLFolderImpl.class,
9705                                                    dlFolder.getPrimaryKeyObj());
9706                            }
9707    
9708                            if (dlFolder != null) {
9709                                    session.delete(dlFolder);
9710                            }
9711                    }
9712                    catch (Exception e) {
9713                            throw processException(e);
9714                    }
9715                    finally {
9716                            closeSession(session);
9717                    }
9718    
9719                    if (dlFolder != null) {
9720                            clearCache(dlFolder);
9721                    }
9722    
9723                    return dlFolder;
9724            }
9725    
9726            @Override
9727            public DLFolder updateImpl(
9728                    com.liferay.portlet.documentlibrary.model.DLFolder dlFolder)
9729                    throws SystemException {
9730                    dlFolder = toUnwrappedModel(dlFolder);
9731    
9732                    boolean isNew = dlFolder.isNew();
9733    
9734                    DLFolderModelImpl dlFolderModelImpl = (DLFolderModelImpl)dlFolder;
9735    
9736                    if (Validator.isNull(dlFolder.getUuid())) {
9737                            String uuid = PortalUUIDUtil.generate();
9738    
9739                            dlFolder.setUuid(uuid);
9740                    }
9741    
9742                    Session session = null;
9743    
9744                    try {
9745                            session = openSession();
9746    
9747                            if (dlFolder.isNew()) {
9748                                    session.save(dlFolder);
9749    
9750                                    dlFolder.setNew(false);
9751                            }
9752                            else {
9753                                    session.merge(dlFolder);
9754                            }
9755                    }
9756                    catch (Exception e) {
9757                            throw processException(e);
9758                    }
9759                    finally {
9760                            closeSession(session);
9761                    }
9762    
9763                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
9764    
9765                    if (isNew || !DLFolderModelImpl.COLUMN_BITMASK_ENABLED) {
9766                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
9767                    }
9768    
9769                    else {
9770                            if ((dlFolderModelImpl.getColumnBitmask() &
9771                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
9772                                    Object[] args = new Object[] { dlFolderModelImpl.getOriginalUuid() };
9773    
9774                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
9775                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
9776                                            args);
9777    
9778                                    args = new Object[] { dlFolderModelImpl.getUuid() };
9779    
9780                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
9781                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
9782                                            args);
9783                            }
9784    
9785                            if ((dlFolderModelImpl.getColumnBitmask() &
9786                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
9787                                    Object[] args = new Object[] {
9788                                                    dlFolderModelImpl.getOriginalUuid(),
9789                                                    dlFolderModelImpl.getOriginalCompanyId()
9790                                            };
9791    
9792                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
9793                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
9794                                            args);
9795    
9796                                    args = new Object[] {
9797                                                    dlFolderModelImpl.getUuid(),
9798                                                    dlFolderModelImpl.getCompanyId()
9799                                            };
9800    
9801                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
9802                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
9803                                            args);
9804                            }
9805    
9806                            if ((dlFolderModelImpl.getColumnBitmask() &
9807                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
9808                                    Object[] args = new Object[] {
9809                                                    dlFolderModelImpl.getOriginalGroupId()
9810                                            };
9811    
9812                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
9813                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
9814                                            args);
9815    
9816                                    args = new Object[] { dlFolderModelImpl.getGroupId() };
9817    
9818                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
9819                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
9820                                            args);
9821                            }
9822    
9823                            if ((dlFolderModelImpl.getColumnBitmask() &
9824                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
9825                                    Object[] args = new Object[] {
9826                                                    dlFolderModelImpl.getOriginalCompanyId()
9827                                            };
9828    
9829                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
9830                                            args);
9831                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
9832                                            args);
9833    
9834                                    args = new Object[] { dlFolderModelImpl.getCompanyId() };
9835    
9836                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
9837                                            args);
9838                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
9839                                            args);
9840                            }
9841    
9842                            if ((dlFolderModelImpl.getColumnBitmask() &
9843                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_REPOSITORYIDLIST.getColumnBitmask()) != 0) {
9844                                    Object[] args = new Object[] {
9845                                                    dlFolderModelImpl.getOriginalRepositoryId()
9846                                            };
9847    
9848                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_REPOSITORYIDLIST,
9849                                            args);
9850                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_REPOSITORYIDLIST,
9851                                            args);
9852    
9853                                    args = new Object[] { dlFolderModelImpl.getRepositoryId() };
9854    
9855                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_REPOSITORYIDLIST,
9856                                            args);
9857                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_REPOSITORYIDLIST,
9858                                            args);
9859                            }
9860    
9861                            if ((dlFolderModelImpl.getColumnBitmask() &
9862                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P.getColumnBitmask()) != 0) {
9863                                    Object[] args = new Object[] {
9864                                                    dlFolderModelImpl.getOriginalGroupId(),
9865                                                    dlFolderModelImpl.getOriginalParentFolderId()
9866                                            };
9867    
9868                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P, args);
9869                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P,
9870                                            args);
9871    
9872                                    args = new Object[] {
9873                                                    dlFolderModelImpl.getGroupId(),
9874                                                    dlFolderModelImpl.getParentFolderId()
9875                                            };
9876    
9877                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P, args);
9878                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P,
9879                                            args);
9880                            }
9881    
9882                            if ((dlFolderModelImpl.getColumnBitmask() &
9883                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_N.getColumnBitmask()) != 0) {
9884                                    Object[] args = new Object[] {
9885                                                    dlFolderModelImpl.getOriginalParentFolderId(),
9886                                                    dlFolderModelImpl.getOriginalName()
9887                                            };
9888    
9889                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_P_N, args);
9890                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_N,
9891                                            args);
9892    
9893                                    args = new Object[] {
9894                                                    dlFolderModelImpl.getParentFolderId(),
9895                                                    dlFolderModelImpl.getName()
9896                                            };
9897    
9898                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_P_N, args);
9899                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_N,
9900                                            args);
9901                            }
9902    
9903                            if ((dlFolderModelImpl.getColumnBitmask() &
9904                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P_H.getColumnBitmask()) != 0) {
9905                                    Object[] args = new Object[] {
9906                                                    dlFolderModelImpl.getOriginalGroupId(),
9907                                                    dlFolderModelImpl.getOriginalMountPoint(),
9908                                                    dlFolderModelImpl.getOriginalParentFolderId(),
9909                                                    dlFolderModelImpl.getOriginalHidden()
9910                                            };
9911    
9912                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_M_P_H, args);
9913                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P_H,
9914                                            args);
9915    
9916                                    args = new Object[] {
9917                                                    dlFolderModelImpl.getGroupId(),
9918                                                    dlFolderModelImpl.getMountPoint(),
9919                                                    dlFolderModelImpl.getParentFolderId(),
9920                                                    dlFolderModelImpl.getHidden()
9921                                            };
9922    
9923                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_M_P_H, args);
9924                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P_H,
9925                                            args);
9926                            }
9927    
9928                            if ((dlFolderModelImpl.getColumnBitmask() &
9929                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_H_S.getColumnBitmask()) != 0) {
9930                                    Object[] args = new Object[] {
9931                                                    dlFolderModelImpl.getOriginalGroupId(),
9932                                                    dlFolderModelImpl.getOriginalParentFolderId(),
9933                                                    dlFolderModelImpl.getOriginalHidden(),
9934                                                    dlFolderModelImpl.getOriginalStatus()
9935                                            };
9936    
9937                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_H_S, args);
9938                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_H_S,
9939                                            args);
9940    
9941                                    args = new Object[] {
9942                                                    dlFolderModelImpl.getGroupId(),
9943                                                    dlFolderModelImpl.getParentFolderId(),
9944                                                    dlFolderModelImpl.getHidden(),
9945                                                    dlFolderModelImpl.getStatus()
9946                                            };
9947    
9948                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_H_S, args);
9949                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_H_S,
9950                                            args);
9951                            }
9952    
9953                            if ((dlFolderModelImpl.getColumnBitmask() &
9954                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P_H_S.getColumnBitmask()) != 0) {
9955                                    Object[] args = new Object[] {
9956                                                    dlFolderModelImpl.getOriginalGroupId(),
9957                                                    dlFolderModelImpl.getOriginalMountPoint(),
9958                                                    dlFolderModelImpl.getOriginalParentFolderId(),
9959                                                    dlFolderModelImpl.getOriginalHidden(),
9960                                                    dlFolderModelImpl.getOriginalStatus()
9961                                            };
9962    
9963                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_M_P_H_S,
9964                                            args);
9965                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P_H_S,
9966                                            args);
9967    
9968                                    args = new Object[] {
9969                                                    dlFolderModelImpl.getGroupId(),
9970                                                    dlFolderModelImpl.getMountPoint(),
9971                                                    dlFolderModelImpl.getParentFolderId(),
9972                                                    dlFolderModelImpl.getHidden(),
9973                                                    dlFolderModelImpl.getStatus()
9974                                            };
9975    
9976                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_M_P_H_S,
9977                                            args);
9978                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P_H_S,
9979                                            args);
9980                            }
9981                    }
9982    
9983                    EntityCacheUtil.putResult(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
9984                            DLFolderImpl.class, dlFolder.getPrimaryKey(), dlFolder);
9985    
9986                    clearUniqueFindersCache(dlFolder);
9987                    cacheUniqueFindersCache(dlFolder);
9988    
9989                    return dlFolder;
9990            }
9991    
9992            protected DLFolder toUnwrappedModel(DLFolder dlFolder) {
9993                    if (dlFolder instanceof DLFolderImpl) {
9994                            return dlFolder;
9995                    }
9996    
9997                    DLFolderImpl dlFolderImpl = new DLFolderImpl();
9998    
9999                    dlFolderImpl.setNew(dlFolder.isNew());
10000                    dlFolderImpl.setPrimaryKey(dlFolder.getPrimaryKey());
10001    
10002                    dlFolderImpl.setUuid(dlFolder.getUuid());
10003                    dlFolderImpl.setFolderId(dlFolder.getFolderId());
10004                    dlFolderImpl.setGroupId(dlFolder.getGroupId());
10005                    dlFolderImpl.setCompanyId(dlFolder.getCompanyId());
10006                    dlFolderImpl.setUserId(dlFolder.getUserId());
10007                    dlFolderImpl.setUserName(dlFolder.getUserName());
10008                    dlFolderImpl.setCreateDate(dlFolder.getCreateDate());
10009                    dlFolderImpl.setModifiedDate(dlFolder.getModifiedDate());
10010                    dlFolderImpl.setRepositoryId(dlFolder.getRepositoryId());
10011                    dlFolderImpl.setMountPoint(dlFolder.isMountPoint());
10012                    dlFolderImpl.setParentFolderId(dlFolder.getParentFolderId());
10013                    dlFolderImpl.setTreePath(dlFolder.getTreePath());
10014                    dlFolderImpl.setName(dlFolder.getName());
10015                    dlFolderImpl.setDescription(dlFolder.getDescription());
10016                    dlFolderImpl.setLastPostDate(dlFolder.getLastPostDate());
10017                    dlFolderImpl.setDefaultFileEntryTypeId(dlFolder.getDefaultFileEntryTypeId());
10018                    dlFolderImpl.setHidden(dlFolder.isHidden());
10019                    dlFolderImpl.setOverrideFileEntryTypes(dlFolder.isOverrideFileEntryTypes());
10020                    dlFolderImpl.setStatus(dlFolder.getStatus());
10021                    dlFolderImpl.setStatusByUserId(dlFolder.getStatusByUserId());
10022                    dlFolderImpl.setStatusByUserName(dlFolder.getStatusByUserName());
10023                    dlFolderImpl.setStatusDate(dlFolder.getStatusDate());
10024    
10025                    return dlFolderImpl;
10026            }
10027    
10028            /**
10029             * Returns the document library folder with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
10030             *
10031             * @param primaryKey the primary key of the document library folder
10032             * @return the document library folder
10033             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
10034             * @throws SystemException if a system exception occurred
10035             */
10036            @Override
10037            public DLFolder findByPrimaryKey(Serializable primaryKey)
10038                    throws NoSuchFolderException, SystemException {
10039                    DLFolder dlFolder = fetchByPrimaryKey(primaryKey);
10040    
10041                    if (dlFolder == null) {
10042                            if (_log.isWarnEnabled()) {
10043                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
10044                            }
10045    
10046                            throw new NoSuchFolderException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
10047                                    primaryKey);
10048                    }
10049    
10050                    return dlFolder;
10051            }
10052    
10053            /**
10054             * Returns the document library folder with the primary key or throws a {@link com.liferay.portlet.documentlibrary.NoSuchFolderException} if it could not be found.
10055             *
10056             * @param folderId the primary key of the document library folder
10057             * @return the document library folder
10058             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
10059             * @throws SystemException if a system exception occurred
10060             */
10061            @Override
10062            public DLFolder findByPrimaryKey(long folderId)
10063                    throws NoSuchFolderException, SystemException {
10064                    return findByPrimaryKey((Serializable)folderId);
10065            }
10066    
10067            /**
10068             * Returns the document library folder with the primary key or returns <code>null</code> if it could not be found.
10069             *
10070             * @param primaryKey the primary key of the document library folder
10071             * @return the document library folder, or <code>null</code> if a document library folder with the primary key could not be found
10072             * @throws SystemException if a system exception occurred
10073             */
10074            @Override
10075            public DLFolder fetchByPrimaryKey(Serializable primaryKey)
10076                    throws SystemException {
10077                    DLFolder dlFolder = (DLFolder)EntityCacheUtil.getResult(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
10078                                    DLFolderImpl.class, primaryKey);
10079    
10080                    if (dlFolder == _nullDLFolder) {
10081                            return null;
10082                    }
10083    
10084                    if (dlFolder == null) {
10085                            Session session = null;
10086    
10087                            try {
10088                                    session = openSession();
10089    
10090                                    dlFolder = (DLFolder)session.get(DLFolderImpl.class, primaryKey);
10091    
10092                                    if (dlFolder != null) {
10093                                            cacheResult(dlFolder);
10094                                    }
10095                                    else {
10096                                            EntityCacheUtil.putResult(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
10097                                                    DLFolderImpl.class, primaryKey, _nullDLFolder);
10098                                    }
10099                            }
10100                            catch (Exception e) {
10101                                    EntityCacheUtil.removeResult(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
10102                                            DLFolderImpl.class, primaryKey);
10103    
10104                                    throw processException(e);
10105                            }
10106                            finally {
10107                                    closeSession(session);
10108                            }
10109                    }
10110    
10111                    return dlFolder;
10112            }
10113    
10114            /**
10115             * Returns the document library folder with the primary key or returns <code>null</code> if it could not be found.
10116             *
10117             * @param folderId the primary key of the document library folder
10118             * @return the document library folder, or <code>null</code> if a document library folder with the primary key could not be found
10119             * @throws SystemException if a system exception occurred
10120             */
10121            @Override
10122            public DLFolder fetchByPrimaryKey(long folderId) throws SystemException {
10123                    return fetchByPrimaryKey((Serializable)folderId);
10124            }
10125    
10126            /**
10127             * Returns all the document library folders.
10128             *
10129             * @return the document library folders
10130             * @throws SystemException if a system exception occurred
10131             */
10132            @Override
10133            public List<DLFolder> findAll() throws SystemException {
10134                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
10135            }
10136    
10137            /**
10138             * Returns a range of all the document library folders.
10139             *
10140             * <p>
10141             * 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.
10142             * </p>
10143             *
10144             * @param start the lower bound of the range of document library folders
10145             * @param end the upper bound of the range of document library folders (not inclusive)
10146             * @return the range of document library folders
10147             * @throws SystemException if a system exception occurred
10148             */
10149            @Override
10150            public List<DLFolder> findAll(int start, int end) throws SystemException {
10151                    return findAll(start, end, null);
10152            }
10153    
10154            /**
10155             * Returns an ordered range of all the document library folders.
10156             *
10157             * <p>
10158             * 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.
10159             * </p>
10160             *
10161             * @param start the lower bound of the range of document library folders
10162             * @param end the upper bound of the range of document library folders (not inclusive)
10163             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10164             * @return the ordered range of document library folders
10165             * @throws SystemException if a system exception occurred
10166             */
10167            @Override
10168            public List<DLFolder> findAll(int start, int end,
10169                    OrderByComparator orderByComparator) throws SystemException {
10170                    boolean pagination = true;
10171                    FinderPath finderPath = null;
10172                    Object[] finderArgs = null;
10173    
10174                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
10175                                    (orderByComparator == null)) {
10176                            pagination = false;
10177                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
10178                            finderArgs = FINDER_ARGS_EMPTY;
10179                    }
10180                    else {
10181                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
10182                            finderArgs = new Object[] { start, end, orderByComparator };
10183                    }
10184    
10185                    List<DLFolder> list = (List<DLFolder>)FinderCacheUtil.getResult(finderPath,
10186                                    finderArgs, this);
10187    
10188                    if (list == null) {
10189                            StringBundler query = null;
10190                            String sql = null;
10191    
10192                            if (orderByComparator != null) {
10193                                    query = new StringBundler(2 +
10194                                                    (orderByComparator.getOrderByFields().length * 3));
10195    
10196                                    query.append(_SQL_SELECT_DLFOLDER);
10197    
10198                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10199                                            orderByComparator);
10200    
10201                                    sql = query.toString();
10202                            }
10203                            else {
10204                                    sql = _SQL_SELECT_DLFOLDER;
10205    
10206                                    if (pagination) {
10207                                            sql = sql.concat(DLFolderModelImpl.ORDER_BY_JPQL);
10208                                    }
10209                            }
10210    
10211                            Session session = null;
10212    
10213                            try {
10214                                    session = openSession();
10215    
10216                                    Query q = session.createQuery(sql);
10217    
10218                                    if (!pagination) {
10219                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
10220                                                            start, end, false);
10221    
10222                                            Collections.sort(list);
10223    
10224                                            list = new UnmodifiableList<DLFolder>(list);
10225                                    }
10226                                    else {
10227                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
10228                                                            start, end);
10229                                    }
10230    
10231                                    cacheResult(list);
10232    
10233                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
10234                            }
10235                            catch (Exception e) {
10236                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
10237    
10238                                    throw processException(e);
10239                            }
10240                            finally {
10241                                    closeSession(session);
10242                            }
10243                    }
10244    
10245                    return list;
10246            }
10247    
10248            /**
10249             * Removes all the document library folders from the database.
10250             *
10251             * @throws SystemException if a system exception occurred
10252             */
10253            @Override
10254            public void removeAll() throws SystemException {
10255                    for (DLFolder dlFolder : findAll()) {
10256                            remove(dlFolder);
10257                    }
10258            }
10259    
10260            /**
10261             * Returns the number of document library folders.
10262             *
10263             * @return the number of document library folders
10264             * @throws SystemException if a system exception occurred
10265             */
10266            @Override
10267            public int countAll() throws SystemException {
10268                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
10269                                    FINDER_ARGS_EMPTY, this);
10270    
10271                    if (count == null) {
10272                            Session session = null;
10273    
10274                            try {
10275                                    session = openSession();
10276    
10277                                    Query q = session.createQuery(_SQL_COUNT_DLFOLDER);
10278    
10279                                    count = (Long)q.uniqueResult();
10280    
10281                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
10282                                            FINDER_ARGS_EMPTY, count);
10283                            }
10284                            catch (Exception e) {
10285                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
10286                                            FINDER_ARGS_EMPTY);
10287    
10288                                    throw processException(e);
10289                            }
10290                            finally {
10291                                    closeSession(session);
10292                            }
10293                    }
10294    
10295                    return count.intValue();
10296            }
10297    
10298            /**
10299             * Returns all the document library file entry types associated with the document library folder.
10300             *
10301             * @param pk the primary key of the document library folder
10302             * @return the document library file entry types associated with the document library folder
10303             * @throws SystemException if a system exception occurred
10304             */
10305            @Override
10306            public List<com.liferay.portlet.documentlibrary.model.DLFileEntryType> getDLFileEntryTypes(
10307                    long pk) throws SystemException {
10308                    return getDLFileEntryTypes(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
10309            }
10310    
10311            /**
10312             * Returns a range of all the document library file entry types associated with the document library folder.
10313             *
10314             * <p>
10315             * 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.
10316             * </p>
10317             *
10318             * @param pk the primary key of the document library folder
10319             * @param start the lower bound of the range of document library folders
10320             * @param end the upper bound of the range of document library folders (not inclusive)
10321             * @return the range of document library file entry types associated with the document library folder
10322             * @throws SystemException if a system exception occurred
10323             */
10324            @Override
10325            public List<com.liferay.portlet.documentlibrary.model.DLFileEntryType> getDLFileEntryTypes(
10326                    long pk, int start, int end) throws SystemException {
10327                    return getDLFileEntryTypes(pk, start, end, null);
10328            }
10329    
10330            /**
10331             * Returns an ordered range of all the document library file entry types associated with the document library folder.
10332             *
10333             * <p>
10334             * 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.
10335             * </p>
10336             *
10337             * @param pk the primary key of the document library folder
10338             * @param start the lower bound of the range of document library folders
10339             * @param end the upper bound of the range of document library folders (not inclusive)
10340             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10341             * @return the ordered range of document library file entry types associated with the document library folder
10342             * @throws SystemException if a system exception occurred
10343             */
10344            @Override
10345            public List<com.liferay.portlet.documentlibrary.model.DLFileEntryType> getDLFileEntryTypes(
10346                    long pk, int start, int end, OrderByComparator orderByComparator)
10347                    throws SystemException {
10348                    return dlFolderToDLFileEntryTypeTableMapper.getRightBaseModels(pk,
10349                            start, end, orderByComparator);
10350            }
10351    
10352            /**
10353             * Returns the number of document library file entry types associated with the document library folder.
10354             *
10355             * @param pk the primary key of the document library folder
10356             * @return the number of document library file entry types associated with the document library folder
10357             * @throws SystemException if a system exception occurred
10358             */
10359            @Override
10360            public int getDLFileEntryTypesSize(long pk) throws SystemException {
10361                    long[] pks = dlFolderToDLFileEntryTypeTableMapper.getRightPrimaryKeys(pk);
10362    
10363                    return pks.length;
10364            }
10365    
10366            /**
10367             * Returns <code>true</code> if the document library file entry type is associated with the document library folder.
10368             *
10369             * @param pk the primary key of the document library folder
10370             * @param dlFileEntryTypePK the primary key of the document library file entry type
10371             * @return <code>true</code> if the document library file entry type is associated with the document library folder; <code>false</code> otherwise
10372             * @throws SystemException if a system exception occurred
10373             */
10374            @Override
10375            public boolean containsDLFileEntryType(long pk, long dlFileEntryTypePK)
10376                    throws SystemException {
10377                    return dlFolderToDLFileEntryTypeTableMapper.containsTableMapping(pk,
10378                            dlFileEntryTypePK);
10379            }
10380    
10381            /**
10382             * Returns <code>true</code> if the document library folder has any document library file entry types associated with it.
10383             *
10384             * @param pk the primary key of the document library folder to check for associations with document library file entry types
10385             * @return <code>true</code> if the document library folder has any document library file entry types associated with it; <code>false</code> otherwise
10386             * @throws SystemException if a system exception occurred
10387             */
10388            @Override
10389            public boolean containsDLFileEntryTypes(long pk) throws SystemException {
10390                    if (getDLFileEntryTypesSize(pk) > 0) {
10391                            return true;
10392                    }
10393                    else {
10394                            return false;
10395                    }
10396            }
10397    
10398            /**
10399             * 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.
10400             *
10401             * @param pk the primary key of the document library folder
10402             * @param dlFileEntryTypePK the primary key of the document library file entry type
10403             * @throws SystemException if a system exception occurred
10404             */
10405            @Override
10406            public void addDLFileEntryType(long pk, long dlFileEntryTypePK)
10407                    throws SystemException {
10408                    dlFolderToDLFileEntryTypeTableMapper.addTableMapping(pk,
10409                            dlFileEntryTypePK);
10410            }
10411    
10412            /**
10413             * 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.
10414             *
10415             * @param pk the primary key of the document library folder
10416             * @param dlFileEntryType the document library file entry type
10417             * @throws SystemException if a system exception occurred
10418             */
10419            @Override
10420            public void addDLFileEntryType(long pk,
10421                    com.liferay.portlet.documentlibrary.model.DLFileEntryType dlFileEntryType)
10422                    throws SystemException {
10423                    dlFolderToDLFileEntryTypeTableMapper.addTableMapping(pk,
10424                            dlFileEntryType.getPrimaryKey());
10425            }
10426    
10427            /**
10428             * 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.
10429             *
10430             * @param pk the primary key of the document library folder
10431             * @param dlFileEntryTypePKs the primary keys of the document library file entry types
10432             * @throws SystemException if a system exception occurred
10433             */
10434            @Override
10435            public void addDLFileEntryTypes(long pk, long[] dlFileEntryTypePKs)
10436                    throws SystemException {
10437                    for (long dlFileEntryTypePK : dlFileEntryTypePKs) {
10438                            dlFolderToDLFileEntryTypeTableMapper.addTableMapping(pk,
10439                                    dlFileEntryTypePK);
10440                    }
10441            }
10442    
10443            /**
10444             * 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.
10445             *
10446             * @param pk the primary key of the document library folder
10447             * @param dlFileEntryTypes the document library file entry types
10448             * @throws SystemException if a system exception occurred
10449             */
10450            @Override
10451            public void addDLFileEntryTypes(long pk,
10452                    List<com.liferay.portlet.documentlibrary.model.DLFileEntryType> dlFileEntryTypes)
10453                    throws SystemException {
10454                    for (com.liferay.portlet.documentlibrary.model.DLFileEntryType dlFileEntryType : dlFileEntryTypes) {
10455                            dlFolderToDLFileEntryTypeTableMapper.addTableMapping(pk,
10456                                    dlFileEntryType.getPrimaryKey());
10457                    }
10458            }
10459    
10460            /**
10461             * 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.
10462             *
10463             * @param pk the primary key of the document library folder to clear the associated document library file entry types from
10464             * @throws SystemException if a system exception occurred
10465             */
10466            @Override
10467            public void clearDLFileEntryTypes(long pk) throws SystemException {
10468                    dlFolderToDLFileEntryTypeTableMapper.deleteLeftPrimaryKeyTableMappings(pk);
10469            }
10470    
10471            /**
10472             * 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.
10473             *
10474             * @param pk the primary key of the document library folder
10475             * @param dlFileEntryTypePK the primary key of the document library file entry type
10476             * @throws SystemException if a system exception occurred
10477             */
10478            @Override
10479            public void removeDLFileEntryType(long pk, long dlFileEntryTypePK)
10480                    throws SystemException {
10481                    dlFolderToDLFileEntryTypeTableMapper.deleteTableMapping(pk,
10482                            dlFileEntryTypePK);
10483            }
10484    
10485            /**
10486             * 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.
10487             *
10488             * @param pk the primary key of the document library folder
10489             * @param dlFileEntryType the document library file entry type
10490             * @throws SystemException if a system exception occurred
10491             */
10492            @Override
10493            public void removeDLFileEntryType(long pk,
10494                    com.liferay.portlet.documentlibrary.model.DLFileEntryType dlFileEntryType)
10495                    throws SystemException {
10496                    dlFolderToDLFileEntryTypeTableMapper.deleteTableMapping(pk,
10497                            dlFileEntryType.getPrimaryKey());
10498            }
10499    
10500            /**
10501             * 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.
10502             *
10503             * @param pk the primary key of the document library folder
10504             * @param dlFileEntryTypePKs the primary keys of the document library file entry types
10505             * @throws SystemException if a system exception occurred
10506             */
10507            @Override
10508            public void removeDLFileEntryTypes(long pk, long[] dlFileEntryTypePKs)
10509                    throws SystemException {
10510                    for (long dlFileEntryTypePK : dlFileEntryTypePKs) {
10511                            dlFolderToDLFileEntryTypeTableMapper.deleteTableMapping(pk,
10512                                    dlFileEntryTypePK);
10513                    }
10514            }
10515    
10516            /**
10517             * 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.
10518             *
10519             * @param pk the primary key of the document library folder
10520             * @param dlFileEntryTypes the document library file entry types
10521             * @throws SystemException if a system exception occurred
10522             */
10523            @Override
10524            public void removeDLFileEntryTypes(long pk,
10525                    List<com.liferay.portlet.documentlibrary.model.DLFileEntryType> dlFileEntryTypes)
10526                    throws SystemException {
10527                    for (com.liferay.portlet.documentlibrary.model.DLFileEntryType dlFileEntryType : dlFileEntryTypes) {
10528                            dlFolderToDLFileEntryTypeTableMapper.deleteTableMapping(pk,
10529                                    dlFileEntryType.getPrimaryKey());
10530                    }
10531            }
10532    
10533            /**
10534             * 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.
10535             *
10536             * @param pk the primary key of the document library folder
10537             * @param dlFileEntryTypePKs the primary keys of the document library file entry types to be associated with the document library folder
10538             * @throws SystemException if a system exception occurred
10539             */
10540            @Override
10541            public void setDLFileEntryTypes(long pk, long[] dlFileEntryTypePKs)
10542                    throws SystemException {
10543                    Set<Long> newDLFileEntryTypePKsSet = SetUtil.fromArray(dlFileEntryTypePKs);
10544                    Set<Long> oldDLFileEntryTypePKsSet = SetUtil.fromArray(dlFolderToDLFileEntryTypeTableMapper.getRightPrimaryKeys(
10545                                            pk));
10546    
10547                    Set<Long> removeDLFileEntryTypePKsSet = new HashSet<Long>(oldDLFileEntryTypePKsSet);
10548    
10549                    removeDLFileEntryTypePKsSet.removeAll(newDLFileEntryTypePKsSet);
10550    
10551                    for (long removeDLFileEntryTypePK : removeDLFileEntryTypePKsSet) {
10552                            dlFolderToDLFileEntryTypeTableMapper.deleteTableMapping(pk,
10553                                    removeDLFileEntryTypePK);
10554                    }
10555    
10556                    newDLFileEntryTypePKsSet.removeAll(oldDLFileEntryTypePKsSet);
10557    
10558                    for (long newDLFileEntryTypePK : newDLFileEntryTypePKsSet) {
10559                            dlFolderToDLFileEntryTypeTableMapper.addTableMapping(pk,
10560                                    newDLFileEntryTypePK);
10561                    }
10562            }
10563    
10564            /**
10565             * 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.
10566             *
10567             * @param pk the primary key of the document library folder
10568             * @param dlFileEntryTypes the document library file entry types to be associated with the document library folder
10569             * @throws SystemException if a system exception occurred
10570             */
10571            @Override
10572            public void setDLFileEntryTypes(long pk,
10573                    List<com.liferay.portlet.documentlibrary.model.DLFileEntryType> dlFileEntryTypes)
10574                    throws SystemException {
10575                    try {
10576                            long[] dlFileEntryTypePKs = new long[dlFileEntryTypes.size()];
10577    
10578                            for (int i = 0; i < dlFileEntryTypes.size(); i++) {
10579                                    com.liferay.portlet.documentlibrary.model.DLFileEntryType dlFileEntryType =
10580                                            dlFileEntryTypes.get(i);
10581    
10582                                    dlFileEntryTypePKs[i] = dlFileEntryType.getPrimaryKey();
10583                            }
10584    
10585                            setDLFileEntryTypes(pk, dlFileEntryTypePKs);
10586                    }
10587                    catch (Exception e) {
10588                            throw processException(e);
10589                    }
10590                    finally {
10591                            FinderCacheUtil.clearCache(DLFolderModelImpl.MAPPING_TABLE_DLFILEENTRYTYPES_DLFOLDERS_NAME);
10592                    }
10593            }
10594    
10595            @Override
10596            protected Set<String> getBadColumnNames() {
10597                    return _badColumnNames;
10598            }
10599    
10600            /**
10601             * Initializes the document library folder persistence.
10602             */
10603            public void afterPropertiesSet() {
10604                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
10605                                            com.liferay.portal.util.PropsUtil.get(
10606                                                    "value.object.listener.com.liferay.portlet.documentlibrary.model.DLFolder")));
10607    
10608                    if (listenerClassNames.length > 0) {
10609                            try {
10610                                    List<ModelListener<DLFolder>> listenersList = new ArrayList<ModelListener<DLFolder>>();
10611    
10612                                    for (String listenerClassName : listenerClassNames) {
10613                                            listenersList.add((ModelListener<DLFolder>)InstanceFactory.newInstance(
10614                                                            getClassLoader(), listenerClassName));
10615                                    }
10616    
10617                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
10618                            }
10619                            catch (Exception e) {
10620                                    _log.error(e);
10621                            }
10622                    }
10623    
10624                    dlFolderToDLFileEntryTypeTableMapper = TableMapperFactory.getTableMapper("DLFileEntryTypes_DLFolders",
10625                                    "folderId", "fileEntryTypeId", this, dlFileEntryTypePersistence);
10626            }
10627    
10628            public void destroy() {
10629                    EntityCacheUtil.removeCache(DLFolderImpl.class.getName());
10630                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
10631                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
10632                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
10633    
10634                    TableMapperFactory.removeTableMapper("DLFileEntryTypes_DLFolders");
10635            }
10636    
10637            @BeanReference(type = DLFileEntryTypePersistence.class)
10638            protected DLFileEntryTypePersistence dlFileEntryTypePersistence;
10639            protected TableMapper<DLFolder, com.liferay.portlet.documentlibrary.model.DLFileEntryType> dlFolderToDLFileEntryTypeTableMapper;
10640            private static final String _SQL_SELECT_DLFOLDER = "SELECT dlFolder FROM DLFolder dlFolder";
10641            private static final String _SQL_SELECT_DLFOLDER_WHERE = "SELECT dlFolder FROM DLFolder dlFolder WHERE ";
10642            private static final String _SQL_COUNT_DLFOLDER = "SELECT COUNT(dlFolder) FROM DLFolder dlFolder";
10643            private static final String _SQL_COUNT_DLFOLDER_WHERE = "SELECT COUNT(dlFolder) FROM DLFolder dlFolder WHERE ";
10644            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "dlFolder.folderId";
10645            private static final String _FILTER_SQL_SELECT_DLFOLDER_WHERE = "SELECT DISTINCT {dlFolder.*} FROM DLFolder dlFolder WHERE ";
10646            private static final String _FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1 =
10647                    "SELECT {DLFolder.*} FROM (SELECT DISTINCT dlFolder.folderId FROM DLFolder dlFolder WHERE ";
10648            private static final String _FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2 =
10649                    ") TEMP_TABLE INNER JOIN DLFolder ON TEMP_TABLE.folderId = DLFolder.folderId";
10650            private static final String _FILTER_SQL_COUNT_DLFOLDER_WHERE = "SELECT COUNT(DISTINCT dlFolder.folderId) AS COUNT_VALUE FROM DLFolder dlFolder WHERE ";
10651            private static final String _FILTER_ENTITY_ALIAS = "dlFolder";
10652            private static final String _FILTER_ENTITY_TABLE = "DLFolder";
10653            private static final String _ORDER_BY_ENTITY_ALIAS = "dlFolder.";
10654            private static final String _ORDER_BY_ENTITY_TABLE = "DLFolder.";
10655            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No DLFolder exists with the primary key ";
10656            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No DLFolder exists with the key {";
10657            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
10658            private static Log _log = LogFactoryUtil.getLog(DLFolderPersistenceImpl.class);
10659            private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
10660                                    "uuid", "hidden"
10661                            });
10662            private static DLFolder _nullDLFolder = new DLFolderImpl() {
10663                            @Override
10664                            public Object clone() {
10665                                    return this;
10666                            }
10667    
10668                            @Override
10669                            public CacheModel<DLFolder> toCacheModel() {
10670                                    return _nullDLFolderCacheModel;
10671                            }
10672                    };
10673    
10674            private static CacheModel<DLFolder> _nullDLFolderCacheModel = new CacheModel<DLFolder>() {
10675                            @Override
10676                            public DLFolder toEntityModel() {
10677                                    return _nullDLFolder;
10678                            }
10679                    };
10680    }