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