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