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