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