001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.documentlibrary.service.persistence;
016    
017    import com.liferay.portal.kernel.bean.BeanReference;
018    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
019    import com.liferay.portal.kernel.dao.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, true);
1916                            }
1917                            else {
1918                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1919                                            orderByComparator, true);
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, true);
3477                            }
3478                            else {
3479                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3480                                            orderByComparator, true);
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_SQL);
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, true);
5288                            }
5289                            else {
5290                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
5291                                            orderByComparator, true);
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_SQL);
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_SQL);
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            private static final String _FINDER_COLUMN_G_M_P_H_HIDDEN_2_SQL = "dlFolder.hidden_ = ?";
5702            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_H_S = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
5703                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
5704                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_P_H_S",
5705                            new String[] {
5706                                    Long.class.getName(), Long.class.getName(),
5707                                    Boolean.class.getName(), Integer.class.getName(),
5708                                    
5709                            Integer.class.getName(), Integer.class.getName(),
5710                                    OrderByComparator.class.getName()
5711                            });
5712            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_H_S =
5713                    new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
5714                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
5715                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_P_H_S",
5716                            new String[] {
5717                                    Long.class.getName(), Long.class.getName(),
5718                                    Boolean.class.getName(), Integer.class.getName()
5719                            },
5720                            DLFolderModelImpl.GROUPID_COLUMN_BITMASK |
5721                            DLFolderModelImpl.PARENTFOLDERID_COLUMN_BITMASK |
5722                            DLFolderModelImpl.HIDDEN_COLUMN_BITMASK |
5723                            DLFolderModelImpl.STATUS_COLUMN_BITMASK |
5724                            DLFolderModelImpl.NAME_COLUMN_BITMASK);
5725            public static final FinderPath FINDER_PATH_COUNT_BY_G_P_H_S = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
5726                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
5727                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P_H_S",
5728                            new String[] {
5729                                    Long.class.getName(), Long.class.getName(),
5730                                    Boolean.class.getName(), Integer.class.getName()
5731                            });
5732    
5733            /**
5734             * Returns all the document library folders where groupId = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
5735             *
5736             * @param groupId the group ID
5737             * @param parentFolderId the parent folder ID
5738             * @param hidden the hidden
5739             * @param status the status
5740             * @return the matching document library folders
5741             * @throws SystemException if a system exception occurred
5742             */
5743            public List<DLFolder> findByG_P_H_S(long groupId, long parentFolderId,
5744                    boolean hidden, int status) throws SystemException {
5745                    return findByG_P_H_S(groupId, parentFolderId, hidden, status,
5746                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
5747            }
5748    
5749            /**
5750             * Returns a range of all the document library folders where groupId = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
5751             *
5752             * <p>
5753             * 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.
5754             * </p>
5755             *
5756             * @param groupId the group ID
5757             * @param parentFolderId the parent folder ID
5758             * @param hidden the hidden
5759             * @param status the status
5760             * @param start the lower bound of the range of document library folders
5761             * @param end the upper bound of the range of document library folders (not inclusive)
5762             * @return the range of matching document library folders
5763             * @throws SystemException if a system exception occurred
5764             */
5765            public List<DLFolder> findByG_P_H_S(long groupId, long parentFolderId,
5766                    boolean hidden, int status, int start, int end)
5767                    throws SystemException {
5768                    return findByG_P_H_S(groupId, parentFolderId, hidden, status, start,
5769                            end, null);
5770            }
5771    
5772            /**
5773             * Returns an ordered range of all the document library folders where groupId = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
5774             *
5775             * <p>
5776             * 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.
5777             * </p>
5778             *
5779             * @param groupId the group ID
5780             * @param parentFolderId the parent folder ID
5781             * @param hidden the hidden
5782             * @param status the status
5783             * @param start the lower bound of the range of document library folders
5784             * @param end the upper bound of the range of document library folders (not inclusive)
5785             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5786             * @return the ordered range of matching document library folders
5787             * @throws SystemException if a system exception occurred
5788             */
5789            public List<DLFolder> findByG_P_H_S(long groupId, long parentFolderId,
5790                    boolean hidden, int status, int start, int end,
5791                    OrderByComparator orderByComparator) throws SystemException {
5792                    boolean pagination = true;
5793                    FinderPath finderPath = null;
5794                    Object[] finderArgs = null;
5795    
5796                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5797                                    (orderByComparator == null)) {
5798                            pagination = false;
5799                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_H_S;
5800                            finderArgs = new Object[] { groupId, parentFolderId, hidden, status };
5801                    }
5802                    else {
5803                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_H_S;
5804                            finderArgs = new Object[] {
5805                                            groupId, parentFolderId, hidden, status,
5806                                            
5807                                            start, end, orderByComparator
5808                                    };
5809                    }
5810    
5811                    List<DLFolder> list = (List<DLFolder>)FinderCacheUtil.getResult(finderPath,
5812                                    finderArgs, this);
5813    
5814                    if ((list != null) && !list.isEmpty()) {
5815                            for (DLFolder dlFolder : list) {
5816                                    if ((groupId != dlFolder.getGroupId()) ||
5817                                                    (parentFolderId != dlFolder.getParentFolderId()) ||
5818                                                    (hidden != dlFolder.getHidden()) ||
5819                                                    (status != dlFolder.getStatus())) {
5820                                            list = null;
5821    
5822                                            break;
5823                                    }
5824                            }
5825                    }
5826    
5827                    if (list == null) {
5828                            StringBundler query = null;
5829    
5830                            if (orderByComparator != null) {
5831                                    query = new StringBundler(6 +
5832                                                    (orderByComparator.getOrderByFields().length * 3));
5833                            }
5834                            else {
5835                                    query = new StringBundler(6);
5836                            }
5837    
5838                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
5839    
5840                            query.append(_FINDER_COLUMN_G_P_H_S_GROUPID_2);
5841    
5842                            query.append(_FINDER_COLUMN_G_P_H_S_PARENTFOLDERID_2);
5843    
5844                            query.append(_FINDER_COLUMN_G_P_H_S_HIDDEN_2);
5845    
5846                            query.append(_FINDER_COLUMN_G_P_H_S_STATUS_2);
5847    
5848                            if (orderByComparator != null) {
5849                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5850                                            orderByComparator);
5851                            }
5852                            else
5853                             if (pagination) {
5854                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
5855                            }
5856    
5857                            String sql = query.toString();
5858    
5859                            Session session = null;
5860    
5861                            try {
5862                                    session = openSession();
5863    
5864                                    Query q = session.createQuery(sql);
5865    
5866                                    QueryPos qPos = QueryPos.getInstance(q);
5867    
5868                                    qPos.add(groupId);
5869    
5870                                    qPos.add(parentFolderId);
5871    
5872                                    qPos.add(hidden);
5873    
5874                                    qPos.add(status);
5875    
5876                                    if (!pagination) {
5877                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
5878                                                            start, end, false);
5879    
5880                                            Collections.sort(list);
5881    
5882                                            list = new UnmodifiableList<DLFolder>(list);
5883                                    }
5884                                    else {
5885                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
5886                                                            start, end);
5887                                    }
5888    
5889                                    cacheResult(list);
5890    
5891                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
5892                            }
5893                            catch (Exception e) {
5894                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5895    
5896                                    throw processException(e);
5897                            }
5898                            finally {
5899                                    closeSession(session);
5900                            }
5901                    }
5902    
5903                    return list;
5904            }
5905    
5906            /**
5907             * Returns the first document library folder in the ordered set where groupId = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
5908             *
5909             * @param groupId the group ID
5910             * @param parentFolderId the parent folder ID
5911             * @param hidden the hidden
5912             * @param status the status
5913             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5914             * @return the first matching document library folder
5915             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
5916             * @throws SystemException if a system exception occurred
5917             */
5918            public DLFolder findByG_P_H_S_First(long groupId, long parentFolderId,
5919                    boolean hidden, int status, OrderByComparator orderByComparator)
5920                    throws NoSuchFolderException, SystemException {
5921                    DLFolder dlFolder = fetchByG_P_H_S_First(groupId, parentFolderId,
5922                                    hidden, status, orderByComparator);
5923    
5924                    if (dlFolder != null) {
5925                            return dlFolder;
5926                    }
5927    
5928                    StringBundler msg = new StringBundler(10);
5929    
5930                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5931    
5932                    msg.append("groupId=");
5933                    msg.append(groupId);
5934    
5935                    msg.append(", parentFolderId=");
5936                    msg.append(parentFolderId);
5937    
5938                    msg.append(", hidden=");
5939                    msg.append(hidden);
5940    
5941                    msg.append(", status=");
5942                    msg.append(status);
5943    
5944                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5945    
5946                    throw new NoSuchFolderException(msg.toString());
5947            }
5948    
5949            /**
5950             * Returns the first document library folder in the ordered set where groupId = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
5951             *
5952             * @param groupId the group ID
5953             * @param parentFolderId the parent folder ID
5954             * @param hidden the hidden
5955             * @param status the status
5956             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5957             * @return the first matching document library folder, or <code>null</code> if a matching document library folder could not be found
5958             * @throws SystemException if a system exception occurred
5959             */
5960            public DLFolder fetchByG_P_H_S_First(long groupId, long parentFolderId,
5961                    boolean hidden, int status, OrderByComparator orderByComparator)
5962                    throws SystemException {
5963                    List<DLFolder> list = findByG_P_H_S(groupId, parentFolderId, hidden,
5964                                    status, 0, 1, orderByComparator);
5965    
5966                    if (!list.isEmpty()) {
5967                            return list.get(0);
5968                    }
5969    
5970                    return null;
5971            }
5972    
5973            /**
5974             * Returns the last document library folder in the ordered set where groupId = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
5975             *
5976             * @param groupId the group ID
5977             * @param parentFolderId the parent folder ID
5978             * @param hidden the hidden
5979             * @param status the status
5980             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5981             * @return the last matching document library folder
5982             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
5983             * @throws SystemException if a system exception occurred
5984             */
5985            public DLFolder findByG_P_H_S_Last(long groupId, long parentFolderId,
5986                    boolean hidden, int status, OrderByComparator orderByComparator)
5987                    throws NoSuchFolderException, SystemException {
5988                    DLFolder dlFolder = fetchByG_P_H_S_Last(groupId, parentFolderId,
5989                                    hidden, status, orderByComparator);
5990    
5991                    if (dlFolder != null) {
5992                            return dlFolder;
5993                    }
5994    
5995                    StringBundler msg = new StringBundler(10);
5996    
5997                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5998    
5999                    msg.append("groupId=");
6000                    msg.append(groupId);
6001    
6002                    msg.append(", parentFolderId=");
6003                    msg.append(parentFolderId);
6004    
6005                    msg.append(", hidden=");
6006                    msg.append(hidden);
6007    
6008                    msg.append(", status=");
6009                    msg.append(status);
6010    
6011                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6012    
6013                    throw new NoSuchFolderException(msg.toString());
6014            }
6015    
6016            /**
6017             * Returns the last document library folder in the ordered set where groupId = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
6018             *
6019             * @param groupId the group ID
6020             * @param parentFolderId the parent folder ID
6021             * @param hidden the hidden
6022             * @param status the status
6023             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6024             * @return the last matching document library folder, or <code>null</code> if a matching document library folder could not be found
6025             * @throws SystemException if a system exception occurred
6026             */
6027            public DLFolder fetchByG_P_H_S_Last(long groupId, long parentFolderId,
6028                    boolean hidden, int status, OrderByComparator orderByComparator)
6029                    throws SystemException {
6030                    int count = countByG_P_H_S(groupId, parentFolderId, hidden, status);
6031    
6032                    List<DLFolder> list = findByG_P_H_S(groupId, parentFolderId, hidden,
6033                                    status, count - 1, count, orderByComparator);
6034    
6035                    if (!list.isEmpty()) {
6036                            return list.get(0);
6037                    }
6038    
6039                    return null;
6040            }
6041    
6042            /**
6043             * 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;.
6044             *
6045             * @param folderId the primary key of the current document library folder
6046             * @param groupId the group ID
6047             * @param parentFolderId the parent folder ID
6048             * @param hidden the hidden
6049             * @param status the status
6050             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6051             * @return the previous, current, and next document library folder
6052             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
6053             * @throws SystemException if a system exception occurred
6054             */
6055            public DLFolder[] findByG_P_H_S_PrevAndNext(long folderId, long groupId,
6056                    long parentFolderId, boolean hidden, int status,
6057                    OrderByComparator orderByComparator)
6058                    throws NoSuchFolderException, SystemException {
6059                    DLFolder dlFolder = findByPrimaryKey(folderId);
6060    
6061                    Session session = null;
6062    
6063                    try {
6064                            session = openSession();
6065    
6066                            DLFolder[] array = new DLFolderImpl[3];
6067    
6068                            array[0] = getByG_P_H_S_PrevAndNext(session, dlFolder, groupId,
6069                                            parentFolderId, hidden, status, orderByComparator, true);
6070    
6071                            array[1] = dlFolder;
6072    
6073                            array[2] = getByG_P_H_S_PrevAndNext(session, dlFolder, groupId,
6074                                            parentFolderId, hidden, status, orderByComparator, false);
6075    
6076                            return array;
6077                    }
6078                    catch (Exception e) {
6079                            throw processException(e);
6080                    }
6081                    finally {
6082                            closeSession(session);
6083                    }
6084            }
6085    
6086            protected DLFolder getByG_P_H_S_PrevAndNext(Session session,
6087                    DLFolder dlFolder, long groupId, long parentFolderId, boolean hidden,
6088                    int status, OrderByComparator orderByComparator, boolean previous) {
6089                    StringBundler query = null;
6090    
6091                    if (orderByComparator != null) {
6092                            query = new StringBundler(6 +
6093                                            (orderByComparator.getOrderByFields().length * 6));
6094                    }
6095                    else {
6096                            query = new StringBundler(3);
6097                    }
6098    
6099                    query.append(_SQL_SELECT_DLFOLDER_WHERE);
6100    
6101                    query.append(_FINDER_COLUMN_G_P_H_S_GROUPID_2);
6102    
6103                    query.append(_FINDER_COLUMN_G_P_H_S_PARENTFOLDERID_2);
6104    
6105                    query.append(_FINDER_COLUMN_G_P_H_S_HIDDEN_2);
6106    
6107                    query.append(_FINDER_COLUMN_G_P_H_S_STATUS_2);
6108    
6109                    if (orderByComparator != null) {
6110                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6111    
6112                            if (orderByConditionFields.length > 0) {
6113                                    query.append(WHERE_AND);
6114                            }
6115    
6116                            for (int i = 0; i < orderByConditionFields.length; i++) {
6117                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6118                                    query.append(orderByConditionFields[i]);
6119    
6120                                    if ((i + 1) < orderByConditionFields.length) {
6121                                            if (orderByComparator.isAscending() ^ previous) {
6122                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6123                                            }
6124                                            else {
6125                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6126                                            }
6127                                    }
6128                                    else {
6129                                            if (orderByComparator.isAscending() ^ previous) {
6130                                                    query.append(WHERE_GREATER_THAN);
6131                                            }
6132                                            else {
6133                                                    query.append(WHERE_LESSER_THAN);
6134                                            }
6135                                    }
6136                            }
6137    
6138                            query.append(ORDER_BY_CLAUSE);
6139    
6140                            String[] orderByFields = orderByComparator.getOrderByFields();
6141    
6142                            for (int i = 0; i < orderByFields.length; i++) {
6143                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6144                                    query.append(orderByFields[i]);
6145    
6146                                    if ((i + 1) < orderByFields.length) {
6147                                            if (orderByComparator.isAscending() ^ previous) {
6148                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6149                                            }
6150                                            else {
6151                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6152                                            }
6153                                    }
6154                                    else {
6155                                            if (orderByComparator.isAscending() ^ previous) {
6156                                                    query.append(ORDER_BY_ASC);
6157                                            }
6158                                            else {
6159                                                    query.append(ORDER_BY_DESC);
6160                                            }
6161                                    }
6162                            }
6163                    }
6164                    else {
6165                            query.append(DLFolderModelImpl.ORDER_BY_JPQL);
6166                    }
6167    
6168                    String sql = query.toString();
6169    
6170                    Query q = session.createQuery(sql);
6171    
6172                    q.setFirstResult(0);
6173                    q.setMaxResults(2);
6174    
6175                    QueryPos qPos = QueryPos.getInstance(q);
6176    
6177                    qPos.add(groupId);
6178    
6179                    qPos.add(parentFolderId);
6180    
6181                    qPos.add(hidden);
6182    
6183                    qPos.add(status);
6184    
6185                    if (orderByComparator != null) {
6186                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
6187    
6188                            for (Object value : values) {
6189                                    qPos.add(value);
6190                            }
6191                    }
6192    
6193                    List<DLFolder> list = q.list();
6194    
6195                    if (list.size() == 2) {
6196                            return list.get(1);
6197                    }
6198                    else {
6199                            return null;
6200                    }
6201            }
6202    
6203            /**
6204             * 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;.
6205             *
6206             * @param groupId the group ID
6207             * @param parentFolderId the parent folder ID
6208             * @param hidden the hidden
6209             * @param status the status
6210             * @return the matching document library folders that the user has permission to view
6211             * @throws SystemException if a system exception occurred
6212             */
6213            public List<DLFolder> filterFindByG_P_H_S(long groupId,
6214                    long parentFolderId, boolean hidden, int status)
6215                    throws SystemException {
6216                    return filterFindByG_P_H_S(groupId, parentFolderId, hidden, status,
6217                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
6218            }
6219    
6220            /**
6221             * 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;.
6222             *
6223             * <p>
6224             * 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.
6225             * </p>
6226             *
6227             * @param groupId the group ID
6228             * @param parentFolderId the parent folder ID
6229             * @param hidden the hidden
6230             * @param status the status
6231             * @param start the lower bound of the range of document library folders
6232             * @param end the upper bound of the range of document library folders (not inclusive)
6233             * @return the range of matching document library folders that the user has permission to view
6234             * @throws SystemException if a system exception occurred
6235             */
6236            public List<DLFolder> filterFindByG_P_H_S(long groupId,
6237                    long parentFolderId, boolean hidden, int status, int start, int end)
6238                    throws SystemException {
6239                    return filterFindByG_P_H_S(groupId, parentFolderId, hidden, status,
6240                            start, end, null);
6241            }
6242    
6243            /**
6244             * 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;.
6245             *
6246             * <p>
6247             * 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.
6248             * </p>
6249             *
6250             * @param groupId the group ID
6251             * @param parentFolderId the parent folder ID
6252             * @param hidden the hidden
6253             * @param status the status
6254             * @param start the lower bound of the range of document library folders
6255             * @param end the upper bound of the range of document library folders (not inclusive)
6256             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6257             * @return the ordered range of matching document library folders that the user has permission to view
6258             * @throws SystemException if a system exception occurred
6259             */
6260            public List<DLFolder> filterFindByG_P_H_S(long groupId,
6261                    long parentFolderId, boolean hidden, int status, int start, int end,
6262                    OrderByComparator orderByComparator) throws SystemException {
6263                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6264                            return findByG_P_H_S(groupId, parentFolderId, hidden, status,
6265                                    start, end, orderByComparator);
6266                    }
6267    
6268                    StringBundler query = null;
6269    
6270                    if (orderByComparator != null) {
6271                            query = new StringBundler(6 +
6272                                            (orderByComparator.getOrderByFields().length * 3));
6273                    }
6274                    else {
6275                            query = new StringBundler(6);
6276                    }
6277    
6278                    if (getDB().isSupportsInlineDistinct()) {
6279                            query.append(_FILTER_SQL_SELECT_DLFOLDER_WHERE);
6280                    }
6281                    else {
6282                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1);
6283                    }
6284    
6285                    query.append(_FINDER_COLUMN_G_P_H_S_GROUPID_2);
6286    
6287                    query.append(_FINDER_COLUMN_G_P_H_S_PARENTFOLDERID_2);
6288    
6289                    query.append(_FINDER_COLUMN_G_P_H_S_HIDDEN_2_SQL);
6290    
6291                    query.append(_FINDER_COLUMN_G_P_H_S_STATUS_2);
6292    
6293                    if (!getDB().isSupportsInlineDistinct()) {
6294                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2);
6295                    }
6296    
6297                    if (orderByComparator != null) {
6298                            if (getDB().isSupportsInlineDistinct()) {
6299                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6300                                            orderByComparator, true);
6301                            }
6302                            else {
6303                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
6304                                            orderByComparator, true);
6305                            }
6306                    }
6307                    else {
6308                            if (getDB().isSupportsInlineDistinct()) {
6309                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
6310                            }
6311                            else {
6312                                    query.append(DLFolderModelImpl.ORDER_BY_SQL);
6313                            }
6314                    }
6315    
6316                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6317                                    DLFolder.class.getName(),
6318                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6319    
6320                    Session session = null;
6321    
6322                    try {
6323                            session = openSession();
6324    
6325                            SQLQuery q = session.createSQLQuery(sql);
6326    
6327                            if (getDB().isSupportsInlineDistinct()) {
6328                                    q.addEntity(_FILTER_ENTITY_ALIAS, DLFolderImpl.class);
6329                            }
6330                            else {
6331                                    q.addEntity(_FILTER_ENTITY_TABLE, DLFolderImpl.class);
6332                            }
6333    
6334                            QueryPos qPos = QueryPos.getInstance(q);
6335    
6336                            qPos.add(groupId);
6337    
6338                            qPos.add(parentFolderId);
6339    
6340                            qPos.add(hidden);
6341    
6342                            qPos.add(status);
6343    
6344                            return (List<DLFolder>)QueryUtil.list(q, getDialect(), start, end);
6345                    }
6346                    catch (Exception e) {
6347                            throw processException(e);
6348                    }
6349                    finally {
6350                            closeSession(session);
6351                    }
6352            }
6353    
6354            /**
6355             * 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;.
6356             *
6357             * @param folderId the primary key of the current document library folder
6358             * @param groupId the group ID
6359             * @param parentFolderId the parent folder ID
6360             * @param hidden the hidden
6361             * @param status the status
6362             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6363             * @return the previous, current, and next document library folder
6364             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
6365             * @throws SystemException if a system exception occurred
6366             */
6367            public DLFolder[] filterFindByG_P_H_S_PrevAndNext(long folderId,
6368                    long groupId, long parentFolderId, boolean hidden, int status,
6369                    OrderByComparator orderByComparator)
6370                    throws NoSuchFolderException, SystemException {
6371                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6372                            return findByG_P_H_S_PrevAndNext(folderId, groupId, parentFolderId,
6373                                    hidden, status, orderByComparator);
6374                    }
6375    
6376                    DLFolder dlFolder = findByPrimaryKey(folderId);
6377    
6378                    Session session = null;
6379    
6380                    try {
6381                            session = openSession();
6382    
6383                            DLFolder[] array = new DLFolderImpl[3];
6384    
6385                            array[0] = filterGetByG_P_H_S_PrevAndNext(session, dlFolder,
6386                                            groupId, parentFolderId, hidden, status, orderByComparator,
6387                                            true);
6388    
6389                            array[1] = dlFolder;
6390    
6391                            array[2] = filterGetByG_P_H_S_PrevAndNext(session, dlFolder,
6392                                            groupId, parentFolderId, hidden, status, orderByComparator,
6393                                            false);
6394    
6395                            return array;
6396                    }
6397                    catch (Exception e) {
6398                            throw processException(e);
6399                    }
6400                    finally {
6401                            closeSession(session);
6402                    }
6403            }
6404    
6405            protected DLFolder filterGetByG_P_H_S_PrevAndNext(Session session,
6406                    DLFolder dlFolder, long groupId, long parentFolderId, boolean hidden,
6407                    int status, OrderByComparator orderByComparator, boolean previous) {
6408                    StringBundler query = null;
6409    
6410                    if (orderByComparator != null) {
6411                            query = new StringBundler(6 +
6412                                            (orderByComparator.getOrderByFields().length * 6));
6413                    }
6414                    else {
6415                            query = new StringBundler(3);
6416                    }
6417    
6418                    if (getDB().isSupportsInlineDistinct()) {
6419                            query.append(_FILTER_SQL_SELECT_DLFOLDER_WHERE);
6420                    }
6421                    else {
6422                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1);
6423                    }
6424    
6425                    query.append(_FINDER_COLUMN_G_P_H_S_GROUPID_2);
6426    
6427                    query.append(_FINDER_COLUMN_G_P_H_S_PARENTFOLDERID_2);
6428    
6429                    query.append(_FINDER_COLUMN_G_P_H_S_HIDDEN_2_SQL);
6430    
6431                    query.append(_FINDER_COLUMN_G_P_H_S_STATUS_2);
6432    
6433                    if (!getDB().isSupportsInlineDistinct()) {
6434                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2);
6435                    }
6436    
6437                    if (orderByComparator != null) {
6438                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6439    
6440                            if (orderByConditionFields.length > 0) {
6441                                    query.append(WHERE_AND);
6442                            }
6443    
6444                            for (int i = 0; i < orderByConditionFields.length; i++) {
6445                                    if (getDB().isSupportsInlineDistinct()) {
6446                                            query.append(_ORDER_BY_ENTITY_ALIAS);
6447                                    }
6448                                    else {
6449                                            query.append(_ORDER_BY_ENTITY_TABLE);
6450                                    }
6451    
6452                                    query.append(orderByConditionFields[i]);
6453    
6454                                    if ((i + 1) < orderByConditionFields.length) {
6455                                            if (orderByComparator.isAscending() ^ previous) {
6456                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6457                                            }
6458                                            else {
6459                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6460                                            }
6461                                    }
6462                                    else {
6463                                            if (orderByComparator.isAscending() ^ previous) {
6464                                                    query.append(WHERE_GREATER_THAN);
6465                                            }
6466                                            else {
6467                                                    query.append(WHERE_LESSER_THAN);
6468                                            }
6469                                    }
6470                            }
6471    
6472                            query.append(ORDER_BY_CLAUSE);
6473    
6474                            String[] orderByFields = orderByComparator.getOrderByFields();
6475    
6476                            for (int i = 0; i < orderByFields.length; i++) {
6477                                    if (getDB().isSupportsInlineDistinct()) {
6478                                            query.append(_ORDER_BY_ENTITY_ALIAS);
6479                                    }
6480                                    else {
6481                                            query.append(_ORDER_BY_ENTITY_TABLE);
6482                                    }
6483    
6484                                    query.append(orderByFields[i]);
6485    
6486                                    if ((i + 1) < orderByFields.length) {
6487                                            if (orderByComparator.isAscending() ^ previous) {
6488                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6489                                            }
6490                                            else {
6491                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6492                                            }
6493                                    }
6494                                    else {
6495                                            if (orderByComparator.isAscending() ^ previous) {
6496                                                    query.append(ORDER_BY_ASC);
6497                                            }
6498                                            else {
6499                                                    query.append(ORDER_BY_DESC);
6500                                            }
6501                                    }
6502                            }
6503                    }
6504                    else {
6505                            if (getDB().isSupportsInlineDistinct()) {
6506                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
6507                            }
6508                            else {
6509                                    query.append(DLFolderModelImpl.ORDER_BY_SQL);
6510                            }
6511                    }
6512    
6513                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6514                                    DLFolder.class.getName(),
6515                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6516    
6517                    SQLQuery q = session.createSQLQuery(sql);
6518    
6519                    q.setFirstResult(0);
6520                    q.setMaxResults(2);
6521    
6522                    if (getDB().isSupportsInlineDistinct()) {
6523                            q.addEntity(_FILTER_ENTITY_ALIAS, DLFolderImpl.class);
6524                    }
6525                    else {
6526                            q.addEntity(_FILTER_ENTITY_TABLE, DLFolderImpl.class);
6527                    }
6528    
6529                    QueryPos qPos = QueryPos.getInstance(q);
6530    
6531                    qPos.add(groupId);
6532    
6533                    qPos.add(parentFolderId);
6534    
6535                    qPos.add(hidden);
6536    
6537                    qPos.add(status);
6538    
6539                    if (orderByComparator != null) {
6540                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
6541    
6542                            for (Object value : values) {
6543                                    qPos.add(value);
6544                            }
6545                    }
6546    
6547                    List<DLFolder> list = q.list();
6548    
6549                    if (list.size() == 2) {
6550                            return list.get(1);
6551                    }
6552                    else {
6553                            return null;
6554                    }
6555            }
6556    
6557            /**
6558             * Removes all the document library folders where groupId = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63; from the database.
6559             *
6560             * @param groupId the group ID
6561             * @param parentFolderId the parent folder ID
6562             * @param hidden the hidden
6563             * @param status the status
6564             * @throws SystemException if a system exception occurred
6565             */
6566            public void removeByG_P_H_S(long groupId, long parentFolderId,
6567                    boolean hidden, int status) throws SystemException {
6568                    for (DLFolder dlFolder : findByG_P_H_S(groupId, parentFolderId, hidden,
6569                                    status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
6570                            remove(dlFolder);
6571                    }
6572            }
6573    
6574            /**
6575             * Returns the number of document library folders where groupId = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
6576             *
6577             * @param groupId the group ID
6578             * @param parentFolderId the parent folder ID
6579             * @param hidden the hidden
6580             * @param status the status
6581             * @return the number of matching document library folders
6582             * @throws SystemException if a system exception occurred
6583             */
6584            public int countByG_P_H_S(long groupId, long parentFolderId,
6585                    boolean hidden, int status) throws SystemException {
6586                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_P_H_S;
6587    
6588                    Object[] finderArgs = new Object[] {
6589                                    groupId, parentFolderId, hidden, status
6590                            };
6591    
6592                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
6593                                    this);
6594    
6595                    if (count == null) {
6596                            StringBundler query = new StringBundler(5);
6597    
6598                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
6599    
6600                            query.append(_FINDER_COLUMN_G_P_H_S_GROUPID_2);
6601    
6602                            query.append(_FINDER_COLUMN_G_P_H_S_PARENTFOLDERID_2);
6603    
6604                            query.append(_FINDER_COLUMN_G_P_H_S_HIDDEN_2);
6605    
6606                            query.append(_FINDER_COLUMN_G_P_H_S_STATUS_2);
6607    
6608                            String sql = query.toString();
6609    
6610                            Session session = null;
6611    
6612                            try {
6613                                    session = openSession();
6614    
6615                                    Query q = session.createQuery(sql);
6616    
6617                                    QueryPos qPos = QueryPos.getInstance(q);
6618    
6619                                    qPos.add(groupId);
6620    
6621                                    qPos.add(parentFolderId);
6622    
6623                                    qPos.add(hidden);
6624    
6625                                    qPos.add(status);
6626    
6627                                    count = (Long)q.uniqueResult();
6628    
6629                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
6630                            }
6631                            catch (Exception e) {
6632                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6633    
6634                                    throw processException(e);
6635                            }
6636                            finally {
6637                                    closeSession(session);
6638                            }
6639                    }
6640    
6641                    return count.intValue();
6642            }
6643    
6644            /**
6645             * 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;.
6646             *
6647             * @param groupId the group ID
6648             * @param parentFolderId the parent folder ID
6649             * @param hidden the hidden
6650             * @param status the status
6651             * @return the number of matching document library folders that the user has permission to view
6652             * @throws SystemException if a system exception occurred
6653             */
6654            public int filterCountByG_P_H_S(long groupId, long parentFolderId,
6655                    boolean hidden, int status) throws SystemException {
6656                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6657                            return countByG_P_H_S(groupId, parentFolderId, hidden, status);
6658                    }
6659    
6660                    StringBundler query = new StringBundler(5);
6661    
6662                    query.append(_FILTER_SQL_COUNT_DLFOLDER_WHERE);
6663    
6664                    query.append(_FINDER_COLUMN_G_P_H_S_GROUPID_2);
6665    
6666                    query.append(_FINDER_COLUMN_G_P_H_S_PARENTFOLDERID_2);
6667    
6668                    query.append(_FINDER_COLUMN_G_P_H_S_HIDDEN_2_SQL);
6669    
6670                    query.append(_FINDER_COLUMN_G_P_H_S_STATUS_2);
6671    
6672                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6673                                    DLFolder.class.getName(),
6674                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6675    
6676                    Session session = null;
6677    
6678                    try {
6679                            session = openSession();
6680    
6681                            SQLQuery q = session.createSQLQuery(sql);
6682    
6683                            q.addScalar(COUNT_COLUMN_NAME,
6684                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
6685    
6686                            QueryPos qPos = QueryPos.getInstance(q);
6687    
6688                            qPos.add(groupId);
6689    
6690                            qPos.add(parentFolderId);
6691    
6692                            qPos.add(hidden);
6693    
6694                            qPos.add(status);
6695    
6696                            Long count = (Long)q.uniqueResult();
6697    
6698                            return count.intValue();
6699                    }
6700                    catch (Exception e) {
6701                            throw processException(e);
6702                    }
6703                    finally {
6704                            closeSession(session);
6705                    }
6706            }
6707    
6708            private static final String _FINDER_COLUMN_G_P_H_S_GROUPID_2 = "dlFolder.groupId = ? AND ";
6709            private static final String _FINDER_COLUMN_G_P_H_S_PARENTFOLDERID_2 = "dlFolder.parentFolderId = ? AND ";
6710            private static final String _FINDER_COLUMN_G_P_H_S_HIDDEN_2 = "dlFolder.hidden = ? AND ";
6711            private static final String _FINDER_COLUMN_G_P_H_S_HIDDEN_2_SQL = "dlFolder.hidden_ = ? AND ";
6712            private static final String _FINDER_COLUMN_G_P_H_S_STATUS_2 = "dlFolder.status = ?";
6713            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_M_P_H_S =
6714                    new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
6715                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
6716                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_M_P_H_S",
6717                            new String[] {
6718                                    Long.class.getName(), Boolean.class.getName(),
6719                                    Long.class.getName(), Boolean.class.getName(),
6720                                    Integer.class.getName(),
6721                                    
6722                            Integer.class.getName(), Integer.class.getName(),
6723                                    OrderByComparator.class.getName()
6724                            });
6725            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P_H_S =
6726                    new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
6727                            DLFolderModelImpl.FINDER_CACHE_ENABLED, DLFolderImpl.class,
6728                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_M_P_H_S",
6729                            new String[] {
6730                                    Long.class.getName(), Boolean.class.getName(),
6731                                    Long.class.getName(), Boolean.class.getName(),
6732                                    Integer.class.getName()
6733                            },
6734                            DLFolderModelImpl.GROUPID_COLUMN_BITMASK |
6735                            DLFolderModelImpl.MOUNTPOINT_COLUMN_BITMASK |
6736                            DLFolderModelImpl.PARENTFOLDERID_COLUMN_BITMASK |
6737                            DLFolderModelImpl.HIDDEN_COLUMN_BITMASK |
6738                            DLFolderModelImpl.STATUS_COLUMN_BITMASK |
6739                            DLFolderModelImpl.NAME_COLUMN_BITMASK);
6740            public static final FinderPath FINDER_PATH_COUNT_BY_G_M_P_H_S = new FinderPath(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
6741                            DLFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
6742                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_M_P_H_S",
6743                            new String[] {
6744                                    Long.class.getName(), Boolean.class.getName(),
6745                                    Long.class.getName(), Boolean.class.getName(),
6746                                    Integer.class.getName()
6747                            });
6748    
6749            /**
6750             * Returns all the document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
6751             *
6752             * @param groupId the group ID
6753             * @param mountPoint the mount point
6754             * @param parentFolderId the parent folder ID
6755             * @param hidden the hidden
6756             * @param status the status
6757             * @return the matching document library folders
6758             * @throws SystemException if a system exception occurred
6759             */
6760            public List<DLFolder> findByG_M_P_H_S(long groupId, boolean mountPoint,
6761                    long parentFolderId, boolean hidden, int status)
6762                    throws SystemException {
6763                    return findByG_M_P_H_S(groupId, mountPoint, parentFolderId, hidden,
6764                            status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
6765            }
6766    
6767            /**
6768             * Returns a range of all the document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
6769             *
6770             * <p>
6771             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.documentlibrary.model.impl.DLFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6772             * </p>
6773             *
6774             * @param groupId the group ID
6775             * @param mountPoint the mount point
6776             * @param parentFolderId the parent folder ID
6777             * @param hidden the hidden
6778             * @param status the status
6779             * @param start the lower bound of the range of document library folders
6780             * @param end the upper bound of the range of document library folders (not inclusive)
6781             * @return the range of matching document library folders
6782             * @throws SystemException if a system exception occurred
6783             */
6784            public List<DLFolder> findByG_M_P_H_S(long groupId, boolean mountPoint,
6785                    long parentFolderId, boolean hidden, int status, int start, int end)
6786                    throws SystemException {
6787                    return findByG_M_P_H_S(groupId, mountPoint, parentFolderId, hidden,
6788                            status, start, end, null);
6789            }
6790    
6791            /**
6792             * 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;.
6793             *
6794             * <p>
6795             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.documentlibrary.model.impl.DLFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6796             * </p>
6797             *
6798             * @param groupId the group ID
6799             * @param mountPoint the mount point
6800             * @param parentFolderId the parent folder ID
6801             * @param hidden the hidden
6802             * @param status the status
6803             * @param start the lower bound of the range of document library folders
6804             * @param end the upper bound of the range of document library folders (not inclusive)
6805             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6806             * @return the ordered range of matching document library folders
6807             * @throws SystemException if a system exception occurred
6808             */
6809            public List<DLFolder> findByG_M_P_H_S(long groupId, boolean mountPoint,
6810                    long parentFolderId, boolean hidden, int status, int start, int end,
6811                    OrderByComparator orderByComparator) throws SystemException {
6812                    boolean pagination = true;
6813                    FinderPath finderPath = null;
6814                    Object[] finderArgs = null;
6815    
6816                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6817                                    (orderByComparator == null)) {
6818                            pagination = false;
6819                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P_H_S;
6820                            finderArgs = new Object[] {
6821                                            groupId, mountPoint, parentFolderId, hidden, status
6822                                    };
6823                    }
6824                    else {
6825                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_M_P_H_S;
6826                            finderArgs = new Object[] {
6827                                            groupId, mountPoint, parentFolderId, hidden, status,
6828                                            
6829                                            start, end, orderByComparator
6830                                    };
6831                    }
6832    
6833                    List<DLFolder> list = (List<DLFolder>)FinderCacheUtil.getResult(finderPath,
6834                                    finderArgs, this);
6835    
6836                    if ((list != null) && !list.isEmpty()) {
6837                            for (DLFolder dlFolder : list) {
6838                                    if ((groupId != dlFolder.getGroupId()) ||
6839                                                    (mountPoint != dlFolder.getMountPoint()) ||
6840                                                    (parentFolderId != dlFolder.getParentFolderId()) ||
6841                                                    (hidden != dlFolder.getHidden()) ||
6842                                                    (status != dlFolder.getStatus())) {
6843                                            list = null;
6844    
6845                                            break;
6846                                    }
6847                            }
6848                    }
6849    
6850                    if (list == null) {
6851                            StringBundler query = null;
6852    
6853                            if (orderByComparator != null) {
6854                                    query = new StringBundler(7 +
6855                                                    (orderByComparator.getOrderByFields().length * 3));
6856                            }
6857                            else {
6858                                    query = new StringBundler(7);
6859                            }
6860    
6861                            query.append(_SQL_SELECT_DLFOLDER_WHERE);
6862    
6863                            query.append(_FINDER_COLUMN_G_M_P_H_S_GROUPID_2);
6864    
6865                            query.append(_FINDER_COLUMN_G_M_P_H_S_MOUNTPOINT_2);
6866    
6867                            query.append(_FINDER_COLUMN_G_M_P_H_S_PARENTFOLDERID_2);
6868    
6869                            query.append(_FINDER_COLUMN_G_M_P_H_S_HIDDEN_2);
6870    
6871                            query.append(_FINDER_COLUMN_G_M_P_H_S_STATUS_2);
6872    
6873                            if (orderByComparator != null) {
6874                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6875                                            orderByComparator);
6876                            }
6877                            else
6878                             if (pagination) {
6879                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
6880                            }
6881    
6882                            String sql = query.toString();
6883    
6884                            Session session = null;
6885    
6886                            try {
6887                                    session = openSession();
6888    
6889                                    Query q = session.createQuery(sql);
6890    
6891                                    QueryPos qPos = QueryPos.getInstance(q);
6892    
6893                                    qPos.add(groupId);
6894    
6895                                    qPos.add(mountPoint);
6896    
6897                                    qPos.add(parentFolderId);
6898    
6899                                    qPos.add(hidden);
6900    
6901                                    qPos.add(status);
6902    
6903                                    if (!pagination) {
6904                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
6905                                                            start, end, false);
6906    
6907                                            Collections.sort(list);
6908    
6909                                            list = new UnmodifiableList<DLFolder>(list);
6910                                    }
6911                                    else {
6912                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
6913                                                            start, end);
6914                                    }
6915    
6916                                    cacheResult(list);
6917    
6918                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
6919                            }
6920                            catch (Exception e) {
6921                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6922    
6923                                    throw processException(e);
6924                            }
6925                            finally {
6926                                    closeSession(session);
6927                            }
6928                    }
6929    
6930                    return list;
6931            }
6932    
6933            /**
6934             * 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;.
6935             *
6936             * @param groupId the group ID
6937             * @param mountPoint the mount point
6938             * @param parentFolderId the parent folder ID
6939             * @param hidden the hidden
6940             * @param status the status
6941             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6942             * @return the first matching document library folder
6943             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
6944             * @throws SystemException if a system exception occurred
6945             */
6946            public DLFolder findByG_M_P_H_S_First(long groupId, boolean mountPoint,
6947                    long parentFolderId, boolean hidden, int status,
6948                    OrderByComparator orderByComparator)
6949                    throws NoSuchFolderException, SystemException {
6950                    DLFolder dlFolder = fetchByG_M_P_H_S_First(groupId, mountPoint,
6951                                    parentFolderId, hidden, status, orderByComparator);
6952    
6953                    if (dlFolder != null) {
6954                            return dlFolder;
6955                    }
6956    
6957                    StringBundler msg = new StringBundler(12);
6958    
6959                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6960    
6961                    msg.append("groupId=");
6962                    msg.append(groupId);
6963    
6964                    msg.append(", mountPoint=");
6965                    msg.append(mountPoint);
6966    
6967                    msg.append(", parentFolderId=");
6968                    msg.append(parentFolderId);
6969    
6970                    msg.append(", hidden=");
6971                    msg.append(hidden);
6972    
6973                    msg.append(", status=");
6974                    msg.append(status);
6975    
6976                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6977    
6978                    throw new NoSuchFolderException(msg.toString());
6979            }
6980    
6981            /**
6982             * 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;.
6983             *
6984             * @param groupId the group ID
6985             * @param mountPoint the mount point
6986             * @param parentFolderId the parent folder ID
6987             * @param hidden the hidden
6988             * @param status the status
6989             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6990             * @return the first matching document library folder, or <code>null</code> if a matching document library folder could not be found
6991             * @throws SystemException if a system exception occurred
6992             */
6993            public DLFolder fetchByG_M_P_H_S_First(long groupId, boolean mountPoint,
6994                    long parentFolderId, boolean hidden, int status,
6995                    OrderByComparator orderByComparator) throws SystemException {
6996                    List<DLFolder> list = findByG_M_P_H_S(groupId, mountPoint,
6997                                    parentFolderId, hidden, status, 0, 1, orderByComparator);
6998    
6999                    if (!list.isEmpty()) {
7000                            return list.get(0);
7001                    }
7002    
7003                    return null;
7004            }
7005    
7006            /**
7007             * 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;.
7008             *
7009             * @param groupId the group ID
7010             * @param mountPoint the mount point
7011             * @param parentFolderId the parent folder ID
7012             * @param hidden the hidden
7013             * @param status the status
7014             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7015             * @return the last matching document library folder
7016             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a matching document library folder could not be found
7017             * @throws SystemException if a system exception occurred
7018             */
7019            public DLFolder findByG_M_P_H_S_Last(long groupId, boolean mountPoint,
7020                    long parentFolderId, boolean hidden, int status,
7021                    OrderByComparator orderByComparator)
7022                    throws NoSuchFolderException, SystemException {
7023                    DLFolder dlFolder = fetchByG_M_P_H_S_Last(groupId, mountPoint,
7024                                    parentFolderId, hidden, status, orderByComparator);
7025    
7026                    if (dlFolder != null) {
7027                            return dlFolder;
7028                    }
7029    
7030                    StringBundler msg = new StringBundler(12);
7031    
7032                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7033    
7034                    msg.append("groupId=");
7035                    msg.append(groupId);
7036    
7037                    msg.append(", mountPoint=");
7038                    msg.append(mountPoint);
7039    
7040                    msg.append(", parentFolderId=");
7041                    msg.append(parentFolderId);
7042    
7043                    msg.append(", hidden=");
7044                    msg.append(hidden);
7045    
7046                    msg.append(", status=");
7047                    msg.append(status);
7048    
7049                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7050    
7051                    throw new NoSuchFolderException(msg.toString());
7052            }
7053    
7054            /**
7055             * 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;.
7056             *
7057             * @param groupId the group ID
7058             * @param mountPoint the mount point
7059             * @param parentFolderId the parent folder ID
7060             * @param hidden the hidden
7061             * @param status the status
7062             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7063             * @return the last matching document library folder, or <code>null</code> if a matching document library folder could not be found
7064             * @throws SystemException if a system exception occurred
7065             */
7066            public DLFolder fetchByG_M_P_H_S_Last(long groupId, boolean mountPoint,
7067                    long parentFolderId, boolean hidden, int status,
7068                    OrderByComparator orderByComparator) throws SystemException {
7069                    int count = countByG_M_P_H_S(groupId, mountPoint, parentFolderId,
7070                                    hidden, status);
7071    
7072                    List<DLFolder> list = findByG_M_P_H_S(groupId, mountPoint,
7073                                    parentFolderId, hidden, status, count - 1, count,
7074                                    orderByComparator);
7075    
7076                    if (!list.isEmpty()) {
7077                            return list.get(0);
7078                    }
7079    
7080                    return null;
7081            }
7082    
7083            /**
7084             * 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;.
7085             *
7086             * @param folderId the primary key of the current document library folder
7087             * @param groupId the group ID
7088             * @param mountPoint the mount point
7089             * @param parentFolderId the parent folder ID
7090             * @param hidden the hidden
7091             * @param status the status
7092             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7093             * @return the previous, current, and next document library folder
7094             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
7095             * @throws SystemException if a system exception occurred
7096             */
7097            public DLFolder[] findByG_M_P_H_S_PrevAndNext(long folderId, long groupId,
7098                    boolean mountPoint, long parentFolderId, boolean hidden, int status,
7099                    OrderByComparator orderByComparator)
7100                    throws NoSuchFolderException, SystemException {
7101                    DLFolder dlFolder = findByPrimaryKey(folderId);
7102    
7103                    Session session = null;
7104    
7105                    try {
7106                            session = openSession();
7107    
7108                            DLFolder[] array = new DLFolderImpl[3];
7109    
7110                            array[0] = getByG_M_P_H_S_PrevAndNext(session, dlFolder, groupId,
7111                                            mountPoint, parentFolderId, hidden, status,
7112                                            orderByComparator, true);
7113    
7114                            array[1] = dlFolder;
7115    
7116                            array[2] = getByG_M_P_H_S_PrevAndNext(session, dlFolder, groupId,
7117                                            mountPoint, parentFolderId, hidden, status,
7118                                            orderByComparator, false);
7119    
7120                            return array;
7121                    }
7122                    catch (Exception e) {
7123                            throw processException(e);
7124                    }
7125                    finally {
7126                            closeSession(session);
7127                    }
7128            }
7129    
7130            protected DLFolder getByG_M_P_H_S_PrevAndNext(Session session,
7131                    DLFolder dlFolder, long groupId, boolean mountPoint,
7132                    long parentFolderId, boolean hidden, int status,
7133                    OrderByComparator orderByComparator, boolean previous) {
7134                    StringBundler query = null;
7135    
7136                    if (orderByComparator != null) {
7137                            query = new StringBundler(6 +
7138                                            (orderByComparator.getOrderByFields().length * 6));
7139                    }
7140                    else {
7141                            query = new StringBundler(3);
7142                    }
7143    
7144                    query.append(_SQL_SELECT_DLFOLDER_WHERE);
7145    
7146                    query.append(_FINDER_COLUMN_G_M_P_H_S_GROUPID_2);
7147    
7148                    query.append(_FINDER_COLUMN_G_M_P_H_S_MOUNTPOINT_2);
7149    
7150                    query.append(_FINDER_COLUMN_G_M_P_H_S_PARENTFOLDERID_2);
7151    
7152                    query.append(_FINDER_COLUMN_G_M_P_H_S_HIDDEN_2);
7153    
7154                    query.append(_FINDER_COLUMN_G_M_P_H_S_STATUS_2);
7155    
7156                    if (orderByComparator != null) {
7157                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7158    
7159                            if (orderByConditionFields.length > 0) {
7160                                    query.append(WHERE_AND);
7161                            }
7162    
7163                            for (int i = 0; i < orderByConditionFields.length; i++) {
7164                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7165                                    query.append(orderByConditionFields[i]);
7166    
7167                                    if ((i + 1) < orderByConditionFields.length) {
7168                                            if (orderByComparator.isAscending() ^ previous) {
7169                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
7170                                            }
7171                                            else {
7172                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
7173                                            }
7174                                    }
7175                                    else {
7176                                            if (orderByComparator.isAscending() ^ previous) {
7177                                                    query.append(WHERE_GREATER_THAN);
7178                                            }
7179                                            else {
7180                                                    query.append(WHERE_LESSER_THAN);
7181                                            }
7182                                    }
7183                            }
7184    
7185                            query.append(ORDER_BY_CLAUSE);
7186    
7187                            String[] orderByFields = orderByComparator.getOrderByFields();
7188    
7189                            for (int i = 0; i < orderByFields.length; i++) {
7190                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7191                                    query.append(orderByFields[i]);
7192    
7193                                    if ((i + 1) < orderByFields.length) {
7194                                            if (orderByComparator.isAscending() ^ previous) {
7195                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
7196                                            }
7197                                            else {
7198                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
7199                                            }
7200                                    }
7201                                    else {
7202                                            if (orderByComparator.isAscending() ^ previous) {
7203                                                    query.append(ORDER_BY_ASC);
7204                                            }
7205                                            else {
7206                                                    query.append(ORDER_BY_DESC);
7207                                            }
7208                                    }
7209                            }
7210                    }
7211                    else {
7212                            query.append(DLFolderModelImpl.ORDER_BY_JPQL);
7213                    }
7214    
7215                    String sql = query.toString();
7216    
7217                    Query q = session.createQuery(sql);
7218    
7219                    q.setFirstResult(0);
7220                    q.setMaxResults(2);
7221    
7222                    QueryPos qPos = QueryPos.getInstance(q);
7223    
7224                    qPos.add(groupId);
7225    
7226                    qPos.add(mountPoint);
7227    
7228                    qPos.add(parentFolderId);
7229    
7230                    qPos.add(hidden);
7231    
7232                    qPos.add(status);
7233    
7234                    if (orderByComparator != null) {
7235                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
7236    
7237                            for (Object value : values) {
7238                                    qPos.add(value);
7239                            }
7240                    }
7241    
7242                    List<DLFolder> list = q.list();
7243    
7244                    if (list.size() == 2) {
7245                            return list.get(1);
7246                    }
7247                    else {
7248                            return null;
7249                    }
7250            }
7251    
7252            /**
7253             * 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;.
7254             *
7255             * @param groupId the group ID
7256             * @param mountPoint the mount point
7257             * @param parentFolderId the parent folder ID
7258             * @param hidden the hidden
7259             * @param status the status
7260             * @return the matching document library folders that the user has permission to view
7261             * @throws SystemException if a system exception occurred
7262             */
7263            public List<DLFolder> filterFindByG_M_P_H_S(long groupId,
7264                    boolean mountPoint, long parentFolderId, boolean hidden, int status)
7265                    throws SystemException {
7266                    return filterFindByG_M_P_H_S(groupId, mountPoint, parentFolderId,
7267                            hidden, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
7268            }
7269    
7270            /**
7271             * 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;.
7272             *
7273             * <p>
7274             * 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.
7275             * </p>
7276             *
7277             * @param groupId the group ID
7278             * @param mountPoint the mount point
7279             * @param parentFolderId the parent folder ID
7280             * @param hidden the hidden
7281             * @param status the status
7282             * @param start the lower bound of the range of document library folders
7283             * @param end the upper bound of the range of document library folders (not inclusive)
7284             * @return the range of matching document library folders that the user has permission to view
7285             * @throws SystemException if a system exception occurred
7286             */
7287            public List<DLFolder> filterFindByG_M_P_H_S(long groupId,
7288                    boolean mountPoint, long parentFolderId, boolean hidden, int status,
7289                    int start, int end) throws SystemException {
7290                    return filterFindByG_M_P_H_S(groupId, mountPoint, parentFolderId,
7291                            hidden, status, start, end, null);
7292            }
7293    
7294            /**
7295             * 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;.
7296             *
7297             * <p>
7298             * 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.
7299             * </p>
7300             *
7301             * @param groupId the group ID
7302             * @param mountPoint the mount point
7303             * @param parentFolderId the parent folder ID
7304             * @param hidden the hidden
7305             * @param status the status
7306             * @param start the lower bound of the range of document library folders
7307             * @param end the upper bound of the range of document library folders (not inclusive)
7308             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7309             * @return the ordered range of matching document library folders that the user has permission to view
7310             * @throws SystemException if a system exception occurred
7311             */
7312            public List<DLFolder> filterFindByG_M_P_H_S(long groupId,
7313                    boolean mountPoint, long parentFolderId, boolean hidden, int status,
7314                    int start, int end, OrderByComparator orderByComparator)
7315                    throws SystemException {
7316                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7317                            return findByG_M_P_H_S(groupId, mountPoint, parentFolderId, hidden,
7318                                    status, start, end, orderByComparator);
7319                    }
7320    
7321                    StringBundler query = null;
7322    
7323                    if (orderByComparator != null) {
7324                            query = new StringBundler(7 +
7325                                            (orderByComparator.getOrderByFields().length * 3));
7326                    }
7327                    else {
7328                            query = new StringBundler(7);
7329                    }
7330    
7331                    if (getDB().isSupportsInlineDistinct()) {
7332                            query.append(_FILTER_SQL_SELECT_DLFOLDER_WHERE);
7333                    }
7334                    else {
7335                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1);
7336                    }
7337    
7338                    query.append(_FINDER_COLUMN_G_M_P_H_S_GROUPID_2);
7339    
7340                    query.append(_FINDER_COLUMN_G_M_P_H_S_MOUNTPOINT_2);
7341    
7342                    query.append(_FINDER_COLUMN_G_M_P_H_S_PARENTFOLDERID_2);
7343    
7344                    query.append(_FINDER_COLUMN_G_M_P_H_S_HIDDEN_2_SQL);
7345    
7346                    query.append(_FINDER_COLUMN_G_M_P_H_S_STATUS_2);
7347    
7348                    if (!getDB().isSupportsInlineDistinct()) {
7349                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2);
7350                    }
7351    
7352                    if (orderByComparator != null) {
7353                            if (getDB().isSupportsInlineDistinct()) {
7354                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7355                                            orderByComparator, true);
7356                            }
7357                            else {
7358                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
7359                                            orderByComparator, true);
7360                            }
7361                    }
7362                    else {
7363                            if (getDB().isSupportsInlineDistinct()) {
7364                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
7365                            }
7366                            else {
7367                                    query.append(DLFolderModelImpl.ORDER_BY_SQL);
7368                            }
7369                    }
7370    
7371                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7372                                    DLFolder.class.getName(),
7373                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7374    
7375                    Session session = null;
7376    
7377                    try {
7378                            session = openSession();
7379    
7380                            SQLQuery q = session.createSQLQuery(sql);
7381    
7382                            if (getDB().isSupportsInlineDistinct()) {
7383                                    q.addEntity(_FILTER_ENTITY_ALIAS, DLFolderImpl.class);
7384                            }
7385                            else {
7386                                    q.addEntity(_FILTER_ENTITY_TABLE, DLFolderImpl.class);
7387                            }
7388    
7389                            QueryPos qPos = QueryPos.getInstance(q);
7390    
7391                            qPos.add(groupId);
7392    
7393                            qPos.add(mountPoint);
7394    
7395                            qPos.add(parentFolderId);
7396    
7397                            qPos.add(hidden);
7398    
7399                            qPos.add(status);
7400    
7401                            return (List<DLFolder>)QueryUtil.list(q, getDialect(), start, end);
7402                    }
7403                    catch (Exception e) {
7404                            throw processException(e);
7405                    }
7406                    finally {
7407                            closeSession(session);
7408                    }
7409            }
7410    
7411            /**
7412             * 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;.
7413             *
7414             * @param folderId the primary key of the current document library folder
7415             * @param groupId the group ID
7416             * @param mountPoint the mount point
7417             * @param parentFolderId the parent folder ID
7418             * @param hidden the hidden
7419             * @param status the status
7420             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7421             * @return the previous, current, and next document library folder
7422             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
7423             * @throws SystemException if a system exception occurred
7424             */
7425            public DLFolder[] filterFindByG_M_P_H_S_PrevAndNext(long folderId,
7426                    long groupId, boolean mountPoint, long parentFolderId, boolean hidden,
7427                    int status, OrderByComparator orderByComparator)
7428                    throws NoSuchFolderException, SystemException {
7429                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7430                            return findByG_M_P_H_S_PrevAndNext(folderId, groupId, mountPoint,
7431                                    parentFolderId, hidden, status, orderByComparator);
7432                    }
7433    
7434                    DLFolder dlFolder = findByPrimaryKey(folderId);
7435    
7436                    Session session = null;
7437    
7438                    try {
7439                            session = openSession();
7440    
7441                            DLFolder[] array = new DLFolderImpl[3];
7442    
7443                            array[0] = filterGetByG_M_P_H_S_PrevAndNext(session, dlFolder,
7444                                            groupId, mountPoint, parentFolderId, hidden, status,
7445                                            orderByComparator, true);
7446    
7447                            array[1] = dlFolder;
7448    
7449                            array[2] = filterGetByG_M_P_H_S_PrevAndNext(session, dlFolder,
7450                                            groupId, mountPoint, parentFolderId, hidden, status,
7451                                            orderByComparator, false);
7452    
7453                            return array;
7454                    }
7455                    catch (Exception e) {
7456                            throw processException(e);
7457                    }
7458                    finally {
7459                            closeSession(session);
7460                    }
7461            }
7462    
7463            protected DLFolder filterGetByG_M_P_H_S_PrevAndNext(Session session,
7464                    DLFolder dlFolder, long groupId, boolean mountPoint,
7465                    long parentFolderId, boolean hidden, int status,
7466                    OrderByComparator orderByComparator, boolean previous) {
7467                    StringBundler query = null;
7468    
7469                    if (orderByComparator != null) {
7470                            query = new StringBundler(6 +
7471                                            (orderByComparator.getOrderByFields().length * 6));
7472                    }
7473                    else {
7474                            query = new StringBundler(3);
7475                    }
7476    
7477                    if (getDB().isSupportsInlineDistinct()) {
7478                            query.append(_FILTER_SQL_SELECT_DLFOLDER_WHERE);
7479                    }
7480                    else {
7481                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1);
7482                    }
7483    
7484                    query.append(_FINDER_COLUMN_G_M_P_H_S_GROUPID_2);
7485    
7486                    query.append(_FINDER_COLUMN_G_M_P_H_S_MOUNTPOINT_2);
7487    
7488                    query.append(_FINDER_COLUMN_G_M_P_H_S_PARENTFOLDERID_2);
7489    
7490                    query.append(_FINDER_COLUMN_G_M_P_H_S_HIDDEN_2_SQL);
7491    
7492                    query.append(_FINDER_COLUMN_G_M_P_H_S_STATUS_2);
7493    
7494                    if (!getDB().isSupportsInlineDistinct()) {
7495                            query.append(_FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2);
7496                    }
7497    
7498                    if (orderByComparator != null) {
7499                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7500    
7501                            if (orderByConditionFields.length > 0) {
7502                                    query.append(WHERE_AND);
7503                            }
7504    
7505                            for (int i = 0; i < orderByConditionFields.length; i++) {
7506                                    if (getDB().isSupportsInlineDistinct()) {
7507                                            query.append(_ORDER_BY_ENTITY_ALIAS);
7508                                    }
7509                                    else {
7510                                            query.append(_ORDER_BY_ENTITY_TABLE);
7511                                    }
7512    
7513                                    query.append(orderByConditionFields[i]);
7514    
7515                                    if ((i + 1) < orderByConditionFields.length) {
7516                                            if (orderByComparator.isAscending() ^ previous) {
7517                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
7518                                            }
7519                                            else {
7520                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
7521                                            }
7522                                    }
7523                                    else {
7524                                            if (orderByComparator.isAscending() ^ previous) {
7525                                                    query.append(WHERE_GREATER_THAN);
7526                                            }
7527                                            else {
7528                                                    query.append(WHERE_LESSER_THAN);
7529                                            }
7530                                    }
7531                            }
7532    
7533                            query.append(ORDER_BY_CLAUSE);
7534    
7535                            String[] orderByFields = orderByComparator.getOrderByFields();
7536    
7537                            for (int i = 0; i < orderByFields.length; i++) {
7538                                    if (getDB().isSupportsInlineDistinct()) {
7539                                            query.append(_ORDER_BY_ENTITY_ALIAS);
7540                                    }
7541                                    else {
7542                                            query.append(_ORDER_BY_ENTITY_TABLE);
7543                                    }
7544    
7545                                    query.append(orderByFields[i]);
7546    
7547                                    if ((i + 1) < orderByFields.length) {
7548                                            if (orderByComparator.isAscending() ^ previous) {
7549                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
7550                                            }
7551                                            else {
7552                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
7553                                            }
7554                                    }
7555                                    else {
7556                                            if (orderByComparator.isAscending() ^ previous) {
7557                                                    query.append(ORDER_BY_ASC);
7558                                            }
7559                                            else {
7560                                                    query.append(ORDER_BY_DESC);
7561                                            }
7562                                    }
7563                            }
7564                    }
7565                    else {
7566                            if (getDB().isSupportsInlineDistinct()) {
7567                                    query.append(DLFolderModelImpl.ORDER_BY_JPQL);
7568                            }
7569                            else {
7570                                    query.append(DLFolderModelImpl.ORDER_BY_SQL);
7571                            }
7572                    }
7573    
7574                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7575                                    DLFolder.class.getName(),
7576                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7577    
7578                    SQLQuery q = session.createSQLQuery(sql);
7579    
7580                    q.setFirstResult(0);
7581                    q.setMaxResults(2);
7582    
7583                    if (getDB().isSupportsInlineDistinct()) {
7584                            q.addEntity(_FILTER_ENTITY_ALIAS, DLFolderImpl.class);
7585                    }
7586                    else {
7587                            q.addEntity(_FILTER_ENTITY_TABLE, DLFolderImpl.class);
7588                    }
7589    
7590                    QueryPos qPos = QueryPos.getInstance(q);
7591    
7592                    qPos.add(groupId);
7593    
7594                    qPos.add(mountPoint);
7595    
7596                    qPos.add(parentFolderId);
7597    
7598                    qPos.add(hidden);
7599    
7600                    qPos.add(status);
7601    
7602                    if (orderByComparator != null) {
7603                            Object[] values = orderByComparator.getOrderByConditionValues(dlFolder);
7604    
7605                            for (Object value : values) {
7606                                    qPos.add(value);
7607                            }
7608                    }
7609    
7610                    List<DLFolder> list = q.list();
7611    
7612                    if (list.size() == 2) {
7613                            return list.get(1);
7614                    }
7615                    else {
7616                            return null;
7617                    }
7618            }
7619    
7620            /**
7621             * Removes all the document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63; from the database.
7622             *
7623             * @param groupId the group ID
7624             * @param mountPoint the mount point
7625             * @param parentFolderId the parent folder ID
7626             * @param hidden the hidden
7627             * @param status the status
7628             * @throws SystemException if a system exception occurred
7629             */
7630            public void removeByG_M_P_H_S(long groupId, boolean mountPoint,
7631                    long parentFolderId, boolean hidden, int status)
7632                    throws SystemException {
7633                    for (DLFolder dlFolder : findByG_M_P_H_S(groupId, mountPoint,
7634                                    parentFolderId, hidden, status, QueryUtil.ALL_POS,
7635                                    QueryUtil.ALL_POS, null)) {
7636                            remove(dlFolder);
7637                    }
7638            }
7639    
7640            /**
7641             * Returns the number of document library folders where groupId = &#63; and mountPoint = &#63; and parentFolderId = &#63; and hidden = &#63; and status = &#63;.
7642             *
7643             * @param groupId the group ID
7644             * @param mountPoint the mount point
7645             * @param parentFolderId the parent folder ID
7646             * @param hidden the hidden
7647             * @param status the status
7648             * @return the number of matching document library folders
7649             * @throws SystemException if a system exception occurred
7650             */
7651            public int countByG_M_P_H_S(long groupId, boolean mountPoint,
7652                    long parentFolderId, boolean hidden, int status)
7653                    throws SystemException {
7654                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_M_P_H_S;
7655    
7656                    Object[] finderArgs = new Object[] {
7657                                    groupId, mountPoint, parentFolderId, hidden, status
7658                            };
7659    
7660                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
7661                                    this);
7662    
7663                    if (count == null) {
7664                            StringBundler query = new StringBundler(6);
7665    
7666                            query.append(_SQL_COUNT_DLFOLDER_WHERE);
7667    
7668                            query.append(_FINDER_COLUMN_G_M_P_H_S_GROUPID_2);
7669    
7670                            query.append(_FINDER_COLUMN_G_M_P_H_S_MOUNTPOINT_2);
7671    
7672                            query.append(_FINDER_COLUMN_G_M_P_H_S_PARENTFOLDERID_2);
7673    
7674                            query.append(_FINDER_COLUMN_G_M_P_H_S_HIDDEN_2);
7675    
7676                            query.append(_FINDER_COLUMN_G_M_P_H_S_STATUS_2);
7677    
7678                            String sql = query.toString();
7679    
7680                            Session session = null;
7681    
7682                            try {
7683                                    session = openSession();
7684    
7685                                    Query q = session.createQuery(sql);
7686    
7687                                    QueryPos qPos = QueryPos.getInstance(q);
7688    
7689                                    qPos.add(groupId);
7690    
7691                                    qPos.add(mountPoint);
7692    
7693                                    qPos.add(parentFolderId);
7694    
7695                                    qPos.add(hidden);
7696    
7697                                    qPos.add(status);
7698    
7699                                    count = (Long)q.uniqueResult();
7700    
7701                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
7702                            }
7703                            catch (Exception e) {
7704                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
7705    
7706                                    throw processException(e);
7707                            }
7708                            finally {
7709                                    closeSession(session);
7710                            }
7711                    }
7712    
7713                    return count.intValue();
7714            }
7715    
7716            /**
7717             * 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;.
7718             *
7719             * @param groupId the group ID
7720             * @param mountPoint the mount point
7721             * @param parentFolderId the parent folder ID
7722             * @param hidden the hidden
7723             * @param status the status
7724             * @return the number of matching document library folders that the user has permission to view
7725             * @throws SystemException if a system exception occurred
7726             */
7727            public int filterCountByG_M_P_H_S(long groupId, boolean mountPoint,
7728                    long parentFolderId, boolean hidden, int status)
7729                    throws SystemException {
7730                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7731                            return countByG_M_P_H_S(groupId, mountPoint, parentFolderId,
7732                                    hidden, status);
7733                    }
7734    
7735                    StringBundler query = new StringBundler(6);
7736    
7737                    query.append(_FILTER_SQL_COUNT_DLFOLDER_WHERE);
7738    
7739                    query.append(_FINDER_COLUMN_G_M_P_H_S_GROUPID_2);
7740    
7741                    query.append(_FINDER_COLUMN_G_M_P_H_S_MOUNTPOINT_2);
7742    
7743                    query.append(_FINDER_COLUMN_G_M_P_H_S_PARENTFOLDERID_2);
7744    
7745                    query.append(_FINDER_COLUMN_G_M_P_H_S_HIDDEN_2_SQL);
7746    
7747                    query.append(_FINDER_COLUMN_G_M_P_H_S_STATUS_2);
7748    
7749                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7750                                    DLFolder.class.getName(),
7751                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7752    
7753                    Session session = null;
7754    
7755                    try {
7756                            session = openSession();
7757    
7758                            SQLQuery q = session.createSQLQuery(sql);
7759    
7760                            q.addScalar(COUNT_COLUMN_NAME,
7761                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
7762    
7763                            QueryPos qPos = QueryPos.getInstance(q);
7764    
7765                            qPos.add(groupId);
7766    
7767                            qPos.add(mountPoint);
7768    
7769                            qPos.add(parentFolderId);
7770    
7771                            qPos.add(hidden);
7772    
7773                            qPos.add(status);
7774    
7775                            Long count = (Long)q.uniqueResult();
7776    
7777                            return count.intValue();
7778                    }
7779                    catch (Exception e) {
7780                            throw processException(e);
7781                    }
7782                    finally {
7783                            closeSession(session);
7784                    }
7785            }
7786    
7787            private static final String _FINDER_COLUMN_G_M_P_H_S_GROUPID_2 = "dlFolder.groupId = ? AND ";
7788            private static final String _FINDER_COLUMN_G_M_P_H_S_MOUNTPOINT_2 = "dlFolder.mountPoint = ? AND ";
7789            private static final String _FINDER_COLUMN_G_M_P_H_S_PARENTFOLDERID_2 = "dlFolder.parentFolderId = ? AND ";
7790            private static final String _FINDER_COLUMN_G_M_P_H_S_HIDDEN_2 = "dlFolder.hidden = ? AND ";
7791            private static final String _FINDER_COLUMN_G_M_P_H_S_HIDDEN_2_SQL = "dlFolder.hidden_ = ? AND ";
7792            private static final String _FINDER_COLUMN_G_M_P_H_S_STATUS_2 = "dlFolder.status = ?";
7793    
7794            /**
7795             * Caches the document library folder in the entity cache if it is enabled.
7796             *
7797             * @param dlFolder the document library folder
7798             */
7799            public void cacheResult(DLFolder dlFolder) {
7800                    EntityCacheUtil.putResult(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
7801                            DLFolderImpl.class, dlFolder.getPrimaryKey(), dlFolder);
7802    
7803                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
7804                            new Object[] { dlFolder.getUuid(), dlFolder.getGroupId() }, dlFolder);
7805    
7806                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_REPOSITORYID,
7807                            new Object[] { dlFolder.getRepositoryId() }, dlFolder);
7808    
7809                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_N,
7810                            new Object[] {
7811                                    dlFolder.getGroupId(), dlFolder.getParentFolderId(),
7812                                    dlFolder.getName()
7813                            }, dlFolder);
7814    
7815                    dlFolder.resetOriginalValues();
7816            }
7817    
7818            /**
7819             * Caches the document library folders in the entity cache if it is enabled.
7820             *
7821             * @param dlFolders the document library folders
7822             */
7823            public void cacheResult(List<DLFolder> dlFolders) {
7824                    for (DLFolder dlFolder : dlFolders) {
7825                            if (EntityCacheUtil.getResult(
7826                                                    DLFolderModelImpl.ENTITY_CACHE_ENABLED,
7827                                                    DLFolderImpl.class, dlFolder.getPrimaryKey()) == null) {
7828                                    cacheResult(dlFolder);
7829                            }
7830                            else {
7831                                    dlFolder.resetOriginalValues();
7832                            }
7833                    }
7834            }
7835    
7836            /**
7837             * Clears the cache for all document library folders.
7838             *
7839             * <p>
7840             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
7841             * </p>
7842             */
7843            @Override
7844            public void clearCache() {
7845                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
7846                            CacheRegistryUtil.clear(DLFolderImpl.class.getName());
7847                    }
7848    
7849                    EntityCacheUtil.clearCache(DLFolderImpl.class.getName());
7850    
7851                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
7852                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
7853                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
7854            }
7855    
7856            /**
7857             * Clears the cache for the document library folder.
7858             *
7859             * <p>
7860             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
7861             * </p>
7862             */
7863            @Override
7864            public void clearCache(DLFolder dlFolder) {
7865                    EntityCacheUtil.removeResult(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
7866                            DLFolderImpl.class, dlFolder.getPrimaryKey());
7867    
7868                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
7869                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
7870    
7871                    clearUniqueFindersCache(dlFolder);
7872            }
7873    
7874            @Override
7875            public void clearCache(List<DLFolder> dlFolders) {
7876                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
7877                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
7878    
7879                    for (DLFolder dlFolder : dlFolders) {
7880                            EntityCacheUtil.removeResult(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
7881                                    DLFolderImpl.class, dlFolder.getPrimaryKey());
7882    
7883                            clearUniqueFindersCache(dlFolder);
7884                    }
7885            }
7886    
7887            protected void cacheUniqueFindersCache(DLFolder dlFolder) {
7888                    if (dlFolder.isNew()) {
7889                            Object[] args = new Object[] {
7890                                            dlFolder.getUuid(), dlFolder.getGroupId()
7891                                    };
7892    
7893                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
7894                                    Long.valueOf(1));
7895                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
7896                                    dlFolder);
7897    
7898                            args = new Object[] { dlFolder.getRepositoryId() };
7899    
7900                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_REPOSITORYID, args,
7901                                    Long.valueOf(1));
7902                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_REPOSITORYID, args,
7903                                    dlFolder);
7904    
7905                            args = new Object[] {
7906                                            dlFolder.getGroupId(), dlFolder.getParentFolderId(),
7907                                            dlFolder.getName()
7908                                    };
7909    
7910                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_P_N, args,
7911                                    Long.valueOf(1));
7912                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_N, args, dlFolder);
7913                    }
7914                    else {
7915                            DLFolderModelImpl dlFolderModelImpl = (DLFolderModelImpl)dlFolder;
7916    
7917                            if ((dlFolderModelImpl.getColumnBitmask() &
7918                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
7919                                    Object[] args = new Object[] {
7920                                                    dlFolder.getUuid(), dlFolder.getGroupId()
7921                                            };
7922    
7923                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
7924                                            Long.valueOf(1));
7925                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
7926                                            dlFolder);
7927                            }
7928    
7929                            if ((dlFolderModelImpl.getColumnBitmask() &
7930                                            FINDER_PATH_FETCH_BY_REPOSITORYID.getColumnBitmask()) != 0) {
7931                                    Object[] args = new Object[] { dlFolder.getRepositoryId() };
7932    
7933                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_REPOSITORYID,
7934                                            args, Long.valueOf(1));
7935                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_REPOSITORYID,
7936                                            args, dlFolder);
7937                            }
7938    
7939                            if ((dlFolderModelImpl.getColumnBitmask() &
7940                                            FINDER_PATH_FETCH_BY_G_P_N.getColumnBitmask()) != 0) {
7941                                    Object[] args = new Object[] {
7942                                                    dlFolder.getGroupId(), dlFolder.getParentFolderId(),
7943                                                    dlFolder.getName()
7944                                            };
7945    
7946                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_P_N, args,
7947                                            Long.valueOf(1));
7948                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_N, args,
7949                                            dlFolder);
7950                            }
7951                    }
7952            }
7953    
7954            protected void clearUniqueFindersCache(DLFolder dlFolder) {
7955                    DLFolderModelImpl dlFolderModelImpl = (DLFolderModelImpl)dlFolder;
7956    
7957                    Object[] args = new Object[] { dlFolder.getUuid(), dlFolder.getGroupId() };
7958    
7959                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
7960                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
7961    
7962                    if ((dlFolderModelImpl.getColumnBitmask() &
7963                                    FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
7964                            args = new Object[] {
7965                                            dlFolderModelImpl.getOriginalUuid(),
7966                                            dlFolderModelImpl.getOriginalGroupId()
7967                                    };
7968    
7969                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
7970                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
7971                    }
7972    
7973                    args = new Object[] { dlFolder.getRepositoryId() };
7974    
7975                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_REPOSITORYID, args);
7976                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_REPOSITORYID, args);
7977    
7978                    if ((dlFolderModelImpl.getColumnBitmask() &
7979                                    FINDER_PATH_FETCH_BY_REPOSITORYID.getColumnBitmask()) != 0) {
7980                            args = new Object[] { dlFolderModelImpl.getOriginalRepositoryId() };
7981    
7982                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_REPOSITORYID, args);
7983                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_REPOSITORYID, args);
7984                    }
7985    
7986                    args = new Object[] {
7987                                    dlFolder.getGroupId(), dlFolder.getParentFolderId(),
7988                                    dlFolder.getName()
7989                            };
7990    
7991                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_N, args);
7992                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P_N, args);
7993    
7994                    if ((dlFolderModelImpl.getColumnBitmask() &
7995                                    FINDER_PATH_FETCH_BY_G_P_N.getColumnBitmask()) != 0) {
7996                            args = new Object[] {
7997                                            dlFolderModelImpl.getOriginalGroupId(),
7998                                            dlFolderModelImpl.getOriginalParentFolderId(),
7999                                            dlFolderModelImpl.getOriginalName()
8000                                    };
8001    
8002                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_N, args);
8003                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P_N, args);
8004                    }
8005            }
8006    
8007            /**
8008             * Creates a new document library folder with the primary key. Does not add the document library folder to the database.
8009             *
8010             * @param folderId the primary key for the new document library folder
8011             * @return the new document library folder
8012             */
8013            public DLFolder create(long folderId) {
8014                    DLFolder dlFolder = new DLFolderImpl();
8015    
8016                    dlFolder.setNew(true);
8017                    dlFolder.setPrimaryKey(folderId);
8018    
8019                    String uuid = PortalUUIDUtil.generate();
8020    
8021                    dlFolder.setUuid(uuid);
8022    
8023                    return dlFolder;
8024            }
8025    
8026            /**
8027             * Removes the document library folder with the primary key from the database. Also notifies the appropriate model listeners.
8028             *
8029             * @param folderId the primary key of the document library folder
8030             * @return the document library folder that was removed
8031             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
8032             * @throws SystemException if a system exception occurred
8033             */
8034            public DLFolder remove(long folderId)
8035                    throws NoSuchFolderException, SystemException {
8036                    return remove((Serializable)folderId);
8037            }
8038    
8039            /**
8040             * Removes the document library folder with the primary key from the database. Also notifies the appropriate model listeners.
8041             *
8042             * @param primaryKey the primary key of the document library folder
8043             * @return the document library folder that was removed
8044             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
8045             * @throws SystemException if a system exception occurred
8046             */
8047            @Override
8048            public DLFolder remove(Serializable primaryKey)
8049                    throws NoSuchFolderException, SystemException {
8050                    Session session = null;
8051    
8052                    try {
8053                            session = openSession();
8054    
8055                            DLFolder dlFolder = (DLFolder)session.get(DLFolderImpl.class,
8056                                            primaryKey);
8057    
8058                            if (dlFolder == null) {
8059                                    if (_log.isWarnEnabled()) {
8060                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
8061                                    }
8062    
8063                                    throw new NoSuchFolderException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
8064                                            primaryKey);
8065                            }
8066    
8067                            return remove(dlFolder);
8068                    }
8069                    catch (NoSuchFolderException nsee) {
8070                            throw nsee;
8071                    }
8072                    catch (Exception e) {
8073                            throw processException(e);
8074                    }
8075                    finally {
8076                            closeSession(session);
8077                    }
8078            }
8079    
8080            @Override
8081            protected DLFolder removeImpl(DLFolder dlFolder) throws SystemException {
8082                    dlFolder = toUnwrappedModel(dlFolder);
8083    
8084                    try {
8085                            clearDLFileEntryTypes.clear(dlFolder.getPrimaryKey());
8086                    }
8087                    catch (Exception e) {
8088                            throw processException(e);
8089                    }
8090                    finally {
8091                            FinderCacheUtil.clearCache(DLFolderModelImpl.MAPPING_TABLE_DLFILEENTRYTYPES_DLFOLDERS_NAME);
8092                    }
8093    
8094                    Session session = null;
8095    
8096                    try {
8097                            session = openSession();
8098    
8099                            if (!session.contains(dlFolder)) {
8100                                    dlFolder = (DLFolder)session.get(DLFolderImpl.class,
8101                                                    dlFolder.getPrimaryKeyObj());
8102                            }
8103    
8104                            if (dlFolder != null) {
8105                                    session.delete(dlFolder);
8106                            }
8107                    }
8108                    catch (Exception e) {
8109                            throw processException(e);
8110                    }
8111                    finally {
8112                            closeSession(session);
8113                    }
8114    
8115                    if (dlFolder != null) {
8116                            clearCache(dlFolder);
8117                    }
8118    
8119                    return dlFolder;
8120            }
8121    
8122            @Override
8123            public DLFolder updateImpl(
8124                    com.liferay.portlet.documentlibrary.model.DLFolder dlFolder)
8125                    throws SystemException {
8126                    dlFolder = toUnwrappedModel(dlFolder);
8127    
8128                    boolean isNew = dlFolder.isNew();
8129    
8130                    DLFolderModelImpl dlFolderModelImpl = (DLFolderModelImpl)dlFolder;
8131    
8132                    if (Validator.isNull(dlFolder.getUuid())) {
8133                            String uuid = PortalUUIDUtil.generate();
8134    
8135                            dlFolder.setUuid(uuid);
8136                    }
8137    
8138                    Session session = null;
8139    
8140                    try {
8141                            session = openSession();
8142    
8143                            if (dlFolder.isNew()) {
8144                                    session.save(dlFolder);
8145    
8146                                    dlFolder.setNew(false);
8147                            }
8148                            else {
8149                                    session.merge(dlFolder);
8150                            }
8151                    }
8152                    catch (Exception e) {
8153                            throw processException(e);
8154                    }
8155                    finally {
8156                            closeSession(session);
8157                    }
8158    
8159                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
8160    
8161                    if (isNew || !DLFolderModelImpl.COLUMN_BITMASK_ENABLED) {
8162                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
8163                    }
8164    
8165                    else {
8166                            if ((dlFolderModelImpl.getColumnBitmask() &
8167                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
8168                                    Object[] args = new Object[] { dlFolderModelImpl.getOriginalUuid() };
8169    
8170                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
8171                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
8172                                            args);
8173    
8174                                    args = new Object[] { dlFolderModelImpl.getUuid() };
8175    
8176                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
8177                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
8178                                            args);
8179                            }
8180    
8181                            if ((dlFolderModelImpl.getColumnBitmask() &
8182                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
8183                                    Object[] args = new Object[] {
8184                                                    dlFolderModelImpl.getOriginalUuid(),
8185                                                    dlFolderModelImpl.getOriginalCompanyId()
8186                                            };
8187    
8188                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
8189                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
8190                                            args);
8191    
8192                                    args = new Object[] {
8193                                                    dlFolderModelImpl.getUuid(),
8194                                                    dlFolderModelImpl.getCompanyId()
8195                                            };
8196    
8197                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
8198                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
8199                                            args);
8200                            }
8201    
8202                            if ((dlFolderModelImpl.getColumnBitmask() &
8203                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
8204                                    Object[] args = new Object[] {
8205                                                    dlFolderModelImpl.getOriginalGroupId()
8206                                            };
8207    
8208                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
8209                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
8210                                            args);
8211    
8212                                    args = new Object[] { dlFolderModelImpl.getGroupId() };
8213    
8214                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
8215                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
8216                                            args);
8217                            }
8218    
8219                            if ((dlFolderModelImpl.getColumnBitmask() &
8220                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
8221                                    Object[] args = new Object[] {
8222                                                    dlFolderModelImpl.getOriginalCompanyId()
8223                                            };
8224    
8225                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
8226                                            args);
8227                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
8228                                            args);
8229    
8230                                    args = new Object[] { dlFolderModelImpl.getCompanyId() };
8231    
8232                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
8233                                            args);
8234                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
8235                                            args);
8236                            }
8237    
8238                            if ((dlFolderModelImpl.getColumnBitmask() &
8239                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P.getColumnBitmask()) != 0) {
8240                                    Object[] args = new Object[] {
8241                                                    dlFolderModelImpl.getOriginalGroupId(),
8242                                                    dlFolderModelImpl.getOriginalParentFolderId()
8243                                            };
8244    
8245                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P, args);
8246                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P,
8247                                            args);
8248    
8249                                    args = new Object[] {
8250                                                    dlFolderModelImpl.getGroupId(),
8251                                                    dlFolderModelImpl.getParentFolderId()
8252                                            };
8253    
8254                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P, args);
8255                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P,
8256                                            args);
8257                            }
8258    
8259                            if ((dlFolderModelImpl.getColumnBitmask() &
8260                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_N.getColumnBitmask()) != 0) {
8261                                    Object[] args = new Object[] {
8262                                                    dlFolderModelImpl.getOriginalParentFolderId(),
8263                                                    dlFolderModelImpl.getOriginalName()
8264                                            };
8265    
8266                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_P_N, args);
8267                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_N,
8268                                            args);
8269    
8270                                    args = new Object[] {
8271                                                    dlFolderModelImpl.getParentFolderId(),
8272                                                    dlFolderModelImpl.getName()
8273                                            };
8274    
8275                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_P_N, args);
8276                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_N,
8277                                            args);
8278                            }
8279    
8280                            if ((dlFolderModelImpl.getColumnBitmask() &
8281                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P_H.getColumnBitmask()) != 0) {
8282                                    Object[] args = new Object[] {
8283                                                    dlFolderModelImpl.getOriginalGroupId(),
8284                                                    dlFolderModelImpl.getOriginalMountPoint(),
8285                                                    dlFolderModelImpl.getOriginalParentFolderId(),
8286                                                    dlFolderModelImpl.getOriginalHidden()
8287                                            };
8288    
8289                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_M_P_H, args);
8290                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P_H,
8291                                            args);
8292    
8293                                    args = new Object[] {
8294                                                    dlFolderModelImpl.getGroupId(),
8295                                                    dlFolderModelImpl.getMountPoint(),
8296                                                    dlFolderModelImpl.getParentFolderId(),
8297                                                    dlFolderModelImpl.getHidden()
8298                                            };
8299    
8300                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_M_P_H, args);
8301                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P_H,
8302                                            args);
8303                            }
8304    
8305                            if ((dlFolderModelImpl.getColumnBitmask() &
8306                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_H_S.getColumnBitmask()) != 0) {
8307                                    Object[] args = new Object[] {
8308                                                    dlFolderModelImpl.getOriginalGroupId(),
8309                                                    dlFolderModelImpl.getOriginalParentFolderId(),
8310                                                    dlFolderModelImpl.getOriginalHidden(),
8311                                                    dlFolderModelImpl.getOriginalStatus()
8312                                            };
8313    
8314                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_H_S, args);
8315                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_H_S,
8316                                            args);
8317    
8318                                    args = new Object[] {
8319                                                    dlFolderModelImpl.getGroupId(),
8320                                                    dlFolderModelImpl.getParentFolderId(),
8321                                                    dlFolderModelImpl.getHidden(),
8322                                                    dlFolderModelImpl.getStatus()
8323                                            };
8324    
8325                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_H_S, args);
8326                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_H_S,
8327                                            args);
8328                            }
8329    
8330                            if ((dlFolderModelImpl.getColumnBitmask() &
8331                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P_H_S.getColumnBitmask()) != 0) {
8332                                    Object[] args = new Object[] {
8333                                                    dlFolderModelImpl.getOriginalGroupId(),
8334                                                    dlFolderModelImpl.getOriginalMountPoint(),
8335                                                    dlFolderModelImpl.getOriginalParentFolderId(),
8336                                                    dlFolderModelImpl.getOriginalHidden(),
8337                                                    dlFolderModelImpl.getOriginalStatus()
8338                                            };
8339    
8340                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_M_P_H_S,
8341                                            args);
8342                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P_H_S,
8343                                            args);
8344    
8345                                    args = new Object[] {
8346                                                    dlFolderModelImpl.getGroupId(),
8347                                                    dlFolderModelImpl.getMountPoint(),
8348                                                    dlFolderModelImpl.getParentFolderId(),
8349                                                    dlFolderModelImpl.getHidden(),
8350                                                    dlFolderModelImpl.getStatus()
8351                                            };
8352    
8353                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_M_P_H_S,
8354                                            args);
8355                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_M_P_H_S,
8356                                            args);
8357                            }
8358                    }
8359    
8360                    EntityCacheUtil.putResult(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
8361                            DLFolderImpl.class, dlFolder.getPrimaryKey(), dlFolder);
8362    
8363                    clearUniqueFindersCache(dlFolder);
8364                    cacheUniqueFindersCache(dlFolder);
8365    
8366                    return dlFolder;
8367            }
8368    
8369            protected DLFolder toUnwrappedModel(DLFolder dlFolder) {
8370                    if (dlFolder instanceof DLFolderImpl) {
8371                            return dlFolder;
8372                    }
8373    
8374                    DLFolderImpl dlFolderImpl = new DLFolderImpl();
8375    
8376                    dlFolderImpl.setNew(dlFolder.isNew());
8377                    dlFolderImpl.setPrimaryKey(dlFolder.getPrimaryKey());
8378    
8379                    dlFolderImpl.setUuid(dlFolder.getUuid());
8380                    dlFolderImpl.setFolderId(dlFolder.getFolderId());
8381                    dlFolderImpl.setGroupId(dlFolder.getGroupId());
8382                    dlFolderImpl.setCompanyId(dlFolder.getCompanyId());
8383                    dlFolderImpl.setUserId(dlFolder.getUserId());
8384                    dlFolderImpl.setUserName(dlFolder.getUserName());
8385                    dlFolderImpl.setCreateDate(dlFolder.getCreateDate());
8386                    dlFolderImpl.setModifiedDate(dlFolder.getModifiedDate());
8387                    dlFolderImpl.setRepositoryId(dlFolder.getRepositoryId());
8388                    dlFolderImpl.setMountPoint(dlFolder.isMountPoint());
8389                    dlFolderImpl.setParentFolderId(dlFolder.getParentFolderId());
8390                    dlFolderImpl.setName(dlFolder.getName());
8391                    dlFolderImpl.setDescription(dlFolder.getDescription());
8392                    dlFolderImpl.setLastPostDate(dlFolder.getLastPostDate());
8393                    dlFolderImpl.setDefaultFileEntryTypeId(dlFolder.getDefaultFileEntryTypeId());
8394                    dlFolderImpl.setHidden(dlFolder.isHidden());
8395                    dlFolderImpl.setOverrideFileEntryTypes(dlFolder.isOverrideFileEntryTypes());
8396                    dlFolderImpl.setStatus(dlFolder.getStatus());
8397                    dlFolderImpl.setStatusByUserId(dlFolder.getStatusByUserId());
8398                    dlFolderImpl.setStatusByUserName(dlFolder.getStatusByUserName());
8399                    dlFolderImpl.setStatusDate(dlFolder.getStatusDate());
8400    
8401                    return dlFolderImpl;
8402            }
8403    
8404            /**
8405             * Returns the document library folder with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
8406             *
8407             * @param primaryKey the primary key of the document library folder
8408             * @return the document library folder
8409             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
8410             * @throws SystemException if a system exception occurred
8411             */
8412            @Override
8413            public DLFolder findByPrimaryKey(Serializable primaryKey)
8414                    throws NoSuchFolderException, SystemException {
8415                    DLFolder dlFolder = fetchByPrimaryKey(primaryKey);
8416    
8417                    if (dlFolder == null) {
8418                            if (_log.isWarnEnabled()) {
8419                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
8420                            }
8421    
8422                            throw new NoSuchFolderException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
8423                                    primaryKey);
8424                    }
8425    
8426                    return dlFolder;
8427            }
8428    
8429            /**
8430             * Returns the document library folder with the primary key or throws a {@link com.liferay.portlet.documentlibrary.NoSuchFolderException} if it could not be found.
8431             *
8432             * @param folderId the primary key of the document library folder
8433             * @return the document library folder
8434             * @throws com.liferay.portlet.documentlibrary.NoSuchFolderException if a document library folder with the primary key could not be found
8435             * @throws SystemException if a system exception occurred
8436             */
8437            public DLFolder findByPrimaryKey(long folderId)
8438                    throws NoSuchFolderException, SystemException {
8439                    return findByPrimaryKey((Serializable)folderId);
8440            }
8441    
8442            /**
8443             * Returns the document library folder with the primary key or returns <code>null</code> if it could not be found.
8444             *
8445             * @param primaryKey the primary key of the document library folder
8446             * @return the document library folder, or <code>null</code> if a document library folder with the primary key could not be found
8447             * @throws SystemException if a system exception occurred
8448             */
8449            @Override
8450            public DLFolder fetchByPrimaryKey(Serializable primaryKey)
8451                    throws SystemException {
8452                    DLFolder dlFolder = (DLFolder)EntityCacheUtil.getResult(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
8453                                    DLFolderImpl.class, primaryKey);
8454    
8455                    if (dlFolder == _nullDLFolder) {
8456                            return null;
8457                    }
8458    
8459                    if (dlFolder == null) {
8460                            Session session = null;
8461    
8462                            try {
8463                                    session = openSession();
8464    
8465                                    dlFolder = (DLFolder)session.get(DLFolderImpl.class, primaryKey);
8466    
8467                                    if (dlFolder != null) {
8468                                            cacheResult(dlFolder);
8469                                    }
8470                                    else {
8471                                            EntityCacheUtil.putResult(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
8472                                                    DLFolderImpl.class, primaryKey, _nullDLFolder);
8473                                    }
8474                            }
8475                            catch (Exception e) {
8476                                    EntityCacheUtil.removeResult(DLFolderModelImpl.ENTITY_CACHE_ENABLED,
8477                                            DLFolderImpl.class, primaryKey);
8478    
8479                                    throw processException(e);
8480                            }
8481                            finally {
8482                                    closeSession(session);
8483                            }
8484                    }
8485    
8486                    return dlFolder;
8487            }
8488    
8489            /**
8490             * Returns the document library folder with the primary key or returns <code>null</code> if it could not be found.
8491             *
8492             * @param folderId the primary key of the document library folder
8493             * @return the document library folder, or <code>null</code> if a document library folder with the primary key could not be found
8494             * @throws SystemException if a system exception occurred
8495             */
8496            public DLFolder fetchByPrimaryKey(long folderId) throws SystemException {
8497                    return fetchByPrimaryKey((Serializable)folderId);
8498            }
8499    
8500            /**
8501             * Returns all the document library folders.
8502             *
8503             * @return the document library folders
8504             * @throws SystemException if a system exception occurred
8505             */
8506            public List<DLFolder> findAll() throws SystemException {
8507                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
8508            }
8509    
8510            /**
8511             * Returns a range of all the document library folders.
8512             *
8513             * <p>
8514             * 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.
8515             * </p>
8516             *
8517             * @param start the lower bound of the range of document library folders
8518             * @param end the upper bound of the range of document library folders (not inclusive)
8519             * @return the range of document library folders
8520             * @throws SystemException if a system exception occurred
8521             */
8522            public List<DLFolder> findAll(int start, int end) throws SystemException {
8523                    return findAll(start, end, null);
8524            }
8525    
8526            /**
8527             * Returns an ordered range of all the document library folders.
8528             *
8529             * <p>
8530             * 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.
8531             * </p>
8532             *
8533             * @param start the lower bound of the range of document library folders
8534             * @param end the upper bound of the range of document library folders (not inclusive)
8535             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8536             * @return the ordered range of document library folders
8537             * @throws SystemException if a system exception occurred
8538             */
8539            public List<DLFolder> findAll(int start, int end,
8540                    OrderByComparator orderByComparator) throws SystemException {
8541                    boolean pagination = true;
8542                    FinderPath finderPath = null;
8543                    Object[] finderArgs = null;
8544    
8545                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8546                                    (orderByComparator == null)) {
8547                            pagination = false;
8548                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
8549                            finderArgs = FINDER_ARGS_EMPTY;
8550                    }
8551                    else {
8552                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
8553                            finderArgs = new Object[] { start, end, orderByComparator };
8554                    }
8555    
8556                    List<DLFolder> list = (List<DLFolder>)FinderCacheUtil.getResult(finderPath,
8557                                    finderArgs, this);
8558    
8559                    if (list == null) {
8560                            StringBundler query = null;
8561                            String sql = null;
8562    
8563                            if (orderByComparator != null) {
8564                                    query = new StringBundler(2 +
8565                                                    (orderByComparator.getOrderByFields().length * 3));
8566    
8567                                    query.append(_SQL_SELECT_DLFOLDER);
8568    
8569                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8570                                            orderByComparator);
8571    
8572                                    sql = query.toString();
8573                            }
8574                            else {
8575                                    sql = _SQL_SELECT_DLFOLDER;
8576    
8577                                    if (pagination) {
8578                                            sql = sql.concat(DLFolderModelImpl.ORDER_BY_JPQL);
8579                                    }
8580                            }
8581    
8582                            Session session = null;
8583    
8584                            try {
8585                                    session = openSession();
8586    
8587                                    Query q = session.createQuery(sql);
8588    
8589                                    if (!pagination) {
8590                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
8591                                                            start, end, false);
8592    
8593                                            Collections.sort(list);
8594    
8595                                            list = new UnmodifiableList<DLFolder>(list);
8596                                    }
8597                                    else {
8598                                            list = (List<DLFolder>)QueryUtil.list(q, getDialect(),
8599                                                            start, end);
8600                                    }
8601    
8602                                    cacheResult(list);
8603    
8604                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
8605                            }
8606                            catch (Exception e) {
8607                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
8608    
8609                                    throw processException(e);
8610                            }
8611                            finally {
8612                                    closeSession(session);
8613                            }
8614                    }
8615    
8616                    return list;
8617            }
8618    
8619            /**
8620             * Removes all the document library folders from the database.
8621             *
8622             * @throws SystemException if a system exception occurred
8623             */
8624            public void removeAll() throws SystemException {
8625                    for (DLFolder dlFolder : findAll()) {
8626                            remove(dlFolder);
8627                    }
8628            }
8629    
8630            /**
8631             * Returns the number of document library folders.
8632             *
8633             * @return the number of document library folders
8634             * @throws SystemException if a system exception occurred
8635             */
8636            public int countAll() throws SystemException {
8637                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
8638                                    FINDER_ARGS_EMPTY, this);
8639    
8640                    if (count == null) {
8641                            Session session = null;
8642    
8643                            try {
8644                                    session = openSession();
8645    
8646                                    Query q = session.createQuery(_SQL_COUNT_DLFOLDER);
8647    
8648                                    count = (Long)q.uniqueResult();
8649    
8650                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
8651                                            FINDER_ARGS_EMPTY, count);
8652                            }
8653                            catch (Exception e) {
8654                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
8655                                            FINDER_ARGS_EMPTY);
8656    
8657                                    throw processException(e);
8658                            }
8659                            finally {
8660                                    closeSession(session);
8661                            }
8662                    }
8663    
8664                    return count.intValue();
8665            }
8666    
8667            /**
8668             * Returns all the document library file entry types associated with the document library folder.
8669             *
8670             * @param pk the primary key of the document library folder
8671             * @return the document library file entry types associated with the document library folder
8672             * @throws SystemException if a system exception occurred
8673             */
8674            public List<com.liferay.portlet.documentlibrary.model.DLFileEntryType> getDLFileEntryTypes(
8675                    long pk) throws SystemException {
8676                    return getDLFileEntryTypes(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
8677            }
8678    
8679            /**
8680             * Returns a range of all the document library file entry types associated with the document library folder.
8681             *
8682             * <p>
8683             * 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.
8684             * </p>
8685             *
8686             * @param pk the primary key of the document library folder
8687             * @param start the lower bound of the range of document library folders
8688             * @param end the upper bound of the range of document library folders (not inclusive)
8689             * @return the range of document library file entry types associated with the document library folder
8690             * @throws SystemException if a system exception occurred
8691             */
8692            public List<com.liferay.portlet.documentlibrary.model.DLFileEntryType> getDLFileEntryTypes(
8693                    long pk, int start, int end) throws SystemException {
8694                    return getDLFileEntryTypes(pk, start, end, null);
8695            }
8696    
8697            public static final FinderPath FINDER_PATH_GET_DLFILEENTRYTYPES = new FinderPath(com.liferay.portlet.documentlibrary.model.impl.DLFileEntryTypeModelImpl.ENTITY_CACHE_ENABLED,
8698                            DLFolderModelImpl.FINDER_CACHE_ENABLED_DLFILEENTRYTYPES_DLFOLDERS,
8699                            com.liferay.portlet.documentlibrary.model.impl.DLFileEntryTypeImpl.class,
8700                            DLFolderModelImpl.MAPPING_TABLE_DLFILEENTRYTYPES_DLFOLDERS_NAME,
8701                            "getDLFileEntryTypes",
8702                            new String[] {
8703                                    Long.class.getName(), Integer.class.getName(),
8704                                    Integer.class.getName(), OrderByComparator.class.getName()
8705                            });
8706    
8707            static {
8708                    FINDER_PATH_GET_DLFILEENTRYTYPES.setCacheKeyGeneratorCacheName(null);
8709            }
8710    
8711            /**
8712             * Returns an ordered range of all the document library file entry types associated with the document library folder.
8713             *
8714             * <p>
8715             * 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.
8716             * </p>
8717             *
8718             * @param pk the primary key of the document library folder
8719             * @param start the lower bound of the range of document library folders
8720             * @param end the upper bound of the range of document library folders (not inclusive)
8721             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8722             * @return the ordered range of document library file entry types associated with the document library folder
8723             * @throws SystemException if a system exception occurred
8724             */
8725            public List<com.liferay.portlet.documentlibrary.model.DLFileEntryType> getDLFileEntryTypes(
8726                    long pk, int start, int end, OrderByComparator orderByComparator)
8727                    throws SystemException {
8728                    boolean pagination = true;
8729                    Object[] finderArgs = null;
8730    
8731                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8732                                    (orderByComparator == null)) {
8733                            pagination = false;
8734                            finderArgs = new Object[] { pk };
8735                    }
8736                    else {
8737                            finderArgs = new Object[] { pk, start, end, orderByComparator };
8738                    }
8739    
8740                    List<com.liferay.portlet.documentlibrary.model.DLFileEntryType> list = (List<com.liferay.portlet.documentlibrary.model.DLFileEntryType>)FinderCacheUtil.getResult(FINDER_PATH_GET_DLFILEENTRYTYPES,
8741                                    finderArgs, this);
8742    
8743                    if (list == null) {
8744                            Session session = null;
8745    
8746                            try {
8747                                    session = openSession();
8748    
8749                                    String sql = null;
8750    
8751                                    if (orderByComparator != null) {
8752                                            sql = _SQL_GETDLFILEENTRYTYPES.concat(ORDER_BY_CLAUSE)
8753                                                                                                      .concat(orderByComparator.getOrderBy());
8754                                    }
8755                                    else {
8756                                            sql = _SQL_GETDLFILEENTRYTYPES;
8757    
8758                                            if (pagination) {
8759                                                    sql = sql.concat(com.liferay.portlet.documentlibrary.model.impl.DLFileEntryTypeModelImpl.ORDER_BY_SQL);
8760                                            }
8761                                    }
8762    
8763                                    SQLQuery q = session.createSQLQuery(sql);
8764    
8765                                    q.addEntity("DLFileEntryType",
8766                                            com.liferay.portlet.documentlibrary.model.impl.DLFileEntryTypeImpl.class);
8767    
8768                                    QueryPos qPos = QueryPos.getInstance(q);
8769    
8770                                    qPos.add(pk);
8771    
8772                                    if (!pagination) {
8773                                            list = (List<com.liferay.portlet.documentlibrary.model.DLFileEntryType>)QueryUtil.list(q,
8774                                                            getDialect(), start, end, false);
8775    
8776                                            Collections.sort(list);
8777    
8778                                            list = new UnmodifiableList<com.liferay.portlet.documentlibrary.model.DLFileEntryType>(list);
8779                                    }
8780                                    else {
8781                                            list = (List<com.liferay.portlet.documentlibrary.model.DLFileEntryType>)QueryUtil.list(q,
8782                                                            getDialect(), start, end);
8783                                    }
8784    
8785                                    dlFileEntryTypePersistence.cacheResult(list);
8786    
8787                                    FinderCacheUtil.putResult(FINDER_PATH_GET_DLFILEENTRYTYPES,
8788                                            finderArgs, list);
8789                            }
8790                            catch (Exception e) {
8791                                    FinderCacheUtil.removeResult(FINDER_PATH_GET_DLFILEENTRYTYPES,
8792                                            finderArgs);
8793    
8794                                    throw processException(e);
8795                            }
8796                            finally {
8797                                    closeSession(session);
8798                            }
8799                    }
8800    
8801                    return list;
8802            }
8803    
8804            public static final FinderPath FINDER_PATH_GET_DLFILEENTRYTYPES_SIZE = new FinderPath(com.liferay.portlet.documentlibrary.model.impl.DLFileEntryTypeModelImpl.ENTITY_CACHE_ENABLED,
8805                            DLFolderModelImpl.FINDER_CACHE_ENABLED_DLFILEENTRYTYPES_DLFOLDERS,
8806                            Long.class,
8807                            DLFolderModelImpl.MAPPING_TABLE_DLFILEENTRYTYPES_DLFOLDERS_NAME,
8808                            "getDLFileEntryTypesSize", new String[] { Long.class.getName() });
8809    
8810            static {
8811                    FINDER_PATH_GET_DLFILEENTRYTYPES_SIZE.setCacheKeyGeneratorCacheName(null);
8812            }
8813    
8814            /**
8815             * Returns the number of document library file entry types associated with the document library folder.
8816             *
8817             * @param pk the primary key of the document library folder
8818             * @return the number of document library file entry types associated with the document library folder
8819             * @throws SystemException if a system exception occurred
8820             */
8821            public int getDLFileEntryTypesSize(long pk) throws SystemException {
8822                    Object[] finderArgs = new Object[] { pk };
8823    
8824                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_DLFILEENTRYTYPES_SIZE,
8825                                    finderArgs, this);
8826    
8827                    if (count == null) {
8828                            Session session = null;
8829    
8830                            try {
8831                                    session = openSession();
8832    
8833                                    SQLQuery q = session.createSQLQuery(_SQL_GETDLFILEENTRYTYPESSIZE);
8834    
8835                                    q.addScalar(COUNT_COLUMN_NAME,
8836                                            com.liferay.portal.kernel.dao.orm.Type.LONG);
8837    
8838                                    QueryPos qPos = QueryPos.getInstance(q);
8839    
8840                                    qPos.add(pk);
8841    
8842                                    count = (Long)q.uniqueResult();
8843    
8844                                    FinderCacheUtil.putResult(FINDER_PATH_GET_DLFILEENTRYTYPES_SIZE,
8845                                            finderArgs, count);
8846                            }
8847                            catch (Exception e) {
8848                                    FinderCacheUtil.removeResult(FINDER_PATH_GET_DLFILEENTRYTYPES_SIZE,
8849                                            finderArgs);
8850    
8851                                    throw processException(e);
8852                            }
8853                            finally {
8854                                    closeSession(session);
8855                            }
8856                    }
8857    
8858                    return count.intValue();
8859            }
8860    
8861            public static final FinderPath FINDER_PATH_CONTAINS_DLFILEENTRYTYPE = new FinderPath(com.liferay.portlet.documentlibrary.model.impl.DLFileEntryTypeModelImpl.ENTITY_CACHE_ENABLED,
8862                            DLFolderModelImpl.FINDER_CACHE_ENABLED_DLFILEENTRYTYPES_DLFOLDERS,
8863                            Boolean.class,
8864                            DLFolderModelImpl.MAPPING_TABLE_DLFILEENTRYTYPES_DLFOLDERS_NAME,
8865                            "containsDLFileEntryType",
8866                            new String[] { Long.class.getName(), Long.class.getName() });
8867    
8868            /**
8869             * Returns <code>true</code> if the document library file entry type is associated with the document library folder.
8870             *
8871             * @param pk the primary key of the document library folder
8872             * @param dlFileEntryTypePK the primary key of the document library file entry type
8873             * @return <code>true</code> if the document library file entry type is associated with the document library folder; <code>false</code> otherwise
8874             * @throws SystemException if a system exception occurred
8875             */
8876            public boolean containsDLFileEntryType(long pk, long dlFileEntryTypePK)
8877                    throws SystemException {
8878                    Object[] finderArgs = new Object[] { pk, dlFileEntryTypePK };
8879    
8880                    Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_DLFILEENTRYTYPE,
8881                                    finderArgs, this);
8882    
8883                    if (value == null) {
8884                            try {
8885                                    value = Boolean.valueOf(containsDLFileEntryType.contains(pk,
8886                                                            dlFileEntryTypePK));
8887    
8888                                    FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_DLFILEENTRYTYPE,
8889                                            finderArgs, value);
8890                            }
8891                            catch (Exception e) {
8892                                    FinderCacheUtil.removeResult(FINDER_PATH_CONTAINS_DLFILEENTRYTYPE,
8893                                            finderArgs);
8894    
8895                                    throw processException(e);
8896                            }
8897                    }
8898    
8899                    return value.booleanValue();
8900            }
8901    
8902            /**
8903             * Returns <code>true</code> if the document library folder has any document library file entry types associated with it.
8904             *
8905             * @param pk the primary key of the document library folder to check for associations with document library file entry types
8906             * @return <code>true</code> if the document library folder has any document library file entry types associated with it; <code>false</code> otherwise
8907             * @throws SystemException if a system exception occurred
8908             */
8909            public boolean containsDLFileEntryTypes(long pk) throws SystemException {
8910                    if (getDLFileEntryTypesSize(pk) > 0) {
8911                            return true;
8912                    }
8913                    else {
8914                            return false;
8915                    }
8916            }
8917    
8918            /**
8919             * 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.
8920             *
8921             * @param pk the primary key of the document library folder
8922             * @param dlFileEntryTypePK the primary key of the document library file entry type
8923             * @throws SystemException if a system exception occurred
8924             */
8925            public void addDLFileEntryType(long pk, long dlFileEntryTypePK)
8926                    throws SystemException {
8927                    try {
8928                            addDLFileEntryType.add(pk, dlFileEntryTypePK);
8929                    }
8930                    catch (Exception e) {
8931                            throw processException(e);
8932                    }
8933                    finally {
8934                            FinderCacheUtil.clearCache(DLFolderModelImpl.MAPPING_TABLE_DLFILEENTRYTYPES_DLFOLDERS_NAME);
8935                    }
8936            }
8937    
8938            /**
8939             * 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.
8940             *
8941             * @param pk the primary key of the document library folder
8942             * @param dlFileEntryType the document library file entry type
8943             * @throws SystemException if a system exception occurred
8944             */
8945            public void addDLFileEntryType(long pk,
8946                    com.liferay.portlet.documentlibrary.model.DLFileEntryType dlFileEntryType)
8947                    throws SystemException {
8948                    try {
8949                            addDLFileEntryType.add(pk, dlFileEntryType.getPrimaryKey());
8950                    }
8951                    catch (Exception e) {
8952                            throw processException(e);
8953                    }
8954                    finally {
8955                            FinderCacheUtil.clearCache(DLFolderModelImpl.MAPPING_TABLE_DLFILEENTRYTYPES_DLFOLDERS_NAME);
8956                    }
8957            }
8958    
8959            /**
8960             * 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.
8961             *
8962             * @param pk the primary key of the document library folder
8963             * @param dlFileEntryTypePKs the primary keys of the document library file entry types
8964             * @throws SystemException if a system exception occurred
8965             */
8966            public void addDLFileEntryTypes(long pk, long[] dlFileEntryTypePKs)
8967                    throws SystemException {
8968                    try {
8969                            for (long dlFileEntryTypePK : dlFileEntryTypePKs) {
8970                                    addDLFileEntryType.add(pk, dlFileEntryTypePK);
8971                            }
8972                    }
8973                    catch (Exception e) {
8974                            throw processException(e);
8975                    }
8976                    finally {
8977                            FinderCacheUtil.clearCache(DLFolderModelImpl.MAPPING_TABLE_DLFILEENTRYTYPES_DLFOLDERS_NAME);
8978                    }
8979            }
8980    
8981            /**
8982             * 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.
8983             *
8984             * @param pk the primary key of the document library folder
8985             * @param dlFileEntryTypes the document library file entry types
8986             * @throws SystemException if a system exception occurred
8987             */
8988            public void addDLFileEntryTypes(long pk,
8989                    List<com.liferay.portlet.documentlibrary.model.DLFileEntryType> dlFileEntryTypes)
8990                    throws SystemException {
8991                    try {
8992                            for (com.liferay.portlet.documentlibrary.model.DLFileEntryType dlFileEntryType : dlFileEntryTypes) {
8993                                    addDLFileEntryType.add(pk, dlFileEntryType.getPrimaryKey());
8994                            }
8995                    }
8996                    catch (Exception e) {
8997                            throw processException(e);
8998                    }
8999                    finally {
9000                            FinderCacheUtil.clearCache(DLFolderModelImpl.MAPPING_TABLE_DLFILEENTRYTYPES_DLFOLDERS_NAME);
9001                    }
9002            }
9003    
9004            /**
9005             * 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.
9006             *
9007             * @param pk the primary key of the document library folder to clear the associated document library file entry types from
9008             * @throws SystemException if a system exception occurred
9009             */
9010            public void clearDLFileEntryTypes(long pk) throws SystemException {
9011                    try {
9012                            clearDLFileEntryTypes.clear(pk);
9013                    }
9014                    catch (Exception e) {
9015                            throw processException(e);
9016                    }
9017                    finally {
9018                            FinderCacheUtil.clearCache(DLFolderModelImpl.MAPPING_TABLE_DLFILEENTRYTYPES_DLFOLDERS_NAME);
9019                    }
9020            }
9021    
9022            /**
9023             * 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.
9024             *
9025             * @param pk the primary key of the document library folder
9026             * @param dlFileEntryTypePK the primary key of the document library file entry type
9027             * @throws SystemException if a system exception occurred
9028             */
9029            public void removeDLFileEntryType(long pk, long dlFileEntryTypePK)
9030                    throws SystemException {
9031                    try {
9032                            removeDLFileEntryType.remove(pk, dlFileEntryTypePK);
9033                    }
9034                    catch (Exception e) {
9035                            throw processException(e);
9036                    }
9037                    finally {
9038                            FinderCacheUtil.clearCache(DLFolderModelImpl.MAPPING_TABLE_DLFILEENTRYTYPES_DLFOLDERS_NAME);
9039                    }
9040            }
9041    
9042            /**
9043             * 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.
9044             *
9045             * @param pk the primary key of the document library folder
9046             * @param dlFileEntryType the document library file entry type
9047             * @throws SystemException if a system exception occurred
9048             */
9049            public void removeDLFileEntryType(long pk,
9050                    com.liferay.portlet.documentlibrary.model.DLFileEntryType dlFileEntryType)
9051                    throws SystemException {
9052                    try {
9053                            removeDLFileEntryType.remove(pk, dlFileEntryType.getPrimaryKey());
9054                    }
9055                    catch (Exception e) {
9056                            throw processException(e);
9057                    }
9058                    finally {
9059                            FinderCacheUtil.clearCache(DLFolderModelImpl.MAPPING_TABLE_DLFILEENTRYTYPES_DLFOLDERS_NAME);
9060                    }
9061            }
9062    
9063            /**
9064             * 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.
9065             *
9066             * @param pk the primary key of the document library folder
9067             * @param dlFileEntryTypePKs the primary keys of the document library file entry types
9068             * @throws SystemException if a system exception occurred
9069             */
9070            public void removeDLFileEntryTypes(long pk, long[] dlFileEntryTypePKs)
9071                    throws SystemException {
9072                    try {
9073                            for (long dlFileEntryTypePK : dlFileEntryTypePKs) {
9074                                    removeDLFileEntryType.remove(pk, dlFileEntryTypePK);
9075                            }
9076                    }
9077                    catch (Exception e) {
9078                            throw processException(e);
9079                    }
9080                    finally {
9081                            FinderCacheUtil.clearCache(DLFolderModelImpl.MAPPING_TABLE_DLFILEENTRYTYPES_DLFOLDERS_NAME);
9082                    }
9083            }
9084    
9085            /**
9086             * 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.
9087             *
9088             * @param pk the primary key of the document library folder
9089             * @param dlFileEntryTypes the document library file entry types
9090             * @throws SystemException if a system exception occurred
9091             */
9092            public void removeDLFileEntryTypes(long pk,
9093                    List<com.liferay.portlet.documentlibrary.model.DLFileEntryType> dlFileEntryTypes)
9094                    throws SystemException {
9095                    try {
9096                            for (com.liferay.portlet.documentlibrary.model.DLFileEntryType dlFileEntryType : dlFileEntryTypes) {
9097                                    removeDLFileEntryType.remove(pk, dlFileEntryType.getPrimaryKey());
9098                            }
9099                    }
9100                    catch (Exception e) {
9101                            throw processException(e);
9102                    }
9103                    finally {
9104                            FinderCacheUtil.clearCache(DLFolderModelImpl.MAPPING_TABLE_DLFILEENTRYTYPES_DLFOLDERS_NAME);
9105                    }
9106            }
9107    
9108            /**
9109             * 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.
9110             *
9111             * @param pk the primary key of the document library folder
9112             * @param dlFileEntryTypePKs the primary keys of the document library file entry types to be associated with the document library folder
9113             * @throws SystemException if a system exception occurred
9114             */
9115            public void setDLFileEntryTypes(long pk, long[] dlFileEntryTypePKs)
9116                    throws SystemException {
9117                    try {
9118                            Set<Long> dlFileEntryTypePKSet = SetUtil.fromArray(dlFileEntryTypePKs);
9119    
9120                            List<com.liferay.portlet.documentlibrary.model.DLFileEntryType> dlFileEntryTypes =
9121                                    getDLFileEntryTypes(pk);
9122    
9123                            for (com.liferay.portlet.documentlibrary.model.DLFileEntryType dlFileEntryType : dlFileEntryTypes) {
9124                                    if (!dlFileEntryTypePKSet.remove(
9125                                                            dlFileEntryType.getPrimaryKey())) {
9126                                            removeDLFileEntryType.remove(pk,
9127                                                    dlFileEntryType.getPrimaryKey());
9128                                    }
9129                            }
9130    
9131                            for (Long dlFileEntryTypePK : dlFileEntryTypePKSet) {
9132                                    addDLFileEntryType.add(pk, dlFileEntryTypePK);
9133                            }
9134                    }
9135                    catch (Exception e) {
9136                            throw processException(e);
9137                    }
9138                    finally {
9139                            FinderCacheUtil.clearCache(DLFolderModelImpl.MAPPING_TABLE_DLFILEENTRYTYPES_DLFOLDERS_NAME);
9140                    }
9141            }
9142    
9143            /**
9144             * 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.
9145             *
9146             * @param pk the primary key of the document library folder
9147             * @param dlFileEntryTypes the document library file entry types to be associated with the document library folder
9148             * @throws SystemException if a system exception occurred
9149             */
9150            public void setDLFileEntryTypes(long pk,
9151                    List<com.liferay.portlet.documentlibrary.model.DLFileEntryType> dlFileEntryTypes)
9152                    throws SystemException {
9153                    try {
9154                            long[] dlFileEntryTypePKs = new long[dlFileEntryTypes.size()];
9155    
9156                            for (int i = 0; i < dlFileEntryTypes.size(); i++) {
9157                                    com.liferay.portlet.documentlibrary.model.DLFileEntryType dlFileEntryType =
9158                                            dlFileEntryTypes.get(i);
9159    
9160                                    dlFileEntryTypePKs[i] = dlFileEntryType.getPrimaryKey();
9161                            }
9162    
9163                            setDLFileEntryTypes(pk, dlFileEntryTypePKs);
9164                    }
9165                    catch (Exception e) {
9166                            throw processException(e);
9167                    }
9168                    finally {
9169                            FinderCacheUtil.clearCache(DLFolderModelImpl.MAPPING_TABLE_DLFILEENTRYTYPES_DLFOLDERS_NAME);
9170                    }
9171            }
9172    
9173            @Override
9174            protected Set<String> getBadColumnNames() {
9175                    return _badColumnNames;
9176            }
9177    
9178            /**
9179             * Initializes the document library folder persistence.
9180             */
9181            public void afterPropertiesSet() {
9182                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
9183                                            com.liferay.portal.util.PropsUtil.get(
9184                                                    "value.object.listener.com.liferay.portlet.documentlibrary.model.DLFolder")));
9185    
9186                    if (listenerClassNames.length > 0) {
9187                            try {
9188                                    List<ModelListener<DLFolder>> listenersList = new ArrayList<ModelListener<DLFolder>>();
9189    
9190                                    for (String listenerClassName : listenerClassNames) {
9191                                            listenersList.add((ModelListener<DLFolder>)InstanceFactory.newInstance(
9192                                                            getClassLoader(), listenerClassName));
9193                                    }
9194    
9195                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
9196                            }
9197                            catch (Exception e) {
9198                                    _log.error(e);
9199                            }
9200                    }
9201    
9202                    containsDLFileEntryType = new ContainsDLFileEntryType();
9203    
9204                    addDLFileEntryType = new AddDLFileEntryType();
9205                    clearDLFileEntryTypes = new ClearDLFileEntryTypes();
9206                    removeDLFileEntryType = new RemoveDLFileEntryType();
9207            }
9208    
9209            public void destroy() {
9210                    EntityCacheUtil.removeCache(DLFolderImpl.class.getName());
9211                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
9212                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
9213                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
9214            }
9215    
9216            @BeanReference(type = DLFileEntryTypePersistence.class)
9217            protected DLFileEntryTypePersistence dlFileEntryTypePersistence;
9218            protected ContainsDLFileEntryType containsDLFileEntryType;
9219            protected AddDLFileEntryType addDLFileEntryType;
9220            protected ClearDLFileEntryTypes clearDLFileEntryTypes;
9221            protected RemoveDLFileEntryType removeDLFileEntryType;
9222    
9223            protected class ContainsDLFileEntryType {
9224                    protected ContainsDLFileEntryType() {
9225                            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
9226                                            "SELECT COUNT(*) AS COUNT_VALUE FROM DLFileEntryTypes_DLFolders WHERE folderId = ? AND fileEntryTypeId = ?",
9227                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT },
9228                                            RowMapper.COUNT);
9229                    }
9230    
9231                    protected boolean contains(long folderId, long fileEntryTypeId) {
9232                            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
9233                                                    new Long(folderId), new Long(fileEntryTypeId)
9234                                            });
9235    
9236                            if (results.size() > 0) {
9237                                    Integer count = results.get(0);
9238    
9239                                    if (count.intValue() > 0) {
9240                                            return true;
9241                                    }
9242                            }
9243    
9244                            return false;
9245                    }
9246    
9247                    private MappingSqlQuery<Integer> _mappingSqlQuery;
9248            }
9249    
9250            protected class AddDLFileEntryType {
9251                    protected AddDLFileEntryType() {
9252                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
9253                                            "INSERT INTO DLFileEntryTypes_DLFolders (folderId, fileEntryTypeId) VALUES (?, ?)",
9254                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
9255                    }
9256    
9257                    protected void add(long folderId, long fileEntryTypeId)
9258                            throws SystemException {
9259                            if (!containsDLFileEntryType.contains(folderId, fileEntryTypeId)) {
9260                                    ModelListener<com.liferay.portlet.documentlibrary.model.DLFileEntryType>[] dlFileEntryTypeListeners =
9261                                            dlFileEntryTypePersistence.getListeners();
9262    
9263                                    for (ModelListener<DLFolder> listener : listeners) {
9264                                            listener.onBeforeAddAssociation(folderId,
9265                                                    com.liferay.portlet.documentlibrary.model.DLFileEntryType.class.getName(),
9266                                                    fileEntryTypeId);
9267                                    }
9268    
9269                                    for (ModelListener<com.liferay.portlet.documentlibrary.model.DLFileEntryType> listener : dlFileEntryTypeListeners) {
9270                                            listener.onBeforeAddAssociation(fileEntryTypeId,
9271                                                    DLFolder.class.getName(), folderId);
9272                                    }
9273    
9274                                    _sqlUpdate.update(new Object[] {
9275                                                    new Long(folderId), new Long(fileEntryTypeId)
9276                                            });
9277    
9278                                    for (ModelListener<DLFolder> listener : listeners) {
9279                                            listener.onAfterAddAssociation(folderId,
9280                                                    com.liferay.portlet.documentlibrary.model.DLFileEntryType.class.getName(),
9281                                                    fileEntryTypeId);
9282                                    }
9283    
9284                                    for (ModelListener<com.liferay.portlet.documentlibrary.model.DLFileEntryType> listener : dlFileEntryTypeListeners) {
9285                                            listener.onAfterAddAssociation(fileEntryTypeId,
9286                                                    DLFolder.class.getName(), folderId);
9287                                    }
9288                            }
9289                    }
9290    
9291                    private SqlUpdate _sqlUpdate;
9292            }
9293    
9294            protected class ClearDLFileEntryTypes {
9295                    protected ClearDLFileEntryTypes() {
9296                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
9297                                            "DELETE FROM DLFileEntryTypes_DLFolders WHERE folderId = ?",
9298                                            new int[] { java.sql.Types.BIGINT });
9299                    }
9300    
9301                    protected void clear(long folderId) throws SystemException {
9302                            ModelListener<com.liferay.portlet.documentlibrary.model.DLFileEntryType>[] dlFileEntryTypeListeners =
9303                                    dlFileEntryTypePersistence.getListeners();
9304    
9305                            List<com.liferay.portlet.documentlibrary.model.DLFileEntryType> dlFileEntryTypes =
9306                                    null;
9307    
9308                            if ((listeners.length > 0) ||
9309                                            (dlFileEntryTypeListeners.length > 0)) {
9310                                    dlFileEntryTypes = getDLFileEntryTypes(folderId);
9311    
9312                                    for (com.liferay.portlet.documentlibrary.model.DLFileEntryType dlFileEntryType : dlFileEntryTypes) {
9313                                            for (ModelListener<DLFolder> listener : listeners) {
9314                                                    listener.onBeforeRemoveAssociation(folderId,
9315                                                            com.liferay.portlet.documentlibrary.model.DLFileEntryType.class.getName(),
9316                                                            dlFileEntryType.getPrimaryKey());
9317                                            }
9318    
9319                                            for (ModelListener<com.liferay.portlet.documentlibrary.model.DLFileEntryType> listener : dlFileEntryTypeListeners) {
9320                                                    listener.onBeforeRemoveAssociation(dlFileEntryType.getPrimaryKey(),
9321                                                            DLFolder.class.getName(), folderId);
9322                                            }
9323                                    }
9324                            }
9325    
9326                            _sqlUpdate.update(new Object[] { new Long(folderId) });
9327    
9328                            if ((listeners.length > 0) ||
9329                                            (dlFileEntryTypeListeners.length > 0)) {
9330                                    for (com.liferay.portlet.documentlibrary.model.DLFileEntryType dlFileEntryType : dlFileEntryTypes) {
9331                                            for (ModelListener<DLFolder> listener : listeners) {
9332                                                    listener.onAfterRemoveAssociation(folderId,
9333                                                            com.liferay.portlet.documentlibrary.model.DLFileEntryType.class.getName(),
9334                                                            dlFileEntryType.getPrimaryKey());
9335                                            }
9336    
9337                                            for (ModelListener<com.liferay.portlet.documentlibrary.model.DLFileEntryType> listener : dlFileEntryTypeListeners) {
9338                                                    listener.onAfterRemoveAssociation(dlFileEntryType.getPrimaryKey(),
9339                                                            DLFolder.class.getName(), folderId);
9340                                            }
9341                                    }
9342                            }
9343                    }
9344    
9345                    private SqlUpdate _sqlUpdate;
9346            }
9347    
9348            protected class RemoveDLFileEntryType {
9349                    protected RemoveDLFileEntryType() {
9350                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
9351                                            "DELETE FROM DLFileEntryTypes_DLFolders WHERE folderId = ? AND fileEntryTypeId = ?",
9352                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
9353                    }
9354    
9355                    protected void remove(long folderId, long fileEntryTypeId)
9356                            throws SystemException {
9357                            if (containsDLFileEntryType.contains(folderId, fileEntryTypeId)) {
9358                                    ModelListener<com.liferay.portlet.documentlibrary.model.DLFileEntryType>[] dlFileEntryTypeListeners =
9359                                            dlFileEntryTypePersistence.getListeners();
9360    
9361                                    for (ModelListener<DLFolder> listener : listeners) {
9362                                            listener.onBeforeRemoveAssociation(folderId,
9363                                                    com.liferay.portlet.documentlibrary.model.DLFileEntryType.class.getName(),
9364                                                    fileEntryTypeId);
9365                                    }
9366    
9367                                    for (ModelListener<com.liferay.portlet.documentlibrary.model.DLFileEntryType> listener : dlFileEntryTypeListeners) {
9368                                            listener.onBeforeRemoveAssociation(fileEntryTypeId,
9369                                                    DLFolder.class.getName(), folderId);
9370                                    }
9371    
9372                                    _sqlUpdate.update(new Object[] {
9373                                                    new Long(folderId), new Long(fileEntryTypeId)
9374                                            });
9375    
9376                                    for (ModelListener<DLFolder> listener : listeners) {
9377                                            listener.onAfterRemoveAssociation(folderId,
9378                                                    com.liferay.portlet.documentlibrary.model.DLFileEntryType.class.getName(),
9379                                                    fileEntryTypeId);
9380                                    }
9381    
9382                                    for (ModelListener<com.liferay.portlet.documentlibrary.model.DLFileEntryType> listener : dlFileEntryTypeListeners) {
9383                                            listener.onAfterRemoveAssociation(fileEntryTypeId,
9384                                                    DLFolder.class.getName(), folderId);
9385                                    }
9386                            }
9387                    }
9388    
9389                    private SqlUpdate _sqlUpdate;
9390            }
9391    
9392            private static final String _SQL_SELECT_DLFOLDER = "SELECT dlFolder FROM DLFolder dlFolder";
9393            private static final String _SQL_SELECT_DLFOLDER_WHERE = "SELECT dlFolder FROM DLFolder dlFolder WHERE ";
9394            private static final String _SQL_COUNT_DLFOLDER = "SELECT COUNT(dlFolder) FROM DLFolder dlFolder";
9395            private static final String _SQL_COUNT_DLFOLDER_WHERE = "SELECT COUNT(dlFolder) FROM DLFolder dlFolder WHERE ";
9396            private static final String _SQL_GETDLFILEENTRYTYPES = "SELECT {DLFileEntryType.*} FROM DLFileEntryType INNER JOIN DLFileEntryTypes_DLFolders ON (DLFileEntryTypes_DLFolders.fileEntryTypeId = DLFileEntryType.fileEntryTypeId) WHERE (DLFileEntryTypes_DLFolders.folderId = ?)";
9397            private static final String _SQL_GETDLFILEENTRYTYPESSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM DLFileEntryTypes_DLFolders WHERE folderId = ?";
9398            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "dlFolder.folderId";
9399            private static final String _FILTER_SQL_SELECT_DLFOLDER_WHERE = "SELECT DISTINCT {dlFolder.*} FROM DLFolder dlFolder WHERE ";
9400            private static final String _FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_1 =
9401                    "SELECT {DLFolder.*} FROM (SELECT DISTINCT dlFolder.folderId FROM DLFolder dlFolder WHERE ";
9402            private static final String _FILTER_SQL_SELECT_DLFOLDER_NO_INLINE_DISTINCT_WHERE_2 =
9403                    ") TEMP_TABLE INNER JOIN DLFolder ON TEMP_TABLE.folderId = DLFolder.folderId";
9404            private static final String _FILTER_SQL_COUNT_DLFOLDER_WHERE = "SELECT COUNT(DISTINCT dlFolder.folderId) AS COUNT_VALUE FROM DLFolder dlFolder WHERE ";
9405            private static final String _FILTER_ENTITY_ALIAS = "dlFolder";
9406            private static final String _FILTER_ENTITY_TABLE = "DLFolder";
9407            private static final String _ORDER_BY_ENTITY_ALIAS = "dlFolder.";
9408            private static final String _ORDER_BY_ENTITY_TABLE = "DLFolder.";
9409            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No DLFolder exists with the primary key ";
9410            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No DLFolder exists with the key {";
9411            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
9412            private static Log _log = LogFactoryUtil.getLog(DLFolderPersistenceImpl.class);
9413            private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
9414                                    "uuid", "hidden"
9415                            });
9416            private static DLFolder _nullDLFolder = new DLFolderImpl() {
9417                            @Override
9418                            public Object clone() {
9419                                    return this;
9420                            }
9421    
9422                            @Override
9423                            public CacheModel<DLFolder> toCacheModel() {
9424                                    return _nullDLFolderCacheModel;
9425                            }
9426                    };
9427    
9428            private static CacheModel<DLFolder> _nullDLFolderCacheModel = new CacheModel<DLFolder>() {
9429                            public DLFolder toEntityModel() {
9430                                    return _nullDLFolder;
9431                            }
9432                    };
9433    }